/* ============================================================
   知源 · Enterprise RAG — 设计系统
   Swiss International Style（瑞士国际风格）
   严格网格 / Helvetica 式无衬线 / 黑白为主 + 红色强调
   全直角、无阴影、无渐变；hover 只变颜色与边框色（duration-150 ease-out 上限）
   ============================================================ */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f0;        /* hover 背景 */
  --line: #cccccc;             /* 细分隔线 / 基准线灰 */
  --border: #000000;           /* 结构边框黑 */
  --border-strong: #000000;

  --text: #000000;
  --text-2: #595959;
  --text-3: #737373;
  --muted: #737373;

  --red: #ff0000;              /* 强调：边框 / 图标 / 填充 */
  --red-text: #e30613;         /* 小字号红色文本（白底 AA ≥ 4.5:1） */
  --blue: #0057b8;             /* 可选第二强调 */

  --danger: #e30613;
  --accent: #ff0000;
  --primary: #ff0000;
  --card: #ffffff;

  --font: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

html[data-theme="dark"] {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #1a1a1a;
  --line: #333333;
  --border: #ffffff;
  --border-strong: #ffffff;

  --text: #ffffff;
  --text-2: #b3b3b3;
  --text-3: #8c8c8c;
  --muted: #8c8c8c;

  --red: #ff0000;
  --red-text: #ff5c5c;         /* 黑底 AA */
  --blue: #4d9fdb;

  --danger: #ff5c5c;
  --accent: #ff0000;
  --primary: #ff0000;
  --card: #0a0a0a;
}

* { box-sizing: border-box; border-radius: 0 !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border: none; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
::-webkit-scrollbar-track { background: transparent; }

::selection { background: var(--red); color: #ffffff; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible,
.composer textarea:focus-visible { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- 布局 ---------- */

.app { display: grid; grid-template-columns: 236px 1fr; height: 100vh; }

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding: 24px 16px 18px;
  gap: 22px;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 2px; }
.brand-mark {
  width: 36px; height: 36px;
  background: var(--text);
  color: var(--bg); font-weight: 700; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.brand-sub { font-size: 10px; color: var(--text-3); letter-spacing: 0.22em; text-transform: uppercase; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
/* Guide Line Extension：左基准线 hover/active 变红 + 背景激活 */
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-left: 3px solid var(--line);
  color: var(--text-2); text-decoration: none; font-size: 13px;
  cursor: pointer;
  transition: color 0.15s ease-out, background-color 0.15s ease-out, border-color 0.15s ease-out;
}
.nav-item:hover { background: var(--surface-2); border-left-color: var(--red); color: var(--text); }
.nav-item.active { background: var(--surface-2); border-left-color: var(--red); color: var(--text); font-weight: 700; }
.nav-item.active svg { color: var(--red-text); }
.nav-item svg { width: 16px; height: 16px; flex: none; color: var(--text-3); transition: color 0.15s ease-out; }
.nav-item:hover svg { color: var(--text); }

.sidebar-foot { display: flex; flex-direction: column; gap: 10px; padding: 0 2px; }
.engine-badge { display: flex; flex-wrap: wrap; gap: 6px; }
.engine-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-2);
  border: 1px solid var(--line); padding: 3px 8px;
  background: var(--surface);
}
.engine-pill .dot { width: 7px; height: 7px; background: var(--line); flex: none; }
.engine-pill.on .dot { background: var(--text); }
.engine-pill.busy .dot { background: var(--red); animation: pulse 1.2s infinite; }
.theme-toggle {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-3); background: none;
  border: none; cursor: pointer; padding: 4px 6px;
  transition: color 0.15s ease-out, background-color 0.15s ease-out;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle svg { width: 14px; height: 14px; }

.main { overflow-y: auto; height: 100vh; }
.view { padding: 34px 42px 56px; max-width: 1180px; margin: 0 auto; }

/* ---------- 页头 ---------- */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-title { font-size: 32px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.05; margin: 0 0 8px; }
.page-desc { font-size: 13px; color: var(--text-2); margin: 0; line-height: 1.7; max-width: 640px; }
.page-actions { display: flex; gap: 10px; flex: none; align-items: center; }

/* ---------- 卡片 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 20px 22px;
}
.card-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--text); margin: 0 0 14px;
}
.grid { display: grid; gap: 14px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 980px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* ---------- KPI ---------- */

.kpi { padding: 18px 20px; }
.kpi .kpi-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text); display: flex; align-items: baseline; gap: 8px;
}
.kpi .kpi-label .muted { font-weight: 400; text-transform: none; letter-spacing: 0.02em; }
.kpi .kpi-num {
  font-size: 36px; font-weight: 700; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; margin-top: 10px; line-height: 1;
}
.kpi .kpi-target { font-size: 11.5px; color: var(--text-3); margin-top: 8px; }
.delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 700; padding: 2px 8px;
  border: 1px solid currentColor;
  font-variant-numeric: tabular-nums;
}
.delta.up { color: var(--blue); }
.delta.down { color: var(--red-text); }
.delta.flat { color: var(--text-3); }
.delta svg { width: 11px; height: 11px; }

/* ---------- 按钮 / 输入 ---------- */

/* 按钮必须带方向性：::after 的 → 是排版的一部分，hover 位移是唯一允许的移动 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  padding: 8px 16px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s ease-out, color 0.15s ease-out, border-color 0.15s ease-out;
}
.btn::after {
  content: "→";
  display: inline-block;
  transition: transform 0.15s ease-out;
}
.btn:hover::after { transform: translateX(3px); }
.btn:hover { background: var(--surface-2); }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn-primary:hover { background: var(--red); border-color: var(--red); color: #ffffff; }
.btn-danger { color: var(--red-text); border-color: var(--red); background: var(--surface); }
.btn-danger:hover { background: var(--red); color: #ffffff; }
.btn-sm { padding: 4px 10px; font-size: 12px; gap: 6px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn[disabled]::after { content: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 1px solid transparent;
  background: none; color: var(--text-3); cursor: pointer;
  transition: color 0.15s ease-out, background-color 0.15s ease-out, border-color 0.15s ease-out;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn svg { width: 15px; height: 15px; }

.input, .select, .textarea {
  font-family: var(--font); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  padding: 8px 12px; width: 100%;
  transition: border-color 0.15s ease-out;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--red); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 74px; line-height: 1.65; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-2);
}
.field .hint { font-size: 11.5px; color: var(--text-3); line-height: 1.5; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* 开关：方形轨道 + 方形滑块，选中态黑底白块 */
.switch { position: relative; display: inline-block; width: 36px; height: 18px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  border: 1px solid var(--border); background: var(--surface);
  transition: background-color 0.15s ease-out; cursor: pointer;
}
.switch .track::after {
  content: ""; position: absolute; width: 12px; height: 12px;
  background: var(--text); top: 2px; left: 2px;
  transition: transform 0.15s ease-out, background-color 0.15s ease-out;
}
.switch input:checked + .track { background: var(--text); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--bg); }

/* ---------- 表格 ---------- */

.table-card { padding: 0; overflow: hidden; }
/* 移动端文档卡片列表：宽屏隐藏，窄屏替代表格 */
.doc-cards { display: none; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text);
  padding: 11px 14px;
  border-bottom: 2px solid var(--border);
  background: var(--surface); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; line-height: 1.5; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color 0.15s ease-out; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { font-variant-numeric: tabular-nums; }
.td-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------- Chips（矩形描边标签） ---------- */

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; padding: 2px 8px;
  border: 1px solid; white-space: nowrap; letter-spacing: 0.02em;
}
.c-gray { color: var(--text); border-color: var(--line); }
.c-blue { color: var(--blue); border-color: var(--blue); }
.c-green { background: var(--text); color: var(--bg); border-color: var(--text); }
.c-red { color: var(--red-text); border-color: var(--red); }
.c-amber { color: var(--blue); border-color: var(--blue); }
.c-violet { background: var(--blue); color: #ffffff; border-color: var(--blue); }

/* ---------- 对话页 ---------- */

/* 对话页容器：两栏（任务面板 + 对话），撑满主区高度；内层 .chat-main 再限宽 860px */
.view-chat { height: 100%; display: flex; flex-direction: column; padding-bottom: 24px; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 16px; }
.chat-head h2 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.chat-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 24px; padding: 10px 2px 20px; }

/* 空状态：左对齐（Swiss 反对居中排版） */
.chat-empty { margin: auto 0; max-width: 520px; padding: 40px 0; }
.chat-empty .glyph {
  width: 56px; height: 56px; margin: 0 0 20px;
  background: var(--text);
  color: var(--bg); font-size: 24px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.chat-empty h3 { font-size: 26px; margin: 0 0 10px; font-weight: 700; letter-spacing: -0.02em; }
.chat-empty p { color: var(--text-2); font-size: 13.5px; line-height: 1.75; margin: 0 0 24px; }
.suggests { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest {
  font-size: 12.5px; color: var(--text-2); background: var(--surface);
  border: 1px solid var(--border); padding: 8px 14px;
  cursor: pointer; text-align: left;
  transition: color 0.15s ease-out, background-color 0.15s ease-out, border-color 0.15s ease-out;
}
.suggest:hover { border-color: var(--red); color: var(--text); background: var(--surface-2); }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px; max-width: 78%; line-height: 1.7; font-size: 14px;
}

.msg-ai { align-items: stretch; }
.ai-head {
  display: flex; align-items: center; gap: 8px; font-size: 11px;
  color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em;
}
.ai-head .ai-mark {
  width: 22px; height: 22px; font-size: 11px;
  background: var(--text); color: var(--bg);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
}
.ai-body { line-height: 1.85; font-size: 14.2px; white-space: pre-wrap; word-break: break-word; padding-left: 30px; }
.ai-body.md-body { white-space: normal; }
.ai-body .ref { color: var(--red-text); font-weight: 700; font-size: 12px; vertical-align: super; }

/* 消息卡：全边框 + 彩色标签（不用单侧粗色条） */
.msg-card { padding: 14px 18px; border: 1px solid var(--border); margin-left: 30px; }
.msg-card .card-tag {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.msg-card.refused .card-tag { color: var(--red-text); }
.msg-card.clarify .card-tag { color: var(--blue); }
.msg-card .card-body { font-size: 13.5px; line-height: 1.8; white-space: pre-wrap; }

.cite-row { display: flex; flex-wrap: wrap; gap: 7px; padding-left: 30px; margin-top: 4px; }
.cite {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-2); background: var(--surface);
  border: 1px solid var(--line); padding: 5px 11px;
  cursor: pointer; max-width: 340px;
  transition: color 0.15s ease-out, background-color 0.15s ease-out, border-color 0.15s ease-out;
}
.cite:hover { border-color: var(--red); color: var(--text); background: var(--surface-2); }
.cite .n {
  width: 17px; height: 17px; flex: none;
  background: var(--red); color: #ffffff; border: none;
  font-size: 10.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.cite .cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ai-foot { display: flex; align-items: center; gap: 6px; padding-left: 30px; margin-top: 6px; }
.ai-meta { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.vote-btn { color: var(--text-3); }
.vote-btn.voted { color: var(--red-text); background: var(--surface-2); border-color: var(--red); }

.typing { display: inline-flex; gap: 5px; padding: 12px 0 4px 30px; }
.typing span {
  width: 7px; height: 7px; background: var(--text-3);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  padding: 10px 10px 10px 16px;
  transition: border-color 0.15s ease-out;
}
.composer:focus-within { border-color: var(--red); }
.composer textarea {
  flex: 1; border: none; resize: none; background: none; outline: none;
  font-family: var(--font); font-size: 14px; color: var(--text); line-height: 1.6;
  max-height: 140px; padding: 6px 0;
}
.composer .send {
  width: 38px; height: 38px; border: none; flex: none;
  background: var(--text); color: var(--bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background-color 0.15s ease-out;
}
.composer .send:hover { background: var(--red); color: #ffffff; }
.composer .send[disabled] { opacity: 0.45; cursor: not-allowed; }
.composer .send svg { width: 16px; height: 16px; }

/* ---------- 抽屉（溯源原文） ---------- */

.drawer-mask, .modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none; transition: opacity 0.15s ease-out; z-index: 40;
}
.drawer-mask.open, .modal-mask.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 430px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--border);
  transform: translateX(102%); transition: transform 0.15s ease-out;
  z-index: 50; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 18px 20px 14px; border-bottom: 2px solid var(--border); }
.drawer-head h3 { margin: 0 0 10px; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.drawer-head h3 svg { width: 16px; height: 16px; color: var(--red-text); flex: none; }
.drawer-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.drawer-body { padding: 18px 20px 30px; overflow-y: auto; font-size: 13.2px; line-height: 1.9; white-space: pre-wrap; color: var(--text); }
.drawer-body mark {
  background: transparent; color: inherit;
  border-bottom: 2px solid var(--red); font-weight: 700; padding: 0;
}
.drawer-close { position: absolute; top: 14px; right: 14px; }

/* ---------- 弹窗 ---------- */

.modal-mask { display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal {
  width: 600px; max-width: 96vw; max-height: 84vh;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 0; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 20px; }

/* ---------- Toast ---------- */

.toasts { position: fixed; top: 18px; right: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  padding: 10px 16px; font-size: 13px;
  display: flex; align-items: center; gap: 8px; max-width: 380px;
  animation: toast-in 0.15s ease-out;
}
.toast::before { content: ""; width: 8px; height: 8px; background: var(--text); flex: none; }
.toast.ok::before { background: var(--text); }
.toast.err::before { background: var(--red); }
.toast.info::before { background: var(--blue); }

/* ---------- 上传区 ---------- */

.dropzone {
  border: 1px solid var(--border);
  padding: 28px; text-align: left; color: var(--text-2); cursor: pointer;
  transition: color 0.15s ease-out, background-color 0.15s ease-out, border-color 0.15s ease-out;
  background: var(--surface);
}
.dropzone:hover, .dropzone.drag { border-color: var(--red); background: var(--surface-2); color: var(--text); }
.dropzone svg { width: 26px; height: 26px; margin-bottom: 10px; }
.dropzone .dz-title { font-size: 14px; font-weight: 700; }
.dropzone .dz-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  padding: 9px 16px; font-size: 13px; color: var(--text-2); cursor: pointer;
  border: none; background: none; font-family: var(--font); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 0.15s ease-out, border-color 0.15s ease-out;
}
.tab:hover { color: var(--red-text); }
.tab.active { color: var(--text); font-weight: 700; border-bottom-color: var(--red); }

/* ---------- 评测报告：环形饼图 ---------- */

.eval-report { padding: 18px 22px 20px; }
.report-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.ring-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 20px 24px;
  padding-top: 18px;
}

/* 单指标环：小号，指标 + 数值在右侧 */
.ring-item { display: flex; align-items: center; gap: 12px; }
.ring-wrap { width: 62px; height: 62px; flex: none; }
.ring-wrap svg { width: 100%; height: 100%; display: block; }
.ring-track { fill: none; stroke: var(--line); stroke-width: 5; }
.ring-value {
  fill: none; stroke: var(--red); stroke-width: 5;
  stroke-linecap: butt;
  transition: stroke-dasharray 0.4s ease-out;
}
.ring-tick { fill: none; stroke: var(--text-3); stroke-width: 1.5; opacity: 0.85; }
.ring-meta { display: flex; flex-direction: column; gap: 2px; }
.ring-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--text);
}
.ring-num {
  font-size: 22px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.ring-sub { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* 组成饼图：大号，图例在下方 */
.pie-block { text-align: center; }
.pie-block > .ring-label { display: block; margin-bottom: 8px; }
.donut-wrap { position: relative; width: 106px; height: 106px; margin: 0 auto; }
.donut-wrap svg { width: 100%; height: 100%; display: block; }
.donut-base { fill: none; stroke: var(--line); stroke-width: 9; }
.donut-seg { fill: none; stroke-width: 9; }
.donut-seg.seg-a { stroke: var(--red); }
.donut-seg.seg-b { stroke: var(--text); }
.donut-seg.seg-c { stroke: var(--blue); }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; pointer-events: none;
}
.donut-center .dc-main {
  font-size: 18px; font-weight: 700; letter-spacing: -0.02em; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.donut-center .dc-sub { font-size: 10px; color: var(--text-3); letter-spacing: 0.04em; }
.pie-legend {
  display: flex; gap: 12px; justify-content: center; margin-top: 10px;
  font-size: 11.5px; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.pie-legend .lg {
  display: inline-block; width: 8px; height: 8px; margin-right: 5px;
  vertical-align: middle;
}
.pie-legend .lg.seg-a { background: var(--red); }
.pie-legend .lg.seg-b { background: var(--text); }

@media (max-width: 900px) {
  .ring-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pie-block { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .ring-row { grid-template-columns: 1fr; gap: 14px; }
  .ring-wrap { width: 54px; height: 54px; }
}

/* ---------- 条形图 ---------- */

.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; font-size: 12.5px; }
.bar-row .bl { width: 108px; color: var(--text-2); flex: none; text-align: right; }
.bar-row .track { flex: 1; height: 10px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--text); }
.bar-row .bv { width: 60px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }

/* ---------- 状态徽标 / 进度 ---------- */

/* 方块状态点 + 文字：颜色不单独传状态 */
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.status-dot::before { content: ""; width: 8px; height: 8px; background: var(--line); }
.st-done::before { background: var(--text); }
.st-running::before { background: var(--blue); animation: pulse 1.2s infinite; }
.st-queued::before { background: var(--line); }
.st-error::before { background: var(--red); }
.st-cancelled::before { background: var(--text-3); }
.st-idle::before { background: var(--line); }

.progress { height: 8px; background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.progress > div { height: 100%; background: var(--text); transition: width 0.15s ease-out; }

/* ---------- 杂项 ---------- */

.empty { text-align: left; padding: 40px 20px; color: var(--text-3); font-size: 13px; }
.empty svg { width: 28px; height: 28px; margin-bottom: 10px; opacity: 0.6; }

.muted { color: var(--text-3); }
.small { font-size: 12px; }
.mono { font-family: var(--font); font-size: 12px; font-variant-numeric: tabular-nums; }
.mt-8 { margin-top: 8px; } .mt-14 { margin-top: 14px; } .mt-20 { margin-top: 20px; } .mt-28 { margin-top: 28px; }
.mb-14 { margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }

.best-row td { background: var(--surface-2) !important; }
.best-badge {
  /* 徽标是不可拆分的整体：一行放不下时整体换到下一行，绝不在「最 / 优」之间断字 */
  display: inline-block; white-space: nowrap;
  font-size: 10.5px; font-weight: 700; color: #ffffff; background: var(--red);
  padding: 2px 7px; letter-spacing: 0.04em; margin-left: 4px;
}

.settings-section { margin-bottom: 18px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
@media (max-width: 860px) { .settings-grid { grid-template-columns: 1fr; } }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: none; }
.switch-row .sw-label { font-size: 13px; }
.switch-row .sw-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

/* ---------- Markdown 渲染 ---------- */

.md-body { line-height: 1.85; font-size: 14.2px; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { font-weight: 700; margin: 18px 0 8px; letter-spacing: -0.02em; }
.md-body h1 { font-size: 18px; border-bottom: 2px solid var(--border); padding-bottom: 6px; }
.md-body h2 { font-size: 16px; }
.md-body h3 { font-size: 14px; color: var(--text-2); }
.md-body p { margin: 0 0 10px; }
.md-body strong { font-weight: 700; }
.md-body blockquote {
  border-left: 1px solid var(--line); padding-left: 14px;
  margin: 8px 0; color: var(--text-2); font-size: 13.5px;
}
.md-body code {
  font-family: var(--font); font-size: 12.5px; font-weight: 700;
  background: var(--surface-2); padding: 2px 6px;
  border: 1px solid var(--line);
}
.md-body pre {
  background: var(--surface); border: 1px solid var(--border);
  padding: 12px 14px; overflow-x: auto;
  font-family: var(--font); font-size: 12.5px; line-height: 1.6;
  margin: 8px 0 12px;
}
.md-body pre code { background: none; border: none; padding: 0; font-size: inherit; font-weight: 400; }
.md-body ul, .md-body ol { padding-left: 20px; margin: 6px 0 10px; }
.md-body li { margin-bottom: 3px; }
.md-body table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  margin: 10px 0 14px; border: 1px solid var(--border);
}
.md-body th {
  background: var(--surface); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; font-size: 11.5px; color: var(--text);
  padding: 7px 12px; text-align: left; border-bottom: 2px solid var(--border);
}
.md-body td { padding: 7px 12px; border-bottom: 1px solid var(--line); }
.md-body tr:last-child td { border-bottom: none; }
.md-body a { color: var(--text); text-decoration: underline; transition: color 0.15s ease-out; }
.md-body a:hover { color: var(--red-text); }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md-body .ref {
  color: var(--red-text); font-weight: 700; font-size: 12px;
  vertical-align: super; cursor: default;
}

/* ================= 流式回答：思维链 ================= */

.reasoning-box {
  margin: 8px 0 10px;
  border-left: 1px solid var(--line);
  padding: 2px 0 2px 12px;
}
.reasoning-box.collapsed .reasoning-body {
  max-height: 90px;
  overflow: hidden;
}
.reasoning-head {
  font-size: 10.5px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.12em;
  margin-bottom: 4px;
}
.reasoning-body {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
/* 回答完成后：思维链折叠为不可展开的说明条（需求：完整回答出现后不能回看） */
.reasoning-folded {
  margin: 6px 0 10px;
  font-size: 12px;
  color: var(--muted);
}
.reasoning-folded summary {
  cursor: default;
  list-style: none;
  user-select: none;
}
.reasoning-folded summary::-webkit-details-marker { display: none; }
.reasoning-cached { display: none; }   /* 只留存不展示 */
.ai-status { color: var(--muted); }

/* ================= 消息卡片：图标尺寸与错误态 ================= */

.msg-card .card-tag > svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  display: block;
}
.msg-card.error { border-color: var(--line); }
.msg-card.error .card-tag { color: var(--text-2); }
.msg-card.error .card-body { color: var(--text-2); font-size: 13px; }

/* ================= 实验看板：运行进度 ================= */

.lab-progress { margin: 0 0 14px; }
.lp-track {
  height: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}
.lp-fill {
  height: 100%;
  background: var(--text);
  transition: width 0.15s ease-out;
}
.lp-text {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--muted);
}
.lp-text b { color: var(--text); font-weight: 700; }

/* 运行中的行轻微高亮，便于一眼定位进度 */
tr:has(.st-running) { background: var(--surface-2); }

/* 进度条里的中断按钮 */
.lp-cancel {
  margin-left: 10px;
  padding: 2px 10px;
  font-size: 12px;
  vertical-align: middle;
}

/* ================= 多用户（登录门 / 任务栏 / 用户框） ================= */

.auth-wrap {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.auth-card {
  width: 380px; max-width: calc(100vw - 40px);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 30px 28px;
}
.auth-card .field { margin-bottom: 12px; }
.auth-card .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.auth-card .tabs .tab {
  border: 0; background: transparent; padding: 8px 14px; cursor: pointer;
  color: var(--text-2); border-bottom: 2px solid transparent; font-size: 13px;
}
.auth-card .tabs .tab.active { color: var(--text); border-bottom-color: var(--red); font-weight: 700; }

/* ---------- 对话页：左侧对话 + 右侧任务面板 ---------- */

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 268px;
  gap: 22px;
  height: 100%;
  min-height: 0;
}

.task-panel {
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.task-panel-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line);
}
.tp-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; }
.tp-sub {
  font-size: 12px; color: var(--text-3); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px;
}
.tp-new { flex: none; }

.task-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px;
}
.task-item {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 11px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease-out, background-color 0.15s ease-out;
}
.task-item:hover { border-color: var(--text-3); background: var(--surface-2); }
.task-item.active { border-color: var(--red); background: var(--surface-2); }
.ti-title {
  font-size: 13px; line-height: 1.45; color: var(--text);
  /* 标题最多两行，超出省略，避免长标题把卡片撑变形 */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.task-item.active .ti-title { font-weight: 700; }
.ti-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 6px;
}
.ti-turns { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ti-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s ease-out; }
.task-item:hover .ti-actions, .task-item.active .ti-actions { opacity: 1; }
.tc-btn {
  border: 0; background: transparent; color: var(--text-3); cursor: pointer;
  font-size: 12px; padding: 0 3px; line-height: 1;
}
.tc-btn:hover { color: var(--red-text); }

.task-empty { padding: 18px 4px; }
.task-empty p { font-size: 12.5px; color: var(--text-3); line-height: 1.7; margin: 0; }

.chat-main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  /* 阅读宽度上限，宽屏时在自己的列内居中，消息行不会拉得过长 */
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.user-box {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 12px; margin-bottom: 8px;
  border: 1px solid var(--border);
}
.user-box .user-meta { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.user-box .user-meta b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================= 动画 ================= */

@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes toast-in { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   移动端适配（手机端 ≤768px；平板收紧 ≤1024px）
   侧栏变左侧滑出层 + 顶栏三条杠（几何线条）；表格横向滚动；
   触控目标 ≥44px；输入 16px 防 iOS 聚焦缩放。全部沿用本风格 token。
   ============================================================ */

body { -webkit-tap-highlight-color: transparent; }

/* Markdown 内表格窄容器横向滚动，不撑破网格 */
.md-body table { display: block; overflow-x: auto; }

/* 桌面端隐藏移动组件 */
.mobile-bar, .mobile-mask { display: none; }

@media (max-width: 1024px) {
  .view { padding: 24px 24px 44px; }
}

@media (max-width: 768px) {
  /* ---------- 外壳：顶栏 + 滑出侧栏 ---------- */

  .app { display: block; height: auto; }
  /* 顶栏 52px 之外的高度全给主区；dvh 让移动浏览器地址栏收起时也贴合 */
  .main { height: calc(100vh - 52px); height: calc(100dvh - 52px); }

  .mobile-bar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 30;
    height: 52px; padding: 0 12px;
    background: var(--bg); border-bottom: 1px solid var(--border);
  }
  .hamburger {
    width: 44px; height: 44px; flex: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    padding: 0; border: 1px solid var(--border); background: var(--surface); cursor: pointer;
    transition: background-color 0.15s ease-out;
  }
  .hamburger span { width: 18px; height: 2px; background: var(--text); transition: background-color 0.15s ease-out; }
  body.nav-open .hamburger span { background: var(--red); }
  .mobile-brand { display: flex; align-items: baseline; gap: 8px; font-size: 15px; font-weight: 700; letter-spacing: -0.02em; }
  .mobile-sub { font-size: 9px; font-weight: 400; letter-spacing: 0.22em; color: var(--text-3); }

  .mobile-mask {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.15s ease-out;
  }
  body.nav-open .mobile-mask { opacity: 1; pointer-events: auto; }

  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(280px, 84vw);
    /* 抽出抽屉时盖住顶栏（含刘海/状态栏），内容从顶栏下方开始 */
    padding-top: calc(60px + env(safe-area-inset-top));
    height: 100vh; height: 100dvh;
    background: var(--bg);
    transform: translateX(-105%); transition: transform 0.15s ease-out;
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: none; }

  /* ---------- 排版与页头：纵向堆叠 ---------- */

  .view { padding: 20px 16px 40px; }
  .page-head { flex-direction: column; gap: 14px; margin-bottom: 20px; }
  .page-title { font-size: 26px; }
  .page-actions { flex-wrap: wrap; width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }

  /* ---------- 表格：横向滚动不换行挤压 ---------- */

  .table-card { overflow-x: auto; }
  table.table { min-width: 720px; }
  .table td { padding: 9px 12px; }

  /* 知识库文档列表：移动端隐藏表格，换成全宽卡片，操作按钮直接可见 */
  .docs-table { display: none; }
  .doc-cards { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
  .doc-card {
    display: flex; flex-direction: column; gap: 10px;
    background: var(--surface); border: 1px solid var(--border);
    padding: 14px 16px;
  }
  .doc-card .dc-name { font-size: 15px; font-weight: 650; word-break: break-all; }
  .doc-card .dc-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .doc-card .dc-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .doc-card .dc-actions { display: flex; gap: 8px; }
  .doc-card .dc-actions .btn { flex: 1; justify-content: center; min-height: 44px; font-size: 13px; }

  /* ---------- 卡片 / 表单 ---------- */

  .card { padding: 16px; }
  .kpi .kpi-num { font-size: 30px; }
  .form-row { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px; }

  /* ---------- 对话页 ---------- */

  /* 对话页占满顶栏之下的全部高度：列表自己滚，输入框永远贴在底部 */
  .view-chat { padding-bottom: 12px; height: calc(100vh - 52px); height: calc(100dvh - 52px); display: flex; flex-direction: column; }
  .chat-head h2 { font-size: 20px; }

  /* 窄屏：两栏塌成一栏，任务面板变成横向滑动的条，不占竖向空间 */
  /* minmax(0,1fr) 关键：1fr 的最小宽度是内容宽，横向滚动的任务条会把整页撑爆 */
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);   /* 任务条按内容高，对话区吃掉剩余高度 */
    gap: 12px;
    height: 100%;
    min-height: 0;
  }
  /* 桌面端面板在右（DOM 在后）；窄屏改成面板在上，任务列表先可见，不用滚到底 */
  .task-panel { min-height: 0; min-width: 0; order: -1; }
  .task-panel-head { padding: 12px 14px; }
  .tp-sub { max-width: 46vw; }
  .task-list {
    flex-direction: row; overflow-x: auto; overflow-y: hidden;
    padding: 10px 12px; gap: 8px;
  }
  .task-item { flex: 0 0 auto; width: 58vw; max-width: 240px; }
  .ti-actions { opacity: 1; }
  .chat-main { max-width: none; min-width: 0; min-height: 0; height: 100%; }
  /* 输入框与底部安全区分开，避免被 iPhone 手势条压住 */
  .composer { margin-top: 8px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

  .msg-user .bubble { max-width: 94%; }
  .ai-body, .cite-row, .ai-foot, .typing { padding-left: 0; }
  .msg-card { margin-left: 0; }
  .chat-empty h3 { font-size: 22px; }
  .composer .send { width: 44px; height: 44px; }
  .composer textarea { font-size: 16px; }
  .suggest { padding: 10px 12px; }

  /* ---------- 输入控件：16px 防 iOS 聚焦缩放 ---------- */

  .input, .select, .textarea { font-size: 16px; }

  /* ---------- 触控目标 / 杂项 ---------- */

  .btn { padding: 10px 14px; }
  .btn-sm { padding: 8px 10px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  /* 抽屉里的导航项加高，整行都好点 */
  .nav-item { min-height: 44px; }
  /* 触控目标：所有图标按钮与微操作补到 44px 热区（图标大小不变） */
  .icon-btn { width: 44px; height: 44px; flex: none; }
  .tc-btn { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; padding: 0 6px; }
  .vote-btn { width: 44px; height: 44px; }
  .theme-toggle { min-height: 44px; padding: 8px 10px; }
  .bar-row .bl { width: 84px; }
  .toasts { left: 16px; right: 16px; top: 12px; }
  .toast { max-width: 100%; }
  .modal-mask { padding: 12px; }
  .modal { max-height: 92vh; }
  .modal-body { overflow: auto; }   /* 逐题结果等宽表横竖都可滚 */
}

/* 实验详情：与基线不同的参数行高亮 */
.param-diff { background: rgba(255, 193, 7, 0.07); }
.param-diff td:first-child { box-shadow: inset 3px 0 0 var(--tan, #c8a165); }

/* 实验详情弹窗：4 列表格需要更宽，否则说明列被挤成细条 */
.modal.modal-wide { width: 940px; max-width: 96vw; }
.modal-wide .modal-body { max-height: 72vh; }
.modal-wide table.table { table-layout: fixed; }
.modal-wide table.table td,
.modal-wide table.table th {
  vertical-align: top;
  padding: 10px 12px;
  line-height: 1.65;
  word-break: break-word;
}
