/* ============================================================
   chat-demo PHP 全栈版 · 全局样式
   ============================================================ */

:root {
    --bg: #f6f8f7;
    --surface: #ffffff;
    --surface-2: #f0f4f2;
    --sidebar: #eef2f0;
    --text: #17201d;
    --text-soft: #3c4a45;
    --muted: #6b7a74;
    --border: #e2e8e5;
    --border-strong: #d3dcd8;
    --accent: #0f766e;
    --accent-strong: #0b5f59;
    --accent-soft: #e3f3ef;
    --accent-text: #ffffff;
    --danger: #c2410c;
    --danger-soft: #fdece4;
    --ok: #15803d;
    --shadow: 0 18px 50px rgba(18, 38, 32, 0.12);
    --radius: 16px;
    --radius-sm: 10px;
    --code-bg: #0f1720;
    --code-text: #e6edf3;
}

[data-theme="dark"] {
    --bg: #0b100e;
    --surface: #121816;
    --surface-2: #17201d;
    --sidebar: #0e1412;
    --text: #e8eeeb;
    --text-soft: #c3cfc9;
    --muted: #8c9c95;
    --border: #23302b;
    --border-strong: #2f3f39;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #10312c;
    --accent-text: #05201c;
    --danger: #fb923c;
    --danger-soft: #33190c;
    --ok: #4ade80;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    --code-bg: #070c0a;
    --code-text: #d7e2dc;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

body.modal-open { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.mobile-only { display: none !important; }

/* ---------- 通用组件 ---------- */
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: var(--accent-text);
    font-size: 18px;
    box-shadow: 0 6px 18px rgba(15, 118, 110, 0.28);
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 650; letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: var(--muted); font-size: 12px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease, opacity 0.16s ease;
    white-space: nowrap;
}

.btn:hover { background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: var(--accent-text); border-color: transparent; }
.btn-primary:hover { filter: brightness(1.05); background: linear-gradient(135deg, var(--accent), var(--accent-strong)); }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger-soft); filter: brightness(0.97); }
.btn-block { width: 100%; }

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    font-size: 18px;
    transition: background 0.15s ease;
}

.icon-btn:hover { background: var(--surface-2); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field input, .field textarea, .field select {
    width: 100%;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 10px;
    padding: 10px 12px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}
.field-hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 4px 0 0; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.inline-form { display: inline; margin: 0; }

.alert {
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.6;
    margin: 0 0 16px;
    border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: rgba(194, 65, 12, 0.18); }
.alert-warning { background: #fff7e6; color: #92400e; border-color: #fde68a; }
[data-theme="dark"] .alert-warning { background: #2a2005; color: #f6c453; border-color: #4d3a06; }
.alert-info { background: var(--accent-soft); color: var(--accent-strong); }

/* ---------- Toast ---------- */
.toast-root {
    position: fixed;
    z-index: 999;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: min(92vw, 460px);
}

.toast {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 13px;
    text-align: center;
    animation: toast-in 0.22s ease;
}
.toast.success { border-color: rgba(21, 128, 61, 0.4); }
.toast.error { border-color: rgba(194, 65, 12, 0.45); }
.toast.leaving { animation: toast-out 0.24s ease forwards; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ============================================================
   登录页
   ============================================================ */
.auth-page {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 32px 18px;
    background:
        radial-gradient(900px 500px at 10% 0%, rgba(15, 118, 110, 0.14), transparent 60%),
        radial-gradient(800px 500px at 100% 100%, rgba(20, 184, 166, 0.12), transparent 60%),
        var(--bg);
    overflow: hidden;
    position: relative;
}

.auth-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.5;
    pointer-events: none;
}
.auth-orb-a { width: 380px; height: 380px; background: rgba(45, 212, 191, 0.35); top: -120px; left: -80px; }
.auth-orb-b { width: 420px; height: 420px; background: rgba(15, 118, 110, 0.28); bottom: -160px; right: -100px; }

.auth-card {
    position: relative;
    width: min(440px, 100%);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
    border-radius: 24px;
    padding: 34px 32px 26px;
    box-shadow: var(--shadow);
}

.auth-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.auth-brand .brand-mark { width: 46px; height: 46px; flex-basis: 46px; border-radius: 14px; font-size: 22px; }
.eyebrow { font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }
.auth-brand h1 { margin: 2px 0 0; font-size: 22px; letter-spacing: 0.4px; }

.auth-greeting { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.auth-sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.auth-foot { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    background: var(--surface-2);
    border-radius: 12px;
    margin-bottom: 20px;
}
.auth-tab {
    border: 0;
    background: transparent;
    border-radius: 9px;
    padding: 9px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06); }

.auth-panel { display: none; }
.auth-panel.active { display: block; animation: fade-in 0.2s ease; }

.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.code-row .btn { height: 44px; flex: 0 0 auto; }

@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============================================================
   聊天主界面
   ============================================================ */
.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
    width: 282px;
    flex: 0 0 282px;
    display: flex;
    flex-direction: column;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    padding: 16px 14px;
    gap: 14px;
    z-index: 30;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 1px dashed var(--border-strong);
    background: color-mix(in srgb, var(--surface) 55%, transparent);
    border-radius: 12px;
    padding: 11px 14px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-soft);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }
.new-chat-icon { font-size: 18px; line-height: 1; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 11px;
}
.search-box input { flex: 1; border: 0; outline: none; background: transparent; font-size: 13px; min-width: 0; }
.search-icon { color: var(--muted); font-size: 15px; }

.session-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; display: flex; flex-direction: column; gap: 3px; }

.session-item {
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 10px;
    padding: 7px 8px 7px 10px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.14s ease, border-color 0.14s ease;
}
.session-item:hover { background: color-mix(in srgb, var(--surface) 75%, transparent); }
.session-item.active { background: var(--surface); border-color: var(--border); box-shadow: 0 2px 8px rgba(15, 30, 25, 0.05); }

.session-title {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    text-align: left;
    font-size: 13.5px;
    color: var(--text-soft);
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
.session-item.active .session-title { color: var(--text); font-weight: 600; }
.session-time { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.session-del {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    padding: 2px 4px;
    border-radius: 6px;
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { background: var(--danger-soft); color: var(--danger); }
.session-empty { color: var(--muted); font-size: 12.5px; text-align: center; padding: 20px 10px; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-meta strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.foot-link { border: 0; background: transparent; padding: 0; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.foot-link:hover { color: var(--text); text-decoration: none; }
.foot-link.danger:hover { color: var(--danger); }

.sidebar-mask { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

.topbar {
    height: 62px;
    flex: 0 0 62px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 20;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-title span { font-size: 11.5px; color: var(--muted); }

.model-picker { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.model-picker select {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 9px;
    padding: 6px 9px;
    font-size: 12.5px;
    outline: none;
}

.chat-scroll { flex: 1; overflow-y: auto; padding: 26px 0 18px; scroll-behavior: smooth; }

.welcome { max-width: 760px; margin: 4vh auto 0; padding: 0 24px; text-align: center; }
.welcome-mark {
    width: 54px;
    height: 54px;
    margin: 0 auto 16px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: var(--accent-text);
    font-size: 24px;
    box-shadow: 0 10px 30px rgba(15, 118, 110, 0.25);
}
.welcome h2 { margin: 0 0 8px; font-size: 22px; letter-spacing: 0.2px; }
.welcome p { margin: 0 auto; max-width: 560px; color: var(--muted); font-size: 13.5px; }
.welcome p strong { color: var(--accent-strong); }

.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 28px; }
.suggestion {
    text-align: left;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 14px;
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.suggestion:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 8px 24px rgba(15, 30, 25, 0.07); }
.suggestion strong { display: block; font-size: 13.5px; margin-bottom: 3px; }
.suggestion span { font-size: 12px; color: var(--muted); }

.messages { max-width: 860px; margin: 0 auto; padding: 0 24px; display: flex; flex-direction: column; gap: 26px; }

.msg { display: flex; gap: 12px; animation: msg-in 0.22s ease; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg-user { justify-content: flex-end; }
.bubble {
    max-width: min(76%, 680px);
    background: linear-gradient(140deg, var(--accent), var(--accent-strong));
    color: var(--accent-text);
    border-radius: 18px 18px 6px 18px;
    padding: 11px 16px;
    box-shadow: 0 6px 18px rgba(15, 118, 110, 0.18);
}
.bubble-text { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.7; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.file-chip {
    font-size: 11.5px;
    padding: 3px 8px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.18);
    color: inherit;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msg-ai { align-items: flex-start; }
.msg-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 16px;
    margin-top: 2px;
}
.msg-body { flex: 1; min-width: 0; padding-top: 2px; }

.thinking {
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 11px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 12.5px;
    color: var(--muted);
}
.thinking summary { cursor: pointer; font-weight: 600; color: var(--text-soft); }
.thinking-text { margin-top: 8px; white-space: pre-wrap; line-height: 1.7; max-height: 320px; overflow-y: auto; color: var(--muted); }

.md { font-size: 14.8px; line-height: 1.78; word-break: break-word; color: var(--text); }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 20px 0 10px; line-height: 1.4; font-weight: 650; }
.md h1 { font-size: 22px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 17px; }
.md h4 { font-size: 15.5px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 12px; }
.md li { margin: 3px 0; }
.md a { border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.md blockquote {
    margin: 0 0 12px;
    padding: 8px 14px;
    border-left: 3px solid var(--accent);
    background: var(--surface-2);
    border-radius: 0 10px 10px 0;
    color: var(--text-soft);
}
.md hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.md :not(pre) > code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 5px;
    font-size: 0.88em;
}
.md .table-scroll { overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.md th { background: var(--surface-2); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }

.code-block { margin: 0 0 14px; border-radius: 12px; overflow: hidden; background: var(--code-bg); border: 1px solid rgba(255, 255, 255, 0.06); }
.code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #93a4b8;
    font-size: 11.5px;
    letter-spacing: 0.04em;
}
.code-copy {
    border: 0;
    background: transparent;
    color: #93a4b8;
    cursor: pointer;
    font-size: 11.5px;
    padding: 2px 6px;
    border-radius: 5px;
}
.code-copy:hover { background: rgba(255, 255, 255, 0.1); color: #e6edf3; }
.code-block pre { margin: 0; padding: 13px 14px; overflow-x: auto; }
.code-block code { color: var(--code-text); font-size: 13px; line-height: 1.65; white-space: pre; }
.diagram { margin: 0 0 14px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; text-align: center; }
.mermaid { display: inline-block; min-width: 120px; }

.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--muted);
    animation: typing-bounce 1.1s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }

.msg-ai.is-streaming .md p:last-child::after {
    content: "▍";
    color: var(--accent);
    margin-left: 2px;
    animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.msg-notice {
    margin-top: 8px;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 12.5px;
}
.msg-notice.error { background: var(--danger-soft); color: var(--danger); }
.msg-notice.muted { background: var(--surface-2); color: var(--muted); }

.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.sources-label { font-size: 11.5px; color: var(--muted); margin-right: 2px; }
.sources a {
    font-size: 11.5px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
}
.sources a:hover { border-color: var(--accent); color: var(--accent-strong); }

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    font-size: 11.5px;
    color: var(--muted);
    flex-wrap: wrap;
}
.msg-actions { display: flex; gap: 10px; }
.msg-actions button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11.5px;
    cursor: pointer;
    padding: 0;
}
.msg-actions button:hover { color: var(--accent-strong); text-decoration: underline; }

/* ---------- 输入区 ---------- */
.composer-wrap { flex: 0 0 auto; padding: 10px 24px 18px; background: linear-gradient(to top, var(--bg) 65%, transparent); }
.attach-list { max-width: 860px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 9px;
    padding: 4px 6px 4px 9px;
    font-size: 11.5px;
    max-width: 260px;
}
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-size { color: var(--muted); font-size: 10.5px; }
.attach-remove {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}
.attach-remove:hover { color: var(--danger); }

.composer {
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    padding: 8px 8px 8px 10px;
    box-shadow: 0 10px 30px rgba(15, 30, 25, 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
.composer.dragging { border-style: dashed; border-color: var(--accent); background: var(--accent-soft); }
.composer-icon {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
    font-size: 17px;
    color: var(--muted);
    flex: 0 0 36px;
}
.composer-icon:hover { background: var(--surface-2); }
.composer textarea {
    flex: 1;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    padding: 8px 4px;
    max-height: 200px;
    min-height: 24px;
    line-height: 1.6;
    font-size: 14.5px;
    color: var(--text);
}
.send-btn {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: var(--accent-text);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.send-btn:hover { transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.stop-btn {
    height: 38px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-soft);
    font-size: 12.5px;
    cursor: pointer;
}

.composer-meta {
    max-width: 860px;
    margin: 8px auto 0;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 6px;
    color: var(--muted);
    font-size: 11.5px;
}
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); width: 14px; height: 14px; }
.composer-hint { margin-left: auto; }
.composer-warning { max-width: 860px; margin: 0 auto 10px; }

/* ============================================================
   设置弹窗
   ============================================================ */
.modal-root { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 12, 10, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.modal {
    position: relative;
    width: min(620px, 100%);
    max-height: min(82dvh, 760px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: modal-in 0.2s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-tabs { display: flex; gap: 6px; padding: 12px 20px 0; }
.modal-tab {
    border: 0;
    background: transparent;
    padding: 8px 12px;
    border-radius: 9px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
}
.modal-tab.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.modal-body { padding: 18px 20px 22px; overflow-y: auto; }
.settings-panel { display: none; }
.settings-panel.active { display: block; animation: fade-in 0.16s ease; }
.info-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.info-row span { color: var(--muted); }
.stack-form { margin-top: 16px; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 18px 0 6px; }
.setting-line { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting-line strong { font-size: 13.5px; }
.setting-line p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.setting-line.danger-line strong { color: var(--danger); }
.compact-select { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; }
.about-text { color: var(--muted); font-size: 13px; line-height: 1.8; }

/* ============================================================
   管理后台
   ============================================================ */
.admin-page { min-height: 100dvh; background: var(--bg); }
.admin-top {
    height: 66px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.admin-top-actions { display: flex; align-items: center; gap: 10px; }
.admin-user { color: var(--muted); font-size: 13px; }
.btn.danger { color: var(--danger); }

.admin-main { max-width: 1240px; margin: 0 auto; padding: 26px 24px 48px; }

.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.stat-card span { font-size: 12px; color: var(--muted); }
.stat-card strong { font-size: 22px; font-weight: 700; letter-spacing: 0.3px; }
.stat-card small { font-size: 11.5px; color: var(--muted); }
.stat-card small b { color: var(--text-soft); }

.admin-tabs { display: flex; gap: 8px; margin: 22px 0 14px; }
.admin-tab {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
}
.admin-tab.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); font-weight: 600; }

.admin-panel { display: none; }
.admin-panel.active { display: block; animation: fade-in 0.18s ease; }

.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.admin-search { width: min(300px, 100%); }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 900px; }
.data-table th, .data-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table th { background: var(--surface-2); font-weight: 600; color: var(--muted); white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 11px; }
.empty-cell { text-align: center !important; color: var(--muted); padding: 28px !important; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 5px; }
.mini-btn {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 7px;
    padding: 4px 8px;
    font-size: 11.5px;
    color: var(--text-soft);
    cursor: pointer;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent-strong); }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--surface-2); color: var(--muted); }
.badge-admin { background: var(--accent-soft); color: var(--accent-strong); }
.badge-ok { background: rgba(21, 128, 61, 0.12); color: var(--ok); }
.badge-off { background: var(--danger-soft); color: var(--danger); }

.settings-form { max-width: 860px; }
.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px 22px;
    margin-bottom: 16px;
}
.form-section h2 { margin: 0 0 4px; font-size: 15px; }
.section-desc { margin: 0 0 16px; color: var(--muted); font-size: 12.5px; }
.section-desc code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); margin: 4px 0 14px; cursor: pointer; }
.check-line input { accent-color: var(--accent); width: 15px; height: 15px; }
.inline-actions { display: flex; align-items: center; gap: 12px; margin: -2px 0 14px; }
.key-state { font-style: normal; color: var(--accent-strong); font-weight: 500; }
.form-actions { display: flex; align-items: center; gap: 14px; padding: 4px 0 20px; }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .mobile-only { display: grid !important; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: translateX(-104%);
        transition: transform 0.22s ease;
        width: min(86vw, 320px);
        flex-basis: auto;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: none; }
    .sidebar-mask { display: block; position: fixed; inset: 0; background: rgba(6, 12, 10, 0.45); opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 25; }
    .sidebar-mask.show { opacity: 1; pointer-events: auto; }

    .topbar { padding: 0 14px; gap: 8px; }
    .topbar-title h1 { font-size: 14px; }
    .model-picker span { display: none; }
    .messages { padding: 0 16px; }
    .composer-wrap { padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); }
    .welcome { margin-top: 3vh; padding: 0 18px; }
    .welcome h2 { font-size: 19px; }
    .bubble { max-width: 84%; }

    .admin-main { padding: 18px 14px 40px; }
    .admin-top { padding: 0 14px; }
    .admin-user { display: none; }
    .panel-head { flex-direction: column; align-items: stretch; }
    .admin-search { width: 100%; }
}

.recording-hint {
    max-width: 860px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 10px;
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 12.5px;
}

.recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: recording-pulse 1.1s infinite ease-in-out;
}

@keyframes recording-pulse {
    0%, 100% { opacity: 0.35; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1.15); }
}

.voice-btn.recording {
    color: var(--danger);
    background: var(--danger-soft);
    animation: recording-pulse 1.4s infinite ease-in-out;
}

.branch-switch {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 10px;
    padding: 1px 4px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 11px;
    color: var(--muted);
}

.branch-switch button {
    border: 0;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 1px 5px;
    border-radius: 999px;
}

.branch-switch button:hover {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.voice-settings {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 14px 0;
}

.voice-settings > strong {
    font-size: 13.5px;
}

.provider-form {
    margin-top: 16px;
    max-width: none;
}

.cell-url,
.cell-models {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 12px;
}

.cell-models { max-width: 300px; }

/* ---------- 画图 / 视频 ---------- */
.composer-tools {
    max-width: 860px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 26px;
}

.mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.mode-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    padding: 4px 11px;
    border-radius: 999px;
    cursor: pointer;
}

.mode-btn.active {
    background: var(--surface);
    color: var(--accent-strong);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(15, 30, 25, 0.08);
}

.mini-tool {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 11.5px;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
}

.mini-tool:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.media-ref-name {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11.5px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 8px;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-ref-name button {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 0 2px;
}

.media-ref-name button:hover { color: var(--danger); }

.media-request-badge {
    display: inline-block;
    margin-top: 6px;
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.18);
    color: inherit;
}

.media-card {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    overflow: hidden;
    max-width: 680px;
    box-shadow: 0 6px 22px rgba(15, 30, 25, 0.05);
}

.media-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
    font-weight: 600;
}

.media-status-label { font-weight: 500; color: var(--muted); }
.media-status-success .media-status-label { color: var(--ok); }
.media-status-failed .media-status-label,
.media-status-expired .media-status-label { color: var(--danger); }

.media-preview {
    min-height: 170px;
    display: grid;
    place-items: center;
    background: var(--surface-2);
}

.media-preview img {
    display: block;
    max-width: 100%;
    max-height: 520px;
}

.media-preview video {
    display: block;
    max-width: 100%;
    max-height: 520px;
    background: #000;
}

.media-placeholder {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 48px 20px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.media-placeholder.error { color: var(--danger); }

.media-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: media-spin 0.8s linear infinite;
}

@keyframes media-spin { to { transform: rotate(360deg); } }

.media-bar {
    position: relative;
    height: 3px;
    background: var(--surface-2);
    margin-top: 12px;
}

.media-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-strong));
    transition: width 0.4s ease;
}

.media-bar-text {
    position: absolute;
    right: 12px;
    top: -18px;
    font-size: 10.5px;
    color: var(--muted);
}

.media-prompt {
    padding: 10px 14px 4px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-soft);
    white-space: pre-wrap;
    word-break: break-word;
}

.media-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px 12px;
    font-size: 11.5px;
    color: var(--muted);
}

.media-actions a { color: var(--accent); }
.media-actions button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11.5px;
    cursor: pointer;
    padding: 0;
}
.media-actions button:hover { color: var(--accent-strong); }
.media-size-label { margin-right: auto; }

@media (max-width: 620px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .suggestions { grid-template-columns: 1fr; }
    .auth-card { padding: 26px 20px 22px; border-radius: 20px; }
    .field-grid { grid-template-columns: 1fr; }
    .composer-hint { display: none; }
    .modal { max-height: 88dvh; }
    .modal-root { padding: 10px; }
    .msg-avatar { width: 30px; height: 30px; flex-basis: 30px; border-radius: 9px; font-size: 14px; }
    .msg-meta { flex-direction: column; align-items: flex-start; gap: 6px; }
}


/* ============================================================
   侧栏收起 / 展开（桌面端）
   ============================================================ */
.sidebar-toggle { transition: transform 0.22s ease; }

@media (max-width: 900px) {
    .sidebar-toggle { display: none !important; }
}

@media (min-width: 901px) {
    .sidebar { transition: width 0.22s ease, flex-basis 0.22s ease, padding 0.22s ease; overflow: hidden; }

    .app.sidebar-collapsed .sidebar {
        width: 70px;
        flex: 0 0 70px;
        padding: 16px 8px;
    }

    .app.sidebar-collapsed .brand-text,
    .app.sidebar-collapsed .new-chat .label,
    .app.sidebar-collapsed .search-box,
    .app.sidebar-collapsed .session-list,
    .app.sidebar-collapsed .sidebar-foot .foot-actions,
    .app.sidebar-collapsed .user-meta {
        display: none;
    }

    .app.sidebar-collapsed .sidebar-head { flex-direction: column; gap: 10px; }
    .app.sidebar-collapsed .brand { justify-content: center; width: 100%; }
    .app.sidebar-collapsed .new-chat { justify-content: center; padding: 11px 0; }
    .app.sidebar-collapsed .sidebar-foot { align-items: center; }
    .app.sidebar-collapsed .user-chip { justify-content: center; }
    .app.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }
}

/* ============================================================
   动态背景图
   ============================================================ */
body.has-ambient {
    background-color: var(--bg);
    background-image: linear-gradient(180deg, rgba(6, 12, 10, 0.26), rgba(6, 12, 10, 0.5)), var(--ambient-image);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
}

body.has-ambient .main {
    background: color-mix(in srgb, var(--bg) 76%, transparent);
}

body.has-ambient .sidebar {
    background: color-mix(in srgb, var(--sidebar) 82%, transparent);
    backdrop-filter: blur(10px);
}

/* ============================================================
   背景音乐开关
   ============================================================ */
.music-toggle {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: blur(8px);
    color: var(--text-soft);
    font-size: 17px;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 40;
    box-shadow: var(--shadow);
    transition: transform 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.music-toggle:hover { transform: translateY(-2px); color: var(--text); }
.music-toggle.playing { color: var(--accent-strong); border-color: var(--accent); }

/* 背景音乐：换一首 */
.music-next {
    position: fixed;
    right: 22px;
    bottom: 68px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: blur(8px);
    color: var(--muted);
    font-size: 14px;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 40;
    transition: transform 0.18s ease, color 0.18s ease;
}

.music-next:hover { transform: translateY(-2px) rotate(90deg); color: var(--text); }

/* 模型显示开关列表 */
.model-visibility {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 4px 16px;
    margin: 4px 0 16px;
}

.model-visibility .check-line { margin: 0; }

/* 管理后台：用户详情 */
.detail-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

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

.detail-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 13px;
}

.detail-item span { color: var(--muted); }
.detail-item strong { font-weight: 600; text-align: right; word-break: break-all; }
.cell-content { max-width: 420px; white-space: normal; line-height: 1.5; }

/* 管理后台：媒体缩略图 */
.media-thumb {
    width: 84px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
    background: var(--surface-2);
}

.link-cell { color: var(--accent); cursor: pointer; }
.link-cell:hover { text-decoration: underline; }
