/* DBASK Chat · AI 对话式数据库知识平台
 * 深色仪器风：墨绿底、薄荷绿信号、等宽字标签。
 */

:root {
  --bg: #070a09;
  --bg-2: #0b100e;
  --surface: rgba(16, 21, 19, 0.86);
  --surface-2: #131a17;
  --surface-3: #18211d;
  --line: #223028;
  --line-strong: #31463a;
  --text: #e9f1eb;
  --text-2: #a6b8ad;
  --muted: #71857a;
  --accent: #58e6ab;
  --accent-strong: #7cf3c0;
  --accent-deep: #123d2c;
  --accent-dim: rgba(88, 230, 171, 0.1);
  --accent-line: rgba(88, 230, 171, 0.32);
  --warn: #e8bd76;
  --warn-dim: rgba(232, 189, 118, 0.09);
  --danger: #ff8a8a;
  --code-bg: #060d0a;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.28);
  --radius: 16px;
  --rail-w: 268px;
  --inspector-w: 348px;
  --mono: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, ui-monospace, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

[data-theme="light"] {
  --bg: #f2f6f0;
  --bg-2: #eaf1e9;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-2: #f7faf5;
  --surface-3: #eff5ee;
  --line: #dbe5dc;
  --line-strong: #bfd1c3;
  --text: #0f1b14;
  --text-2: #43584b;
  --muted: #6c8175;
  --accent: #0a8a63;
  --accent-strong: #056e4f;
  --accent-deep: #cdeee0;
  --accent-dim: rgba(10, 138, 99, 0.08);
  --accent-line: rgba(10, 138, 99, 0.3);
  --warn: #a97319;
  --warn-dim: rgba(169, 115, 25, 0.08);
  --danger: #c0392b;
  --code-bg: #0c1712;
  --shadow: 0 22px 55px rgba(25, 57, 40, 0.13);
  --shadow-sm: 0 8px 22px rgba(25, 57, 40, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 18% -10%, rgba(88, 230, 171, 0.09), transparent 62%),
    radial-gradient(900px 600px at 92% 8%, rgba(72, 130, 255, 0.06), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 55%);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 20%, #000 0%, transparent 78%);
  z-index: -1;
}
[data-theme="light"] body::before {
  background-image:
    linear-gradient(rgba(20, 60, 40, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 60, 40, 0.045) 1px, transparent 1px);
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 40;
  background: var(--accent); color: #04120c; padding: 8px 12px; border-radius: 8px;
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; }

/* ---------- 布局 ---------- */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--inspector-w);
  grid-template-areas: "rail stage inspector";
}
.rail { grid-area: rail; }
.stage { grid-area: stage; }
.inspector { grid-area: inspector; }

/* ---------- 侧栏 ---------- */
.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 18px 18px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(14, 20, 17, 0.9), rgba(9, 13, 11, 0.94));
  backdrop-filter: blur(18px);
  overflow: hidden;
  z-index: 20;
}
[data-theme="light"] .rail { background: linear-gradient(180deg, #ffffff, #f4f9f2); }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { height: 20px; width: auto; opacity: 0.95; filter: brightness(0) invert(1); }
[data-theme="light"] .brand img { filter: none; }
.brand-tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em;
  color: var(--accent); border: 1px solid var(--accent-line);
  padding: 3px 6px; border-radius: 5px; background: var(--accent-dim);
}

.new-chat {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 11px 12px;
  border-radius: 11px; border: 1px solid var(--accent-line);
  background: linear-gradient(135deg, rgba(88, 230, 171, 0.16), rgba(88, 230, 171, 0.05));
  color: var(--text); font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s, background 0.2s;
}
.new-chat svg { color: var(--accent); }
.new-chat kbd {
  margin-left: auto; font-family: var(--mono); font-size: 10px; font-weight: 500;
  color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 2px 5px;
}
.new-chat:hover { border-color: var(--accent); transform: translateY(-1px); }

.rail-search {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.02);
}
.rail-search svg { width: 15px; height: 15px; color: var(--muted); }
.rail-search input {
  width: 100%; border: 0; background: transparent; color: var(--text);
  font-size: 12.5px; outline: none; font-family: inherit;
}
.rail-search input::placeholder { color: var(--muted); }

.rail-block { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.rail-label {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--muted);
  text-transform: uppercase;
}
.rail-label button {
  border: 0; background: none; color: var(--muted); font-size: 10px; cursor: pointer;
  font-family: inherit; padding: 2px 4px;
}
.rail-label button:hover { color: var(--danger); }

.session-list {
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto; max-height: 34vh; padding-right: 2px;
}
.session-list:empty::after {
  content: "还没有会话，从右侧提一个问题开始。";
  display: block; font-size: 11.5px; color: var(--muted); line-height: 1.6; padding: 6px 4px;
}
.session-item {
  display: flex; align-items: center; gap: 2px;
  padding: 2px 4px; border-radius: 9px;
  border: 1px solid transparent; background: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.session-item:hover { background: var(--surface-2); border-color: var(--line); }
.session-item.is-active { background: var(--surface-2); border-color: var(--accent-line); }
.session-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px;
  align-items: flex-start; padding: 6px 8px;
  border: 0; background: none; color: var(--text-2); cursor: pointer;
  text-align: left; font-family: inherit; font-size: 12.5px; line-height: 1.4;
}
.session-open strong { width: 100%; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-open span { font-size: 10px; color: var(--muted); font-family: var(--mono); }
.session-item.is-active .session-open, .session-item:hover .session-open { color: var(--text); }
.session-item .kill {
  flex: none; width: 25px; height: 25px; display: grid; place-items: center;
  border: 0; background: none; color: var(--muted); border-radius: 6px; cursor: pointer;
  opacity: 0; transition: opacity 0.15s, color 0.15s;
}
.session-item .kill svg { width: 12px; height: 12px; }
.session-item:hover .kill { opacity: 1; }
.session-item .kill:hover { color: var(--danger); background: rgba(255, 138, 138, 0.1); }

.rail-nav { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }
.rail-nav button {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; color: var(--text-2);
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
  font-size: 13px; font-family: inherit; text-align: left;
}
.rail-nav button svg { width: 16px; height: 16px; color: var(--muted); }
.rail-nav button:hover { background: var(--surface-2); color: var(--text); }
.rail-nav button.is-active { color: var(--text); background: var(--accent-dim); }
.rail-nav button.is-active svg { color: var(--accent); }

.rail-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.engine-state { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-2); font-family: var(--mono); }
.engine-state i { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.engine-state.is-ready i { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.rail-foot p { margin: 0; font-size: 10.5px; color: var(--muted); }

/* ---------- 顶栏 ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 64px; padding: 0 22px; flex: none;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 14, 12, 0.62); backdrop-filter: blur(14px);
  z-index: 10;
}
[data-theme="light"] .topbar { background: rgba(250, 253, 249, 0.8); }
.topbar-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kicker { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.18em; color: var(--muted); }
.topbar-title h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ghost-btn, .icon-btn, .primary-btn {
  font-family: inherit; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2);
  border-radius: 9px; transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.ghost-btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; font-size: 12px; }
.ghost-btn svg { width: 15px; height: 15px; }
.ghost-btn:hover, .icon-btn:hover { border-color: var(--accent-line); color: var(--text); }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; }
.icon-btn svg { width: 16px; height: 16px; }
.primary-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; font-size: 12.5px; font-weight: 600;
  color: var(--accent); border-color: var(--accent-line);
  background: var(--accent-dim);
}
.primary-btn:hover { background: rgba(88, 230, 171, 0.18); color: var(--accent-strong); }
.primary-btn svg { width: 15px; height: 15px; }
.only-mobile { display: none; }
#inspector-toggle { display: none; }
[hidden] { display: none !important; }

/* ---------- 欢迎页 ---------- */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-gutter: stable; }
.chat-scroll::-webkit-scrollbar, .inspector-body::-webkit-scrollbar, .page-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb, .inspector-body::-webkit-scrollbar-thumb, .page-scroll::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 8px;
}

.welcome { max-width: 940px; margin: 0 auto; padding: 46px 32px 24px; }
.hero .eyebrow { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; color: var(--muted); }
.eyebrow i { width: 18px; height: 1px; background: var(--accent); }
.eyebrow .mono { margin-left: auto; color: var(--accent); opacity: 0.8; }
.hero h1 {
  margin: 18px 0 14px; font-size: clamp(30px, 3.6vw, 47px); line-height: 1.12;
  letter-spacing: -0.028em; font-weight: 700;
}
.hero .grad {
  background: linear-gradient(100deg, var(--accent-strong), var(--accent) 55%, #6fb9ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero .lede { max-width: 640px; margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.85; }

.stat-row { display: flex; flex-wrap: wrap; gap: 0; margin: 26px 0 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stat { flex: 1 1 0; min-width: 120px; padding: 14px 16px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; font-family: var(--mono); font-size: 20px; color: var(--accent); letter-spacing: -0.02em; }
.stat span { font-size: 11px; color: var(--muted); }

.section-line { display: flex; align-items: center; gap: 12px; margin: 38px 0 14px; }
.section-line span { font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; color: var(--muted); text-transform: uppercase; }
.section-line i { flex: 1; height: 1px; background: var(--line); }

.starter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.starter {
  position: relative; display: flex; flex-direction: column; gap: 8px;
  padding: 16px 16px 14px; border-radius: 13px; cursor: pointer; text-align: left;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-family: inherit;
  transition: border-color 0.18s, transform 0.18s, background 0.18s;
}
.starter:hover { border-color: var(--accent-line); transform: translateY(-2px); background: var(--surface-2); }
.starter .starter-top { display: flex; align-items: center; gap: 8px; }
.starter .db-tag {
  font-family: var(--mono); font-size: 10px; color: var(--accent);
  border: 1px solid var(--accent-line); border-radius: 4px; padding: 2px 6px; background: var(--accent-dim);
}
.starter .kind { font-size: 10px; color: var(--muted); }
.starter strong { font-size: 13.5px; line-height: 1.55; font-weight: 550; }
.starter .go { margin-top: auto; display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.starter .go svg { width: 14px; height: 14px; }
.starter:hover .go { color: var(--accent); }

.db-row { margin-top: 30px; display: flex; align-items: flex-start; gap: 14px; }
.db-row-label { flex: none; margin-top: 5px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 5px 11px; border-radius: 20px; font-size: 11.5px;
  border: 1px solid var(--line); background: transparent; color: var(--text-2);
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.chip:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-dim); }

.cap-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--line); }
.cap { display: flex; gap: 10px; align-items: flex-start; }
.cap svg { width: 17px; height: 17px; color: var(--accent); flex: none; margin-top: 2px; }
.cap strong { display: block; font-size: 12.5px; font-weight: 600; }
.cap span { display: block; margin-top: 3px; font-size: 11px; line-height: 1.6; color: var(--muted); }

/* ---------- 对话线程 ---------- */
.thread { max-width: 900px; margin: 0 auto; padding: 32px 32px 40px; display: flex; flex-direction: column; gap: 26px; }
.msg { display: flex; animation: rise 0.35s ease both; }
/* 从本地会话恢复的历史消息直接显示，不在后台标签页里停在 opacity:0 的动画首帧 */
.msg.is-restored, .msg.is-restored .block { animation: none; }
.msg.user { justify-content: flex-end; }
.msg .bubble {
  max-width: 78%; padding: 13px 16px; border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, rgba(88, 230, 171, 0.16), rgba(88, 230, 171, 0.05));
  border: 1px solid var(--accent-line); font-size: 13.5px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
}
[data-theme="light"] .msg .bubble { background: #e6f5ee; }
.msg.user .meta { align-self: flex-end; font-family: var(--mono); font-size: 10px; color: var(--muted); margin: 0 4px 0 10px; }

.msg.ai { gap: 12px; align-items: flex-start; }
.ai-avatar {
  flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--accent-line); background: var(--accent-dim); color: var(--accent);
  box-shadow: inset 0 0 20px rgba(88, 230, 171, 0.12);
}
.ai-avatar svg { width: 17px; height: 17px; }
.ai-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }

.thinking {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 13px 15px; display: flex; flex-direction: column; gap: 8px;
  max-width: 520px;
}
.think-row { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); }
.think-row .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--line-strong); display: grid; place-items: center; }
.think-row .dot i { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }
.think-row.is-active { color: var(--text-2); }
.think-row.is-active .dot { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.think-row.is-active .dot i { background: var(--accent); animation: pulse 1s infinite; }
.think-row.is-done { color: var(--text-2); }
.think-row.is-done .dot { border-color: var(--accent); background: var(--accent); }
.think-row.is-done .dot i { background: transparent; }
.think-row .think-text { flex: 1; }
.think-row .think-time { font-family: var(--mono); font-size: 10px; color: var(--muted); }

/* ---------- 答案 ---------- */
.answer {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.answer .block { padding: 16px 18px; animation: rise 0.4s ease both; }
.answer .block + .block { border-top: 1px solid var(--line); }

/* AI 解读：作为检索答案的补充块，明确区别于知识库原文 */
.ai-insight { background: linear-gradient(180deg, var(--accent-dim), transparent 72%); border-left: 2px solid var(--accent-line); }
.ai-insight-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 9px; }
.ai-insight-head .tag.ai { color: var(--accent); border-color: var(--accent-line); background: var(--accent-dim); }
.ai-model, .ai-time { font-family: var(--mono); font-size: 9.5px; color: var(--muted); }
.ai-summary { margin: 0 0 9px; font-size: 13px; line-height: 1.75; color: var(--text); }
.ai-steps { margin: 0; padding-left: 18px; display: grid; gap: 5px; }
.ai-steps li { font-size: 12.5px; line-height: 1.65; color: var(--text-2); }
.ai-risk { margin-top: 9px; padding: 8px 10px; border-radius: 8px; background: var(--warn-dim); color: var(--text-2); font-size: 11.5px; line-height: 1.65; }
.ai-disclaimer { margin-top: 8px; font-family: var(--mono); font-size: 9.5px; color: var(--muted); }
.ai-sources { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 11px; }
.ai-sources > span { color: var(--muted); font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.04em; }
.ai-sources a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-line); }
.ai-sources a:hover { color: var(--text); }
.ai-insight.is-loading { color: var(--muted); font-size: 11.5px; }
.ai-load-row { display: flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.04em; }
.ai-load-row i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
.ai-skeleton { margin-top: 10px; height: 30px; border-radius: 6px; background: linear-gradient(90deg, var(--line), var(--surface-3), var(--line)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.ans-head { display: flex; flex-direction: column; gap: 10px; }
.ans-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em;
  padding: 3px 7px; border-radius: 5px; color: var(--accent);
  border: 1px solid var(--accent-line); background: var(--accent-dim);
}
.tag.ghost { color: var(--text-2); border-color: var(--line); background: transparent; }
.tag.warn { color: var(--warn); border-color: rgba(232, 189, 118, 0.35); background: var(--warn-dim); }
.ans-tags .conf { margin-left: auto; display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.conf-bars { display: flex; gap: 2px; }
.conf-bars i { width: 5px; height: 10px; border-radius: 2px; background: var(--line-strong); }
.conf-bars i.on { background: var(--accent); }
.ans-title { margin: 0; font-size: 19px; line-height: 1.45; font-weight: 650; letter-spacing: -0.015em; }
.ans-summary { margin: 0; color: var(--text-2); font-size: 13px; line-height: 1.8; }
.ans-cites { display: flex; flex-wrap: wrap; gap: 6px; }
.cite {
  font-family: var(--mono); font-size: 9.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; cursor: pointer;
  background: transparent;
}
.cite:hover { color: var(--accent); border-color: var(--accent-line); }

.ans-sec-title {
  display: flex; align-items: center; gap: 8px; margin: 0 0 12px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--muted);
  text-transform: uppercase;
}
.ans-sec-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.step { position: relative; display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; padding-bottom: 16px; }
.step:last-child { padding-bottom: 0; }
.step::before {
  content: ""; position: absolute; left: 16px; top: 26px; bottom: 0; width: 1px; background: var(--line);
}
.step:last-child::before { display: none; }
.step-idx {
  width: 33px; height: 33px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--mono); font-size: 11px; color: var(--accent);
  border: 1px solid var(--accent-line); background: var(--accent-dim); flex: none;
}
.step strong { display: block; font-size: 13px; font-weight: 600; margin: 5px 0 4px; }
.step p { margin: 0; font-size: 12.5px; line-height: 1.75; color: var(--text-2); }

.code-block { border-radius: 10px; overflow: hidden; border: 1px solid var(--line-strong); background: var(--code-bg); }
.code-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: #8fb3a4;
}
.code-head .lang { color: var(--accent); }
.code-head button {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid rgba(255, 255, 255, 0.14); background: transparent; color: #a9c4b6;
  border-radius: 5px; padding: 3px 8px; font-size: 10px; font-family: inherit; cursor: pointer;
}
.code-head button:hover { border-color: var(--accent); color: var(--accent); }
.code-head svg { width: 12px; height: 12px; }
.code-block pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.75; color: #d7e9df;
  tab-size: 2;
}

.ans-note {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 11px 13px; border-radius: 9px;
  border: 1px solid rgba(232, 189, 118, 0.26); background: var(--warn-dim);
  font-size: 12px; line-height: 1.7; color: var(--warn);
}
.ans-note svg { width: 15px; height: 15px; flex: none; margin-top: 1px; }

.doc-list { display: flex; flex-direction: column; gap: 6px; }
.doc-item { display: flex; align-items: baseline; gap: 9px; font-size: 12px; line-height: 1.6; }
.doc-item .no { font-family: var(--mono); font-size: 9.5px; color: var(--accent); flex: none; }
.doc-item a { color: var(--text-2); text-decoration: none; border-bottom: 1px dashed var(--line-strong); }
.doc-item a:hover { color: var(--accent); border-color: var(--accent-line); }
.doc-item span.desc { color: var(--muted); }

.ans-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.act {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 7px; font-size: 11.5px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--text-2); font-family: inherit;
}
.act:hover { border-color: var(--accent-line); color: var(--accent); }
.act svg { width: 13px; height: 13px; }
.ans-actions .label { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.12em; color: var(--muted); }

.followups { display: flex; flex-direction: column; gap: 7px; }
.follow {
  display: flex; align-items: center; gap: 9px; text-align: left;
  padding: 9px 11px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-3);
  font-size: 12px; color: var(--text-2); font-family: inherit; line-height: 1.5;
}
.follow:hover { border-color: var(--accent-line); color: var(--text); }
.follow svg { width: 13px; height: 13px; color: var(--accent); flex: none; }

/* ---------- 输入区 ---------- */
.dock {
  flex: none; padding: 10px 22px 16px;
  background: linear-gradient(180deg, transparent, rgba(7, 10, 9, 0.72) 26%, var(--bg) 100%);
  border-top: 1px solid transparent;
}
[data-theme="light"] .dock { background: linear-gradient(180deg, transparent, #f2f6f0 30%); }
.dock-inner { max-width: 900px; margin: 0 auto; }
.quick-asks { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; min-height: 0; }
.quick-asks:empty { display: none; }
.quick-asks button {
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.02);
  color: var(--text-2); font-size: 11px; padding: 4px 9px; border-radius: 6px;
  cursor: pointer; font-family: inherit;
}
.quick-asks button:hover { color: var(--accent); border-color: var(--accent-line); }

.composer {
  border: 1px solid var(--line-strong); border-radius: 14px;
  background: var(--surface); backdrop-filter: blur(16px);
  padding: 10px 12px 9px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
}
.composer:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-sm); }
.composer-head { display: flex; align-items: center; gap: 10px; }
.composer-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.14em; color: var(--accent);
}
.composer-badge svg { width: 13px; height: 13px; }
.ai-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.08em;
  color: var(--accent); border: 1px solid var(--accent-line); border-radius: 5px;
  background: var(--accent-dim); padding: 2px 6px;
}
.ai-badge::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.ai-badge[hidden] { display: none; }
.composer-status { margin-left: auto; display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 9.5px; color: var(--muted); }
.composer-status i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.composer-status.is-busy i { background: var(--warn); animation: pulse 1s infinite; }
.composer textarea {
  width: 100%; resize: none; border: 0; outline: none; background: transparent;
  color: var(--text); font-family: inherit; font-size: 14px; line-height: 1.65;
  padding: 9px 2px 6px; max-height: 168px; min-height: 26px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-foot { display: flex; align-items: center; gap: 10px; }
.counter { font-family: var(--mono); font-size: 9.5px; color: var(--muted); }
.send-wrap { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.kbd-hint { font-size: 10px; color: var(--muted); }
.kbd-hint kbd {
  font-family: var(--mono); font-size: 9px; border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 4px; color: var(--text-2);
}
.send {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent-line); background: linear-gradient(135deg, rgba(88, 230, 171, 0.24), rgba(88, 230, 171, 0.1));
  color: var(--accent); font-weight: 600; font-size: 12.5px; padding: 7px 14px; border-radius: 9px;
  cursor: pointer; font-family: inherit; transition: transform 0.15s, background 0.15s;
}
.send svg { width: 14px; height: 14px; }
.send:hover { background: rgba(88, 230, 171, 0.3); transform: translateY(-1px); }
.send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.legal { display: flex; gap: 7px; margin: 9px 2px 0; font-size: 10.5px; line-height: 1.6; color: var(--muted); }
.legal svg { width: 13px; height: 13px; flex: none; margin-top: 1px; }

/* ---------- 依据面板 ---------- */
.inspector {
  display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, #0e1512, #090f0c);
}
[data-theme="light"] .inspector { background: linear-gradient(180deg, #ffffff, #f6faf4); }
.inspector-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); flex: none;
}
.inspector-head h3 { margin: 2px 0 0; font-size: 13px; font-weight: 600; }
.inspector-body { flex: 1; overflow-y: auto; padding: 14px 16px 24px; }
.inspector-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 18px 4px; color: var(--muted); }
.inspector-empty svg { width: 22px; height: 22px; color: var(--line-strong); }
.inspector-empty p { margin: 0; font-size: 11.5px; line-height: 1.8; }

.insp-section { margin-bottom: 18px; }
.insp-section h4 {
  display: flex; align-items: center; gap: 8px; margin: 0 0 9px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase;
}
.insp-section h4::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.src-card {
  display: block; width: 100%; text-align: left; margin-bottom: 7px;
  padding: 10px 11px; border-radius: 9px; cursor: default;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); font-family: inherit;
}
.src-card.is-link { cursor: pointer; }
.src-card.is-link:hover { border-color: var(--accent-line); }
.src-card .src-top { display: flex; align-items: center; gap: 7px; }
.src-no {
  flex: none; width: 18px; height: 18px; display: grid; place-items: center;
  font-family: var(--mono); font-size: 9px; color: var(--accent);
  border: 1px solid var(--accent-line); border-radius: 4px; background: var(--accent-dim);
}
.src-kind { font-family: var(--mono); font-size: 9px; color: var(--muted); letter-spacing: 0.06em; }
.src-card strong { display: block; margin: 6px 0 3px; font-size: 11.5px; font-weight: 550; line-height: 1.5; overflow-wrap: anywhere; }
.src-card small { display: block; font-size: 10px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.src-card .open { display: inline-flex; align-items: center; gap: 4px; margin-top: 5px; font-size: 9.5px; color: var(--accent); }
.src-card .open svg { width: 11px; height: 11px; }

.trace-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.trace-cell { padding: 8px 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface-2); }
.trace-cell span { display: block; font-family: var(--mono); font-size: 9px; color: var(--muted); }
.trace-cell strong { display: block; margin-top: 3px; font-size: 11px; font-weight: 550; }
.token-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.token-list i {
  font-style: normal; font-family: var(--mono); font-size: 9px;
  color: var(--text-2); border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px;
}
.insp-related { display: flex; flex-direction: column; gap: 5px; }
.insp-related button {
  width: 100%; text-align: left; border: 1px solid var(--line); background: transparent; color: var(--text-2);
  padding: 8px 9px; border-radius: 7px; font-size: 11px; line-height: 1.5; cursor: pointer; font-family: inherit;
  overflow-wrap: anywhere;
}
.insp-related button:hover { color: var(--accent); border-color: var(--accent-line); }
.insp-note { border-top: 1px solid var(--line); padding-top: 12px; font-size: 10px; line-height: 1.7; color: var(--muted); }

/* ---------- 分页视图 ---------- */
.page-scroll { flex: 1; overflow-y: auto; padding: 36px 36px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; max-width: 1180px; margin: 0 auto 26px; }
.page-head h2 { margin: 12px 0 8px; font-size: clamp(24px, 2.6vw, 32px); letter-spacing: -0.025em; }
.page-head p { margin: 0; max-width: 640px; color: var(--text-2); font-size: 12.5px; line-height: 1.8; }
.page-stat { text-align: right; flex: none; }
.page-stat strong { display: block; font-family: var(--mono); font-size: 24px; color: var(--accent); }
.page-stat span { font-size: 10.5px; color: var(--muted); }

.lib-toolbar { display: flex; gap: 10px; max-width: 1180px; margin: 0 auto; flex-wrap: wrap; }
.lib-search {
  display: flex; align-items: center; gap: 9px; flex: 1 1 320px; min-width: 240px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.lib-search:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-dim); }
.lib-search svg { width: 15px; height: 15px; color: var(--muted); }
.lib-search input { flex: 1; border: 0; outline: none; background: transparent; color: var(--text); font-family: inherit; font-size: 13px; }
.lib-search input::placeholder { color: var(--muted); }
.lib-search kbd { font-family: var(--mono); font-size: 9px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.lib-select {
  padding: 10px 30px 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-2); font-family: inherit; font-size: 12.5px;
  appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 49%, var(--muted) 50%), linear-gradient(-45deg, transparent 49%, var(--muted) 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.lib-select:focus { outline: none; border-color: var(--accent-line); }

.lib-modes { display: flex; gap: 4px; max-width: 1180px; margin: 16px auto 0; flex-wrap: wrap; }
.lib-modes button {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid transparent; background: transparent; color: var(--text-2);
  padding: 7px 11px; border-radius: 8px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.lib-modes button:hover { color: var(--text); background: var(--surface-2); }
.lib-modes button.is-active { color: var(--accent); background: var(--accent-dim); border-color: var(--accent-line); }
.lib-modes span { font-family: var(--mono); font-size: 9.5px; color: var(--muted); }
.lib-meta { max-width: 1180px; margin: 16px auto 12px; font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.04em; }

.library-grid { max-width: 1180px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.lib-card {
  display: flex; flex-direction: column; gap: 9px; padding: 15px 15px 13px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  cursor: pointer; text-align: left; color: var(--text); font-family: inherit;
  transition: border-color 0.16s, transform 0.16s, background 0.16s;
  min-height: 132px;
}
.lib-card:hover { border-color: var(--accent-line); transform: translateY(-2px); background: var(--surface-2); }
.lib-card .lc-top { display: flex; align-items: center; gap: 6px; }
.lc-type { font-family: var(--mono); font-size: 9px; letter-spacing: 0.08em; padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.lc-type.article { color: var(--accent); border-color: var(--accent-line); background: var(--accent-dim); }
.lc-type.doc { color: #86b7ff; border-color: rgba(134, 183, 255, 0.32); background: rgba(134, 183, 255, 0.08); }
.lc-type.topicSection { color: var(--warn); border-color: rgba(232, 189, 118, 0.32); background: var(--warn-dim); }
.lc-db { margin-left: auto; font-size: 10px; color: var(--muted); }
.lib-card strong { font-size: 13px; line-height: 1.5; font-weight: 550; }
.lib-card p { margin: 0; font-size: 11px; line-height: 1.65; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.lib-card .lc-foot { margin-top: auto; display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 9px; color: var(--muted); }
.lib-card .lc-foot svg { width: 12px; height: 12px; }
.empty-state { max-width: 1180px; margin: 40px auto; padding: 34px; text-align: center; border: 1px dashed var(--line-strong); border-radius: 12px; color: var(--muted); font-size: 12.5px; line-height: 1.8; }
.load-more-wrap { max-width: 1180px; margin: 18px auto 0; display: flex; justify-content: center; }

/* ---------- 错误码 ---------- */
.err-panel {
  max-width: 1180px; margin: 0 auto; padding: 16px;
  border: 1px solid var(--line); border-radius: 13px; background: var(--surface);
}
.err-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.err-controls .lib-select { min-width: 210px; }
.err-controls .lib-search { flex: 1 1 320px; }
.err-hint { margin: 12px 2px 0; font-size: 11px; color: var(--muted); line-height: 1.6; }
.err-meta { max-width: 1180px; margin: 16px auto 10px; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.err-list { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.err-row {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) 88px; gap: 12px; align-items: center;
  padding: 10px 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  cursor: pointer; text-align: left; color: var(--text); font-family: inherit;
}
.err-row:hover { border-color: var(--accent-line); background: var(--surface-2); }
.err-row code { font-family: var(--mono); font-size: 11px; color: var(--accent); }
.err-row span { font-size: 11.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err-row em { font-style: normal; font-family: var(--mono); font-size: 9px; color: var(--muted); text-align: right; }
.err-empty { padding: 26px; text-align: center; color: var(--muted); font-size: 12px; border: 1px dashed var(--line-strong); border-radius: 10px; }

/* ---------- 弹窗 ---------- */
.detail-dialog {
  width: min(760px, 94vw); max-height: 86vh; padding: 0;
  border: 1px solid var(--line-strong); border-radius: 14px;
  background: var(--surface-2); color: var(--text); box-shadow: var(--shadow);
  overflow: hidden;
}
.detail-dialog::backdrop { background: rgba(3, 6, 5, 0.62); backdrop-filter: blur(6px); }
.dialog-shell { display: flex; flex-direction: column; max-height: 86vh; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 3px 0 0; font-size: 15px; line-height: 1.45; font-weight: 600; }
.dialog-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.dialog-foot { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); }
.dialog-foot span { font-size: 10px; color: var(--muted); }
.dialog-foot .primary-btn { margin-left: auto; }
.dlg-summary { margin: 0; font-size: 12.5px; line-height: 1.8; color: var(--text-2); }
.dlg-meta { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- 其他 ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(3, 6, 5, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 24;
}
.scrim.is-on { opacity: 1; pointer-events: auto; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 12px);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 8px 14px; font-size: 12px; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 60; box-shadow: var(--shadow-sm);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .inspector {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw);
    transform: translateX(102%); transition: transform 0.25s ease; z-index: 30;
    box-shadow: var(--shadow);
  }
  .inspector.is-open { transform: none; }
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  #inspector-toggle { display: inline-flex; }
  .scrim.is-on { z-index: 26; }
}
@media (min-width: 1181px) {
  #inspector-toggle span { display: none; }
  #inspector-close { display: none; }
  .app.compact { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .app.compact .inspector { display: none; }
}
@media (max-width: 980px) {
  .rail {
    position: fixed; top: 0; bottom: 0; left: 0; width: 282px;
    transform: translateX(-102%); transition: transform 0.25s ease; z-index: 28;
  }
  .rail.is-open { transform: none; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 0 14px; }
  .page-scroll { padding: 24px 18px 48px; }
  .welcome { padding: 30px 20px 18px; }
  .thread { padding: 22px 18px 32px; }
  .dock { padding: 8px 14px 12px; }
  .cap-row { grid-template-columns: 1fr; gap: 10px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-stat { text-align: left; }
}
@media (max-width: 680px) {
  .starter-grid { grid-template-columns: 1fr; }
  .stat-row { display: grid; grid-template-columns: repeat(2, 1fr); }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
  .stat:nth-child(odd) { border-right: 1px solid var(--line); }
  .stat:nth-child(3), .stat:nth-child(4) { border-bottom: 0; }
  .hero h1 { font-size: 29px; }
  .db-row { flex-direction: column; gap: 7px; }
  .kbd-hint { display: none; }
  .msg .bubble { max-width: 92%; }
  .err-row { grid-template-columns: 82px minmax(0, 1fr); }
  .err-row em { display: none; }
  .topbar-actions .ghost-btn span { display: none; }
  .quick-asks { display: none; }
}

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