/* ========== CSS变量 & 主题 ========== */
:root, [data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f7f8fa;
    --bg-hover: #eef5f0;
    --bg-input: #ffffff;
    --text-primary: #1a1d21;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;
    --border-color: #e1e4e8;
    --border-light: #f0f1f3;
    --accent: #0d9e4f;
    --accent-dark: #0a7c3e;
    --accent-light: #d4edda;
    --accent-gradient: linear-gradient(135deg, #0d9e4f 0%, #0a7c3e 100%);
    --success: #0d9e4f;
    --warning: #e8a500;
    --error: #d93025;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;
    --msg-user-bg: #0d9e4f;
    --msg-user-text: #ffffff;
    --msg-bot-bg: #f7f8fa;
    --msg-bot-text: #1a1d21;
    --scrollbar-thumb: #c1c6ce;
    --sidebar-bg: #f7f8fa;
    --input-focus: rgba(13,158,79,0.15);
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-surface: #161b22;
    --bg-surface-alt: #1c2128;
    --bg-hover: #1a2f23;
    --bg-input: #1c2128;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --border-light: #21262d;
    --accent: #3fb950;
    --accent-dark: #2ea043;
    --accent-light: #1a4028;
    --accent-gradient: linear-gradient(135deg, #3fb950 0%, #2ea043 100%);
    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    --msg-user-bg: #238636;
    --msg-user-text: #ffffff;
    --msg-bot-bg: #1c2128;
    --msg-bot-text: #e6edf3;
    --scrollbar-thumb: #484f58;
    --sidebar-bg: #0d1117;
    --input-focus: rgba(63,185,80,0.15);
}

/* ========== 全局重置 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    height: 100vh;
    overflow: hidden;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'kern' 1;
    text-rendering: optimizeLegibility;
}

/* ========== 布局容器 ========== */
.container {
    display: flex;
    height: 100vh;
    margin: 0;
    padding: 0;
    gap: 0;
}

.container.sidebar-hidden .chat-area {
    max-width: 100%;
}

/* ========== 通用按钮 ========== */
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background 0.2s, color 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ========== 侧边栏 ========== */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--sidebar-bg);
    border-radius: 0;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    transition: transform 0.3s cubic-bezier(.4,0,.2,1), opacity 0.3s ease;
    z-index: 20;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

/* 品牌标识 */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-logo {
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(13,158,79,0.25));
}
.brand-text {
    display: flex;
    flex-direction: column;
}
.brand-name {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    line-height: 1.2;
}
.brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.3px;
    margin-top: 2px;
}

.sidebar-close {
    opacity: 0.5;
    transition: opacity 0.2s;
}
.sidebar-close:hover { opacity: 1; }

.new-chat-btn {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.new-chat-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}

.menu { flex: 1; overflow-y: auto; }

.menu-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 14px 12px 6px;
    letter-spacing: 0.8px;
}

.menu-item {
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}
.menu-item svg { flex-shrink: 0; opacity: 0.6; }
.menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.menu-item:hover svg { opacity: 1; }
.menu-item.active {
    background: var(--bg-hover);
    color: var(--accent);
    font-weight: 600;
}
.menu-item.active svg { opacity: 1; color: var(--accent); }

.session-item {
    flex-wrap: wrap;
}
.session-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13.5px;
}
.session-time {
    font-size: 11px;
    color: var(--text-muted);
    width: 100%;
    padding-left: 24px;
}

/* 侧边栏统计 — 2x2 网格 */
.sidebar-stats {
    margin-top: auto;
    padding-top: 12px;
}
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.stat-card {
    background: var(--bg-surface-alt);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
    border: 1px solid var(--border-light);
}
.stat-value {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}
.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.3px;
    margin-top: 2px;
}

/* 侧边栏底部 */
.sidebar-footer {
    margin-top: 12px;
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
}
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px;
    font-size: 13.5px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

/* 自定义开关 */
.toggle-switch {
    -webkit-appearance: none;
    appearance: none;
    width: 38px;
    height: 20px;
    background: var(--border-color);
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    outline: none;
    flex-shrink: 0;
}
.toggle-switch::before {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch:checked {
    background: var(--accent);
}
.toggle-switch:checked::before {
    transform: translateX(18px);
}

.sidebar-version {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ========== 聊天主区域 ========== */
.chat-area {
    flex: 1;
    background: var(--bg-surface);
    border-radius: 0;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    overflow: hidden;
    min-width: 0;
    border: none;
}

/* 聊天顶栏 */
.chat-header {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
    flex-shrink: 0;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-title {
    display: flex;
    flex-direction: column;
}
.header-title h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}
.header-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.2px;
}
.menu-toggle { font-size: 22px; }

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}
.search-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}
.search-toggle:hover { border-color: var(--accent); color: var(--accent); }
.search-toggle.active {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}
.search-toggle input[type="checkbox"] {
    display: none;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 20px;
}
.status-dot-icon {
    width: 7px; height: 7px;
    border-radius: 50%;
    display: inline-block;
}
.status-indicator.ok { color: var(--success); background: rgba(16,185,129,0.1); }
.status-indicator.ok .status-dot-icon { background: var(--success); box-shadow: 0 0 6px var(--success); animation: pulse-dot 2s infinite; }
.status-indicator.checking { color: var(--warning); background: rgba(245,158,11,0.1); }
.status-indicator.checking .status-dot-icon { background: var(--warning); }
.status-indicator.error, .status-indicator.degraded { color: var(--error); background: rgba(239,68,68,0.1); }
.status-indicator.error .status-dot-icon, .status-indicator.degraded .status-dot-icon { background: var(--error); }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========== 消息区域 ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}
.chat-messages > .message,
.chat-messages > .welcome {
    max-width: 1060px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 40px;
    padding-right: 40px;
}

/* ========== 欢迎页 ========== */
.welcome {
    text-align: center;
    padding-top: 48px;
    padding-bottom: 32px;
    animation: fadeIn 0.5s ease;
}

.welcome-hero {
    margin-bottom: 32px;
}
.welcome-logo {
    margin-bottom: 16px;
    filter: drop-shadow(0 2px 8px rgba(13,158,79,0.2));
    display: inline-block;
    animation: float 4s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}
.welcome-title {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
    letter-spacing: -0.5px;
    line-height: 1.3;
}
.text-gradient {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.welcome-desc {
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1.7;
    max-width: 540px;
    margin: 0 auto;
}

/* 能力卡片网格 */
.capability-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 28px;
}
.cap-card {
    padding: 20px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    text-align: center;
    transition: all 0.2s cubic-bezier(.4,0,.2,1);
    cursor: default;
}
.cap-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.cap-icon {
    font-size: 30px;
    margin-bottom: 8px;
    line-height: 1;
}
.cap-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.cap-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* 建议问题 */
.suggestions {
    text-align: left;
}
.suggestions-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-align: center;
}
.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.suggestion-card {
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(.4,0,.2,1);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}
.suggestion-icon {
    font-size: 16px;
    flex-shrink: 0;
}
.suggestion-text {
    flex: 1;
}
.suggestion-arrow {
    flex-shrink: 0;
    opacity: 0;
    transition: all 0.2s;
    color: var(--accent);
}
.suggestion-card:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}
.suggestion-card:hover .suggestion-arrow {
    opacity: 1;
    transform: translateX(3px);
}

/* 消息 */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    animation: msgIn 0.35s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.message.user {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.msg-sender {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 5px;
    letter-spacing: 0.2px;
}
.message.user .msg-sender { text-align: right; }
.message.assistant .msg-sender { color: var(--accent); }

.msg-body {
    max-width: 82%;
    min-width: 60px;
}
.message.assistant .msg-body {
    max-width: 100%;
}
.msg-text {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    line-height: 1.8;
    word-wrap: break-word;
    font-size: 15.5px;
}
.message.user .msg-text {
    background: var(--msg-user-bg);
    color: var(--msg-user-text);
    border-bottom-right-radius: 4px;
}
.user-text {
    white-space: pre-wrap;
}
.assistant-text {
    background: transparent;
    color: var(--msg-bot-text);
    padding: 4px 0;
    border: none;
}
.message.error-msg .msg-text {
    background: rgba(217,48,37,0.06);
    border: 1px solid rgba(217,48,37,0.15);
    color: var(--error);
    border-radius: var(--radius-md);
    padding: 12px 16px;
}

.msg-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    padding: 0 4px;
}
.message.user .msg-time { text-align: right; }

/* Markdown渲染样式 */
.msg-text h1, .msg-text h2, .msg-text h3, .msg-text h4 {
    margin: 12px 0 6px;
    font-weight: 700;
    color: var(--text-primary);
}
.msg-text h1 { font-size: 1.4em; }
.msg-text h2 { font-size: 1.25em; }
.msg-text h3 { font-size: 1.1em; }
.msg-text p { margin: 8px 0; }
.msg-text ul, .msg-text ol { padding-left: 22px; margin: 8px 0; }
.msg-text li { margin: 4px 0; line-height: 1.8; }
.msg-text code {
    background: rgba(0,0,0,0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'Fira Code', 'Consolas', monospace;
}
[data-theme="dark"] .msg-text code {
    background: rgba(255,255,255,0.1);
}
.msg-text pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 18px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 12px 0;
    font-size: 14px;
    line-height: 1.6;
    border: 1px solid var(--border-color);
}
[data-theme="dark"] .msg-text pre {
    background: #0f172a;
    border-color: #334155;
}
.msg-text pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}
/* highlight.js dark mode override */
[data-theme="dark"] .hljs {
    background: #0f172a !important;
    color: #e2e8f0 !important;
}
.msg-text blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 14px;
    margin: 8px 0;
    background: var(--bg-surface-alt);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}
.msg-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 14px;
}
.msg-text th, .msg-text td {
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    text-align: left;
}
.msg-text th {
    background: var(--bg-surface-alt);
    font-weight: 600;
}
.msg-text a {
    color: var(--accent);
    text-decoration: none;
}
.msg-text a:hover { text-decoration: underline; }

/* 流式输出指示器 */
.streaming-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 12px;
    color: var(--text-muted);
}
.typing-animation {
    display: flex;
    gap: 4px;
    align-items: center;
}
.typing-animation span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-animation span:nth-child(1) { animation-delay: 0s; }
.typing-animation span:nth-child(2) { animation-delay: 0.2s; }
.typing-animation span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}
.streaming-text {
    font-weight: 500;
    color: var(--accent);
}

/* 消息工具栏 */
.msg-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.message:hover .msg-toolbar { opacity: 1; }
.tool-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.tool-btn svg { flex-shrink: 0; }
.tool-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}
.tool-btn.feedback-active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.msg-badges {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

/* 徽标 */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
}
.cache-badge { background: rgba(245,158,11,0.1); color: var(--warning); }
.time-badge { background: var(--bg-surface-alt); color: var(--text-muted); }
.search-badge { background: rgba(16,185,129,0.1); color: var(--success); }
.img-badge { background: rgba(139,92,246,0.1); color: #8b5cf6; }
.tool-badge { background: rgba(59,130,246,0.1); color: #3b82f6; }

/* 参考来源 */
.sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}
.sources-header {
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
    user-select: none;
}
.sources-header:hover { background: var(--bg-hover); }
.sources-header .arrow { font-size: 11px; }

.sources-list { margin-top: 8px; }
.source-item {
    padding: 12px 14px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 14px;
    border-left: 3px solid var(--accent);
    box-shadow: var(--shadow-sm);
}
.source-item.web { border-left-color: var(--success); }
.source-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--text-secondary);
}
.source-score {
    font-weight: 400;
    color: var(--accent);
    font-size: 11px;
}
.source-content {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
    margin: 4px 0;
}
.source-item small {
    color: var(--text-muted);
    font-size: 11px;
}
.source-item a {
    color: var(--accent);
    text-decoration: none;
}
.source-item a:hover { text-decoration: underline; }

/* 加载动画 */
.loading-dots {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
}
.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: loadBounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }
@keyframes loadBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ========== 输入区域 ========== */
.input-area {
    padding: 16px 0 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}
.input-area > * {
    max-width: 1060px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 40px;
    padding-right: 40px;
}
.image-preview-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding-top: 10px;
    padding-bottom: 10px;
    background: var(--bg-surface-alt);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.preview-thumb {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 2px solid var(--accent);
}
.preview-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}
.remove-img { font-size: 14px; }

/* 工具选择器 */
.tool-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
    padding-bottom: 6px;
}
.tool-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 14px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.tool-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-hover);
}
.tool-chip.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}
.tool-chip-icon {
    font-size: 14px;
    line-height: 1;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.input-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}
.attach-btn {
    cursor: pointer;
    flex-shrink: 0;
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all 0.2s;
}
.attach-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
}

.input-row textarea {
    flex: 1;
    padding: 14px 18px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 15px;
    resize: none;
    font-family: inherit;
    min-height: 52px;
    max-height: 180px;
    background: var(--bg-surface-alt);
    color: var(--text-primary);
    line-height: 1.5;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.input-row textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--input-focus);
    background: var(--bg-input);
}
.input-row textarea::placeholder {
    color: var(--text-muted);
    font-size: 14px;
}

.input-footer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    letter-spacing: 0.2px;
}

.send-btn {
    width: 48px;
    height: 48px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.send-btn:hover:not(:disabled) {
    background: var(--accent-dark);
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(13,158,79,0.3);
}
.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.send-btn.sending {
    background: var(--text-muted);
}

/* SVG spin animation for loading */
.spin {
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== 弹窗 ========== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}
.modal-box {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 520px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.modal-wide {
    max-width: 700px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}
.modal-body {
    padding: 24px;
    overflow-y: auto;
}

/* 表单元素 */
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.form-select {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14.5px;
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
    appearance: auto;
}
.form-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* 上传区域 */
.upload-hint {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 16px;
}
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 36px 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    position: relative;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}
.upload-zone:hover {
    border-color: var(--accent);
    background: var(--bg-surface-alt);
}
.upload-zone.uploading {
    border-color: var(--accent);
    background: var(--bg-surface-alt);
    cursor: wait;
}
.upload-zone.drag-active {
    border-color: var(--accent);
    background: var(--bg-hover);
    transform: scale(1.01);
    border-style: solid;
}
.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.upload-placeholder svg {
    color: var(--text-muted);
}
.upload-placeholder p {
    margin: 0;
}
.upload-formats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}
.format-tag {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-light);
    border-radius: 4px;
}
.upload-icon {
    font-size: 36px;
    margin-bottom: 8px;
}
.file-input {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
}
.upload-result {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}
.upload-result.success {
    background: rgba(16,185,129,0.1);
    color: var(--success);
    border: 1px solid rgba(16,185,129,0.2);
}
.upload-result.error {
    background: rgba(239,68,68,0.08);
    color: var(--error);
    border: 1px solid rgba(239,68,68,0.2);
}

/* Spinner */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 10px;
}
.upload-progress {
    color: var(--text-secondary);
    font-size: 15px;
}

/* 知识库管理 */
.doc-loading, .doc-empty {
    text-align: center;
    padding: 30px 0;
    color: var(--text-secondary);
}
.doc-empty p {
    font-size: 16px;
    margin-bottom: 16px;
}
.action-btn {
    padding: 10px 24px;
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}
.action-btn:hover {
    transform: translateY(-1px);
}
.doc-summary {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}
.doc-table {
    font-size: 13px;
}
.doc-row {
    display: flex;
    align-items: center;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-light);
    gap: 8px;
}
.doc-row:last-child {
    border-bottom: none;
}
.doc-header-row {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 12px;
    background: var(--bg-surface-alt);
    border-radius: var(--radius-sm);
}
.doc-col-name {
    flex: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}
.doc-col-cat { flex: 1; }
.doc-col-chunks {
    width: 60px;
    text-align: center;
    flex-shrink: 0;
}
.doc-col-action {
    width: 90px;
    text-align: right;
    flex-shrink: 0;
}
.cat-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-surface-alt);
    border-radius: 10px;
    font-size: 11px;
    color: var(--text-secondary);
}
.del-btn {
    padding: 4px 10px;
    border: 1px solid var(--error);
    background: transparent;
    color: var(--error);
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.del-btn:hover:not(:disabled) {
    background: var(--error);
    color: #fff;
}
.del-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-primary);
    color: var(--bg-surface);
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 2000;
    box-shadow: var(--shadow-md);
}
.toast-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========== 滚动条 ========== */
.chat-messages::-webkit-scrollbar,
.menu::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 5px;
}
.chat-messages::-webkit-scrollbar-track,
.menu::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb,
.menu::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
}
.chat-messages::-webkit-scrollbar-thumb:hover,
.menu::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ========== 响应式适配 ========== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 280px;
        z-index: 100;
        box-shadow: 4px 0 20px rgba(0,0,0,0.2);
    }
    .chat-messages > .message,
    .chat-messages > .welcome {
        padding-left: 16px;
        padding-right: 16px;
    }
    .input-area > * {
        padding-left: 16px;
        padding-right: 16px;
    }
    .capability-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .suggestion-cards {
        grid-template-columns: 1fr;
    }
    .msg-body {
        max-width: 88%;
    }
    .welcome { padding-top: 24px; padding-bottom: 16px; }
    .welcome-title { font-size: 28px; }
    .welcome-desc { font-size: 15px; }
    .modal-box { width: 95%; }
    .modal-wide { max-width: 95%; }
    .header-subtitle { display: none; }
    .status-text { display: none; }
}

@media (max-width: 480px) {
    .header-title h3 { font-size: 16px; }
    .chat-header { padding: 10px 12px; }
    .chat-messages { padding: 16px 0; }
    .chat-messages > .message,
    .chat-messages > .welcome {
        padding-left: 12px;
        padding-right: 12px;
    }
    .input-area > * {
        padding-left: 12px;
        padding-right: 12px;
    }
    .msg-text { padding: 12px 14px; font-size: 14.5px; }
    .msg-body { max-width: 92%; }
    .doc-col-cat { display: none; }
    .capability-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .cap-card { padding: 12px 8px; }
    .cap-icon { font-size: 22px; }
    .cap-title { font-size: 12px; }
    .cap-desc { font-size: 10px; }
    .search-toggle span { display: none; }
}
