/* ClinMedAgent Lite — 界面样式（无外部依赖，纯 CSS）
   设计目标：学术/医学工具的清爽专业感 + 长文阅读舒适度 + 响应式。 */

/* ============ 设计令牌 ============ */
:root {
  /* 中性色阶 */
  --bg: #f2f5f9;
  --bg-soft: #e9eef6;
  --bg-card: #ffffff;
  --bg-inset: #f7f9fc;
  --border: #e3e9f2;
  --border-strong: #cfd8e6;

  /* 文字 */
  --text: #1a2433;
  --text-soft: #475569;
  --text-muted: #6b7a90;

  /* 主色（医学青蓝） */
  --primary: #0f6fd6;
  --primary-dark: #0a56a8;
  --primary-soft: #e7f1fd;
  --primary-line: #bcd8f6;
  --accent: #0d9bb8;
  --accent-soft: #e2f6fa;

  /* 语义色 */
  --ok: #0f9d58;
  --ok-soft: #e6f6ed;
  --warn: #c77700;
  --warn-soft: #fdf3e3;
  --err: #d92d20;
  --err-soft: #fdecea;

  /* 形状与阴影 */
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 30, 54, .06);
  --shadow: 0 1px 3px rgba(16, 30, 54, .07), 0 8px 24px -12px rgba(16, 30, 54, .12);
  --shadow-lg: 0 2px 6px rgba(16, 30, 54, .06), 0 24px 48px -24px rgba(16, 30, 54, .22);
  --ring: 0 0 0 3px rgba(15, 111, 214, .16);

  /* 字体：中文优先，英文/数字跟随系统；正文追求长时间阅读舒适 */
  --font: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei UI", "Microsoft YaHei",
          "Source Han Sans SC", "Noto Sans SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --fs-body: 15px;
  --lh-body: 1.75;
  --tr: .18s cubic-bezier(.4, 0, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1420;
    --bg-soft: #121c2b;
    --bg-card: #16202e;
    --bg-inset: #111a26;
    --border: #253345;
    --border-strong: #33455c;
    --text: #e8eef6;
    --text-soft: #c3cedd;
    --text-muted: #92a1b6;
    --primary: #4b9ef0;
    --primary-dark: #2b7fd0;
    --primary-soft: #14283f;
    --primary-line: #24486d;
    --accent: #35bdd6;
    --accent-soft: #102b31;
    --ok: #35c07a;
    --ok-soft: #102a1e;
    --warn: #e0a13a;
    --warn-soft: #2c2415;
    --err: #f27269;
    --err-soft: #2e1a19;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .45), 0 10px 30px -14px rgba(0, 0, 0, .6);
    --shadow-lg: 0 30px 60px -28px rgba(0, 0, 0, .7);
    --ring: 0 0 0 3px rgba(75, 158, 240, .22);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { line-height: 1.35; font-weight: 700; letter-spacing: -.01em; }
b, strong { font-weight: 600; }
code, pre, .mono { font-family: var(--font-mono); font-size: .92em; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--bg-card) 88%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 11px 24px;
  box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--primary), var(--accent));
  color: #fff; font-weight: 700; font-size: 19px; letter-spacing: .02em;
  box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--primary) 65%, transparent);
}
.brand-text h1 { font-size: 17.5px; font-weight: 700; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.tabs { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.tab {
  border: 1px solid transparent; background: transparent; color: var(--text-soft);
  font-size: 14px; padding: 8px 15px; border-radius: 999px; cursor: pointer;
  transition: all var(--tr); white-space: nowrap;
}
.tab:hover { background: var(--primary-soft); color: var(--primary); }
.tab.active {
  background: var(--primary); color: #fff; font-weight: 600;
  box-shadow: 0 4px 14px -6px color-mix(in srgb, var(--primary) 70%, transparent);
}

.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-inset); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; color: var(--text-muted);
  white-space: nowrap;
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent);
}
.status-pill.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-pill.err .dot { background: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }
.user-badge {
  font-size: 12.5px; color: var(--primary); background: var(--primary-soft);
  border: 1px solid var(--primary-line); border-radius: 999px; padding: 4px 13px;
  white-space: nowrap; font-weight: 500;
}
.user-badge .admin { color: var(--warn); font-weight: 700; }
.btn-ghost {
  border: 1px solid var(--border-strong); background: transparent; color: var(--text-soft);
  border-radius: var(--radius-sm); padding: 6px 13px; font-size: 13px; cursor: pointer;
  transition: all var(--tr);
}
.btn-ghost:hover { color: var(--err); border-color: var(--err); background: var(--err-soft); }

/* ============ 主体 ============ */
.content { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 26px 24px 56px; }
.panel { display: none; animation: fade .22s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============ 登录/注册 ============ */
.auth-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1100px 620px at 12% -8%, var(--primary-soft), transparent 60%),
    radial-gradient(900px 560px at 104% 6%, var(--accent-soft), transparent 58%),
    var(--bg);
  padding: 24px; overflow: auto;
}
.auth-card {
  width: 400px; max-width: 100%; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 30px 32px 26px;
  display: flex; flex-direction: column; gap: 15px;
}
.auth-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.auth-brand h1 { font-size: 21px; margin-top: 10px; }
.auth-brand .brand-sub { font-size: 12.5px; }
.auth-tabs {
  display: flex; gap: 4px; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg-inset); padding: 4px;
}
.auth-tab {
  flex: 1; padding: 9px 0; border: none; background: transparent; cursor: pointer;
  font-size: 14px; color: var(--text-muted); border-radius: var(--radius-sm); transition: all var(--tr);
}
.auth-tab.active { background: var(--bg-card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: 13px; }
.auth-form label {
  font-size: 13px; display: flex; flex-direction: column; gap: 7px; color: var(--text-soft); font-weight: 500;
}
.auth-form input {
  border: 1px solid var(--border-strong); background: var(--bg-card); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 14.5px; transition: all var(--tr);
}
.auth-form input:focus { border-color: var(--primary); box-shadow: var(--ring); }
.auth-msg { font-size: 13px; min-height: 19px; color: var(--err); }
.auth-msg.ok { color: var(--ok); }

/* ============ 按钮 ============ */
.btn-primary {
  border: none; cursor: pointer; color: #fff; font-weight: 600; font-size: 14.5px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--radius-sm); padding: 10px 22px; transition: all var(--tr);
  box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--primary) 75%, transparent);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px -8px color-mix(in srgb, var(--primary) 80%, transparent); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ============ 检索 / 名词解释 ============ */
.search-hero { text-align: center; padding: 26px 0 18px; }
.search-hero h2 { font-size: 26px; margin-bottom: 8px; }
.hero-sub { color: var(--text-muted); font-size: 14.5px; max-width: 640px; margin: 0 auto 22px; }
.search-box {
  display: flex; gap: 10px; max-width: 780px; margin: 0 auto; align-items: stretch;
  flex-wrap: wrap;
}
.search-box input[type="text"] {
  flex: 1 1 300px; min-width: 0;
  border: 1px solid var(--border-strong); background: var(--bg-card); color: var(--text);
  border-radius: var(--radius); padding: 13px 16px; font-size: 15px; transition: all var(--tr);
  box-shadow: var(--shadow-sm);
}
.search-box input[type="text"]:focus { border-color: var(--primary); box-shadow: var(--ring); }
.book-select {
  border: 1px solid var(--border-strong); background: var(--bg-card); color: var(--text-soft);
  border-radius: var(--radius); padding: 0 12px; font-size: 14px; max-width: 260px; cursor: pointer;
  transition: all var(--tr);
}
.book-select:focus { border-color: var(--primary); box-shadow: var(--ring); }

.results { max-width: 900px; margin: 16px auto 0; display: flex; flex-direction: column; gap: 12px; }
.result-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 18px; box-shadow: var(--shadow-sm); transition: all var(--tr);
}
.result-card:hover { border-color: var(--primary-line); box-shadow: var(--shadow); transform: translateY(-1px); }
.result-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 9px; font-size: 12.5px; }
.result-book { color: var(--primary); background: var(--primary-soft); border-radius: 6px; padding: 2px 9px; font-weight: 600; }
.result-page { color: var(--text-muted); }
.result-section { color: var(--text-muted); border-left: 1px solid var(--border-strong); padding-left: 9px; }
.result-text { font-size: 14.5px; color: var(--text-soft); line-height: 1.8; }
.result-text mark, mark { background: #fff3bf; color: inherit; border-radius: 3px; padding: 0 2px; }
@media (prefers-color-scheme: dark) { mark { background: #4a3c14; color: #ffe9a8; } }
.empty-state { text-align: center; color: var(--text-muted); padding: 26px; font-size: 14px; }
.empty { color: var(--text-muted); }

/* ============ 名词解释卡片 ============ */
.term-card {
  background: var(--bg-card); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
}
.term-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.term-name {
  font-size: 19px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); border-radius: 9px; padding: 4px 14px;
}
.term-note { font-size: 12.5px; color: var(--text-muted); }
.term-body {
  font-size: 15px; line-height: 1.85; color: var(--text); white-space: pre-wrap;
  font-feature-settings: "palt" 1;
}

/* ============ 问答 ============ */
/* 用 flex + min-height:0 让聊天区自适应容器，避免 calc(100vh - N) 这类
   魔法数字在手机端（顶栏换行、地址栏伸缩）被算错，导致输入框压住消息。
   2026-09-18 追加修复：min-height 原本是固定 380px，矮窗口下会把输入框顶到
   折叠线以外（详见下方 .chat-wrap 注释），改为 clamp() 随可用高度退让。 */
.chat-wrap {
  display: flex; flex-direction: column;
  height: calc(100vh - 210px);                 /* 旧浏览器回退 */
  height: min(720px, calc(100dvh - 200px));    /* 支持 dvh 时更准（手机地址栏伸缩） */
  /* 关键修复（输入框被挤出折叠线）：短窗口（笔记本小窗、125% 缩放、手机横屏）里
     calc(100dvh - 200px) 会小于 380px，此时固定的 min-height: 380px 顶住了高度，
     .chat-wrap 被撑得比可视区还高，底部的 #askForm 打字输入框就落到折叠线以下，
     屏幕最底部只剩输入框的一条边——用户必须先滚动页面才能打字。
     clamp(下限, 可用高度, 380px) 让 min-height 随着矮窗口一起退让：
       · 窗口够高 → 仍是 380px 下限（保持原版观感）
       · 窗口变矮 → 等于可用高度，wrap 不再溢出，输入框始终完整可见
       · 窗口极矮 → 保底 150px，至少装得下 .ask-box（约 73px）而不被 overflow 裁掉 */
  min-height: clamp(150px, calc(100vh - 210px), 380px);
  min-height: clamp(150px, calc(100dvh - 200px), 380px);
  max-width: 900px; margin: 0 auto;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); overflow: hidden;
}
.chat-log {
  flex: 1 1 auto; min-height: 0;                /* 关键：允许收缩，内容才在框内滚动 */
  overflow-y: auto; padding: 20px 22px;
  display: flex; flex-direction: column; gap: 16px;
}
.chat-hint {
  background: var(--bg-inset); border: 1px dashed var(--border-strong);
  border-radius: var(--radius); padding: 15px 18px; color: var(--text-soft); font-size: 13.5px;
}
.chat-hint p { font-weight: 600; margin-bottom: 7px; }
.chat-hint ul { padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.chat-hint li { color: var(--text-muted); }

.msg { display: flex; flex-direction: column; gap: 6px; max-width: 88%; }
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-assistant { align-self: flex-start; }
.msg-label { font-size: 12px; color: var(--text-muted); font-weight: 600; padding-left: 2px; }
.msg-body {
  padding: 12px 16px; border-radius: var(--radius); font-size: 14.8px; line-height: 1.8;
  white-space: pre-wrap; word-break: break-word;
}
.msg-user .msg-body {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff;
  border-bottom-right-radius: 4px; box-shadow: 0 6px 16px -10px color-mix(in srgb, var(--primary) 80%, transparent);
}
.msg-assistant .msg-body {
  background: var(--bg-inset); border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.thinking .msg-body { color: var(--text-muted); }
.typing-dots::after {
  content: ""; display: inline-block; width: 1em; text-align: left;
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots { 0% { content: ""; } 25% { content: "·"; } 50% { content: "··"; } 75% { content: "···"; } }

.cite {
  color: var(--primary); background: var(--primary-soft); border-radius: 5px;
  padding: 1px 6px; font-size: .92em; font-weight: 600; white-space: nowrap;
}
.evidence-block {
  margin-top: 10px; background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px;
}
.evidence-block .msg-label { margin-bottom: 8px; }
.evidence-item {
  font-size: 13.2px; color: var(--text-soft); line-height: 1.7;
  padding: 9px 0; border-top: 1px solid var(--border);
}
.evidence-item:first-of-type { border-top: none; }
.evidence-item b { color: var(--primary); font-weight: 600; }

/* ---------------- 公式 / 化学符号 ----------------
 * 教材语料里带 LaTeX（OCR 刻意保留），由 mathfmt.js + KaTeX 还原。
 * 要点：
 *  1) 行内公式不要撑破行高，display 公式允许横向滚动（长公式在手机上不能溢出）；
 *  2) 降级为 Unicode 的 .math-plain 保持与正文同样的字号，不显得像“代码”；
 *  3) 证据块字号较小，公式要跟着缩，否则会明显跳出正文。
 */
.math-inline { white-space: nowrap; }
.math-inline .katex { font-size: 1.06em; }
.math-display {
  display: block; margin: 8px 0; overflow-x: auto; overflow-y: hidden;
  padding: 2px 0;
}
/* 长公式在手机上不能溢出容器。
   这里用 width:fit-content + 两侧 auto 外边距居中，而不是 KaTeX 默认的
   text-align:center：fit-content 让块宽恒等于内容宽，于是
     · 公式窄于容器 → 两侧 auto 外边距等分，视觉居中；
     · 公式宽于容器 → auto 外边距退化为 0，左端固定对齐 0，
       scrollLeft 从 0 起就能完整滑到最右，不会出现「开头的等号左边滚不出来」。
   实测本页两种写法在 Chrome 里表现一致，但 fit-content 是构造上就正确的，
   不依赖浏览器对「居中内容溢出」的处理细节，换个浏览器也稳。 */
.math-display .katex-display {
  margin: 0; width: fit-content;
  margin-left: auto; margin-right: auto;
}
.math-plain { font-style: normal; font-variant-numeric: normal; }
/* KaTeX 把 Na 和上标 + 渲染成两个独立元素，选中复制会得到 "Na \n+"；
   而它输出的 MathML 无障碍副本（1×1px 隐藏）若参与选区，又会让公式被抄两遍。
   两者都会污染「复制到笔记」的结果，所以：
     · .math-copy —— 公式的 Unicode 明文，视觉隐藏但【参与选区】，提供干净文本；
     · .katex     —— 退出选区，避免复制到拆散的片段和重复内容。
   读屏仍走 KaTeX 的 MathML（.math-copy 带 aria-hidden 且视觉隐藏），语义不丢。 */
.math-copy {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}
.katex { user-select: none; -webkit-user-select: none; }
.katex-mathml { user-select: none; -webkit-user-select: none; }
.evidence-item .math-inline .katex { font-size: 1em; }
.evidence-item .math-display { margin: 5px 0; }
.result-text .math-display, .result-text .math-inline { color: var(--text-soft); }
/* KaTeX 的 .katex 默认继承字体，中文环境里显式指定，避免回退到宋体数字 */
.katex { font-family: KaTeX_Main, "Times New Roman", "Songti SC", serif; }
.katex .mord.text, .katex .mord.textord { font-family: inherit; }

.ask-box {
  display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border);
  background: var(--bg-card); align-items: flex-end;
}
.ask-box textarea {
  flex: 1; resize: none; border: 1px solid var(--border-strong); background: var(--bg-inset);
  color: var(--text); border-radius: var(--radius); padding: 11px 14px; font-size: 14.5px;
  line-height: 1.6; max-height: 160px; transition: all var(--tr);
}
.ask-box textarea:focus { border-color: var(--primary); background: var(--bg-card); box-shadow: var(--ring); }

/* ============ 卡片与教材库 ============ */
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px 22px; box-shadow: var(--shadow-sm); transition: box-shadow var(--tr);
}
.card:hover { box-shadow: var(--shadow); }
.card h3 { font-size: 15.5px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card.full { grid-column: 1 / -1; }
.lib-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.muted { color: var(--text-muted); }
.muted.small, .small { font-size: 12.5px; line-height: 1.6; }
.card > .muted { font-size: 13.5px; }

.tool-download {
  margin-left: auto; font-size: 12.5px; font-weight: 600; text-decoration: none;
  color: var(--ok); background: var(--ok-soft); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
  border-radius: 999px; padding: 4px 12px; transition: all var(--tr); white-space: nowrap;
}
.tool-download:hover { background: var(--ok); color: #fff; }

.drop-zone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--bg-inset); padding: 22px 16px; text-align: center; cursor: pointer;
  transition: all var(--tr);
}
.drop-zone:hover { border-color: var(--primary); background: var(--primary-soft); }
.drop-zone.dragover { border-color: var(--primary); background: var(--primary-soft); box-shadow: var(--ring); }
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 7px; color: var(--text-soft); }
.drop-icon { font-size: 30px; }
.upload-meta { margin-top: 14px; display: flex; flex-direction: column; gap: 9px; }

/* 选择文件 / 上传并识别：并排两个按钮 */
.upload-steps { display: grid; grid-template-columns: auto 1fr; gap: 9px; align-items: center; }
.upload-steps .btn-primary { width: 100%; }
.upload-steps .btn-ghost { white-space: nowrap; }
.upload-meta .btn-primary:disabled { opacity: .45; cursor: not-allowed; }
/* 拖放区不再响应点击，去掉手型光标 */
.drop-zone { cursor: default; }
.upload-actions { margin-top: 10px; }
.btn-ghost {
  border: 1px solid var(--border-strong); background: transparent; color: var(--ink-soft);
  border-radius: var(--radius-sm); padding: 9px 15px; font-size: 13px; cursor: pointer;
  transition: var(--tr);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

/* 进度行：标签 + 进度条 + 百分比 */
.prog-row { display: grid; grid-template-columns: 46px 1fr 48px; align-items: center; gap: 9px; }
.prog-label { font-size: 12px; color: var(--ink-soft); letter-spacing: .04em; }
.prog-pct { font-size: 12px; color: var(--ink-soft); text-align: right; font-variant-numeric: tabular-nums; }
.progress-bar-ocr { background: linear-gradient(90deg, #4a8ab5, #6fb0d0); }
.upload-meta input[type="text"] {
  border: 1px solid var(--border-strong); background: var(--bg-card); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 13px; font-size: 14px;
}
.upload-progress { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.progress-track {
  height: 8px; background: var(--bg-soft); border-radius: 999px; overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 100%; width: 0; border-radius: 999px; transition: width .35s ease;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.job-list, .book-list { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.job-item {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  background: var(--bg-inset); display: flex; flex-direction: column; gap: 8px;
}
.job-head { display: flex; align-items: center; gap: 9px; justify-content: space-between; }
.job-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46%; }
.job-badge {
  font-size: 11.5px; border-radius: 999px; padding: 2px 9px; font-weight: 600;
  background: var(--bg-soft); color: var(--text-muted); white-space: nowrap;
}
.job-badge.queued { background: var(--warn-soft); color: var(--warn); }
.job-badge.ocr, .job-badge.indexing { background: var(--primary-soft); color: var(--primary); }
.job-badge.done { background: var(--ok-soft); color: var(--ok); }
.job-badge.error, .job-badge.cancelled { background: var(--err-soft); color: var(--err); }
.job-badge.text { background: var(--accent-soft); color: var(--accent); }
.job-meta { font-size: 12.2px; color: var(--text-muted); }

.book-item {
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 16px;
  background: var(--bg-inset); transition: all var(--tr);
}
.book-item:hover { border-color: var(--primary-line); background: var(--bg-card); box-shadow: var(--shadow-sm); }
.b-main { min-width: 0; flex: 1; }
.b-title { font-size: 14.8px; font-weight: 600; margin-bottom: 3px; overflow-wrap: anywhere; }
.b-meta { font-size: 12.3px; color: var(--text-muted); }
/* 封面：固定 3:4 竖版比例，未加载时用占位符撑住高度，避免列表跳动 */
.b-cover {
  flex: none; width: 54px; aspect-ratio: 3 / 4; border-radius: 4px; overflow: hidden;
  background: var(--bg-card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.b-cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.b-cover-ph { font-size: 22px; opacity: .45; }
.b-actions { flex: none; display: flex; gap: 8px; }
.b-rename-input {
  font: inherit; font-size: 14.8px; font-weight: 600; width: 100%;
  padding: 3px 8px; border: 1px solid var(--primary-line); border-radius: var(--radius-sm);
  background: var(--bg-card); color: var(--text);
}
.book-rename {
  flex: none; border: 1px solid var(--border-strong); background: transparent; color: var(--text-muted);
  border-radius: var(--radius-sm); padding: 6px 14px; font-size: 13px; cursor: pointer; transition: all var(--tr);
}
.book-rename:hover { color: #fff; background: var(--primary); border-color: var(--primary); }
.book-rename:disabled { opacity: .6; cursor: progress; }
.book-del {
  flex: none; border: 1px solid var(--border-strong); background: transparent; color: var(--text-muted);
  border-radius: var(--radius-sm); padding: 6px 14px; font-size: 13px; cursor: pointer; transition: all var(--tr);
}
.book-del:hover { color: #fff; background: var(--err); border-color: var(--err); }
.book-del:disabled { opacity: .6; cursor: progress; }

/* 公用教材：只读标记（替代改名/删除按钮）。
   公用书在服务器上只有一份、所有用户共用，所以任何用户都不能改名或删除。 */
.b-public-tag {
  flex: none; border: 1px solid var(--border-strong); background: transparent; color: var(--text-muted);
  border-radius: var(--radius-sm); padding: 6px 12px; font-size: 13px; white-space: nowrap;
}
.b-public-dot {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; vertical-align: middle;
  color: var(--accent, #2b6cb0); background: color-mix(in srgb, var(--accent, #2b6cb0) 12%, transparent);
}

/* ============ 设置 ============ */
.settings-wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
/* 共用 API 状态行（只读展示，故不用表单样式） */
.key-state { font-size: 13.4px; margin: 5px 0; }
.key-state.is-ok { color: var(--ok, #2f9e5f); }
.key-state.is-bad { color: var(--warn, #c8871a); }
.key-form { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.key-form label {
  font-size: 13.2px; color: var(--text-soft); display: flex; flex-direction: column; gap: 7px; font-weight: 500;
}
.key-form input {
  border: 1px solid var(--border-strong); background: var(--bg-inset); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 13px; font-size: 14px; font-family: var(--font-mono);
  transition: all var(--tr);
}
.key-form input:focus { border-color: var(--primary); background: var(--bg-card); box-shadow: var(--ring); }
.sys-status { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.sys-status .row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13.6px; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid transparent;
}
.sys-status .row:nth-child(odd) { background: var(--bg-inset); }
.sys-status .row > span { color: var(--text-muted); }
.sys-status .row > b { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.v-ok { color: var(--ok); }
.v-err { color: var(--err); }

/* [hidden] 必须真的隐藏：作者样式里的 display 会覆盖浏览器默认的 display:none */
[hidden] { display: none !important; }

/* ---------- 版本标记（用于判断浏览器是否在用旧页面） ---------- */
.build-tag {
  text-align: center; font-size: 11.5px; color: var(--text-muted);
  margin: 6px 0 0; letter-spacing: .3px;
}
.build-tag span { font-family: var(--mono); color: var(--text-soft); }

/* ---------- 问答配图（多模态） ---------- */
.btn-icon {
  flex: none; width: 42px; height: 42px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-inset); color: var(--text-soft);
  font-size: 18px; cursor: pointer; transition: all var(--tr); display: grid; place-items: center;
}
.btn-icon:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.ask-images {
  display: flex; gap: 10px; flex-wrap: wrap; padding: 12px 16px 0;
  border-top: 1px solid var(--border); background: var(--bg-card);
}
.ask-thumb {
  position: relative; width: 74px; height: 74px; border-radius: var(--radius-sm);
  overflow: hidden; border: 1px solid var(--border-strong); background: var(--bg-inset);
}
.ask-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-del {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%;
  border: none; background: rgba(15, 23, 42, .72); color: #fff; font-size: 14px; line-height: 1;
  cursor: pointer; display: grid; place-items: center; transition: background var(--tr);
}
.thumb-del:hover { background: var(--err); }

.msg-images { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 9px; }
.msg-images img {
  max-width: 190px; max-height: 190px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); display: block; background: #fff;
}
.msg-note {
  display: block; margin-top: 10px; padding: 7px 11px;
  font-size: 12.4px; line-height: 1.5; color: var(--text-muted);
  background: color-mix(in srgb, var(--primary) 7%, transparent);
  border-left: 3px solid var(--primary-line); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
/* 注入的块级内容（提示 / 证据）不要继承气泡的 pre-wrap，否则会多出空行 */
.msg-body > .msg-note,
.msg-body > .evidence-block { white-space: normal; }
.msg-body > .msg-note { margin-top: 12px; }

/* ============ 轻提示 ============ */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: var(--text); color: var(--bg-card); font-size: 13.6px; font-weight: 500;
  padding: 10px 20px; border-radius: 999px; box-shadow: var(--shadow-lg); z-index: 200;
  animation: toast-in .24s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============ 历史记录 / 管理后台 ============ */
.hist-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding: 8px 0 16px;
}
.hist-head h2 { font-size: 22px; margin-bottom: 6px; }
.hist-head .hero-sub { margin: 0; max-width: 720px; text-align: left; }
.hist-head .btn-ghost { flex: none; }

.hist-filter, .adm-filter {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 12px 14px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.hist-filter input[type="text"], .adm-filter input[type="text"] {
  flex: 1 1 240px; min-width: 180px;
}
.hist-filter input, .adm-filter input {
  border: 1px solid var(--border-strong); background: var(--bg-inset); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 14px;
  font-family: inherit; transition: all var(--tr);
}
.hist-filter input:focus, .adm-filter input:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--ring);
}

/* 概览指标卡 */
.hist-stats, .adm-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-sm);
}
.stat-card .stat-num {
  font-size: 21px; font-weight: 700; color: var(--primary);
  font-variant-numeric: tabular-nums; line-height: 1.25;
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

/* 历史列表 */
.hist-list { display: flex; flex-direction: column; gap: 10px; }
.hist-item {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: all var(--tr);
}
.hist-item:hover {
  border-color: var(--primary-line); box-shadow: var(--shadow); transform: translateY(-1px);
}
.hist-item-top {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 7px;
}
.hist-kind {
  font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--primary-line); background: var(--primary-soft); color: var(--primary);
  white-space: nowrap;
}
.hist-kind.k-term { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.hist-kind.k-search { border-color: var(--border-strong); color: var(--text-soft); background: var(--bg-inset); }
.hist-user {
  font-size: 12.5px; font-weight: 600; color: var(--primary);
  background: var(--primary-soft); border: 1px solid var(--primary-line);
  border-radius: 999px; padding: 2px 10px; white-space: nowrap;
}
.hist-time { font-size: 12px; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.hist-q { font-size: 14.5px; font-weight: 600; margin-bottom: 5px; overflow-wrap: anywhere; }
.hist-a {
  font-size: 13.4px; color: var(--text-soft); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere;
}
.hist-meta {
  display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px;
  font-size: 12px; color: var(--text-muted);
}
.hist-badge { color: var(--text-muted); }
.hist-badge.bad { color: var(--err); font-weight: 600; }
.hist-pager {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px;
}

/* 管理后台 */
.adm-tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.adm-tab {
  border: 1px solid var(--border-strong); background: var(--bg-inset); color: var(--text-soft);
  font-size: 13.5px; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  transition: all var(--tr); font-family: inherit;
}
.adm-tab:hover { border-color: var(--primary); color: var(--primary); }
.adm-tab.active {
  background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600;
}
.adm-user-list, .adm-book-list { display: flex; flex-direction: column; gap: 10px; }
.adm-user {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
  transition: all var(--tr);
}
.adm-user:hover { border-color: var(--primary-line); box-shadow: var(--shadow); }
.adm-user-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
}
.adm-user-name { font-size: 15.5px; font-weight: 700; overflow-wrap: anywhere; }
.adm-role {
  font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  background: var(--warn); color: #fff; white-space: nowrap;
}
.adm-role.user { background: var(--bg-inset); color: var(--text-muted); border: 1px solid var(--border-strong); font-weight: 600; }
.adm-user-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px 14px; margin-bottom: 11px;
}
.adm-user-meta .k { font-size: 11.5px; color: var(--text-muted); }
.adm-user-meta .v {
  font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.adm-user-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.adm-user-actions .btn-ghost { font-size: 12.5px; padding: 5px 12px; }
.adm-books-preview {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
  display: flex; flex-direction: column; gap: 5px;
}
.adm-book-line { font-size: 13px; color: var(--text-soft); overflow-wrap: anywhere; }
.adm-book-line .muted { font-size: 12px; }
.adm-book {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 14px; box-shadow: var(--shadow-sm);
}
.adm-book-head {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 5px;
}
.adm-book-title { font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; }
.adm-book-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.pill-public {
  font-size: 11px; padding: 1px 8px; border-radius: 999px;
  background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent);
}

/* ---------- 管理后台：公用库 ---------- */
.adm-pub-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin: 4px 0 10px; font-size: 13.5px; font-weight: 600;
}
/* 一行一本：勾选框 + 书名/篇幅 + 当前状态。整行可点，勾选区域够大。 */
.adm-pub-row {
  display: flex; align-items: center; gap: 11px; padding: 10px 13px; margin-bottom: 7px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer;
}
.adm-pub-row:hover { border-color: var(--border-strong); }
.adm-pub-row.on { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.adm-pub-row input { flex: none; width: 17px; height: 17px; accent-color: var(--accent, #2b6cb0); cursor: pointer; }
.adm-pub-row input:disabled { cursor: not-allowed; }
.adm-pub-main { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.adm-pub-state { flex: none; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.adm-pub-row.on .adm-pub-state { color: var(--ok); font-weight: 600; }

/* 弹层（历史详情） */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150; display: flex;
  align-items: center; justify-content: center; padding: 22px;
  background: color-mix(in srgb, var(--text) 42%, transparent);
  backdrop-filter: blur(3px); overflow: auto;
}
.modal-card {
  width: 760px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex: none;
}
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 16px 18px 20px; overflow: auto; }
.modal-body .row {
  display: flex; justify-content: space-between; gap: 14px; padding: 6px 8px;
  border-radius: var(--radius-sm); font-size: 13.4px;
}
.modal-body .row:nth-child(odd) { background: var(--bg-inset); }
.modal-body .row > span { color: var(--text-muted); flex: none; }
.modal-body .row > b { font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.modal-section { margin-top: 16px; }
.modal-section > h4 {
  font-size: 13.5px; color: var(--text-muted); margin-bottom: 8px;
  font-weight: 600; letter-spacing: .02em;
}
.modal-answer {
  font-size: 14.4px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px;
}
.modal-evidence { display: flex; flex-direction: column; gap: 8px; }

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  .lib-grid, .settings-wrap { grid-template-columns: 1fr; }
  .content { padding: 20px 16px 44px; }
  .search-hero { padding: 18px 0 12px; }
  .search-hero h2 { font-size: 22px; }
}
@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 10px 14px; }
  .brand-text h1 { font-size: 15.5px; }
  .brand-sub { display: none; }
  .tabs { width: 100%; margin-left: 0; overflow-x: auto; padding-bottom: 2px; }
  .tab { font-size: 13px; padding: 7px 12px; }
  .top-right { width: 100%; justify-content: space-between; }
  .chat-wrap {
    height: calc(100vh - 268px); height: min(660px, calc(100dvh - 268px));
    /* 同上：窄屏 + 矮窗口（手机横屏）也不能让固定下限把输入框顶出折叠线。
       这里同时收紧 380→220：手机横屏时还要给 .ask-images 缩略图留空间。 */
    min-height: clamp(150px, calc(100vh - 268px), 220px);
    min-height: clamp(150px, calc(100dvh - 268px), 220px);
  }
  .chat-log { padding: 15px 14px; gap: 13px; }
  .msg { max-width: 96%; }
  .msg-note { margin-top: 10px; padding: 6px 10px; }
  .search-box input[type="text"] { flex: 1 1 100%; }
  .book-select { max-width: none; width: 100%; padding: 10px 12px; }
  .search-box .btn-primary { width: 100%; }
}

/* 滚动条（WebKit） */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* 打印：去掉交互外壳，便于导出教材证据 */
@media print {
  .topbar, .ask-box, .drop-zone, .tool-download, .book-del, .book-rename, .b-rename-input, .toast { display: none !important; }
  .content { max-width: none; padding: 0; }
  .chat-wrap, .card, .result-card, .term-card { box-shadow: none; border-color: #ccc; }
}