/* ==========================================
   AI Gateway Portal - 用户端样式
   暗色/亮色双主题 + 聊天布局 + 移动端适配
   ========================================== */

/* ---- CSS Variables ---- */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-chat: #1a1a2e;
    --bg-sidebar: #121424;
    --bg-input: #1e1e3a;
    --bg-bubble-user: #0f3460;
    --bg-bubble-ai: #16213e;
    --bg-bubble-summary: #1a2744;
    --bg-hover: rgba(255,255,255,0.04);
    --bg-active: rgba(255,255,255,0.08);
    --border-color: rgba(255,255,255,0.08);
    --border-strong: rgba(255,255,255,0.14);
    --text-primary: #e4e6eb;
    --text-secondary: #a0a4b0;
    --text-tertiary: #6c7080;
    --text-bubble-user: #e4e6eb;
    --text-bubble-ai: #d0d4e0;
    --accent: #4f8cff;
    --accent-hover: #6ba0ff;
    --accent-dim: rgba(79,140,255,0.15);
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #22c55e;
    --warning: #f59e0b;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 亮色主题 */
[data-theme="light"] {
    --bg-primary: #f8f9fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8ecf1;
    --bg-chat: #f8f9fb;
    --bg-sidebar: #f0f2f5;
    --bg-input: #ffffff;
    --bg-bubble-user: #e3f0ff;
    --bg-bubble-ai: #ffffff;
    --bg-bubble-summary: #f0f4ff;
    --bg-hover: rgba(0,0,0,0.04);
    --bg-active: rgba(0,0,0,0.08);
    --border-color: rgba(0,0,0,0.08);
    --border-strong: rgba(0,0,0,0.14);
    --text-primary: #1a1d26;
    --text-secondary: #5a5f6e;
    --text-tertiary: #8a8fa0;
    --text-bubble-user: #1a1d26;
    --text-bubble-ai: #1f2937;
    --accent: #2563eb;
    --accent-hover: #3b82f6;
    --accent-dim: rgba(37,99,235,0.1);
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%;
    height: 100dvh; /* 动态视口高度，避免地址栏跳动 */
    overflow: hidden;
    /* 禁止 iOS 文字缩放 */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    /* 禁止页面弹性滚动（iOS橡皮筋效果干扰布局） */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}
body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* 消除点击高亮 */
    -webkit-tap-highlight-color: transparent;
    /* 消除 300ms 点击延迟 */
    touch-action: manipulation;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, textarea, select {
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ---- Login Page ---- */
.login-container {
    display: flex; align-items: center; justify-content: center;
    height: 100vh; height: 100dvh;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    background: linear-gradient(135deg, #e8ecf1 0%, #f0f4f8 30%, #f8f9fb 70%, #e3eaf3 100%);
}
.login-card {
    width: 100%; max-width: 420px;
    background: #ffffff;
    border: 1px solid #e2e6ec;
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
}
.login-card .logo {
    text-align: center; margin-bottom: 32px;
    font-size: 28px; font-weight: 700;
    color: #2563eb; letter-spacing: -0.5px;
}
.login-card .logo span { color: #1a1d26; }
.login-card h2 {
    text-align: center; font-size: 18px; font-weight: 500;
    color: #5a5f6e; margin-bottom: 28px;
}
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 500;
    color: #5a5f6e; margin-bottom: 6px;
}
.form-group input {
    width: 100%; padding: 10px 14px;
    border: 1px solid #d0d5dd;
    border-radius: var(--radius);
    background: #f9fafb;
    color: #1a1d26;
    font-size: 16px; /* ≥16px 防止 iOS 自动缩放 */
    transition: var(--transition);
}
.form-group input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
    outline: none;
    background: #fff;
}
.login-error {
    color: var(--danger); font-size: 13px;
    text-align: center; min-height: 20px; margin-bottom: 12px;
}
.btn-login {
    width: 100%; padding: 11px; font-size: 15px; font-weight: 600;
    background: #2563eb; color: #fff;
    border-radius: var(--radius); transition: var(--transition);
}
.btn-login:hover { background: #3b82f6; }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Main Layout ---- */
.app-layout {
    display: flex;
    height: 100vh; height: 100dvh;
    opacity: 0; transition: opacity 0.3s;
}
.app-layout.ready { opacity: 1; }

/* ---- Sidebar ---- */
.sidebar {
    width: 280px; min-width: 280px;
    height: 100vh; height: 100dvh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column;
    transition: width 0.25s ease, min-width 0.25s ease;
    position: relative; z-index: 10; overflow: hidden;
}
.sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; border: none; }

/* Sidebar Header */
.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    transition: opacity 0.15s;
}
.sidebar-logo-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
}
.sidebar-logo {
    font-size: 20px; font-weight: 700;
    color: var(--accent); letter-spacing: -0.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-logo span { color: var(--text-primary); }

/* 侧边栏折叠按钮 — 朝左（展开态）= 点击折叠 */
.btn-sidebar-collapse {
    flex-shrink: 0;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none;
    color: var(--text-tertiary);
    font-size: 14px; border-radius: 6px;
    cursor: pointer; transition: var(--transition);
}
.btn-sidebar-collapse:hover {
    background: var(--bg-hover); color: var(--text-primary);
}

/* 桌面端：侧边栏折叠 → 收窄 */
@media (min-width: 769px) {
    .sidebar-collapsed {
        width: 56px !important; min-width: 56px !important; overflow: visible !important;
    }
    .sidebar-collapsed .sidebar-logo,
    .sidebar-collapsed .sidebar-search,
    .sidebar-collapsed .btn-new-chat,
    .sidebar-collapsed .sidebar-history,
    .sidebar-collapsed .sidebar-footer { display: none; }
    .sidebar-collapsed .sidebar-header {
        border-bottom: none; padding: 12px 0 4px;
    }
    .sidebar-collapsed .sidebar-logo-row { justify-content: center; margin-bottom: 0; }
    /* 折叠按钮：折叠态朝右（点击展开） */
    .sidebar-collapsed .btn-sidebar-collapse svg { transform: rotate(180deg); }
    /* 折叠后图标列显示 */
    .sidebar-collapsed .sidebar-collapsed-icons { display: flex; }
}

/* 折叠后的迷你图标列 */
.sidebar-collapsed-icons {
    display: none;
    flex-direction: column; align-items: center; gap: 12px;
    padding: 8px 0; margin-top: 4px;
}
.collapsed-icon-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    background: none; color: var(--text-tertiary);
    transition: var(--transition);
}
.collapsed-icon-btn:hover {
    background: var(--bg-hover); color: var(--text-primary);
}

.sidebar-search {
    position: relative;
    margin-bottom: 10px;
}
.sidebar-search input {
    width: 100%; padding: 8px 12px 8px 32px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px; text-align: center;
    transition: var(--transition);
}
.sidebar-search input:focus {
    border-color: var(--accent); outline: none;
}
.sidebar-search .search-icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text-tertiary); pointer-events: none;
    display: flex; align-items: center;
}
.btn-new-chat {
    display: block; width: 100%; margin-top: 10px;
    padding: 8px 12px; font-size: 13px;
    background: var(--accent-dim); color: var(--accent);
    border-radius: var(--radius); text-align: center;
    transition: var(--transition);
}
.btn-new-chat:hover { background: var(--accent); color: #fff; }

/* Sidebar History */
.sidebar-history {
    padding: 8px 10px; flex: 1; overflow-y: auto;
}
.history-group { margin-bottom: 8px; }
.history-group-label {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    color: var(--text-tertiary); padding: 6px 8px 4px;
    letter-spacing: 0.5px;
}
.history-item {
    display: flex; align-items: center;
    padding: 8px 10px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-size: 13px;
    cursor: pointer; transition: var(--transition);
    position: relative; gap: 8px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item:hover { background: var(--bg-hover); }
.history-item.active { background: var(--bg-active); color: var(--text-primary); }
.history-item .item-icon { flex-shrink: 0; opacity: 0.4; display: flex; align-items: center; }
.history-item .item-text { overflow: hidden; text-overflow: ellipsis; }
.history-item .item-menu {
    margin-left: auto; opacity: 0;
    background: none; color: var(--text-tertiary);
    font-size: 14px; padding: 2px 4px; border-radius: 4px;
    transition: var(--transition);
}
.history-item:hover .item-menu { opacity: 1; }
.history-item .item-menu:hover { background: var(--bg-active); color: var(--text-primary); }
.history-empty {
    text-align: center; padding: 32px 16px;
    color: var(--text-tertiary); font-size: 13px;
}

/* Sidebar Footer */
.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding: 8px 10px;
}
.fold-panel { margin-bottom: 2px; }
.fold-toggle {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
    background: none; color: var(--text-secondary);
    font-size: 13px; transition: var(--transition);
}
.fold-toggle:hover { background: var(--bg-hover); }
.fold-toggle .fold-arrow {
    color: var(--text-tertiary);
    transition: transform 0.2s; width: 14px; height: 14px;
    display: flex; align-items: center; justify-content: center;
}
.fold-toggle .fold-arrow svg { transition: transform 0.2s; }
.fold-panel.open .fold-arrow svg { transform: rotate(90deg); }
.fold-toggle .fold-icon { flex-shrink: 0; opacity: 0.7; }
.fold-menu { display: none; }
.fold-panel.open .fold-menu { display: block; }
.fold-menu-item {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 7px 10px 7px 30px;
    border-radius: var(--radius-sm);
    background: none; color: var(--text-secondary);
    font-size: 13px; transition: var(--transition);
    text-align: left;
}
.fold-menu-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.fold-menu-item .menu-icon { width: 18px; height: 14px; text-align: center; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }

/* Sidebar Footer - 站点信息 */
.site-footer-info {
    margin-top: 8px; padding: 6px 10px;
    font-size: 11px; color: var(--text-tertiary);
    text-align: center; line-height: 1.5;
}
.site-footer-info a { color: var(--text-tertiary); text-decoration: none; }
.site-footer-info a:hover { color: var(--primary); }

/* ---- Main Content ---- */
.main-content {
    flex: 1; display: flex; flex-direction: column;
    height: 100vh; height: 100dvh; min-width: 0; position: relative;
}

/* ---- Top Toolbar (Mobile) ---- */
.top-toolbar {
    display: none;
    align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    min-height: 48px;
}
.toolbar-left, .toolbar-right {
    display: flex; align-items: center; gap: 4px;
    flex-shrink: 0;
}
.toolbar-logo {
    font-size: 15px; font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    flex: 1; text-align: center; min-width: 0;
}
.btn-sidebar-toggle {
    background: none; color: var(--text-secondary);
    padding: 4px; border-radius: 6px;
    display: flex; align-items: center;
    transition: var(--transition);
}
.btn-sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

/* 移动端工具栏图标按钮 */
.toolbar-icon-btn {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    background: none; color: var(--text-tertiary);
    transition: var(--transition);
}
.toolbar-icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* 移动端新建对话按钮 */
.btn-toolbar-new-chat {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--accent-dim); color: var(--accent);
    transition: var(--transition);
}
.btn-toolbar-new-chat:hover { background: var(--accent); color: #fff; }

/* Sidebar Overlay (Mobile) */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 8;
    background: rgba(0,0,0,0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.sidebar-overlay.visible {
    display: block; opacity: 1; pointer-events: all;
}

/* AI Disclaimer Banner */
.disclaimer-banner {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 8px 16px; background: var(--accent-dim);
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 12px; color: var(--text-secondary);
    text-align: center; transition: all 0.3s;
}
.disclaimer-banner.hidden { display: none; }
.disclaimer-banner .disclaimer-icon { flex-shrink: 0; display: flex; align-items: center; }
.disclaimer-banner button {
    margin-left: 8px; background: none; color: var(--text-tertiary);
    font-size: 16px; padding: 0 4px; line-height: 1; border-radius: 4px;
    transition: var(--transition);
}
.disclaimer-banner button:hover { color: var(--text-primary); }

/* ---- 助手名称状态栏（桌面端） ---- */
.assistant-name-bar {
    padding: 6px 24px;
    font-size: 13px; font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    text-align: center;
    display: none;  /* 默认隐藏，有内容时显示 */
}
.assistant-name-bar:not(:empty) { display: block; }

/* Chat Area */
.chat-area {
    flex: 1; overflow-y: auto; padding: 20px 0;
    position: relative;
    transition: justify-content 0.4s;
}
.chat-area.input-centered {
    display: flex; flex-direction: column;
    justify-content: center;
}

/* 对话区域移到顶部时 */
.chat-area.input-top {
    display: block;
}

.chat-messages {
    max-width: 800px; margin: 0 auto; padding: 0 24px;
    width: 100%;
}

/* 右侧对话导航定位点 */
.chat-nav-dots {
    position: fixed; right: 24px; top: 50%; transform: translateY(-50%);
    z-index: 50; display: flex; flex-direction: column; align-items: center;
    gap: 6px; padding: 8px 4px;
    border-radius: 20px;
    background: rgba(0,0,0,0.15);
    backdrop-filter: blur(8px);
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s;
}
[data-theme="light"] .chat-nav-dots {
    background: rgba(0,0,0,0.06);
}
.chat-nav-dots.visible {
    opacity: 1; pointer-events: all;
}
.chat-nav-dot {
    position: relative;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--border-strong);
    cursor: pointer; border: none; padding: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}
.chat-nav-dot:hover,
.chat-nav-dot.active {
    background: var(--accent);
    transform: scale(1.3);
}
.chat-nav-dot::after {
    content: attr(data-tooltip);
    position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
    white-space: nowrap; max-width: 220px;
    overflow: hidden; text-overflow: ellipsis;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px; font-size: 12px;
    box-shadow: var(--shadow);
    opacity: 0; pointer-events: none;
    transition: opacity 0.15s;
}
.chat-nav-dot:hover::after { opacity: 1; }

/* Message Bubbles */
.message-wrapper {
    display: flex; flex-direction: column;
    margin-bottom: 24px;
}
.message-wrapper.user { align-items: flex-end; }
.message-wrapper.ai { align-items: flex-start; }

.role-label {
    font-size: 12px; font-weight: 600;
    color: var(--accent); padding: 0 4px 4px 4px;
    display: flex; align-items: center; gap: 6px;
}
.role-label::before {
    content: ''; display: inline-block;
    width: 8px; height: 8px; border-radius: 2px;
    background: var(--accent); flex-shrink: 0;
    opacity: 0.6;
}
.message-wrapper.summary .role-label { color: var(--success); }
.message-wrapper.summary .role-label::before { background: var(--success); }

.chat-bubble {
    max-width: 85%; padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px; line-height: 1.7;
    white-space: pre-wrap; word-break: break-word;
    position: relative;
    transition: max-height 0.3s, opacity 0.3s;
    overflow: hidden;
}
.chat-bubble.collapsed {
    max-height: 48px; opacity: 0.6;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    cursor: pointer;
}
.chat-bubble.user {
    background: var(--bg-bubble-user);
    color: var(--text-bubble-user);
    border-bottom-right-radius: 4px;
}
.chat-bubble.ai {
    background: var(--bg-bubble-ai);
    color: var(--text-bubble-ai);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent);
    border-bottom-left-radius: 4px;
}
.chat-bubble.summary {
    background: var(--bg-bubble-summary);
    border: 1px solid rgba(34,197,94,0.2);
    border-bottom-left-radius: 4px;
}
.chat-bubble .cursor-blink {
    display: inline; color: var(--accent);
    animation: blink 0.8s infinite; font-weight: 700;
}
@keyframes blink { 0%,50% { opacity: 1; } 51%,100% { opacity: 0; } }

/* Markdown 渲染样式 */
.chat-bubble.ai h1, .chat-bubble.ai h2, .chat-bubble.ai h3, .chat-bubble.ai h4,
.chat-bubble.summary h1, .chat-bubble.summary h2, .chat-bubble.summary h3, .chat-bubble.summary h4 {
    margin: 16px 0 8px; font-weight: 600; line-height: 1.4;
}
.chat-bubble.ai h3, .chat-bubble.summary h3 { font-size: 15px; color: var(--text-primary); }
.chat-bubble.ai h4, .chat-bubble.summary h4 { font-size: 14px; color: var(--text-primary); }
.chat-bubble.ai strong,
.chat-bubble.summary strong { font-weight: 600; color: var(--text-primary); }
.chat-bubble.ai em,
.chat-bubble.summary em { font-style: italic; }
.chat-bubble.ai ul, .chat-bubble.ai ol,
.chat-bubble.summary ul, .chat-bubble.summary ol {
    margin: 8px 0; padding-left: 20px;
}
.chat-bubble.ai li,
.chat-bubble.summary li { margin-bottom: 4px; }
.chat-bubble.ai p,
.chat-bubble.summary p { margin: 8px 0; }
.chat-bubble.ai p:first-child,
.chat-bubble.summary p:first-child { margin-top: 0; }
.chat-bubble.ai p:last-child,
.chat-bubble.summary p:last-child { margin-bottom: 0; }
.chat-bubble.ai code,
.chat-bubble.summary code {
    background: rgba(0,0,0,0.06); padding: 2px 6px; border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace; font-size: 13px;
}
.chat-bubble.ai pre,
.chat-bubble.summary pre {
    background: #1e1e2e; color: #cdd6f4; padding: 12px 16px;
    border-radius: 6px; overflow-x: auto; margin: 8px 0;
    font-size: 13px; line-height: 1.5;
}
.chat-bubble.ai pre code,
.chat-bubble.summary pre code { background: none; padding: 0; }
.chat-bubble.ai blockquote,
.chat-bubble.summary blockquote {
    border-left: 3px solid var(--accent); margin: 8px 0;
    padding: 4px 12px; color: var(--text-secondary); background: rgba(0,0,0,0.02);
    border-radius: 0 4px 4px 0;
}
.chat-bubble.ai hr,
.chat-bubble.summary hr {
    border: none; border-top: 1px solid var(--border-color); margin: 16px 0;
}
.chat-bubble.ai a,
.chat-bubble.summary a {
    color: var(--accent); text-decoration: underline;
}
.chat-bubble.ai table,
.chat-bubble.summary table {
    border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px;
}
.chat-bubble.ai th, .chat-bubble.ai td,
.chat-bubble.summary th, .chat-bubble.summary td {
    border: 1px solid var(--border-color); padding: 6px 10px; text-align: left;
}
.chat-bubble.ai th,
.chat-bubble.summary th { background: rgba(0,0,0,0.03); font-weight: 600; }
/* 总结气泡默认不用 white-space:pre-wrap，由 markdown 的 p 标签接管换行 */
.chat-bubble.ai.markdown, .chat-bubble.summary.markdown { white-space: normal; }

/* Bubble Actions */
.bubble-actions {
    display: flex; align-items: center; gap: 6px;
    margin-top: 6px; opacity: 0;
    transition: opacity 0.2s;
}
.message-wrapper:hover .bubble-actions,
.message-wrapper:last-child .bubble-actions { opacity: 1; }
.bubble-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px;
    border-radius: 6px; border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-tertiary);
    font-size: 12px; cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.bubble-btn:hover {
    background: var(--bg-active);
    color: var(--text-primary);
    border-color: var(--border-strong);
}
.bubble-btn svg { flex-shrink: 0; }
.bubble-btn.active { border-color: var(--accent); color: var(--accent); }
.bubble-btn.bubble-btn-like.active { border-color: var(--success); color: var(--success); }
.bubble-btn.bubble-btn-dislike.active { border-color: var(--danger); color: var(--danger); }
.bubble-btn-collapse {
    margin-left: auto;
    border: none; background: none;
    padding: 4px 6px; color: var(--text-tertiary);
}
.bubble-btn-collapse:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.bubble-time {
    font-size: 11px; color: var(--text-tertiary);
    padding: 2px 4px; margin-top: 2px;
}

/* Phase Separator */
.phase-separator {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 0; margin: 8px 0;
    color: var(--text-tertiary); font-size: 12px;
}
.phase-separator::before, .phase-separator::after {
    content: ''; flex: 1; height: 1px;
    background: var(--border-color);
}
.phase-separator .dot {
    display: inline-block; width: 6px; height: 6px;
    border-radius: 50%; margin-right: 4px;
}
.phase-separator .dot.green { background: var(--success); }
.phase-separator .dot.yellow { background: var(--warning); }

/* Progress Overlay */
.progress-overlay {
    position: sticky; top: 0; z-index: 5;
    max-width: 800px; margin: 0 auto;
    padding: 10px 24px;
    background: linear-gradient(180deg, var(--bg-chat) 60%, transparent);
    transition: all 0.3s;
}
.progress-overlay.hidden { display: none; }
.progress-card {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 13px; color: var(--text-secondary);
}
.progress-card .pulse-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--accent); flex-shrink: 0;
    animation: pulse 1.2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}
.progress-card .step-list { flex: 1; }
.progress-card .step-item {
    padding: 2px 0; font-size: 12px;
    display: flex; align-items: center; gap: 6px;
}
.step-item .step-icon { font-size: 13px; width: 16px; text-align: center; }
.step-item.done { color: var(--success); }
.step-item.active { color: var(--text-primary); }
.step-item.pending { color: var(--text-tertiary); }

/* ---- Input Area ---- */
.input-area {
    padding: 12px 24px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-chat);
    transition: position 0.4s, bottom 0.4s;
}
.input-area.input-centered {
    position: absolute; bottom: 50%; transform: translateY(50%);
    border-top: none; padding-bottom: 0;
    width: 100%;
}
.input-area.input-normal {
    position: relative; bottom: auto; transform: none;
}

.input-container {
    max-width: 860px; margin: 0 auto;
}

/* 输入区上方名称 + 副标题 */
.input-header {
    text-align: center; margin-bottom: 12px;
}
.input-site-title {
    font-size: 22px; font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}
.input-site-subtitle {
    font-size: 13px; color: var(--text-tertiary);
    margin-top: 2px;
}

/* 输入框包裹 */
.input-box {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-input);
    transition: var(--transition);
    overflow: hidden;
}
.input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
.input-box textarea {
    display: block; width: 100%;
    padding: 14px 16px 50px; /* 底部留空给操作栏 */
    border: none; background: transparent;
    color: var(--text-primary);
    font-size: 14px; resize: none;
    min-height: 120px; max-height: 200px;
    line-height: 1.6;
    outline: none;
}
.input-box textarea:disabled { opacity: 0.5; cursor: not-allowed; }
.input-box textarea::placeholder { color: var(--text-tertiary); }

/* 输入框底部操作栏 */
.input-actions {
    position: absolute; bottom: 0; left: 0; right: 0;
    display: flex; align-items: center;
    padding: 6px 10px;
    pointer-events: none;
}
.input-actions > * { pointer-events: all; }
.input-mode { flex: 1; }
.input-mode .mode-switch-bar { display: flex; }
.input-mode .mode-switch-group {
    display: inline-flex; gap: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 6px; overflow: hidden;
}
.input-mode .mode-btn {
    padding: 3px 12px; font-size: 12px;
    background: none; color: var(--text-secondary);
    transition: var(--transition); cursor: pointer;
    border: none; font-weight: 500; white-space: nowrap;
}
.input-mode .mode-btn:hover { background: var(--bg-active); }
.input-mode .mode-btn.active {
    background: var(--accent); color: #fff;
}
.input-mode .mode-btn:first-child { border-right: 1px solid var(--border-color); }
.input-mode .mode-btn.active:first-child { border-right-color: transparent; }
.btn-send, .btn-stop {
    width: 34px; height: 34px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition); flex-shrink: 0;
    margin-left: 6px;
}
.btn-send {
    background: var(--accent); color: #fff;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-stop {
    background: var(--danger); color: #fff;
    animation: pulse-bg 1.5s infinite;
}
@keyframes pulse-bg {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.btn-stop:hover { background: var(--danger-hover); }
.input-status {
    text-align: center; font-size: 11px; color: var(--text-tertiary);
    margin-top: 6px; min-height: 16px;
}
.input-status.error { color: var(--danger); }

/* AI生成内容提示（输入框下方） */
.ai-disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-tertiary);
    padding: 4px 24px 8px;
    max-width: 860px;
    margin: 0 auto;
    opacity: 0.7;
}

/* ---- Settings Panel ---- */
.settings-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.settings-overlay.open { opacity: 1; pointer-events: all; }
.settings-panel {
    width: 90%; max-width: 440px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.settings-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border-color);
    font-size: 16px; font-weight: 600;
}
.settings-panel-header button {
    background: none; color: var(--text-tertiary);
    font-size: 20px; padding: 2px 6px; border-radius: 4px;
}
.settings-panel-header button:hover { color: var(--text-primary); }
.settings-panel-body { padding: 16px 20px; }
.settings-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0; border-bottom: 1px solid var(--border-color);
    gap: 12px;
}
.settings-item:last-child { border-bottom: none; }
.settings-item .si-label { font-size: 14px; color: var(--text-primary); }
.settings-item .si-desc { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.toggle-switch {
    position: relative; width: 44px; height: 24px; flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-switch .slider {
    position: absolute; inset: 0;
    background: var(--border-strong); border-radius: 12px;
    cursor: pointer; transition: var(--transition);
}
.toggle-switch .slider::before {
    content: ''; position: absolute; left: 3px; top: 3px;
    width: 18px; height: 18px; border-radius: 50%;
    background: #fff; transition: var(--transition);
}
.toggle-switch input:checked + .slider { background: var(--accent); }
.toggle-switch input:checked + .slider::before { transform: translateX(20px); }
.settings-btn {
    display: block; width: 100%; padding: 10px;
    background: var(--bg-hover); color: var(--text-primary);
    border-radius: var(--radius); font-size: 14px;
    margin-top: 8px; transition: var(--transition); text-align: center;
}
.settings-btn:hover { background: var(--bg-active); }
.settings-btn.export-btn { color: var(--accent); }
.settings-version {
    text-align: center; font-size: 11px; color: var(--text-tertiary);
    margin-top: 16px;
}

/* ---- Toast ---- */
.toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 10px 18px; border-radius: var(--radius);
    font-size: 13px; color: #fff; box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 360px; word-break: break-word;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--accent); }
.toast.warning { background: var(--warning); color: #1a1a2e; }
@keyframes slideIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center; padding: 60px 20px;
    color: var(--text-tertiary);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; font-weight: 500; color: var(--text-secondary); margin-bottom: 8px; }

/* PC 端副标题 */
.empty-desc-pc { font-size: 13px; max-width: 360px; margin: 0 auto; }

/* 移动端站点名+副标题（默认隐藏，移动端显示） */
.empty-desc-mobile { display: none; margin-top: 6px; }
.empty-desc-mobile .empty-site-title {
    font-size: 16px; font-weight: 600;
    color: var(--text-primary);
}
.empty-desc-mobile .empty-site-subtitle {
    font-size: 13px; color: var(--text-tertiary);
    margin-top: 2px;
}

/* ---- Responsive: 移动端 ---- */
@media (max-width: 768px) {
    /* === 侧边栏覆盖显示 === */
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 20;
        width: 280px; min-width: 280px;
        height: 100vh; height: 100dvh;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,0.15);
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .sidebar-overlay { display: block; }
    .sidebar .sidebar-collapsed-icons { display: none !important; }
    .sidebar .btn-sidebar-collapse { display: none; }

    /* === 主布局 === */
    .app-layout {
        position: relative;
        height: 100vh; height: 100dvh;
    }
    .main-content {
        width: 100%;
        height: 100vh; height: 100dvh;
        min-width: 0;
    }

    /* === 顶部工具栏 === */
    .top-toolbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 14px;
        padding-top: max(0px, env(safe-area-inset-top));
        height: 48px;
        min-height: 48px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
        gap: 10px;
    }
    .toolbar-left,
    .toolbar-right {
        display: flex; align-items: center;
        flex-shrink: 0;
    }
    .toolbar-logo {
        flex: 1; text-align: center;
        font-size: 15px; font-weight: 700;
        color: var(--text-primary);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        min-width: 0;
    }
    .btn-sidebar-toggle {
        background: none; color: var(--text-secondary);
        padding: 6px; border-radius: 6px;
        display: flex; align-items: center;
        transition: var(--transition);
    }
    .btn-sidebar-toggle:active { background: var(--bg-hover); }
    .btn-toolbar-new-chat {
        width: 34px; height: 34px;
        display: flex; align-items: center; justify-content: center;
        border-radius: var(--radius-sm);
        background: var(--accent-dim); color: var(--accent);
        transition: var(--transition);
    }
    .btn-toolbar-new-chat:active { background: var(--accent); color: #fff; }

    /* === 隐藏桌面端特有元素 === */
    .assistant-name-bar { display: none !important; }
    .disclaimer-banner { display: none !important; }
    .chat-nav-dots { display: none !important; }

    /* === 对话区域 === */
    .chat-area {
        flex: 1; overflow-y: auto;
        padding: 12px 0;
        display: block !important; /* 移动端不用 flex 居中 */
    }
    .chat-area.input-centered {
        display: block !important;
        justify-content: initial;
    }
    .chat-messages { max-width: 100%; padding: 0 14px; }
    .empty-state { padding: 40px 14px; }
    .empty-desc-pc { display: none; }
    .empty-desc-mobile { display: block; }
    .empty-desc-mobile .empty-site-title { font-size: 18px; }
    .empty-desc-mobile .empty-site-subtitle { font-size: 13px; }

    /* === 消息气泡 === */
    .chat-bubble { max-width: 95%; }
    .chat-bubble.user { border-bottom-right-radius: 2px; }
    .chat-bubble.ai { border-bottom-left-radius: 2px; }
    .bubble-btn span { display: none; }
    .bubble-btn { padding: 4px 8px; }

    /* === 输入区域（始终底部，忽略居中模式） === */
    .input-area {
        flex-shrink: 0;
        padding: 10px 14px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        border-top: 1px solid var(--border-color);
        background: var(--bg-secondary);
        position: relative !important;
        bottom: auto !important;
        transform: none !important;
    }

    /* 移动端隐藏输入区上方的标题（工具栏已有名称） */
    .input-header { display: none !important; }

    /* 输入框 */
    .input-box {
        border-radius: var(--radius);
        border: 1px solid var(--border-color);
        background: var(--bg-input);
    }
    .input-box textarea {
        min-height: 44px;
        max-height: 120px;
        padding: 12px 14px 48px;
        font-size: 16px; /* 必须 ≥16px 防止 iOS 自动缩放 */
        line-height: 1.55;
    }
    .input-box:focus-within {
        border-color: var(--accent);
        box-shadow: 0 0 0 2px var(--accent-dim);
    }

    /* 操作栏 */
    .input-actions {
        padding: 4px 8px;
    }
    .input-mode .mode-switch-group {
        border-radius: 6px;
    }
    .input-mode .mode-btn {
        padding: 4px 12px; font-size: 12px;
    }
    .btn-send, .btn-stop {
        width: 32px; height: 32px;
        margin-left: 6px;
    }

    /* === AI 声明（输入框下方） === */
    .ai-disclaimer {
        flex-shrink: 0;
        font-size: 11px;
        padding: 2px 14px 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        text-align: center;
        color: var(--text-tertiary);
        opacity: 0.65;
        background: transparent;
    }

    /* === 进度横幅 === */
    .progress-overlay { padding: 8px 14px; }

    /* === 登录页 === */
    .login-card { padding: 32px 24px; margin: 16px; }

    /* === 设置面板 === */
    .settings-panel { max-width: 100%; margin: 20px; }
}

/* 小屏手机 (< 480px) */
@media (max-width: 480px) {
    .sidebar { width: 260px; min-width: 260px; }
    .top-toolbar {
        padding: 0 10px;
        padding-top: max(0px, env(safe-area-inset-top));
        height: 46px; min-height: 46px;
    }
    .toolbar-logo { font-size: 14px; }
    .btn-sidebar-toggle { padding: 4px; }
    .btn-sidebar-toggle svg { width: 18px; height: 18px; }
    .btn-toolbar-new-chat { width: 30px; height: 30px; }
    .btn-toolbar-new-chat svg { width: 16px; height: 16px; }

    .chat-messages { padding: 0 10px; }
    .chat-bubble {
        max-width: 98%; padding: 10px 12px; font-size: 14px;
    }

    .input-area { padding: 8px 10px 10px; }
    .input-box textarea {
        min-height: 42px; max-height: 110px;
        padding: 10px 12px 44px; font-size: 16px;
    }
    .input-actions { padding: 3px 6px; }
    .input-mode .mode-btn { padding: 3px 10px; font-size: 11px; }
    .btn-send, .btn-stop { width: 30px; height: 30px; }

    .ai-disclaimer { font-size: 10px; padding: 2px 10px 8px; }

    .empty-state { padding: 30px 12px; }
    .empty-state h3 { font-size: 15px; }
    .empty-state .empty-icon { margin-bottom: 10px; }
    .empty-state .empty-icon svg { width: 28px; height: 28px; }

    .login-card { padding: 28px 20px; }
    .login-card .logo { font-size: 24px; }
    .settings-item { flex-direction: column; align-items: flex-start; gap: 8px; }
    .bubble-actions { flex-wrap: wrap; }
    .progress-overlay { padding: 6px 10px; }
}

/* 平板 (769-1024) */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar { width: 240px; min-width: 240px; }
    .chat-messages { padding: 0 20px; }
    .chat-bubble { max-width: 90%; }
}
