/* ============================================================
   AI 中转 — 样式层
   设计令牌（唯一颜色 / 时长 / 字体来源）· 去味液态玻璃 · 全交互缓动
   规则：文字左对齐、单一低饱和强调色、无渐变鲜艳色、无 emoji
   ============================================================ */
:root {
  /* 色彩（暗色为默认调校值） */
  --bg: #101013;
  --surface: #17171B;
  --surface-2: #1F1F25;
  --border: #26262C;
  --text: #F2F2F5;
  --text-2: #A0A0A8;
  --text-3: #6E6E76;
  --accent: #6E8FF7;
  --accent-hover: #8AA8F9;
  --accent-subtle: rgba(110, 143, 247, .12);
  --danger: #E56B6B;
  --danger-subtle: rgba(229, 107, 107, .12);

  /* 字体 */
  --font-display: "Sora", "PingFang SC", sans-serif;
  --font-ui: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Consolas, monospace;

  /* 字号阶梯 */
  --fs-11: .6875rem; --fs-12: .75rem; --fs-13: .8125rem;
  --fs-15: .9375rem; --fs-18: 1.125rem; --fs-24: 1.5rem;

  /* 间距（4pt 网格） */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-6: 24px; --sp-8: 32px; --sp-12: 48px;

  /* 圆角 */
  --r-ctrl: 6px; --r-card: 10px; --r-modal: 14px; --r-pill: 999px;

  /* 阴影（克制贴近） */
  --shadow-float: 0 1px 2px rgb(0 0 0 / .06), 0 4px 12px rgb(0 0 0 / .18);
  --shadow-modal: 0 8px 32px rgb(0 0 0 / .30), 0 2px 8px rgb(0 0 0 / .18);

  /* 动效：语义曲线 + 时长分级 */
  --dur-micro: 120ms; --dur-fast: 200ms; --dur-base: 280ms; --dur-slow: 400ms;
  --ease-out-cubic: cubic-bezier(.215, .61, .355, 1);
  --ease-out-expo: cubic-bezier(.16, 1, .3, 1);
  --ease-in-out-quart: cubic-bezier(.77, 0, .175, 1);
  --ease-back: cubic-bezier(.34, 1.56, .64, 1);
}

[data-theme="light"] {
  --bg: #F7F7F8; --surface: #FFFFFF; --surface-2: #F0F0F2;
  --border: #E5E5E8; --text: #17171A; --text-2: #6E6E76; --text-3: #9C9CA4;
  --accent: #3B6FF5; --accent-hover: #2F5BD8; --accent-subtle: rgba(59, 111, 245, .10);
  --danger: #D64545; --danger-subtle: rgba(214, 69, 69, .10);
  --shadow-float: 0 1px 2px rgb(0 0 0 / .05), 0 4px 12px rgb(0 0 0 / .08);
  --shadow-modal: 0 8px 32px rgb(0 0 0 / .12), 0 2px 8px rgb(0 0 0 / .08);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; text-align: left; }
[hidden] { display: none !important; }  /* 修复：hidden 属性被组件 display 覆盖导致弹窗关不掉 */
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs-15) var(--font-ui);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.num, td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
h1, h2 { font-family: var(--font-display); font-weight: 600; margin: 0; }
button, input, textarea, [tabindex] { font-family: inherit; }

/* 全局交互缓动（覆盖每个可交互元素） */
a, button, input, textarea, select, .seg-item, .model-item, [role="button"], [tabindex] {
  transition:
    transform var(--dur-micro) var(--ease-out-cubic),
    background-color var(--dur-micro) var(--ease-out-cubic),
    border-color var(--dur-micro) var(--ease-out-cubic),
    box-shadow var(--dur-micro) var(--ease-out-cubic),
    color var(--dur-micro) var(--ease-out-cubic);
}
:where(a, button, input, textarea, select):hover { transform: translateY(-1px); }
:where(a, button, input, textarea, select):active { transform: translateY(1px); transition-duration: 100ms; }
:where(a, button, input, textarea, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 背景柔光（中性，无彩色光斑） ---------- */
.bg-field {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(60% 50% at 18% 12%, rgba(255, 255, 255, .025), transparent 70%),
    radial-gradient(50% 40% at 88% 88%, rgba(255, 255, 255, .020), transparent 70%);
}

/* ---------- 去味液态玻璃 ---------- */
.glass {
  background: rgba(255, 255, 255, .055);
  backdrop-filter: blur(20px) saturate(120%);
  -webkit-backdrop-filter: blur(20px) saturate(120%);
  border: 1px solid rgba(255, 255, 255, .10);
  border-top-color: rgba(255, 255, 255, .20);
  border-radius: var(--r-card);
}
[data-theme="light"] .glass {
  background: rgba(255, 255, 255, .62);
  border: 1px solid rgba(0, 0, 0, .08);
  border-top-color: rgba(255, 255, 255, .9);
}

/* ---------- 布局 ---------- */
.app { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; padding: var(--sp-4); gap: var(--sp-4); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) var(--sp-4); flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); }
.brand-mark { width: 34px; height: 34px; color: var(--accent); display: inline-flex; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-text h1 { font-size: var(--fs-18); line-height: 1.2; }
.brand-sub { margin: 0; font-size: var(--fs-11); color: var(--text-3); }

.topbar-right { display: flex; align-items: center; gap: var(--sp-3); }
.status { display: inline-flex; align-items: center; gap: var(--sp-2); padding: var(--sp-1) var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-pill); font-size: var(--fs-12); color: var(--text-2); }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); transition: background-color var(--dur-base) var(--ease-out-cubic); }
.status[data-state="ok"] .dot { background: #4CC38A; }
.status[data-state="warn"] .dot { background: #E0A33E; }
.status[data-state="err"] .dot { background: var(--danger); }

.main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); gap: var(--sp-4); }

/* ---------- 按钮 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); height: 36px; padding: 0 var(--sp-4); border-radius: var(--r-ctrl); border: 1px solid transparent; font-size: var(--fs-13); font-weight: 500; cursor: pointer; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); box-shadow: 0 2px 10px var(--accent-subtle); }
.btn--primary:active { box-shadow: inset 0 1px 2px rgb(0 0 0 / .18); }
.btn--ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn--ghost:hover { color: var(--text); background: var(--surface-2); }
.btn:disabled { opacity: .4; pointer-events: none; }
.icon-btn { padding: 0; width: 36px; height: 36px; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- 侧栏 ---------- */
.sidebar { display: flex; flex-direction: column; min-height: 0; padding: var(--sp-3); }
.sidebar-head { padding: var(--sp-2) var(--sp-2) var(--sp-3); }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: var(--sp-3); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search-input { width: 100%; padding-left: var(--sp-8); height: 36px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctrl); color: var(--text); font-size: var(--fs-13); }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); outline: none; }
.search-input::placeholder { color: var(--text-3); }

.model-list { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-1); display: flex; flex-direction: column; gap: var(--sp-1); scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.model-list::-webkit-scrollbar { width: 6px; }
.model-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.group-label { font-size: var(--fs-11); color: var(--text-3); text-transform: none; padding: var(--sp-3) var(--sp-2) var(--sp-1); letter-spacing: .04em; }
.model-item { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-ctrl); border: 1px solid transparent; cursor: pointer; position: relative; }
.model-item:hover { background: var(--surface-2); }
.model-item.active { background: var(--accent-subtle); border-color: rgba(110, 143, 247, .35); }
.model-item.active::before { content: ""; position: absolute; left: 0; top: 20%; bottom: 20%; width: 3px; border-radius: 3px; background: var(--accent); transition: transform var(--dur-base) var(--ease-out-expo); }
.model-name { font-size: var(--fs-13); font-weight: 500; color: var(--text); display: flex; align-items: center; gap: var(--sp-2); }
.model-tag { font-size: var(--fs-11); color: var(--text-3); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 0 var(--sp-2); }
.model-desc { font-size: var(--fs-11); color: var(--text-3); line-height: 1.45; }
.model-item.empty { color: var(--text-3); font-size: var(--fs-12); cursor: default; }
.model-item.empty:hover { background: transparent; }

.sidebar-foot { padding: var(--sp-2); border-top: 1px solid var(--border); }
.hint { margin: 0; font-size: var(--fs-11); color: var(--text-3); }

/* ---------- 对话区 ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; gap: var(--sp-4); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-2) var(--sp-4); flex-shrink: 0; }
.chip { display: inline-flex; align-items: center; height: 28px; padding: 0 var(--sp-3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); font-size: var(--fs-12); color: var(--text); }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-2) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.empty { margin: auto; text-align: left; max-width: 420px; color: var(--text-2); animation: fadeUp var(--dur-slow) var(--ease-out-expo) both; }
.empty-icon { width: 40px; height: 40px; color: var(--text-3); display: inline-flex; margin-bottom: var(--sp-3); }
.empty-icon svg { width: 100%; height: 100%; }
.empty h2 { font-size: var(--fs-24); color: var(--text); margin-bottom: var(--sp-2); }
.empty p { margin: 0; font-size: var(--fs-13); color: var(--text-3); }

.msg { display: flex; gap: var(--sp-3); max-width: 880px; width: 100%; animation: fadeUp var(--dur-base) var(--ease-out-expo) both; }
.msg-avatar { width: 30px; height: 30px; border-radius: var(--r-ctrl); flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.msg.user .msg-avatar { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.msg.assistant .msg-avatar { background: var(--accent-subtle); border: 1px solid rgba(110, 143, 247, .35); color: var(--accent); }
.msg-avatar svg { width: 16px; height: 16px; }
.msg-body { flex: 1; min-width: 0; }
.msg-role { font-size: var(--fs-11); color: var(--text-3); margin-bottom: var(--sp-1); }
.msg-content { font-size: var(--fs-15); color: var(--text); line-height: 1.65; word-break: break-word; }
.msg-content p { margin: 0 0 var(--sp-2); }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content pre.code { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctrl); padding: var(--sp-3); overflow-x: auto; font-family: var(--font-mono); font-size: var(--fs-13); line-height: 1.5; margin: var(--sp-2) 0; }
.msg-content code.inline { font-family: var(--font-mono); font-size: .9em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; }
.msg-content strong { color: var(--text); font-weight: 600; }
.cursor { display: inline-block; width: 7px; height: 1.05em; background: var(--accent); border-radius: 1px; vertical-align: text-bottom; margin-left: 2px; animation: blink 1s steps(2, start) infinite; }

/* ---------- 输入区 ---------- */
.composer { display: flex; align-items: flex-end; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); flex-shrink: 0; }
.composer-input { flex: 1; min-height: 24px; max-height: 180px; resize: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); color: var(--text); font-size: var(--fs-15); line-height: 1.5; padding: var(--sp-3); transition: border-color var(--dur-micro) var(--ease-out-cubic), box-shadow var(--dur-micro) var(--ease-out-cubic); }
.composer-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); outline: none; }
.composer-input::placeholder { color: var(--text-3); }
.composer-actions { display: flex; gap: var(--sp-2); }
.send-btn { width: 84px; }
.send-btn .send-icon { width: 16px; height: 16px; }

/* ---------- 设置弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .45); display: flex; align-items: center; justify-content: center; padding: var(--sp-4); animation: fadeIn var(--dur-fast) var(--ease-out-cubic) both; }
.modal { width: min(480px, 100%); border-radius: var(--r-modal); box-shadow: var(--shadow-modal); overflow: hidden; animation: modalIn var(--dur-base) var(--ease-out-expo) both; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: var(--fs-18); }
.modal-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-6); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-4); border-top: 1px solid var(--border); }

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field-label { font-size: var(--fs-13); font-weight: 500; color: var(--text); }
.field-help { margin: 0; font-size: var(--fs-11); color: var(--text-3); line-height: 1.5; }
.field-help code, .field-help { font-family: var(--font-mono); }
.input { height: 36px; padding: 0 var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctrl); color: var(--text); font-size: var(--fs-13); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); outline: none; }
.input::placeholder { color: var(--text-3); }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-ctrl); gap: 3px; }
.seg-item { flex: 1; height: 32px; border: none; background: transparent; color: var(--text-2); border-radius: 4px; font-size: var(--fs-13); cursor: pointer; }
.seg-item.active { background: var(--accent); color: #fff; }

/* ---------- 提示条 ---------- */
.toast { position: fixed; left: 50%; bottom: var(--sp-8); transform: translateX(-50%); z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctrl); padding: var(--sp-3) var(--sp-4); font-size: var(--fs-13); color: var(--text); box-shadow: var(--shadow-float); max-width: 80vw; animation: toastIn var(--dur-base) var(--ease-out-expo) both; }
.toast[data-kind="err"] { border-color: rgba(229, 107, 107, .5); color: var(--danger); }

/* ---------- 动效关键帧 ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 820px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app { padding: var(--sp-2); }
}
