:root {
    --bg: #eef2f8;
    --surface: #ffffff;
    --text: #1f1f1f;
    --muted: #61656b;
    --outline: #dbe2ea;
    --primary: #4f46e5;
    --primary-strong: #4338ca;
    --primary-light: #eef2ff;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --shadow: 0 14px 36px rgba(23, 34, 58, 0.08);
    --font-body: 15px;
    --font-title: 16px;
    --font-muted: 13px;
    --system-font-size: 14px;
    --system-font-weight: 500;
    --system-line-height: 1.45;
    --sidebar-width: 276px;
    --sidebar-mini-width: 64px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-xl: 24px;
}

* { box-sizing: border-box; }

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: "SF Pro Text", "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
    background:
        radial-gradient(circle at 100% 0%, rgba(79, 70, 229, 0.06), transparent 40%),
        radial-gradient(circle at 0% 100%, rgba(245, 158, 11, 0.06), transparent 40%),
        var(--bg);
    color: var(--text);
    font-size: var(--font-body);
    line-height: 1.56;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    min-height: 100dvh;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ==================== SIDEBAR ==================== */
.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(24, 30, 42, 0.34);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 1090;
}
.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-mini-width);
    height: 100dvh; height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--outline);
    transition: width 0.22s cubic-bezier(0.2, 0, 0, 1), transform 0.22s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.22s cubic-bezier(0.2, 0, 0, 1);
    z-index: 1100; display: flex; flex-direction: column; overflow: hidden;
}
.sidebar.open {
    width: var(--sidebar-width);
    box-shadow: 0 16px 34px rgba(18, 28, 52, 0.18);
}

.sidebar-header { padding: 10px 12px 6px; display: flex; flex-direction: column; gap: 6px; }
.sidebar-top-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.sidebar-toggle-btn, .menu-btn {
    width: 36px; height: 36px; border: none; border-radius: 18px;
    background: transparent; color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.15s ease; flex-shrink: 0;
}
.sidebar-toggle-btn:hover, .menu-btn:hover { background: rgba(0,0,0,0.05); color: #2b3037; }
.sidebar-toggle-btn svg, .menu-btn svg { width: 20px; height: 20px; }

.sidebar-search-btn {
    height: 32px; min-width: 42px; padding: 0 12px; border: none; border-radius: 16px;
    background: #edf2f9; color: #5f6368;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-search-btn:hover { background: #e4ebf6; color: #2b3037; }
.sidebar-search-btn svg { width: 18px; height: 18px; }

.sidebar:not(.open) .sidebar-header { align-items: center; padding: 10px 10px 8px; }
.sidebar:not(.open) .sidebar-top-row { justify-content: center; }
.sidebar:not(.open) .sidebar-search-btn,
.sidebar:not(.open) .sidebar-newchat,
.sidebar:not(.open) .sidebar-section,
.sidebar:not(.open) .sidebar-footer { display: none; }

.sidebar-newchat {
    width: 100%; height: 36px; border-radius: 18px;
    background: transparent; color: #2b3037; text-decoration: none;
    display: inline-flex; align-items: center; justify-content: flex-start;
    gap: 10px; padding: 0 12px;
    font-size: var(--system-font-size); font-weight: var(--system-font-weight);
    line-height: var(--system-line-height);
    transition: background 0.15s ease;
    cursor: pointer; border: none; font-family: inherit;
}
.sidebar-newchat:hover { background: #f2f6fc; }
.sidebar-newchat svg { width: 18px; height: 18px; color: #5f6368; flex-shrink: 0; }

.sidebar-section { padding: 0 8px; flex: 0 0 auto; overflow: visible; }
.sidebar-section + .sidebar-section { margin-top: 4px; padding-top: 6px; }
.sidebar-section-conversations { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; }

.sidebar-section-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px 5px;
}
.sidebar-section-label {
    margin: 0; padding: 0;
    font-size: var(--system-font-size); font-weight: var(--system-font-weight);
    line-height: var(--system-line-height); color: #6f757d;
}
.sidebar-section-btn {
    width: 24px; height: 24px; border: none; border-radius: 50%;
    background: transparent; color: #707985; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-section-btn:hover { background: rgba(0,0,0,0.04); color: #2b3037; }
.sidebar-section-btn svg { width: 14px; height: 14px; display: block; }

.sidebar-agent-list {
    margin-top: 2px; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0;
}

.sidebar-history {
    padding: 0 6px 8px;
    display: flex; flex: 1 1 auto; flex-direction: column; gap: 1px;
    min-height: 0; overflow-y: auto;
}

.sidebar-history::-webkit-scrollbar { width: 4px; }
.sidebar-history::-webkit-scrollbar-thumb { background: #dbe2ea; border-radius: 4px; }

.sidebar-history-row {
    position: relative; display: flex; align-items: flex-start;
    border-radius: var(--radius); transition: background 0.15s ease;
}
.sidebar-history-row:hover { background: #f2f6fc; }
.sidebar-history-row.active { background: var(--primary-light); }

.sidebar-history-item {
    display: block; flex: 1 1 auto; min-width: 0; text-decoration: none;
    border-radius: var(--radius); padding: 10px 6px 10px 10px; cursor: pointer;
}
.sidebar-history-title {
    display: block; font-size: var(--system-font-size); font-weight: var(--system-font-weight);
    color: #2b3037; line-height: var(--system-line-height);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-history-summary {
    display: block; margin-top: 2px; font-size: 12px; line-height: 1.35;
    color: #7f8690; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-history-menu {
    width: 28px; height: 28px; margin: 6px 6px 0 0; border: none; border-radius: 14px;
    background: transparent; color: #6f757d; cursor: pointer; flex: 0 0 28px;
    display: inline-flex; align-items: center; justify-content: center;
    font-family: inherit; font-size: 18px; line-height: 1;
    opacity: 0; transition: opacity 0.15s ease, background 0.15s ease;
}
.sidebar-history-row:hover .sidebar-history-menu,
.sidebar-history-menu:focus-visible { opacity: 1; }
.sidebar-history-menu:hover { background: #e8eef7; color: #2b3037; }

.sidebar-agent-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    border-radius: var(--radius); cursor: pointer; transition: background 0.15s ease;
    font-size: var(--system-font-size); font-weight: var(--system-font-weight);
    line-height: var(--system-line-height); color: #2b3037;
    border: none; background: transparent; font-family: inherit; width: 100%; text-align: left;
}
.sidebar-agent-item:hover { background: #f2f6fc; }
.sidebar-agent-item.active { background: var(--primary-light); color: var(--primary); }
.sidebar-agent-icon { font-size: 20px; flex-shrink: 0; }
.sidebar-agent-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer {
    position: relative; padding: 6px 8px calc(10px + var(--safe-area-bottom));
    border-top: 1px solid #edf1f6; background: var(--surface); flex-shrink: 0; z-index: 4;
}
.sidebar-settings {
    width: 100%; border: none; background: transparent; cursor: pointer;
    display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    justify-content: flex-start; font-family: inherit;
    font-size: var(--system-font-size); font-weight: var(--system-font-weight);
    color: #2b3037; border-radius: var(--radius); transition: background 0.15s ease;
}
.sidebar-settings:hover { background: #f2f6fc; }

.sidebar-empty {
    padding: 16px 12px; text-align: center; font-size: 13px; color: #9aa0a6;
}

/* ==================== TOPBAR ==================== */
.topbar {
    position: sticky; top: 0; z-index: 100;
    background: rgba(255,255,255,0.85); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--outline);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; height: 56px;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
    font-size: 22px; width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700;
}
.brand-text { font-size: 17px; font-weight: 700; color: #2b3037; letter-spacing: -0.01em; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.user-menu { position: relative; }
.user-chip {
    display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px;
    border-radius: 24px; border: none; background: #f2f6fc; cursor: pointer;
    font-family: inherit; font-size: 13px; color: #2b3037;
    transition: background 0.15s ease;
}
.user-chip:hover { background: #e8eef7; }
.user-chip-credits { color: var(--accent); font-weight: 600; font-size: 12px; }
.user-chip-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600;
}
.user-chip-arrow { width: 16px; height: 16px; color: #6f757d; }
.user-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0;
    min-width: 160px; background: var(--surface);
    border: 1px solid var(--outline); border-radius: var(--radius);
    box-shadow: 0 12px 30px rgba(19, 31, 48, 0.14);
    padding: 5px; z-index: 200; display: flex; flex-direction: column;
}
.user-dropdown-item {
    width: 100%; height: 36px; border: none; border-radius: 8px;
    background: transparent; color: #2b3037; cursor: pointer;
    font-family: inherit; font-size: 13px; text-align: left; padding: 0 12px;
    display: flex; align-items: center; justify-content: space-between;
    transition: background 0.15s ease;
}
.user-dropdown-item:hover { background: #f2f6fc; }
.user-dropdown-item.danger { color: var(--danger); }

.topbar-btn {
    height: 36px; padding: 0 20px; border-radius: 18px;
    border: none; background: var(--primary); color: #fff;
    cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 500;
    transition: all 0.15s ease;
}
.topbar-btn:hover { background: var(--primary-strong); transform: translateY(-1px); }

/* ==================== MAIN CONTENT ==================== */
.main-content {
    margin-left: var(--sidebar-mini-width);
    transition: margin-left 0.22s cubic-bezier(0.2, 0, 0, 1);
    min-height: calc(100vh - 56px);
    padding: 0 20px 40px;
}
.sidebar.open ~ .main-content { margin-left: var(--sidebar-width); }

/* ==================== HERO ==================== */
.hero-area { text-align: center; padding: 48px 20px 32px; }
.hero-greeting {
    font-size: 28px; font-weight: 700; color: #2b3037; margin: 0 0 8px;
}
.hero-title {
    font-size: 40px; font-weight: 800; margin: 0;
    background: linear-gradient(135deg, var(--primary), #7c3aed, var(--accent));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ==================== COMBO CARD (Input Area) ==================== */
.combo-card {
    max-width: 760px; margin: 0 auto 40px;
    background: var(--surface); border-radius: var(--radius-xl);
    box-shadow: var(--shadow); border: 1px solid var(--outline);
}
.entry-panel { padding: 10px 16px 8px; }
.entry-input {
    width: 100%; border: none; outline: none; resize: none;
    font-family: inherit; font-size: 16px; line-height: 1.5;
    color: var(--text); background: transparent;
    min-height: 48px; max-height: 200px; padding: 6px 0;
}
.entry-input::placeholder { color: #9aa0a6; }
.entry-input:focus { outline: none; }

.entry-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding-top: 6px; border-top: 1px solid #f0f3f7;
}
.entry-left-actions, .entry-right-actions { display: flex; align-items: center; gap: 4px; }

.entry-icon-btn {
    width: 36px; height: 36px; border: none; border-radius: 18px;
    background: transparent; color: #5f6368; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.15s ease;
}
.entry-icon-btn:hover { background: #f2f6fc; }
.entry-icon-btn svg { width: 20px; height: 20px; }

.entry-tools-btn {
    height: 32px; padding: 0 12px; border: none; border-radius: 16px;
    background: #edf2f9; color: #5f6368; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    font-family: inherit; font-size: 13px; font-weight: 500;
    transition: background 0.15s ease;
}
.entry-tools-btn:hover { background: #e4ebf6; }
.entry-tools-btn svg { width: 18px; height: 18px; }

.entry-model-btn {
    height: 32px; padding: 0 12px; border: 1px solid var(--outline);
    border-radius: 16px; background: var(--surface); color: #2b3037;
    cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
    font-family: inherit; font-size: 13px; font-weight: 500;
    transition: background 0.15s ease;
}
.entry-model-btn:hover { background: #f8fafc; }
.entry-model-btn svg { width: 14px; height: 14px; }

.entry-send-btn {
    width: 36px; height: 36px; border: none; border-radius: 18px;
    background: var(--primary); color: #fff; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.15s ease;
}
.entry-send-btn:hover { background: var(--primary-strong); }
.entry-send-btn:disabled { background: #dbe2ea; color: #9aa0a6; cursor: not-allowed; }
.entry-send-btn svg { width: 18px; height: 18px; }

.entry-file-input { display: none; }
.entry-file-preview { padding: 4px 0; display: flex; gap: 6px; flex-wrap: wrap; }
.entry-file-preview-item {
    display: flex; align-items: center; gap: 4px;
    padding: 4px 10px; background: #f2f6fc; border-radius: 10px;
    font-size: 12px; color: #5f6368;
}
.entry-file-preview-item button {
    border: none; background: none; cursor: pointer; color: #9aa0a6; font-size: 14px; padding: 0;
}

.entry-popover {
    position: absolute; bottom: calc(100% + 8px); left: 0;
    min-width: 140px; background: var(--surface);
    border: 1px solid var(--outline); border-radius: var(--radius);
    box-shadow: 0 12px 30px rgba(19, 31, 48, 0.14);
    padding: 5px; z-index: 300;
}
.entry-popover-item {
    width: 100%; height: 36px; border: none; border-radius: 8px;
    background: transparent; color: #2b3037; cursor: pointer;
    font-family: inherit; font-size: 13px; text-align: left; padding: 0 12px;
    transition: background 0.15s ease;
}
.entry-popover-item:hover { background: #f2f6fc; }
.entry-popover-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

/* ==================== MODULE CARDS ==================== */
.modules-section { max-width: 900px; margin: 0 auto; }
.category-group { margin-bottom: 32px; }

.section-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 4px; margin-bottom: 12px;
}
.section-title {
    margin: 0; font-size: 14px; font-weight: 600; color: #5f6368;
    display: flex; align-items: center; gap: 8px;
    letter-spacing: 0.01em;
}
.category-icon { font-size: 16px; }
.section-count {
    font-size: 12px; color: #9aa0a6; font-weight: 500;
    background: #f2f6fc; padding: 2px 10px; border-radius: 10px;
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.module-card {
    display: flex; align-items: center; gap: 14px;
    padding: 16px 18px; background: var(--surface);
    border-radius: var(--radius-lg); border: 1px solid var(--outline);
    cursor: pointer; text-decoration: none;
    transition: all 0.2s ease;
}
.module-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(23, 34, 58, 0.1);
    border-color: var(--primary);
}
.module-card-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; flex-shrink: 0;
}
.module-card-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.module-card-name {
    font-size: 14px; font-weight: 600; color: #2b3037;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.module-card-desc {
    font-size: 12px; color: #7f8690; line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==================== AUTH MODALS ==================== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(24, 30, 42, 0.4);
    backdrop-filter: blur(4px); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal {
    background: var(--surface); border-radius: var(--radius-xl);
    padding: 36px; width: 400px; max-width: 90vw;
    box-shadow: 0 24px 60px rgba(0,0,0,0.18);
    animation: modalIn 0.25s ease;
}
@keyframes modalIn {
    from { transform: scale(0.92) translateY(16px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}
.modal h2 { text-align: center; margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.modal-subtitle { text-align: center; color: #7f8690; margin: 0 0 24px; font-size: 14px; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600; color: #5f6368; margin-bottom: 6px;
}
.form-group input {
    width: 100%; padding: 12px 16px; border: 2px solid var(--outline);
    border-radius: 12px; font-size: 16px; font-family: inherit;
    outline: none; transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--primary); }
.code-row { display: flex; gap: 10px; }
.code-row input { flex: 1; }
.code-row .btn {
    padding: 12px 20px; border-radius: 12px; white-space: nowrap;
    background: var(--surface); border: 2px solid var(--outline);
    color: var(--primary); cursor: pointer; font-family: inherit;
    font-size: 14px; font-weight: 500; transition: all 0.15s ease;
}
.code-row .btn:hover { background: var(--primary-light); border-color: var(--primary); }
.code-row .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full {
    width: 100%; padding: 14px; border-radius: 12px; font-size: 16px; font-weight: 600;
    border: none; cursor: pointer; font-family: inherit;
    background: var(--primary); color: #fff; margin-top: 8px;
    transition: all 0.15s ease;
}
.btn-full:hover { background: var(--primary-strong); }
.btn-full:disabled { opacity: 0.6; cursor: not-allowed; }
.error-msg { color: var(--danger); font-size: 13px; text-align: center; margin-top: 8px; display: none; }
.modal-footer-text { text-align: center; margin-top: 16px; font-size: 12px; color: #9aa0a6; }

/* ==================== CHAT PAGE ==================== */
.chat-page { display: flex; flex-direction: column; height: calc(100vh - 56px); }

.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px;
    max-width: 800px; margin: 0 auto; width: 100%;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #dbe2ea; border-radius: 4px; }

.chat-msg { margin-bottom: 24px; display: flex; gap: 12px; animation: msgIn 0.3s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.chat-msg-avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.chat-msg.user .chat-msg-avatar { background: var(--primary-light); color: var(--primary); }
.chat-msg.assistant .chat-msg-avatar { background: #fef3c7; color: var(--accent); }
.chat-msg-content { flex: 1; min-width: 0; }
.chat-msg-role { font-size: 12px; font-weight: 600; margin-bottom: 4px; color: #5f6368; }
.chat-msg-text {
    font-size: 15px; line-height: 1.7; color: #2b3037; white-space: pre-wrap; word-break: break-word;
}
.chat-msg-text p { margin: 0 0 8px; }
.chat-msg-text p:last-child { margin-bottom: 0; }
.chat-msg-text code {
    background: #f2f6fc; padding: 2px 6px; border-radius: 4px; font-size: 13px;
}
.chat-msg-text pre {
    background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: 10px;
    overflow-x: auto; font-size: 13px; line-height: 1.5; margin: 8px 0;
}
.chat-msg-text pre code { background: none; padding: 0; color: inherit; }

.chat-input-area {
    padding: 12px 20px 20px; border-top: 1px solid var(--outline);
    background: rgba(255,255,255,0.85); backdrop-filter: blur(12px);
    max-width: 800px; margin: 0 auto; width: 100%;
}

.chat-welcome {
    text-align: center; padding: 60px 20px; color: #5f6368;
}
.chat-welcome-icon { font-size: 64px; margin-bottom: 16px; display: block; }
.chat-welcome h2 { font-size: 24px; font-weight: 700; color: #2b3037; margin: 0 0 8px; }
.chat-welcome p { margin: 0; font-size: 15px; }
.chat-welcome-suggestions {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px;
}
.chat-welcome-suggestion {
    padding: 8px 16px; border: 1px solid var(--outline); border-radius: 20px;
    background: var(--surface); cursor: pointer; font-size: 13px; color: #5f6368;
    transition: all 0.15s ease;
}
.chat-welcome-suggestion:hover { border-color: var(--primary); color: var(--primary); }

.chat-typing {
    display: flex; align-items: center; gap: 4px; padding: 8px 0;
}
.chat-typing-dot {
    width: 8px; height: 8px; border-radius: 50%; background: #c4c7cc;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.chat-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chat-typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); }
    40% { transform: scale(1); }
}

/* ==================== HISTORY PAGE ==================== */
.history-list { max-width: 700px; margin: 0 auto; padding: 20px 0; }
.history-group-title { font-size: 12px; font-weight: 600; color: #9aa0a6; padding: 12px 4px 8px; }
.history-item {
    display: flex; align-items: center; gap: 14px; padding: 14px 16px;
    background: var(--surface); border-radius: var(--radius); border: 1px solid var(--outline);
    margin-bottom: 8px; cursor: pointer; transition: all 0.15s ease; text-decoration: none; color: inherit;
}
.history-item:hover { border-color: var(--primary); box-shadow: 0 2px 12px rgba(0,0,0,0.04); }
.history-item-icon { font-size: 24px; flex-shrink: 0; }
.history-item-info { flex: 1; min-width: 0; }
.history-item-title { font-size: 14px; font-weight: 600; color: #2b3037; }
.history-item-meta { font-size: 12px; color: #9aa0a6; margin-top: 2px; }
.history-item-time { font-size: 12px; color: #9aa0a6; flex-shrink: 0; }

/* ==================== SEARCH OVERLAY ==================== */
.search-layer { position: fixed; inset: 0; z-index: 1200; }
.search-backdrop {
    position: absolute; inset: 0; background: rgba(24, 30, 42, 0.3);
}
.search-panel {
    position: absolute; top: 0; left: var(--sidebar-width); right: 0; bottom: 0;
    background: var(--surface); max-width: 420px;
    border-right: 1px solid var(--outline); box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateX(-20px); opacity: 0; } to { transform: none; opacity: 1; } }
.search-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--outline);
}
.search-header h2 { margin: 0; font-size: 16px; }
.search-close {
    width: 32px; height: 32px; border: none; border-radius: 16px;
    background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.search-close:hover { background: #f2f6fc; }
.search-input-wrap {
    display: flex; align-items: center; gap: 8px; padding: 12px 16px;
    border-bottom: 1px solid var(--outline);
}
.search-input-wrap svg { width: 20px; height: 20px; color: #9aa0a6; flex-shrink: 0; }
.search-input {
    flex: 1; border: none; outline: none; font-family: inherit; font-size: 15px;
    background: transparent;
}
.search-meta { padding: 8px 16px; font-size: 12px; color: #9aa0a6; }
.search-results { flex: 1; overflow-y: auto; padding: 0 8px; }

/* ==================== TOAST ==================== */
.toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 3000;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 12px 20px; border-radius: 12px; background: #1e293b; color: #fff;
    font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    animation: toastIn 0.3s ease; max-width: 360px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ==================== RESPONSIVE ==================== */
/* ========== 手机端优化 ========== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
    .sidebar.open { transform: translateX(0); }
    .sidebar:not(.open) { transform: translateX(-100%); }
    .main-content { margin-left: 0 !important; }
    .sidebar.open ~ .main-content { margin-left: 0; }
    .hero-title { font-size: 26px; }
    .topbar { padding: 0 10px; height: 48px; }
    .brand-text { display: none; }
    .chat-messages { padding: 12px; }

    /* 2列网格 + 更小卡片 */
    .module-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .module-card { padding: 10px 12px; gap: 8px; }
    .module-card-icon { width: 36px; height: 36px; font-size: 18px; border-radius: 10px; }
    .module-card-name { font-size: 13px; }
    .module-card-desc { font-size: 11px; -webkit-line-clamp: 1; }

    /* Section 间距 */
    .modules-section { margin-bottom: 16px; }
    .section-row { margin-bottom: 8px; }
    .section-title { font-size: 15px; }
    .section-count { font-size: 11px; }

    /* 顶部栏紧凑 */
    .topbar-brand { gap: 8px; }
    .brand-icon { width: 28px; height: 28px; font-size: 16px; }
    .topbar-btn { padding: 6px 12px; font-size: 13px; }
}

@media (max-width: 380px) {
    /* 超小屏：更紧凑 */
    .module-grid { gap: 6px; }
    .module-card { padding: 8px 10px; gap: 6px; }
    .module-card-icon { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }
    .module-card-name { font-size: 12px; }
    .module-card-desc { font-size: 10px; }
    .hero-title { font-size: 20px; }
    .section-title { font-size: 14px; }
    .page-wrap { padding: 10px; }
}

@media (max-width: 480px) {
    .hero-title { font-size: 22px; }
    .combo-card { border-radius: var(--radius-lg); }
    .modal { padding: 24px; }
}


/* ========== 手机底部导航 ========== */
.mobile-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: #fff; border-top: 1px solid #e2e8f0;
    padding: 6px 16px env(safe-area-inset-bottom, 8px);
    z-index: 900; justify-content: space-around;
    box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.mobile-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    text-decoration: none; color: #94a3b8; font-size: 10px; padding: 4px 8px;
    transition: color .15s; font-weight: 500;
}
.mobile-nav a .nav-icon { font-size: 20px; }
.mobile-nav a.active { color: var(--primary, #4f46e5); }

@media (max-width: 768px) {
    .mobile-nav { display: flex; }
    body { padding-bottom: 60px; }
}

/* 回到顶部按钮 */
.back-to-top {
    position: fixed; bottom: 72px; right: 16px;
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary, #4f46e5); color: #fff;
    border: none; font-size: 18px; cursor: pointer;
    box-shadow: 0 2px 12px rgba(79,70,229,.3);
    z-index: 899; opacity: 0; pointer-events: none;
    transition: opacity .25s; display: flex; align-items: center; justify-content: center;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; }

/* Login tabs */
.login-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid #e2e8f0;
}
.login-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: #f8fafc;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    transition: all 0.2s;
}
.login-tab.active {
    background: #4f46e5;
    color: #fff;
}
.hidden { display: none !important; }

/* Voice & Speak buttons */
.chat-speak-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    opacity: 0.5;
    transition: opacity 0.2s;
    vertical-align: middle;
}
.chat-speak-btn:hover { opacity: 1; }

.entry-icon-btn.listening {
    background: #ef4444 !important;
    color: #fff !important;
    animation: pulse 0.8s infinite;
}
@keyframes pulse {
    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); }
}
