/* ============================================================
   AI 对话窗口样式（view-chat）
   · 依赖 --ui-* 视觉变量（enhancements.css v3 主题系统）
   · 全屏三栏式：头部 / 消息流 / 输入区
   ============================================================ */

.chat-main {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
}

.chat-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--ui-surface);
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}

/* ---------- 头部 ---------- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--ui-border);
    background: var(--ui-surface);
    flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-header-icon { font-size: 18px; color: var(--ui-brand); flex-shrink: 0; }
.chat-header-left h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--ui-text); white-space: nowrap; }
.chat-header-sep { color: var(--ui-text-muted); font-size: 13px; }
.chat-header-sub { font-size: 12px; color: var(--ui-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chat-model-select {
    min-width: 160px;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--ui-text);
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
    outline: none;
    cursor: pointer;
}
.chat-model-select:focus { border-color: var(--ui-brand); }

/* 自定义角色卡输入框 */
.chat-role-custom {
    min-width: 180px;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--ui-text);
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
    outline: none;
}
.chat-role-custom:focus { border-color: var(--ui-brand); }
.chat-role-custom[hidden] { display: none; }

/* ---------- 消息流 ---------- */
.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--ui-surface-soft);
    scroll-behavior: smooth;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--ui-text-muted);
    max-width: 480px;
}
.chat-empty-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--ui-brand-soft);
    color: var(--ui-brand);
}
.chat-empty-icon svg { width: 26px; height: 26px; }
.chat-empty p { margin: 0 0 8px; font-size: 14px; color: var(--ui-text-secondary); }
.chat-empty .chat-empty-hint { font-size: 12px; color: var(--ui-text-muted); margin-top: 12px; }

/* 快捷提示词 */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}
.chat-suggest-chip {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--ui-text-secondary);
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: 999px;
    cursor: pointer;
    transition: all .15s;
}
.chat-suggest-chip:hover {
    color: var(--ui-brand);
    border-color: var(--ui-brand);
    background: var(--ui-brand-soft);
}

/* 单条消息 */
.chat-msg { display: flex; gap: 10px; max-width: 88%; }
.chat-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg-assistant { align-self: flex-start; }

/* 角色头像 */
.chat-msg-avatar {
    flex-shrink: 0;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 13px; font-weight: 700;
    margin-top: 2px;
}
.chat-msg-user .chat-msg-avatar { background: var(--ui-brand); color: #fff; }
.chat-msg-assistant .chat-msg-avatar { background: var(--ui-brand-soft); color: var(--ui-brand); }

.chat-msg-body { display: flex; flex-direction: column; min-width: 0; }
.chat-msg-user .chat-msg-body { align-items: flex-end; }
.chat-msg-assistant .chat-msg-body { align-items: flex-start; }

.chat-msg-content {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.7;
    word-break: break-word;
    border-radius: var(--ui-radius-md);
    color: var(--ui-text);
}
.chat-msg-user .chat-msg-content {
    background: var(--ui-brand);
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}
.chat-msg-assistant .chat-msg-content {
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-bottom-left-radius: 4px;
}

/* Markdown 渲染样式（仅 assistant 消息） */
.chat-msg-assistant .chat-msg-content p { margin: 0 0 8px; }
.chat-msg-assistant .chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-assistant .chat-msg-content h1,
.chat-msg-assistant .chat-msg-content h2,
.chat-msg-assistant .chat-msg-content h3 {
    margin: 14px 0 8px; font-weight: 700; line-height: 1.4;
}
.chat-msg-assistant .chat-msg-content h1 { font-size: 17px; }
.chat-msg-assistant .chat-msg-content h2 { font-size: 16px; }
.chat-msg-assistant .chat-msg-content h3 { font-size: 15px; }
.chat-msg-assistant .chat-msg-content ul,
.chat-msg-assistant .chat-msg-content ol { margin: 6px 0 8px; padding-left: 22px; }
.chat-msg-assistant .chat-msg-content li { margin: 3px 0; }
.chat-msg-assistant .chat-msg-content code {
    font-family: 'Consolas','Monaco','Courier New',monospace;
    font-size: 13px;
    padding: 1px 5px;
    background: var(--ui-surface-soft);
    border-radius: 3px;
    color: var(--ui-brand);
}
.chat-msg-assistant .chat-msg-content pre {
    margin: 8px 0;
    padding: 12px 14px;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}
.chat-msg-assistant .chat-msg-content pre code {
    padding: 0; background: none; color: var(--ui-text); border-radius: 0;
}
.chat-msg-assistant .chat-msg-content blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid var(--ui-brand);
    color: var(--ui-text-muted);
}
.chat-msg-assistant .chat-msg-content a {
    color: var(--ui-brand); text-decoration: underline;
}
.chat-msg-assistant .chat-msg-content table {
    border-collapse: collapse; margin: 8px 0; font-size: 13px;
}
.chat-msg-assistant .chat-msg-content th,
.chat-msg-assistant .chat-msg-content td {
    border: 1px solid var(--ui-border); padding: 5px 10px;
}
.chat-msg-assistant .chat-msg-content th { background: var(--ui-surface-soft); font-weight: 600; }
.chat-msg-assistant .chat-msg-content hr { border: none; border-top: 1px solid var(--ui-border); margin: 12px 0; }

/* 消息操作栏（复制等） */
.chat-msg-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity .15s;
}
.chat-msg:hover .chat-msg-actions { opacity: 1; }
.chat-msg-copy-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px;
    font-size: 11px;
    color: var(--ui-text-muted);
    background: transparent;
    border: 1px solid var(--ui-border);
    border-radius: 4px;
    cursor: pointer;
    transition: all .15s;
}
.chat-msg-copy-btn:hover { color: var(--ui-brand); border-color: var(--ui-brand); }
.chat-msg-copy-btn.copied { color: #22c55e; border-color: #22c55e; }

.chat-msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--ui-text-muted);
}

/* 图片附件气泡内预览 */
.chat-msg-content img.chat-inline-image {
    max-width: 240px;
    max-height: 200px;
    display: block;
    border-radius: 8px;
    margin-bottom: 8px;
}
.chat-msg-user .chat-msg-content img.chat-inline-image { border: 1px solid rgba(255,255,255,.3); }

/* 打字指示器 */
.chat-typing { display: inline-flex; gap: 4px; align-items: center; }
.chat-typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--ui-text-muted);
    animation: chat-blink 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-blink { 0%,80%,100% { opacity:.25; transform: translateY(0); } 40% { opacity:1; transform: translateY(-3px); } }

/* ---------- 输入区 ---------- */
.chat-composer {
    padding: 10px 20px 12px;
    border-top: 1px solid var(--ui-border);
    background: var(--ui-surface);
    flex-shrink: 0;
}
.chat-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chat-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 260px;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--ui-text-secondary);
    background: var(--ui-surface-soft);
    border: 1px solid var(--ui-border);
    border-radius: 999px;
}
.chat-attachment-chip .chat-att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-attachment-chip .chat-att-remove {
    cursor: pointer; border: none; background: none; color: var(--ui-text-muted);
    font-size: 15px; line-height: 1; padding: 0 2px;
}
.chat-attachment-chip .chat-att-remove:hover { color: var(--ui-danger); }
.chat-attachment-chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.chat-attach-btn {
    flex: 0 0 auto;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    color: var(--ui-text-muted);
    background: transparent;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
    cursor: pointer;
    transition: all .15s;
}
.chat-attach-btn:hover { color: var(--ui-brand); border-color: var(--ui-brand); background: var(--ui-brand-soft); }
.chat-attach-btn svg { width: 17px; height: 17px; }

.chat-input {
    flex: 1 1 auto;
    resize: none;
    min-height: 38px;
    max-height: 180px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--ui-text);
    background: var(--ui-surface-soft);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
    outline: none;
}
.chat-input:focus { border-color: var(--ui-brand); background: var(--ui-surface); }

.chat-stop-btn {
    flex: 0 0 auto;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; background: var(--ui-danger, #ef4444);
    border: none; border-radius: var(--ui-radius-md);
    cursor: pointer; transition: opacity .15s;
}
.chat-stop-btn:hover { opacity: .85; }
.chat-stop-btn svg { width: 16px; height: 16px; }

.chat-send-btn {
    flex: 0 0 auto;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; background: var(--ui-brand);
    border: none; border-radius: var(--ui-radius-md);
    cursor: pointer; transition: background .15s, opacity .15s;
}
.chat-send-btn:hover { background: var(--ui-brand-hover); }
.chat-send-btn:disabled { opacity: .5; cursor: not-allowed; }
.chat-send-btn svg { width: 17px; height: 17px; }

.chat-composer-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-top: 8px;
}
.chat-composer-actions { display: flex; align-items: center; gap: 4px; }
.chat-tool-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 10px;
    font-size: 12px; color: var(--ui-text-secondary);
    background: transparent; border: 1px solid transparent; border-radius: var(--ui-radius-sm);
    cursor: pointer; transition: background .15s, color .15s;
}
.chat-tool-btn:hover { background: var(--ui-surface-soft); color: var(--ui-text); }
.chat-tool-btn svg { width: 15px; height: 15px; }
.chat-control-icon { display: inline-flex; align-items: center; }
/* 这两个类显式声明了 display，会覆盖 hidden 属性，必须补回隐藏规则 */
.chat-tool-btn[hidden],
.chat-stop-btn[hidden] { display: none; }
.chat-control-btn:hover { background: var(--ui-brand-soft); color: var(--ui-brand); }
.chat-composer-hint { font-size: 11px; color: var(--ui-text-muted); white-space: nowrap; }
.chat-tokens-info { font-size: 11px; color: var(--ui-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    .chat-main { height: calc(100vh - 56px - 16px); }
    .chat-header { padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
    .chat-header-sub { display: none; }
    .chat-model-select { min-width: 0; max-width: 150px; }
    .chat-messages { padding: 14px 12px; }
    .chat-msg { max-width: 94%; }
    .chat-composer { padding: 8px 12px 10px; }
    .chat-composer-hint { display: none; }
    .chat-suggest-chip { font-size: 12px; padding: 6px 12px; }
    .chat-attach-btn { width: 34px; height: 34px; }
    .chat-send-btn, .chat-stop-btn { width: 34px; height: 34px; }
}
