/* ==========================================================================
   Agent Q&A — 全站样式
   1. 设计变量与基础  2. 通用组件  3. 登录  4. 聊天布局
   5. 消息与 Markdown  6. 输入区  7. 浮层与提示  8. 管理后台
   ========================================================================== */

/* 1. 设计变量 ------------------------------------------------------------- */
:root {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 288px;
  --topbar-h: 64px;
  --content-w: 820px;
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --fast: 150ms;
  --normal: 220ms;
  --z-sidebar: 40;
  --z-scrim: 35;
  --z-overlay: 80;
  --z-toast: 100;
  --z-dialog: 110;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1011;
  --bg-soft: #131416;
  --sidebar-bg: #121314;
  --surface: #181a1c;
  --surface-2: #1d2022;
  --surface-hover: #212427;
  --surface-active: #292c2f;
  --text: #f1eee8;
  --text-2: #c3beb4;
  --muted: #a09b91;
  --faint: #8f8a80;
  --border: rgba(255, 255, 255, .075);
  --border-strong: rgba(255, 255, 255, .14);
  --accent: #e98d68;
  --accent-hover: #f2a07f;
  --accent-strong: #f0a17e;
  --on-accent: #23130c;
  --accent-soft: rgba(233, 141, 104, .11);
  --accent-border: rgba(233, 141, 104, .27);
  --user-bubble: #24211d;
  --user-bubble-border: rgba(255, 255, 255, .055);
  --link: #eea887;
  --code-bg: #0a0b0c;
  --code-inline-bg: #1b1e20;
  --code-head-bg: #141618;
  --focus: #91b6ff;
  --danger: #f09191;
  --danger-strong: #e06d6d;
  --on-danger: #2a0c0c;
  --danger-soft: rgba(240, 145, 145, .1);
  --success: #87caa4;
  --success-soft: rgba(135, 202, 164, .1);
  --warning: #e7be72;
  --warning-soft: rgba(231, 190, 114, .1);
  --code-key: #e3a4c8;
  --code-string: #a8cfa0;
  --code-number: #e8be83;
  --code-comment: #75786f;
  --code-tag: #e3a4c8;
  --code-attr: #e8be83;
  --code-func: #9ec6ed;
  --chart-bar: #d9835f;
  --chart-bar-hover: #f0a17e;
  --chart-grid: rgba(255, 255, 255, .07);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .45);
  --scrim: rgba(4, 5, 6, .64);
  --skeleton: linear-gradient(90deg, #1a1c1e 25%, #222527 50%, #1a1c1e 75%);
  --selection: rgba(233, 141, 104, .3);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f6f2;
  --bg-soft: #f2efe9;
  --sidebar-bg: #f3f0ea;
  --surface: #fffefc;
  --surface-2: #f7f4ef;
  --surface-hover: #efebe4;
  --surface-active: #e8e2d9;
  --text: #201e1a;
  --text-2: #4f4a43;
  --muted: #655f56;
  --faint: #736c62;
  --border: rgba(32, 30, 26, .1);
  --border-strong: rgba(32, 30, 26, .18);
  --accent: #b9542f;
  --accent-hover: #a54826;
  --accent-strong: #9d4322;
  --on-accent: #fffaf7;
  --accent-soft: #f7e8e0;
  --accent-border: rgba(185, 84, 47, .26);
  --user-bubble: #f1ece4;
  --user-bubble-border: rgba(32, 30, 26, .06);
  --link: #a24622;
  --code-bg: #f5f2ed;
  --code-inline-bg: #f0ece5;
  --code-head-bg: #ece8e1;
  --focus: #2563eb;
  --danger: #b3261e;
  --danger-strong: #941c16;
  --on-danger: #fff8f6;
  --danger-soft: rgba(179, 38, 30, .07);
  --success: #217a48;
  --success-soft: rgba(33, 122, 72, .08);
  --warning: #8a5a13;
  --warning-soft: rgba(138, 90, 19, .08);
  --code-key: #9b3f75;
  --code-string: #3e7340;
  --code-number: #9a6418;
  --code-comment: #8d877c;
  --code-tag: #9b3f75;
  --code-attr: #8a5a13;
  --code-func: #2c5d8f;
  --chart-bar: #c86a48;
  --chart-bar-hover: #a94d2c;
  --chart-grid: rgba(32, 30, 26, .08);
  --shadow-sm: 0 1px 2px rgba(44, 36, 28, .05);
  --shadow-md: 0 8px 26px rgba(44, 36, 28, .08);
  --shadow-lg: 0 24px 70px rgba(44, 36, 28, .16);
  --scrim: rgba(32, 28, 23, .38);
  --skeleton: linear-gradient(90deg, #f1ede6 25%, #f7f4ef 50%, #f1ede6 75%);
  --selection: rgba(185, 84, 47, .16);
}

/* 2. 基础与通用组件 ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
[hidden] { display: none !important; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--normal) ease, color var(--normal) ease;
}
::selection { background: var(--selection); }
img, svg { display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { flex: none; }
hr { border: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: 10px; left: 10px; z-index: 200; padding: 10px 16px;
  border-radius: var(--r-sm); background: var(--text); color: var(--bg);
  transform: translateY(-160%); transition: transform var(--fast) var(--ease);
}
.skip-link:focus { transform: none; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { width: 16px; height: 16px; }
.noscript {
  position: fixed; inset: 0; z-index: 300; display: grid; place-items: center;
  padding: 24px; background: var(--bg); color: var(--text); text-align: center;
}
.eyebrow {
  display: flex; align-items: center; gap: 8px; color: var(--muted);
  font-size: 12px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { border-radius: 9px; box-shadow: var(--shadow-sm); }
.brand-copy { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-copy strong { font-size: 14.5px; font-weight: 680; letter-spacing: -.015em; white-space: nowrap; }
.brand-copy small { margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 450; letter-spacing: .01em; white-space: nowrap; }
.brand--quiet { gap: 8px; color: var(--text-2); font-size: 14px; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text); font-size: 14px; font-weight: 600;
  line-height: 1; white-space: nowrap; user-select: none;
  transition: background-color var(--fast) ease, border-color var(--fast) ease,
    color var(--fast) ease, transform var(--fast) ease, box-shadow var(--fast) ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .48; transform: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: transparent; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }
.btn-ghost { border-color: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-strong); }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; gap: 5px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-lg { min-height: 48px; padding: 0 20px; border-radius: var(--r-md); font-size: 15px; }
.btn.is-loading .btn-label { opacity: .55; }
.btn.is-loading .spinner { display: block; }
.btn .spinner { display: none; }
.text-btn {
  padding: 2px; border: 0; background: none; color: var(--accent-strong);
  font-size: 12.5px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: none; padding: 0; border: 1px solid transparent;
  border-radius: var(--r-sm); background: transparent; color: var(--muted);
  transition: color var(--fast) ease, background-color var(--fast) ease, border-color var(--fast) ease;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:active { background: var(--surface-active); }
.icon-btn.bordered { border-color: var(--border); background: var(--surface); }
.icon-btn .icon { width: 18px; height: 18px; }
.spinner {
  width: 16px; height: 16px; flex: none; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner--dark { color: var(--on-accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.field-label, .form-field > label {
  display: block; margin-bottom: 7px; color: var(--text-2);
  font-size: 12.5px; font-weight: 600; letter-spacing: .01em;
}
.input, .select {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-size: 14px; outline: none;
  transition: border-color var(--fast) ease, box-shadow var(--fast) ease, background-color var(--fast) ease;
}
.input:hover, .select:hover { border-color: var(--faint); }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--faint); }
.select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.select-sm { min-height: 34px; width: auto; padding: 6px 34px 6px 10px; font-size: 12.5px; background-position: calc(100% - 16px) 14px, calc(100% - 11px) 14px; }
.password-field { position: relative; }
.password-field .input, .password-field input { padding-right: 46px; }
.password-field .pwd-toggle { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); width: 34px; height: 34px; }
.password-field .field-icon { position: absolute; left: 13px; top: 50%; width: 17px; height: 17px; color: var(--faint); transform: translateY(-50%); pointer-events: none; }
.password-field .field-icon + input { padding-left: 39px; }
.form-error { min-height: 20px; margin-top: 7px; color: var(--danger); font-size: 12.5px; line-height: 1.55; }
.form-field { min-width: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-hint { margin-top: 6px; color: var(--muted); font-size: 11.5px; line-height: 1.55; }
.input-suffix { position: relative; display: flex; align-items: center; }
.input-suffix input { padding-right: 64px; }
.input-suffix > span { position: absolute; right: 12px; color: var(--faint); font-size: 12px; pointer-events: none; }
.form-status { font-size: 12.5px; color: var(--muted); }
.form-status.is-ok { color: var(--success); }
.form-status.is-error { color: var(--danger); }

.boot-view {
  position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; background: var(--bg); color: var(--muted);
  font-size: 12.5px; letter-spacing: .04em;
}
.boot-view img { border-radius: 12px; animation: boot-pulse 1.8s var(--ease) infinite; }
.boot-dots { display: flex; gap: 5px; }
.boot-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); animation: dot-bounce 1.2s infinite ease-in-out; }
.boot-dots i:nth-child(2) { animation-delay: .15s; }
.boot-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes boot-pulse { 50% { transform: scale(.94); opacity: .72; } }
@keyframes dot-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes fade-in-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 3. 登录 ----------------------------------------------------------------- */
.login-view {
  position: relative; display: flex; min-height: 100dvh; flex-direction: column;
  align-items: center; justify-content: center; padding: 72px 20px 56px; overflow: hidden;
  background:
    radial-gradient(ellipse 900px 520px at 50% -8%, var(--accent-soft), transparent 70%),
    radial-gradient(ellipse 720px 460px at 85% 110%, rgba(125, 144, 255, .045), transparent 70%),
    var(--bg);
}
.login-view::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .32;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000, transparent 78%);
}
.login-topline {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center;
  justify-content: space-between; padding: 24px 28px; z-index: 1;
}
.login-card {
  position: relative; z-index: 1; width: min(100%, 430px); padding: 36px 36px 26px;
  border: 1px solid var(--border); border-radius: 24px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow-lg); backdrop-filter: blur(16px); animation: fade-in-up .4s var(--ease) both;
}
.login-mark { margin-bottom: 24px; border-radius: 14px; box-shadow: var(--shadow-md); }
.login-card h1 { margin-top: 12px; font-size: clamp(27px, 4vw, 32px); font-weight: 680; letter-spacing: -.035em; line-height: 1.18; }
.login-lede { margin: 9px 0 28px; color: var(--muted); font-size: 13.5px; line-height: 1.65; }
.login-card .password-field input {
  width: 100%; height: 48px; border: 1px solid var(--border-strong); border-radius: 11px;
  background: var(--surface-2); color: var(--text); outline: none; padding: 0 48px 0 40px;
  font-size: 15px; letter-spacing: .09em; transition: border-color var(--fast) ease, box-shadow var(--fast) ease;
}
.login-card .password-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--surface); }
.login-card .password-field input::placeholder { letter-spacing: 0; color: var(--faint); }
.login-card .pwd-toggle { right: 7px; width: 36px; height: 36px; }
.login-submit { width: 100%; margin-top: 3px; }
.login-foot {
  display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 26px;
  padding-top: 18px; border-top: 1px solid var(--border); color: var(--faint);
  font-size: 11px; line-height: 1.55; text-align: center;
}
.login-foot .icon { width: 13px; height: 13px; color: var(--success); }
.login-copyright { position: relative; z-index: 1; margin-top: 28px; color: var(--faint); font-size: 11px; letter-spacing: .03em; }
.is-shaking { animation: shake .42s ease both; }
@keyframes shake {
  0%, 100% { transform: translateX(0); } 18% { transform: translateX(-8px); }
  36% { transform: translateX(7px); } 54% { transform: translateX(-5px); } 72% { transform: translateX(3px); }
}

/* 4. 聊天布局 ------------------------------------------------------------- */
.app { position: relative; display: flex; width: 100%; height: 100dvh; overflow: hidden; background: var(--bg); }
.sidebar {
  position: relative; z-index: var(--z-sidebar); display: flex; flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w); flex-direction: column; min-height: 0;
  border-right: 1px solid var(--border); background: var(--sidebar-bg);
  transition: margin-left var(--normal) var(--ease), transform var(--normal) var(--ease), opacity var(--normal) ease;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 20px 16px 14px 18px; }
.sidebar-close { display: none; }
.sidebar-foot { flex: none; margin-top: auto; padding: 10px 12px max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.sidebar-link {
  display: flex; align-items: center; gap: 9px; margin-bottom: 8px; padding: 9px 10px;
  border-radius: var(--r-sm); color: var(--text-2); font-size: 12.5px; font-weight: 550;
  transition: background-color var(--fast) ease, color var(--fast) ease;
}
.sidebar-link:hover { background: var(--surface-hover); color: var(--text); }
.sidebar-link .icon { width: 16px; height: 16px; color: var(--muted); }
.role-badge {
  margin-left: auto; padding: 1px 6px; border: 1px solid var(--accent-border); border-radius: 5px;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 9px;
  font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.account-row { display: flex; align-items: center; gap: 9px; padding: 7px 6px 0; }
.account-avatar {
  display: grid; place-items: center; width: 31px; height: 31px; flex: none;
  border: 1px solid var(--border-strong); border-radius: 50%;
  background: var(--surface-2); color: var(--text-2); font-size: 11px; font-weight: 650;
}
.account-meta { display: flex; flex: 1; min-width: 0; flex-direction: column; line-height: 1.35; }
.account-meta strong { overflow: hidden; color: var(--text-2); font-size: 11.5px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.account-meta small { color: var(--faint); font-size: 10px; }
.account-row .icon-btn { width: 31px; height: 31px; }
.account-row .icon-btn .icon { width: 16px; height: 16px; }
.new-chat-btn {
  display: flex; align-items: center; gap: 9px; margin: 0 12px 18px; padding: 10px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-sm); transition: background-color var(--fast) ease, border-color var(--fast) ease, transform var(--fast) ease;
}
.new-chat-btn:hover { background: var(--surface-hover); border-color: var(--faint); }
.new-chat-btn:active { transform: translateY(1px); }
.new-chat-btn .icon { width: 17px; height: 17px; color: var(--muted); }
.shortcut { margin-left: auto; padding: 2px 5px; border: 1px solid var(--border); border-radius: 5px; color: var(--faint); font-family: var(--font-mono); font-size: 9.5px; font-weight: 400; }
.conversation-section { display: flex; flex: 1; min-height: 0; flex-direction: column; padding: 0 8px; }
.section-label {
  display: flex; align-items: center; justify-content: space-between; padding: 0 9px 8px;
  color: var(--faint); font-size: 11px; font-weight: 650; letter-spacing: .075em; text-transform: uppercase;
}
.section-count { min-width: 16px; padding: 1px 4px; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 9.5px; text-align: center; letter-spacing: 0; }
.conversation-list { overflow-x: hidden; overflow-y: auto; padding-bottom: 10px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-thumb { border-radius: 4px; background: var(--border-strong); }
.conv-group-label { padding: 13px 9px 5px; color: var(--faint); font-size: 10px; font-weight: 600; letter-spacing: .05em; }
.conversation-item {
  position: relative; display: flex; align-items: center; min-height: 39px;
  margin: 1px 0; border-radius: var(--r-sm); color: var(--text-2);
  transition: background-color var(--fast) ease, color var(--fast) ease;
}
.conversation-item:hover { background: var(--surface-hover); color: var(--text); }
.conversation-item.is-active { background: var(--surface-active); color: var(--text); }
.conversation-item.is-active::before {
  content: ""; position: absolute; left: 0; top: 11px; bottom: 11px; width: 2px;
  border-radius: 2px; background: var(--accent);
}
.conv-main {
  display: flex; flex: 1; min-width: 0; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 7px 10px 7px 12px; border: 0; border-radius: var(--r-sm); background: none;
  color: inherit; text-align: left;
}
.conv-title { display: block; width: 100%; overflow: hidden; font-size: 13px; font-weight: 520; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item.is-active .conv-title { font-weight: 590; }
.conv-meta { max-width: 100%; overflow: hidden; color: var(--faint); font-size: 10.5px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.conv-actions { display: flex; flex: none; gap: 0; padding-right: 4px; opacity: 0; transition: opacity var(--fast) ease; }
.conversation-item:hover .conv-actions, .conversation-item:focus-within .conv-actions { opacity: 1; }
.conv-action {
  display: grid; place-items: center; width: 25px; height: 25px; padding: 0; border: 0;
  border-radius: 5px; background: transparent; color: var(--muted);
}
.conv-action:hover { background: var(--surface-2); color: var(--text); }
.conv-action .icon { width: 13px; height: 13px; }
.conv-action--danger:hover { color: var(--danger); }
.conv-rename-form { flex: 1; min-width: 0; padding: 5px 7px 5px 10px; }
.conv-rename-input {
  width: 100%; height: 28px; padding: 3px 7px; border: 1px solid var(--accent);
  border-radius: 5px; background: var(--bg); color: var(--text); font-size: 12.5px; outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.conversation-empty { display: flex; flex-direction: column; align-items: flex-start; padding: 18px 10px; color: var(--faint); }
.conversation-empty .icon { width: 16px; height: 16px; margin-bottom: 8px; color: var(--muted); }
.conversation-empty p { color: var(--text-2); font-size: 12px; font-weight: 550; }
.conversation-empty span { margin-top: 2px; font-size: 10.5px; line-height: 1.5; }
.sidebar-scrim { display: none; }
.app.sidebar-collapsed .sidebar { margin-left: calc(var(--sidebar-w) * -1); opacity: 0; pointer-events: none; }

.main { position: relative; display: flex; flex: 1; min-width: 0; flex-direction: column; overflow: hidden; }
.topbar {
  position: relative; z-index: 20; display: flex; flex: none; align-items: center;
  justify-content: space-between; gap: 16px; height: var(--topbar-h); padding: 0 22px;
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(14px);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-left { flex: 1; }
.topbar-right { flex: none; }
.topbar .icon-btn { color: var(--muted); }
.chat-heading { min-width: 0; padding-left: 2px; }
.chat-kicker { display: block; color: var(--faint); font-size: 9.5px; font-weight: 600; letter-spacing: .075em; text-transform: uppercase; line-height: 1.2; }
.chat-title { overflow: hidden; max-width: 46vw; margin-top: 2px; color: var(--text); font-size: 13.5px; font-weight: 560; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.quota-pill {
  display: flex; align-items: center; gap: 7px; min-height: 29px; padding: 4px 10px 4px 7px;
  border: 1px solid var(--border); border-radius: var(--r-full); background: var(--surface);
  color: var(--text-2); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.quota-ring {
  width: 15px; height: 15px; flex: none; border-radius: 50%;
  background: conic-gradient(var(--success) calc(var(--quota-ratio, 1) * 1turn), var(--border-strong) 0);
  -webkit-mask: radial-gradient(circle, transparent 55%, #000 57%);
  mask: radial-gradient(circle, transparent 55%, #000 57%);
}
.quota-pill.is-low { color: var(--warning); }
.quota-pill.is-low .quota-ring { background: conic-gradient(var(--warning) calc(var(--quota-ratio, .1) * 1turn), var(--border-strong) 0); }
.quota-pill.is-empty { color: var(--danger); }
.quota-pill.is-empty .quota-ring { background: var(--danger); }
.quota-pill.is-loading .quota-ring { background: var(--border-strong); animation: soft-pulse 1.4s ease infinite; }
@keyframes soft-pulse { 50% { opacity: .45; } }
.messages-scroller { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.messages-scroller::-webkit-scrollbar { width: 8px; }
.messages-scroller::-webkit-scrollbar-thumb { border: 2px solid var(--bg); border-radius: 8px; background: var(--border-strong); }
.messages { display: flex; width: min(100%, var(--content-w)); margin: 0 auto; padding: 34px 24px 22px; flex-direction: column; gap: 30px; }

/* 5. 欢迎、消息与 Markdown ------------------------------------------------ */
.welcome { position: relative; display: flex; flex-direction: column; align-items: center; padding: clamp(28px, 7vh, 76px) 0 10px; text-align: center; animation: fade-in-up .4s var(--ease) both; }
.welcome-orbit { position: absolute; top: -32px; left: 50%; width: min(560px, 84vw); color: var(--faint); transform: translateX(-50%); opacity: .3; pointer-events: none; }
.welcome-mark { position: relative; margin-bottom: 18px; border-radius: 15px; box-shadow: var(--shadow-md); }
.welcome h2 { position: relative; margin-top: 8px; font-size: clamp(25px, 3.3vw, 34px); font-weight: 660; letter-spacing: -.035em; line-height: 1.24; }
.welcome-sub { position: relative; max-width: 460px; margin-top: 9px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.suggestion-grid { position: relative; display: grid; width: 100%; max-width: 690px; margin-top: 28px; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.suggestion-card {
  display: flex; align-items: flex-start; gap: 12px; min-height: 82px; padding: 14px 14px 14px 13px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
  color: var(--text-2); text-align: left; box-shadow: var(--shadow-sm);
  transition: transform var(--fast) var(--ease), border-color var(--fast) ease, background-color var(--fast) ease, color var(--fast) ease;
}
.suggestion-card:hover { transform: translateY(-2px); border-color: var(--accent-border); background: var(--surface-hover); color: var(--text); }
.suggestion-card:active { transform: translateY(0); }
.suggestion-icon {
  display: grid; place-items: center; width: 29px; height: 29px; flex: none;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); color: var(--accent-strong);
}
.suggestion-icon .icon { width: 15px; height: 15px; }
.suggestion-copy { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.suggestion-copy strong { color: var(--text); font-size: 12.5px; font-weight: 600; line-height: 1.4; }
.suggestion-copy span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.welcome-tip { margin-top: 22px; color: var(--faint); font-size: 10.5px; letter-spacing: .015em; }
.messages-loading { display: flex; flex-direction: column; gap: 22px; padding: 14px 0; }
.skeleton-msg { display: flex; gap: 13px; }
.skeleton-avatar { width: 30px; height: 30px; flex: none; border-radius: 8px; background: var(--skeleton); background-size: 200% 100%; animation: shimmer 1.5s infinite linear; }
.skeleton-lines { display: flex; flex: 1; flex-direction: column; gap: 9px; padding-top: 3px; }
.skeleton-line { height: 11px; max-width: 620px; border-radius: 4px; background: var(--skeleton); background-size: 200% 100%; animation: shimmer 1.5s infinite linear; }
.skeleton-line:nth-child(2) { width: 76%; animation-delay: .1s; }
.skeleton-line:nth-child(3) { width: 48%; animation-delay: .2s; }
@keyframes shimmer { to { background-position: -200% 0; } }

.message { display: flex; gap: 13px; align-items: flex-start; animation: fade-in-up .32s var(--ease) both; }
.message--user { justify-content: flex-end; }
.message-avatar {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none; margin-top: 2px;
  overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.message-avatar img { width: 19px; height: 19px; border-radius: 5px; }
.message-avatar .icon { width: 16px; height: 16px; color: var(--accent-strong); }
.message-body { min-width: 0; max-width: 100%; }
.message--assistant .message-body { flex: 1; padding-top: 3px; }
.assistant-name { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; color: var(--text-2); font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.assistant-name .ai-badge { padding: 1px 5px; border: 1px solid var(--border); border-radius: 4px; color: var(--faint); font-size: 8.5px; font-weight: 600; letter-spacing: .06em; }
.message--user .message-body { display: flex; max-width: min(82%, 640px); flex-direction: column; align-items: flex-end; }
.user-bubble {
  max-width: 100%; padding: 11px 15px; border: 1px solid var(--user-bubble-border);
  border-radius: 17px 17px 5px 17px; background: var(--user-bubble); color: var(--text);
  box-shadow: var(--shadow-sm);
}
.user-bubble .markdown { font-size: 15px; line-height: 1.65; }
.user-bubble .markdown > :last-child { margin-bottom: 0; }
.user-meta { display: flex; align-items: center; gap: 6px; margin-top: 5px; padding-right: 4px; color: var(--faint); font-size: 10.5px; }
.message-attachments { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-bottom: 6px; }
.message-file {
  display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 5px 9px 5px 7px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text-2);
  font-size: 10.5px;
}
.message-file .icon { width: 13px; height: 13px; color: var(--muted); }
.message-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-file small { flex: none; color: var(--faint); font-size: 9px; }
.assistant-actions { display: flex; align-items: center; gap: 2px; margin-top: 7px; opacity: 0; transition: opacity var(--fast) ease; }
.message:hover .assistant-actions, .message:focus-within .assistant-actions, .assistant-actions.is-ready { opacity: 1; }
.assistant-actions { gap: 2px; min-height: 26px; }
.assistant-action-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 7px;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
  color: var(--muted); font-size: 11px; font-weight: 500;
  transition: color var(--fast) ease, background-color var(--fast) ease, border-color var(--fast) ease;
}
.assistant-action-btn:hover { background: var(--surface-hover); color: var(--text); }
.assistant-action-btn .icon { width: 13px; height: 13px; }
.message-error {
  display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: var(--r-sm);
  background: var(--danger-soft); color: var(--danger); font-size: 11.5px; line-height: 1.55;
}
.message-error .icon { width: 14px; height: 14px; margin-top: 1px; }
.stream-cursor {
  display: inline-block; width: 6px; height: 1.1em; margin-left: 2px; vertical-align: -2px;
  border-radius: 1px; background: var(--accent); animation: cursor-blink .9s steps(2, end) infinite;
}
@keyframes cursor-blink { 0%, 45% { opacity: 1; } 46%, 100% { opacity: 0; } }
.thinking { display: flex; align-items: center; gap: 9px; min-height: 25px; color: var(--muted); font-size: 12px; }
.typing-dots { display: inline-flex; align-items: center; gap: 3px; height: 16px; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); animation: typing 1.15s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: .14s; }
.typing-dots i:nth-child(3) { animation-delay: .28s; }
@keyframes typing { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.stop-note { margin-top: 8px; color: var(--faint); font-size: 10.5px; }

.markdown { min-width: 0; color: var(--text); font-size: 15px; line-height: 1.76; overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0 !important; }
.markdown > :last-child { margin-bottom: 0 !important; }
.markdown p { margin: 0 0 .9em; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 { margin: 1.4em 0 .55em; color: var(--text); font-weight: 650; line-height: 1.35; letter-spacing: -.018em; }
.markdown h1 { font-size: 1.42em; }
.markdown h2 { font-size: 1.24em; }
.markdown h3 { font-size: 1.1em; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 1em; }
.markdown strong { font-weight: 650; color: var(--text); }
.markdown em { font-style: italic; }
.markdown del { color: var(--muted); }
.markdown a { color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 45%, transparent); text-underline-offset: 3px; transition: color var(--fast) ease; }
.markdown a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }
.markdown ul, .markdown ol { margin: 0 0 .95em; padding-left: 1.45em; }
.markdown li { margin: .2em 0; padding-left: .15em; }
.markdown li > p { margin-bottom: .35em; }
.markdown li > ul, .markdown li > ol { margin-top: .3em; margin-bottom: .3em; }
.markdown li::marker { color: var(--muted); }
.markdown li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.25em; }
.markdown input[type="checkbox"] { width: 13px; height: 13px; margin: 0 6px 0 0; border-radius: 3px; accent-color: var(--accent); vertical-align: -1px; }
.markdown blockquote {
  margin: 0 0 1em; padding: 2px 0 2px 14px; border-left: 2px solid var(--accent-border);
  color: var(--text-2);
}
.markdown blockquote p:last-child { margin-bottom: 0; }
.markdown hr { height: 1px; margin: 1.4em 0; border: 0; background: var(--border); }
.markdown code { font-family: var(--font-mono); font-size: .86em; }
.markdown :not(pre) > code {
  padding: .15em .38em; border: 1px solid var(--border); border-radius: 5px;
  background: var(--code-inline-bg); color: var(--text); white-space: break-spaces;
}
.code-block { margin: 1em 0; overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; height: 34px; padding: 0 7px 0 12px; border-bottom: 1px solid var(--border); background: var(--code-head-bg); }
.code-lang { color: var(--muted); font-family: var(--font-mono); font-size: 10px; letter-spacing: .04em; text-transform: lowercase; }
.code-copy {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 7px; border: 0; border-radius: 5px;
  background: transparent; color: var(--muted); font-size: 10px;
  transition: background-color var(--fast) ease, color var(--fast) ease;
}
.code-copy:hover { background: var(--surface-hover); color: var(--text); }
.code-copy .icon { width: 12px; height: 12px; }
.code-block pre { margin: 0; padding: 13px 15px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.code-block pre code { display: block; min-width: max-content; color: var(--text-2); font-size: 12.5px; line-height: 1.65; white-space: pre; tab-size: 2; }
.code-block pre code .tok-comment { color: var(--code-comment); font-style: italic; }
.code-block pre code .tok-string { color: var(--code-string); }
.code-block pre code .tok-number, .code-block pre code .tok-literal { color: var(--code-number); }
.code-block pre code .tok-key { color: var(--code-key); font-weight: 500; }
.code-block pre code .tok-tag { color: var(--code-tag); }
.code-block pre code .tok-attr { color: var(--code-attr); }
.code-block pre code .tok-func, .code-block pre code .tok-builtin { color: var(--code-func); }
.md-table-wrap { margin: 1em 0; overflow-x: auto; border: 1px solid var(--border); border-radius: 9px; }
.markdown table { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 1.55; }
.markdown th, .markdown td { padding: 8px 11px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.markdown th { background: var(--surface-2); color: var(--text-2); font-size: 11.5px; font-weight: 650; letter-spacing: .01em; }
.markdown tr:last-child td { border-bottom: 0; }
.markdown tbody tr:hover { background: color-mix(in srgb, var(--surface) 55%, transparent); }

.scroll-bottom-btn {
  position: absolute; left: 50%; z-index: 15; display: flex; align-items: center; gap: 6px;
  bottom: calc(var(--composer-height, 166px) + 12px); padding: 7px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  background: var(--surface); color: var(--text-2); font-size: 11px; font-weight: 550;
  box-shadow: var(--shadow-md); transform: translateX(-50%);
  transition: opacity var(--fast) ease, transform var(--fast) var(--ease), background-color var(--fast) ease;
}
.scroll-bottom-btn:hover { background: var(--surface-hover); color: var(--text); }
.scroll-bottom-btn .icon { width: 14px; height: 14px; }

/* 6. 输入区 --------------------------------------------------------------- */
.composer-wrap {
  position: relative; z-index: 10; flex: none; padding: 2px 24px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 55%, color-mix(in srgb, var(--bg) 80%, transparent) 82%, transparent);
}
.composer {
  position: relative; width: min(100%, var(--content-w)); margin: 0 auto; padding: 9px 10px 9px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-xl); background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .025) inset, var(--shadow-md);
  transition: border-color var(--fast) ease, box-shadow var(--fast) ease;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 58%, var(--border-strong)); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-md); }
.composer-top { display: flex; align-items: center; justify-content: space-between; min-height: 26px; gap: 10px; }
.composer-mode { overflow: hidden; padding-right: 4px; color: var(--faint); font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.composer-mode.is-active { color: var(--accent-strong); }
.model-picker {
  position: relative; display: inline-flex; align-items: center; gap: 5px; min-width: 0;
  padding: 3px 5px 3px 6px; border-radius: var(--r-xs); color: var(--muted);
  transition: background-color var(--fast) ease, color var(--fast) ease;
}
.model-picker:hover { background: var(--surface-hover); color: var(--text); }
.model-picker .icon { width: 14px; height: 14px; color: var(--accent-strong); }
.model-picker .model-chevron { width: 12px; height: 12px; margin-left: -1px; color: var(--faint); pointer-events: none; }
.model-picker-label { color: var(--faint); font-size: 10px; font-weight: 600; letter-spacing: .02em; }
.model-picker select {
  max-width: 220px; min-width: 40px; padding: 1px 16px 1px 1px; border: 0;
  appearance: none; background: transparent; color: var(--text-2); font-size: 11.5px;
  font-weight: 550; outline: none; cursor: pointer; text-overflow: ellipsis;
}
.model-picker select option { background: var(--surface); color: var(--text); }
.attachment-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 5px 2px 3px; }
.attachment-chip {
  position: relative; display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 250px;
  padding: 5px 7px 5px 5px; overflow: hidden; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface-2);
}
.attachment-thumb { display: grid; place-items: center; width: 31px; height: 31px; flex: none; overflow: hidden; border-radius: 6px; background: var(--bg-soft); color: var(--muted); }
.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment-thumb .icon { width: 15px; height: 15px; }
.attachment-info { display: flex; min-width: 0; flex-direction: column; gap: 1px; }
.attachment-name { overflow: hidden; max-width: 150px; color: var(--text-2); font-size: 10.5px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.attachment-size { color: var(--faint); font-size: 9px; }
.attachment-remove { display: grid; place-items: center; width: 22px; height: 22px; flex: none; margin-left: 2px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--faint); }
.attachment-remove:hover { background: var(--surface-hover); color: var(--danger); }
.attachment-remove .icon { width: 12px; height: 12px; }
.suggestion-card:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.suggestion-card:disabled:hover { border-color: var(--border); background: var(--surface); }
.load-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px;
  min-height: 320px; padding: 50px 20px; text-align: center;
}
.load-state-icon {
  display: grid; place-items: center; width: 42px; height: 42px; margin-bottom: 3px;
  border-radius: 12px; background: var(--danger-soft); color: var(--danger);
}
.load-state-icon .icon { width: 20px; height: 20px; }
.load-state h2 { font-size: 17px; font-weight: 640; letter-spacing: -.02em; }
.load-state p { max-width: 380px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.load-state .btn { margin-top: 9px; }
.attachment-chip.is-error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.attachment-progress { position: absolute; right: 0; bottom: 0; left: 0; height: 2px; background: var(--border); }
.attachment-progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 120ms linear; }
.composer-input {
  display: block; width: 100%; min-height: 52px; max-height: 200px; padding: 8px 3px 3px;
  overflow-y: auto; border: 0; background: transparent; color: var(--text);
  font-size: 15px; line-height: 1.65; outline: none; resize: none;
}
.composer-input::placeholder { color: var(--faint); }
.composer-input:disabled { cursor: not-allowed; }
.composer-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; min-height: 38px; padding-top: 2px; }
.composer-tools { display: flex; align-items: center; gap: 7px; min-width: 0; }
.attach-btn { width: 32px; height: 32px; border-radius: 7px; }
.attach-btn .icon { width: 17px; height: 17px; }
.composer-hint-inline { color: var(--faint); font-size: 10.5px; white-space: nowrap; }
.send-wrap { display: flex; align-items: center; gap: 9px; }
.enter-hint { color: var(--faint); font-size: 10px; white-space: nowrap; }
.send-btn {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none; padding: 0;
  border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent);
  box-shadow: var(--shadow-sm); transition: background-color var(--fast) ease, opacity var(--fast) ease, transform var(--fast) ease;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:active:not(:disabled) { transform: scale(.95); }
.send-btn:disabled { cursor: not-allowed; opacity: .35; }
.send-btn .icon { width: 18px; height: 18px; stroke-width: 2; }
.send-btn .stop-icon { display: none; }
.send-btn .spinner { display: none; width: 15px; height: 15px; }
.send-btn.is-busy .send-icon { display: none; }
.send-btn.is-busy .stop-icon { display: block; }
.send-btn.is-busy .spinner { display: block; }
.composer.is-stop-mode .send-btn { background: var(--danger); color: var(--on-danger); opacity: 1; }
.composer.is-stop-mode .send-btn .send-icon { display: none; }
.composer.is-stop-mode .send-btn .stop-icon { display: block; width: 15px; height: 15px; }
.composer-footnote {
  width: min(100%, var(--content-w)); margin: 7px auto 0; color: var(--faint);
  font-size: 10px; line-height: 1.5; text-align: center;
}
.quota-notice {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: min(100%, var(--content-w)); margin: 0 auto 8px; padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: var(--r-sm);
  background: var(--danger-soft); color: var(--danger); font-size: 11.5px;
}
.quota-notice .icon { width: 14px; height: 14px; }
.drop-overlay {
  position: absolute; inset: 0; z-index: var(--z-overlay); display: grid; place-items: center;
  padding: 24px; background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(8px); pointer-events: none;
}
.drop-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(420px, 90%);
  padding: 34px 28px; border: 1.5px dashed var(--accent-border); border-radius: var(--r-xl);
  background: var(--surface); box-shadow: var(--shadow-lg); text-align: center;
}
.drop-card .icon { width: 30px; height: 30px; color: var(--accent); }
.drop-card strong { font-size: 15px; }
.drop-card span { color: var(--muted); font-size: 11.5px; line-height: 1.6; }

/* 7. 浮层与反馈 ----------------------------------------------------------- */
.toast-region {
  position: fixed; right: 18px; top: calc(var(--topbar-h) + 12px); z-index: var(--z-toast);
  display: flex; width: min(360px, calc(100vw - 36px)); flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 9px; padding: 11px 12px;
  border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface);
  color: var(--text-2); font-size: 12px; line-height: 1.55; box-shadow: var(--shadow-lg);
  pointer-events: auto; animation: toast-in .25s var(--ease) both;
}
.toast.is-leaving { animation: toast-out .18s ease both; }
.toast .toast-icon { width: 16px; height: 16px; margin-top: 1px; flex: none; color: var(--accent); }
.toast--success .toast-icon { color: var(--success); }
.toast--error .toast-icon { color: var(--danger); }
.toast--warning .toast-icon { color: var(--warning); }
.toast-message { flex: 1; min-width: 0; }
.toast-close { display: grid; place-items: center; width: 20px; height: 20px; flex: none; margin: -2px -2px 0 1px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--faint); }
.toast-close:hover { background: var(--surface-hover); color: var(--text); }
.toast-close .icon { width: 12px; height: 12px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px) scale(.98); } }
.confirm-dialog {
  position: fixed; inset: 0; width: min(390px, calc(100vw - 32px)); height: fit-content;
  max-height: calc(100dvh - 32px); margin: auto; padding: 0; overflow: visible;
  border: 0; border-radius: var(--r-lg); background: transparent; color: var(--text);
}
.confirm-dialog::backdrop { background: var(--scrim); backdrop-filter: blur(4px); }
.dialog-card {
  padding: 24px; border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-lg); animation: dialog-in .22s var(--ease) both;
}
.dialog-icon { display: grid; place-items: center; width: 38px; height: 38px; margin-bottom: 13px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); }
.dialog-icon .icon { width: 19px; height: 19px; }
.dialog-card h2 { font-size: 17px; font-weight: 650; letter-spacing: -.015em; }
.dialog-card p { margin-top: 7px; color: var(--muted); font-size: 12.5px; line-height: 1.65; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.dialog-actions .btn { min-height: 38px; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* 8. 管理后台 ------------------------------------------------------------- */
.page-admin { background: var(--bg-soft); }
.admin-shell { min-height: 100dvh; }
.admin-topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; min-height: 62px; padding: 0 max(24px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(14px);
}
.admin-topbar-left, .admin-topbar-right { display: flex; align-items: center; gap: 13px; min-width: 0; }
.topbar-divider { width: 1px; height: 20px; background: var(--border-strong); }
.admin-page-label { color: var(--muted); font-size: 12px; font-weight: 550; }
.admin-main { width: min(100% - 48px, 1180px); margin: 0 auto; padding: 40px 0 30px; }
.admin-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.admin-page-head h1 { margin-top: 8px; font-size: clamp(26px, 3.2vw, 33px); font-weight: 680; letter-spacing: -.035em; line-height: 1.2; }
.page-lede { margin-top: 8px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.admin-head-actions { display: flex; align-items: center; gap: 12px; padding-bottom: 2px; }
.last-updated { color: var(--faint); font-size: 10.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card { padding: 17px 17px 15px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11.5px; font-weight: 550; }
.stat-icon { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--bg-soft); color: var(--accent-strong); }
.stat-icon .icon { width: 14px; height: 14px; }
.stat-value { display: block; margin-top: 9px; color: var(--text); font-size: clamp(23px, 2.6vw, 29px); font-weight: 650; letter-spacing: -.035em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-value.is-small { font-size: 22px; padding-top: 3px; }
.stat-foot { margin-top: 6px; color: var(--faint); font-size: 10.5px; }
.stat-foot span { color: var(--text-2); font-weight: 550; }
.panel { margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 19px 13px; }
.panel-head h2 { color: var(--text); font-size: 14px; font-weight: 630; letter-spacing: -.01em; line-height: 1.4; }
.panel-sub { margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.panel-title-group { display: flex; align-items: flex-start; gap: 10px; }
.panel-icon { display: grid; place-items: center; width: 29px; height: 29px; flex: none; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); color: var(--accent-strong); }
.panel-icon .icon { width: 15px; height: 15px; }
.panel-actions { display: flex; align-items: center; gap: 7px; }
.segmented { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); }
.segment { padding: 5px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 10.5px; font-weight: 550; transition: color var(--fast) ease, background-color var(--fast) ease, box-shadow var(--fast) ease; }
.segment:hover { color: var(--text); }
.segment.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.chart-panel { padding-bottom: 12px; }
.chart-stage { position: relative; min-height: 250px; padding: 8px 18px 0; }
.chart-canvas { position: relative; width: 100%; min-height: 240px; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-axis text { fill: var(--faint); font-family: var(--font-sans); font-size: 10px; }
.chart-grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart-bar { fill: var(--chart-bar); transition: fill var(--fast) ease, opacity var(--fast) ease; rx: 4; }
.bar-group { cursor: default; outline: none; }
.bar-group:hover .chart-bar, .bar-group:focus-visible .chart-bar { fill: var(--chart-bar-hover); }
.bar-group:focus-visible .chart-bar { stroke: var(--text); stroke-width: 1.4; }
.chart-value-label { fill: var(--text-2); font-family: var(--font-sans); font-size: 9px; font-variant-numeric: tabular-nums; opacity: 0; transition: opacity var(--fast) ease; }
.bar-group:hover .chart-value-label, .bar-group:focus-visible .chart-value-label { opacity: 1; }
.chart-empty, .chart-loading { display: flex; min-height: 240px; flex-direction: column; align-items: center; justify-content: center; gap: 9px; color: var(--faint); font-size: 11.5px; text-align: center; }
.chart-loading { flex-direction: row; gap: 8px; }
.chart-loading .spinner { width: 14px; height: 14px; color: var(--accent); }
.chart-empty .icon { width: 25px; height: 25px; color: var(--muted); }
.chart-empty p { color: var(--text-2); font-size: 12px; font-weight: 550; }
.chart-empty span { font-size: 10.5px; }
.chart-meta { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 4px 19px 5px; color: var(--faint); font-size: 10px; }
.chart-tip {
  position: absolute; z-index: 5; display: flex; width: 164px; flex-direction: column; gap: 3px;
  padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); box-shadow: var(--shadow-md); pointer-events: none;
}
.chart-tip strong { color: var(--text); font-size: 10.5px; font-weight: 600; }
.chart-tip span { color: var(--muted); font-size: 9.5px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.table-loading-cell { height: 120px; color: var(--faint); font-size: 11px; text-align: center; }
.table-loading-cell .spinner { display: inline-block; width: 13px; height: 13px; margin-right: 7px; vertical-align: -2px; color: var(--accent); }
.btn.is-loading .spinner { display: block; }
.btn.is-loading .icon { animation: spin 1s linear infinite; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 7px; height: 7px; border-radius: 2px; background: var(--chart-bar); }
.chart-total { font-variant-numeric: tabular-nums; }
.logs-panel .panel-head { padding-bottom: 14px; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--border); }
.logs-table { width: 100%; min-width: 750px; border-collapse: collapse; font-size: 11.5px; }
.logs-table th { padding: 9px 14px; border-bottom: 1px solid var(--border); background: var(--bg-soft); color: var(--faint); font-size: 9.5px; font-weight: 600; letter-spacing: .035em; text-align: left; white-space: nowrap; }
.logs-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text-2); vertical-align: middle; white-space: nowrap; }
.logs-table tbody tr { transition: background-color var(--fast) ease; }
.logs-table tbody tr:hover { background: var(--surface-2); }
.logs-table tbody tr:last-child td { border-bottom: 0; }
.logs-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.logs-table .mono { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: -.01em; }
.logs-table .td-time { color: var(--text-2); font-variant-numeric: tabular-nums; }
.logs-table .td-ip { color: var(--muted); }
.model-chip { display: inline-block; max-width: 150px; overflow: hidden; padding: 2px 6px; border: 1px solid var(--border); border-radius: 4px; color: var(--text-2); font-family: var(--font-mono); font-size: 9.5px; text-overflow: ellipsis; vertical-align: middle; }
.status-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 4px; font-size: 9.5px; font-weight: 550; }
.status-chip::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
.status-chip.is-ok { background: var(--success-soft); color: var(--success); }
.status-chip.is-fail { background: var(--danger-soft); color: var(--danger); }
.table-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; min-height: 160px; color: var(--faint); font-size: 11px; }
.table-empty .icon { width: 23px; height: 23px; color: var(--muted); }
.table-empty p { color: var(--text-2); font-size: 12px; }
.table-empty .form-status { max-width: 80%; text-align: center; }
.logs-foot { display: flex; align-items: center; justify-content: space-between; min-height: 38px; padding: 0 18px; border-top: 1px solid var(--border); color: var(--faint); font-size: 10px; }
.settings-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; align-items: start; }
.settings-panel { margin-bottom: 0; }
.settings-form { display: flex; flex-direction: column; gap: 15px; padding: 2px 19px 19px; }
.settings-form .form-field > label { font-size: 11.5px; }
.settings-form .input, .settings-form .select { min-height: 39px; font-size: 13px; }
.settings-form .form-status { font-size: 11.5px; }
.form-actions { display: flex; align-items: center; gap: 12px; padding-top: 2px; min-height: 38px; }
.form-actions .btn { min-height: 38px; }
.security-note { display: flex; align-items: flex-start; gap: 8px; margin: 0 19px 19px; padding: 10px 11px; border-radius: 7px; background: var(--bg-soft); color: var(--muted); font-size: 10.5px; line-height: 1.55; }
.security-note .icon { width: 14px; height: 14px; margin-top: 1px; color: var(--success); }
.admin-foot { display: flex; justify-content: space-between; gap: 14px; padding: 6px 2px 12px; color: var(--faint); font-size: 10px; }
.admin-denied { display: flex; min-height: 100dvh; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(ellipse 700px 400px at 50% 20%, var(--accent-soft), transparent 70%), var(--bg); }
.denied-card { width: min(100%, 430px); padding: 32px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-lg); text-align: center; }
.denied-icon { display: grid; place-items: center; width: 46px; height: 46px; margin: 0 auto 18px; border: 1px solid var(--accent-border); border-radius: 13px; background: var(--accent-soft); color: var(--accent-strong); }
.denied-icon .icon { width: 23px; height: 23px; }
.denied-card .eyebrow { justify-content: center; }
.denied-card h1 { margin-top: 9px; font-size: 26px; letter-spacing: -.03em; }
.denied-card > p:not(.eyebrow) { margin-top: 9px; color: var(--muted); font-size: 12.5px; line-height: 1.7; }
.denied-actions { display: flex; justify-content: center; gap: 8px; margin-top: 23px; }
.denied-logout { display: inline-block; margin-top: 17px; color: var(--muted); font-size: 11px; text-decoration: underline; text-underline-offset: 3px; }
.denied-logout:hover { color: var(--text); }

/* 9. 响应式与动效降级 ----------------------------------------------------- */
@media (max-height: 760px) and (min-width: 701px) {
  .welcome { padding-top: 12px; }
  .welcome-mark { width: 42px; height: 42px; margin-bottom: 10px; border-radius: 12px; }
  .welcome h2 { margin-top: 5px; font-size: 28px; }
  .welcome-sub { margin-top: 6px; font-size: 12px; }
  .suggestion-grid { margin-top: 17px; }
  .suggestion-card { min-height: 68px; padding: 10px 12px; }
  .welcome-tip { margin-top: 13px; }
  .welcome-orbit { top: -26px; opacity: .22; }
}
@media (max-width: 1120px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .app { display: block; }
  .admin-top-link, .shortcut { display: none !important; }
  .conv-actions { opacity: 1; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: var(--z-sidebar);
    width: min(86vw, 320px); flex-basis: auto; transform: translateX(-102%);
    border-right: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .app.sidebar-collapsed .sidebar { margin-left: 0; opacity: 1; pointer-events: auto; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: var(--z-scrim); display: block; background: var(--scrim); backdrop-filter: blur(2px); animation: fade-in .18s ease both; }
  .sidebar-close { display: inline-flex; }
  .main { height: 100dvh; }
  .topbar { padding: 0 14px; }
  .chat-title { max-width: 43vw; }
  .admin-topbar { padding: 0 16px; }
  .admin-main { width: min(100% - 32px, 1180px); padding-top: 28px; }
  .admin-page-head { align-items: flex-start; flex-direction: column; gap: 14px; }
  .admin-head-actions { width: 100%; justify-content: space-between; }
}
@media (max-width: 700px) {
  :root { --content-w: 100%; }
  .messages { padding: 23px 16px 16px; gap: 25px; }
  .topbar { height: 58px; }
  .topbar-right { gap: 5px; }
  .topbar-right .icon-btn { width: 33px; height: 33px; }
  .chat-kicker { display: none; }
  .chat-title { max-width: 38vw; margin-top: 0; font-size: 13px; }
  .quota-pill { padding-right: 8px; font-size: 10px; }
  .quota-pill .quota-ring { width: 13px; height: 13px; }
  .login-card { padding: 28px 22px 22px; border-radius: 20px; }
  .login-view { padding: 80px 16px 40px; }
  .login-topline { padding: 18px; }
  .login-copyright { margin-top: 20px; }
  .welcome { padding-top: 26px; }
  .welcome-orbit { top: -16px; opacity: .22; }
  .welcome h2 { font-size: 26px; }
  .suggestion-grid { grid-template-columns: 1fr; margin-top: 22px; gap: 8px; }
  .suggestion-card { min-height: 68px; padding: 11px 12px; }
  .suggestion-copy strong { font-size: 12px; }
  .suggestion-copy span { font-size: 10.5px; }
  .message--user .message-body { max-width: 88%; }
  .message { gap: 10px; }
  .message-avatar { width: 27px; height: 27px; border-radius: 8px; }
  .message-avatar img { width: 17px; height: 17px; }
  .assistant-name { margin-bottom: 3px; }
  .markdown { font-size: 14.5px; line-height: 1.72; }
  .user-bubble .markdown { font-size: 14.5px; }
  .code-block pre code { font-size: 11.5px; }
  .markdown table { min-width: 420px; }
  .composer-wrap { padding: 2px 10px max(10px, env(safe-area-inset-bottom)); }
  .composer { padding: 7px 8px 7px 9px; border-radius: 17px; }
  .composer-input { min-height: 45px; font-size: 16px; }
  .composer-hint-inline, .enter-hint { display: none; }
  .composer-footnote { display: none; }
  .model-picker select { max-width: 150px; }
  .attach-btn { width: 36px; height: 36px; }
  .send-btn { width: 40px; height: 40px; border-radius: 11px; }
  .scroll-bottom-btn { bottom: calc(var(--composer-height, 140px) + 10px); }
  .toast-region { right: 10px; top: 68px; width: calc(100vw - 20px); }
  .dialog-card { padding: 20px; }
  .admin-main { width: calc(100% - 24px); padding-top: 22px; }
  .admin-topbar { min-height: 56px; gap: 10px; }
  .admin-page-label, .admin-topbar .brand-copy small { display: none; }
  .topbar-divider { display: none; }
  .back-link span { display: none; }
  .admin-page-head h1 { font-size: 26px; }
  .page-lede { font-size: 12px; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 13px; }
  .stat-value { font-size: 24px; }
  .panel-head { padding: 15px 14px 11px; gap: 10px; }
  .segmented { flex: none; }
  .segment { padding: 4px 7px; }
  .chart-stage { padding: 4px 8px 0; min-height: 210px; }
  .chart-empty, .chart-loading { min-height: 200px; }
  .chart-meta { padding: 4px 14px 5px; }
  .settings-form { padding: 2px 14px 16px; }
  .security-note { margin: 0 14px 14px; }
  .form-row { grid-template-columns: 1fr; gap: 15px; }
  .logs-table { min-width: 680px; }
  .admin-foot { flex-direction: column; gap: 4px; padding-top: 10px; }
  .admin-topbar .back-link { padding: 0 8px; }
}
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .quota-pill { padding-left: 6px; padding-right: 7px; gap: 5px; font-size: 10.5px; }
  .chat-title { max-width: 32vw; }
}
@media (hover: none) {
  .assistant-actions { opacity: 1; }
  .conv-actions { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    scroll-behavior: auto !important; transition-duration: .001ms !important;
  }
  .stream-cursor { animation: none; opacity: 1; }
}
