/* 本地 AI 工作台 —— 设计系统
 *
 * 取向：Linear 式的克制。信息密集但可读，靠留白与对齐分区，不靠给每个区域套边框。
 * 全局只有一个强调色（操作与焦点）；L0/L1/L2 三色只在调度语义里出现。
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --sunken: #fbfcfd;
  --ink: #14161a;
  --ink-2: #3a4048;
  --muted: #6b7480;
  --faint: #9aa1ab;
  --line: #e6e8ec;
  --line-2: #d8dce2;

  --accent: #2563eb;
  --accent-ink: #1d4ed8;
  --accent-wash: #eef4ff;

  --l0: #0f9d8a;
  --l1: #3b6fe0;
  --l2: #b7791f;
  --reserve: #c9ced6;

  --ok: #15803d;
  --warn: #b45309;
  --bad: #b42318;
  --ok-wash: #eaf6ee;
  --warn-wash: #fdf3e3;
  --bad-wash: #fdeceb;

  --radius: 8px;
  --radius-lg: 12px;

  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* ---------- shell ---------- */

.app {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr) 296px;
  height: 100vh;
  overflow: hidden;
}

.rail {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
}
.brand .mark {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
}
.brand strong { display: block; font-size: 13.5px; font-weight: 650; }
.brand-sub { display: block; font-size: 11px; color: var(--faint); }

.nav { list-style: none; margin: 0; padding: 0 8px; }
.nav button {
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.nav button:hover { background: var(--bg); }
.nav button.on { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }

.rail-sessions {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding: 12px 8px 0;
}
.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 8px;
  font-size: 11px; font-weight: 650; color: var(--muted);
  letter-spacing: .02em;
}
.sessions { list-style: none; margin: 0; padding: 0 0 8px; overflow-y: auto; flex: 1; }
.sessions li {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink-2);
}
.sessions li:hover { background: var(--bg); }
.sessions li.on { background: var(--bg); color: var(--ink); font-weight: 600; }
.sessions .t {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sessions .n { font-family: var(--mono); font-size: 10.5px; color: var(--faint); }
.sessions .x {
  border: 0; background: transparent; color: var(--faint);
  cursor: pointer; font-size: 13px; line-height: 1; padding: 0 2px;
  opacity: 0;
}
.sessions li:hover .x { opacity: 1; }
.sessions .x:hover { color: var(--bad); }
.sessions .empty { color: var(--faint); cursor: default; font-size: 12px; }

.rail-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }

/* ---------- main ---------- */

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

.view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.view[hidden] { display: none; }

.view-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}
.view-head h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.head-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- 上下文预算条 ---------- */

/* 常驻在对话视图顶部。它决定下一条请求会不会被 409 拒绝，所以不能只放在
   hover 里。整体配色由 data-pressure 驱动：四段共用一套色，分段各自上色会
   让人误以为每段有独立的告警级别，而预算是一个整体。 */
.ctxbar {
  flex: none;
  padding: 9px 22px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--sunken);
  font-size: 12px;
  color: var(--ink-2);
}
.ctxbar[hidden] { display: none; }

.ctxbar-head {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: default;
}
.ctxbar-label { color: var(--muted); flex: none; }
.ctxbar-num { font-family: var(--mono); font-size: 11.5px; flex: none; }
.ctxbar-pct { font-weight: 650; flex: none; min-width: 40px; }
.ctxbar-mini { display: none; font-weight: 650; }

.ctxbar-meter {
  flex: 1; min-width: 60px; height: 8px;
  display: flex; gap: 1px;
  border-radius: 4px; overflow: hidden;
  background: var(--line);
}
.ctxbar-meter i { display: block; height: 100%; background: var(--accent); }
.ctxbar[data-pressure="warn"] .ctxbar-meter i { background: var(--warn); }
.ctxbar[data-pressure="tight"] .ctxbar-meter i { background: #c2410c; }
.ctxbar[data-pressure="over"] .ctxbar-meter i { background: var(--bad); }

/* 预留输出不是已经用掉的上下文，用斜纹跟前三段区分开。 */
.ctxbar-meter i.s-res {
  opacity: .5;
  background-image: repeating-linear-gradient(
    45deg, rgba(255, 255, 255, .6) 0 3px, transparent 3px 6px);
}

.ctxbar-body { margin-top: 7px; display: grid; gap: 4px; }
.ctxbar-segs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  color: var(--muted);
}
.ctxbar-segs .seg b {
  color: var(--ink); font-weight: 600;
  font-family: var(--mono); font-size: 11.5px;
}
.ctxbar-segs .sep { color: var(--line-2); }
.ctxbar-segs .dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 2px; margin-right: 4px; background: var(--accent);
}
.ctxbar[data-pressure="warn"] .ctxbar-segs .dot { background: var(--warn); }
.ctxbar[data-pressure="tight"] .ctxbar-segs .dot { background: #c2410c; }
.ctxbar[data-pressure="over"] .ctxbar-segs .dot { background: var(--bad); }
.ctxbar-segs .dot.s-res { opacity: .5; }

/* 上一轮实测：跟主数字并排解释「为什么预计会跳这么多」。 */
.ctxbar-last { color: var(--muted); }
.ctxbar-last[hidden] { display: none; }
.ctxbar-last b {
  color: var(--ink); font-weight: 600;
  font-family: var(--mono); font-size: 11.5px;
}

/* 实测 / 估算拆分：主数字里有多少是引擎真量到的，多少是按比率猜的。 */
.ctxbar-split { color: var(--muted); }
.ctxbar-split[hidden] { display: none; }
.ctxbar-split b {
  color: var(--ink); font-weight: 600;
  font-family: var(--mono); font-size: 11.5px;
}

.ctxbar-kv { color: var(--muted); }
.ctxbar-kv b {
  color: var(--ink); font-weight: 600;
  font-family: var(--mono); font-size: 11.5px;
}
.ctxbar-advice { color: var(--muted); }
.ctxbar[data-pressure="tight"] .ctxbar-advice { color: var(--warn); }
.ctxbar[data-pressure="over"] .ctxbar-advice { color: var(--bad); font-weight: 600; }

/* 压缩行：状态在左、两个按钮在右。按钮用 .btn.mini，不新造一套尺寸。 */
.ctxbar-compact {
  display: flex; align-items: center; gap: 10px;
  padding-top: 4px; margin-top: 2px;
  border-top: 1px dashed var(--line);
}
.ctxbar-compact[hidden] { display: none; }
.ctxbar-compact-state { color: var(--muted); flex: 1; min-width: 0; }
.ctxbar-compact-state b {
  color: var(--ink); font-weight: 600;
  font-family: var(--mono); font-size: 11.5px;
}
.ctxbar-compact-btns { display: flex; gap: 6px; flex: none; }
.ctxbar-compact-note { color: var(--muted); opacity: .8; }

.ctxbar[data-pressure="warn"] .ctxbar-pct { color: var(--warn); }
.ctxbar[data-pressure="tight"] .ctxbar-pct { color: #c2410c; }
.ctxbar[data-pressure="over"] .ctxbar-pct { color: var(--bad); }
.ctxbar[data-pressure="over"] { background: var(--bad-wash); }

/* ---------- 发送前闸门 ---------- */

/* 拦在输入框上面而不是弹窗：它跟「现在能不能发」是同一件事，弹窗会挡住对话。
   文案说清后果和出路，按钮直接触发既有的 压缩历史 / 新会话 / 清空对话。 */
.chat-gate {
  flex: none;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 22px;
  border-top: 1px solid var(--line);
  background: var(--warn-wash, var(--sunken));
  font-size: 12px; color: var(--ink-2);
}
.chat-gate[hidden] { display: none; }
.chat-gate[data-level="over"] { background: var(--bad-wash); }
.chat-gate-text { flex: 1; min-width: 200px; }
.chat-gate[data-level="over"] .chat-gate-text { color: var(--bad); font-weight: 600; }
.chat-gate-btns { display: flex; gap: 6px; flex: none; }

/* ---------- controls ---------- */

.btn {
  padding: 6px 12px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn.file { display: inline-flex; align-items: center; }

.link {
  border: 0; background: transparent; padding: 0;
  color: var(--accent); font: inherit; cursor: pointer;
}
.link:hover { text-decoration: underline; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 11px; font-weight: 600; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline.narrow input { width: 64px; }

input[type=text], input[type=number], select, textarea {
  padding: 7px 10px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  outline: none;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }

.hint { font-size: 11.5px; color: var(--muted); }
.note { font-size: 11.5px; color: var(--faint); margin: 8px 0 0; }
.note.warn { color: var(--warn); }
.note.bad { color: var(--bad); font-weight: 600; }

/*
 * 告警横幅。熔断器状态与手动操作被拒的理由都要能停留足够久——
 * 它们是一整句话，不是一个图标能说完的。
 */
.banner {
  margin: 10px 0 0;
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 12.5px;
  line-height: 1.55;
  border: 1px solid var(--line);
  background: #f6f7f9;
  color: var(--ink);
}
.banner[hidden] { display: none; }
.banner.warn { background: var(--warn-wash); border-color: #f0d9b0; color: #7a4400; }
.banner.bad { background: #fdecea; border-color: #f3c3bd; color: #8f1d14; }

/*
 * 顶部告警横幅。整体配色由 level 驱动，一条告警一个色，不逐字段上色——
 * 逐字段上色会让人以为每个数字各自有严重程度。
 *
 * flex:none + 列表限高，是为了让横幅永远抢不走视图的空间：.app 是
 * height:100vh + overflow:hidden 的固定壳，横幅一旦超过视口，下面的 .view
 * 会被压到 0 并裁掉，而且没有滚动条可以救。22 条告警实测把对话输入框推到
 * 视口底边之下 700px。
 */
.alert-banner {
  flex: none;
  /* 22px 两侧内边距对齐下面 .view-head 的内边距；顶部留 12px，不然卡片贴着
     窗口上沿，和下面的内容不在一个版心上。 */
  padding: 12px 22px 0;
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
.alert-banner[hidden] { display: none; }

/* 摘要行：常驻，折起来也留这一行。配色跟最严重的那一档走。 */
.alert-sum {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f6f7f9;
  font-size: 12px;
  color: var(--ink-2);
}
.alert-sum.bad { background: #fdecea; border-color: #f3c3bd; color: #8f1d14; }
.alert-sum.warn { background: var(--warn-wash); border-color: #f0d9b0; color: #7a4400; }
.alert-sum.info { background: #eef4fb; border-color: #c7dcf3; color: #17456f; }
.alert-chip {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .08);
}
.alert-sum-text { flex: 1 1 auto; min-width: 0; }
.alert-fold {
  flex: none;
  padding: 2px 8px;
  border: 1px solid rgba(0, 0, 0, .16);
  border-radius: 5px;
  background: rgba(255, 255, 255, .55);
  color: inherit;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.alert-fold:hover { background: rgba(255, 255, 255, .9); }

/* 列表自己滚。34vh 是给视图留位置的硬上限：857px 高的视口里横幅最多占
   约 290px，对话区还剩 560px。 */
.alert-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 34vh;
  overflow-y: auto;
  min-height: 0;
}
.alert-banner.is-folded .alert-list { display: none; }

.alert-row {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f6f7f9;
  overflow: hidden;
  flex: none;
}
.alert-row.bad { background: #fdecea; border-color: #f3c3bd; color: #8f1d14; }
.alert-row.warn { background: var(--warn-wash); border-color: #f0d9b0; color: #7a4400; }
.alert-row.info { background: #eef4fb; border-color: #c7dcf3; color: #17456f; }
.alert-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
/* 折叠态压成一行：16 条 info 每条省 10px 就是 160px。 */
.alert-row.folded .alert-head { padding: 4px 12px; }
.alert-lv {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .08);
}
.alert-title { flex: 1 1 auto; font-size: 12.5px; font-weight: 600; min-width: 0; }
.alert-since { flex: none; font-size: 11px; opacity: .75; }
.alert-body { padding: 0 12px 9px; font-size: 12.5px; line-height: 1.55; }
.alert-body p { margin: 0 0 5px; }
.alert-ev {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 12px;
  font-size: 11px;
  opacity: .85;
  border-top: 1px dashed rgba(0, 0, 0, .14);
  padding-top: 5px;
}
.alert-ev b { font-weight: 600; opacity: .8; }
#act-error { cursor: pointer; }
#act-error::after {
  content: '点击关闭';
  display: block;
  margin-top: 4px;
  font-size: 11px;
  opacity: .7;
}

/* 左栏底部两个指示各占一行：安全阀与熔断器是两件事，不该挤成一句。 */
.rail-foot { flex-direction: column; align-items: stretch; gap: 5px; }
.foot-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.foot-row span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 估算明细：比 m-meta 更淡，因为它描述的是「将会怎样」而不是「现在怎样」。 */
.m-est {
  display: flex; flex-wrap: wrap; gap: 3px 9px;
  margin-top: 4px; padding-top: 4px;
  border-top: 1px dashed var(--line);
  font-size: 11px; color: var(--faint);
}
.m-est b { color: var(--muted); font-weight: 600; }
.m-est .chip { padding: 0 5px; border-radius: 3px; background: var(--warn-wash); color: #8a4b00; font-size: 10px; font-weight: 600; }

/* ---------- thread ---------- */

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.thread .empty-state {
  margin: auto;
  max-width: 420px;
  text-align: center;
  color: var(--muted);
}
.thread .empty-state h3 { margin: 0 0 6px; font-size: 14px; color: var(--ink); font-weight: 650; }
.thread .empty-state p { margin: 0; font-size: 12.5px; }

.msg { max-width: 780px; }
.msg-head {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 5px;
  font-size: 11px; color: var(--muted);
}
.msg-head .who { font-weight: 650; color: var(--ink-2); }
.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink);
}
.msg.user .msg-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 10px 13px;
  display: inline-block;
}
.msg.pending .msg-body { color: var(--muted); font-style: italic; }
.msg.error .msg-body { color: var(--bad); }

.cites { margin-top: 10px; display: grid; gap: 6px; }
.cite {
  border-left: 2px solid var(--line-2);
  padding: 2px 0 2px 10px;
  font-size: 12px;
  color: var(--muted);
}
.cite .cite-head { display: flex; gap: 8px; align-items: baseline; }
.cite .n {
  font-family: var(--mono); font-size: 10.5px;
  color: var(--accent); font-weight: 600;
}
.cite .src { font-weight: 600; color: var(--ink-2); }
.cite .score { font-family: var(--mono); font-size: 10.5px; color: var(--faint); }
.cite .snippet { margin-top: 3px; white-space: pre-wrap; }

/* ---------- composer ---------- */

.composer {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer textarea, .composer input { width: 100%; }
.composer.slim { flex-direction: row; align-items: center; gap: 12px; }
.composer.slim input { flex: 1; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- compare ---------- */

.cmp-models {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}
.cmp-models .label { font-size: 11px; font-weight: 600; color: var(--muted); padding-top: 5px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 10px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.chip:hover { border-color: var(--faint); }
.chip.on { background: var(--accent-wash); border-color: #bcd3fb; color: var(--accent-ink); font-weight: 600; }
.chip.off { opacity: .45; text-decoration: line-through; cursor: not-allowed; }

.cmp-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 22px;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-content: start;
}
.cmp-col {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  min-height: 180px;
}
.cmp-col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.cmp-col-head .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-col-head .st { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.cmp-col-head .st.pending { color: var(--warn); }
.cmp-col-head .st.done { color: var(--ok); }
.cmp-col-head .st.error { color: var(--bad); }
.cmp-col-body {
  padding: 11px 12px;
  font-size: 13px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
}
.cmp-q {
  grid-column: 1 / -1;
  font-size: 12.5px;
  color: var(--muted);
  padding-bottom: 2px;
}
.cmp-q b { color: var(--ink); font-weight: 600; }

/* ---------- knowledge ---------- */

.kb-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.kb-docs {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 12px;
  overflow-y: auto;
}
.sub-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; font-weight: 650; color: var(--muted);
  letter-spacing: .02em;
  margin-bottom: 8px;
}
.docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.docs li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.docs li:hover { background: var(--bg); }
.docs li.on { background: var(--accent-wash); }
.docs .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.docs .m { font-family: var(--mono); font-size: 10.5px; color: var(--faint); flex: none; }
.docs .x { border: 0; background: transparent; color: var(--faint); cursor: pointer; opacity: 0; padding: 0 2px; }
.docs li:hover .x { opacity: 1; }
.docs .x:hover { color: var(--bad); }
.docs .empty { color: var(--faint); font-size: 12px; cursor: default; }

.kb-ask { display: flex; flex-direction: column; min-height: 0; }

/* ---------- vision ---------- */

.vis-drop {
  margin: 16px 22px 0;
  padding: 22px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-lg);
  background: var(--sunken);
  text-align: center;
  cursor: pointer;
  flex: none;
}
.vis-drop.over { border-color: var(--accent); background: var(--accent-wash); }
.drop-title { margin: 0; font-size: 13px; color: var(--ink-2); }
.drop-sub { margin: 5px 0 0; font-size: 11.5px; color: var(--faint); }

.vis-results {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px 22px 22px;
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-content: start;
}
.vcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex; flex-direction: column;
}
/* contain 而非 cover：OCR 的图多为竖长文档，cover 会把中间裁成空白，看不出选了哪张。 */
.vcard img { width: 100%; height: 180px; object-fit: contain; background: var(--bg); display: block; }
.vcard-body { padding: 10px 12px 12px; }
.vcard-name {
  font-size: 11.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 6px;
}
.vcard-out { font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.vcard-out.pending { color: var(--muted); font-style: italic; }
.vcard-out.error { color: var(--bad); }

/* ---------- templates ---------- */

.tpl-body {
  display: grid; grid-template-columns: 248px minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
  min-height: 0;
  flex: none;
}
.tpl-list { border-right: 1px solid var(--line); background: var(--surface); padding: 14px 12px; }
.tpl-editor { padding: 16px 22px; display: grid; gap: 12px; align-content: start; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor-actions { display: flex; align-items: center; gap: 10px; }

.tpl-run { padding: 16px 22px 22px; overflow-y: auto; flex: 1; min-height: 0; display: grid; gap: 10px; align-content: start; }
.tpl-run textarea { width: 100%; }
.runs { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.run-row {
  display: grid; grid-template-columns: 54px 1fr 110px 90px 70px;
  gap: 10px; align-items: center;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
}
.run-row:hover { background: var(--surface); }
.run-row.on { background: var(--surface); box-shadow: inset 2px 0 0 var(--accent); }
.run-row .id { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.run-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-row .md { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-row .pg { font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: right; }
.status { font-size: 11px; font-weight: 600; }
.status.done { color: var(--ok); }
.status.running { color: var(--warn); }
.status.partial { color: var(--warn); }
.status.failed { color: var(--bad); }

.run-detail { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.ritem {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
}
.ritem-head {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 11px; color: var(--muted); margin-bottom: 4px;
}
.ritem-head .n { font-family: var(--mono); color: var(--faint); }
.ritem-in { font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.ritem-out { font-size: 12.5px; margin-top: 5px; white-space: pre-wrap; word-break: break-word; }
.ritem-out.error { color: var(--bad); }

/* ---------- scheduling view ---------- */

.sched-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 18px 22px 24px;
  display: grid;
  /* 轨道必须显式给 minmax(0,1fr)。默认的 auto 轨道会被子项的 min-content 撑开——
     各模型表现表有 min-width，一条窄屏下整列都会被它顶宽，曲线跟着一起溢出。 */
  grid-template-columns: minmax(0, 1fr);
  gap: 22px; align-content: start;
}
/* 下面这几个都是单列 grid。轨道一律显式写 minmax(0,1fr)：默认的 auto 轨道会被子项的
   min-content 撑开，一旦某处有 min-width 或长不换行内容，整列连同曲线一起溢出容器。 */
.block { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.block-head h2 { margin: 0; font-size: 12px; font-weight: 650; color: var(--muted); letter-spacing: .02em; }
.cols { display: grid; grid-template-columns: 1.35fr 1fr; gap: 22px; }
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }

.membar {
  display: flex; height: 30px;
  border-radius: 7px; overflow: hidden;
  background: #eceef1;
}
.membar.thin { height: 8px; border-radius: 4px; }
.seg {
  display: flex; align-items: center; justify-content: center;
  min-width: 0; overflow: hidden;
  font-size: 10.5px; font-weight: 600; color: #fff; white-space: nowrap;
  transition: width .25s ease;
}
.membar.thin .seg { font-size: 0; }
.seg.L0 { background: var(--l0); }
.seg.L1 { background: var(--l1); }
.seg.L2 { background: var(--l2); }
.seg.reserve { background: var(--reserve); }
.seg.free { background: transparent; color: var(--muted); }
.seg.over { background: var(--bad); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--muted); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 8px; height: 8px; border-radius: 2px; }
.legend .dot.ring {
  background: transparent;
  border: 2px solid var(--bad);
  border-radius: 50%;
}

.models { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.tier-title { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 11.5px; color: var(--muted); }
.tier-title .tag { padding: 1px 6px; border-radius: 4px; color: #fff; font-size: 10.5px; font-weight: 650; }
.tag.L0 { background: var(--l0); }
.tag.L1 { background: var(--l1); }
.tag.L2 { background: var(--l2); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.m {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: var(--surface);
}
.m.on { border-color: #a8ded3; background: #f4fbf9; }
.m-top { display: flex; align-items: center; gap: 8px; }
.m-name { flex: 1; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { flex: none; padding: 1px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 600; }
.pill.on { background: #d8f3ea; color: #0b6b5c; }
.pill.off { background: #eef0f3; color: var(--muted); }
.m-meta { display: flex; flex-wrap: wrap; gap: 3px 9px; margin-top: 5px; font-size: 11.5px; color: var(--muted); }
.m-meta b { color: var(--ink); font-weight: 600; }
.m-meta .chip { padding: 0 5px; border-radius: 3px; background: var(--warn-wash); color: #8a4b00; font-size: 10.5px; font-weight: 600; }

.events { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; max-height: 380px; overflow-y: auto; }
.ev {
  display: grid; grid-template-columns: 58px 68px 1fr;
  gap: 8px; align-items: baseline;
  padding: 6px 9px;
  border-radius: 6px;
  background: var(--surface);
  font-size: 12px;
}
.ev time { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.kind { justify-self: start; padding: 0 6px; border-radius: 4px; font-size: 10.5px; font-weight: 650; text-align: center; }
.kind.load { background: var(--ok-wash); color: var(--ok); }
.kind.unload { background: var(--warn-wash); color: var(--warn); }
.kind.refuse, .kind.load_failed, .kind.overrun, .kind.safety_stuck { background: var(--bad-wash); color: var(--bad); }
.kind.corrected { background: #f1ecfd; color: #5b3fd6; }
.kind.adopt, .kind.worker_error { background: #eef0f3; color: var(--muted); }
.ev-body { color: var(--ink-2); word-break: break-word; }
.ev-body .dim { color: var(--muted); }
.empty { color: var(--faint); font-size: 12.5px; padding: 6px 0; }

.health { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 12.5px; }
.health dt { color: var(--muted); }
.health dd { margin: 0; font-weight: 600; }
.health dd.bad { color: var(--bad); }
.health dd.warn { color: var(--warn); }

/* ---------- 路由预演 ---------- */

.route { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.rt {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px 10px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 12px;
}
.rt-role { flex: none; min-width: 40px; color: var(--muted); font-weight: 600; }
.rt-model { font-weight: 600; }
.rt .tag { padding: 1px 6px; border-radius: 4px; color: #fff; font-size: 10.5px; font-weight: 650; }
.rt-est { color: var(--muted); }
.rt-est b { color: var(--ink); font-weight: 600; }
.rt-why { color: var(--muted); }
.rt-none { color: var(--faint); }

/* ---------- 调度统计 ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 6px; }
.stat {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 8px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.stat-k { color: var(--muted); font-size: 11.5px; }
.stat-v { font-size: 14px; font-weight: 650; }
.stat-x { grid-column: 1 / -1; color: var(--faint); font-size: 11px; }
.stat.bad .stat-v { color: var(--bad); }

/* ---------- inspector ---------- */

.inspector {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.insp-block { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.insp-block.grow { flex: 1; min-height: 0; overflow-y: auto; border-bottom: 0; }
.insp-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 9px;
  font-size: 11px; font-weight: 650; color: var(--muted); letter-spacing: .02em;
}

.res-list, .model-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.res-list li, .model-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 12px;
}
.res-list .tag { flex: none; width: 22px; text-align: center; padding: 0; border-radius: 3px; color: #fff; font-size: 10px; font-weight: 650; }
.res-list .nm, .model-list .nm {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--ink-2);
}
.res-list .sz, .model-list .sz { font-family: var(--mono); font-size: 10.5px; color: var(--faint); flex: none; }
.model-list li { cursor: default; }
.model-list li.dim { opacity: .5; }
.model-list li.on { background: #f4fbf9; }
.model-list .st { font-size: 10.5px; color: var(--faint); flex: none; }
.model-list li.on .st { color: var(--ok); font-weight: 600; }
.insp-foot { padding: 10px 16px; border-top: 1px solid var(--line); }

/* ---------- toasts ---------- */

.toasts {
  position: fixed; right: 20px; bottom: 20px;
  display: grid; gap: 8px; z-index: 50;
  max-width: 380px;
}
.toast {
  padding: 10px 13px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .16);
}
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* 视觉隐藏但保留在可访问树里：屏幕阅读器能到达，文件选择器也能被关联到。
   用 hidden 属性会把元素整个移出可访问树。 */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
  .app { grid-template-columns: 200px minmax(0, 1fr); }
  .inspector { display: none; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }
  .kb-body, .tpl-body { grid-template-columns: 1fr; }
  .kb-docs, .tpl-list { border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-grid { grid-template-columns: 1fr; }
}

/* ---------- 手动调度 ---------- */

.m-acts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; align-items: center; }
.btn.mini { padding: 3px 8px; font-size: 11px; border-radius: 5px; }
.btn.mini.on { background: var(--accent-wash); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.m-acts .dim { font-size: 11px; }

.flag { flex: none; padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 650; }
.flag.pin { background: var(--accent-wash); color: var(--accent-ink); }
.flag.excl { background: #fdecea; color: var(--bad); }
.m.excl { border-style: dashed; }

/* ---------- 变化曲线 ---------- */

.range { display: flex; flex-wrap: wrap; gap: 4px; }

.chart-block { margin-top: 14px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.chart-head h3 { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink-2); }

.chart-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sunken);
  padding: 6px 8px 2px;
}
.chart { display: block; width: 100%; height: 170px; }
/* 概览页那份是矮版：只给「正在变紧还是变松」一个形状，细节留给「时序」页签。 */
.chart-box.compact .chart { height: 120px; }
.chart-box.compact .chart-empty { padding: 16px 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { font-size: 9.5px; fill: var(--faint); font-family: var(--mono); }
.chart .line { stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.chart .marker { stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker-label { font-size: 9.5px; }
.chart-empty { margin: 0; padding: 26px 10px; text-align: center; font-size: 11.5px; color: var(--faint); }

.chart-block .legend { margin-top: 6px; }
.chart-block .legend b { color: var(--ink); font-weight: 600; }

/* ---------- 条形 / 水位 / 堆叠 / 散点 ---------- */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin: 10px 0 14px;
}

.bars, .meters { display: grid; gap: 5px; }

.bar-row, .meter-row {
  display: grid;
  grid-template-columns: minmax(96px, 26%) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
}

.bar-label, .meter-label {
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meter-label .dim { color: var(--faint); font-size: 10.5px; }

.bar-track, .meter-track {
  position: relative;
  height: 10px;
  background: var(--line);
  border-radius: 5px;
}
.bar-track { overflow: hidden; }

.bar-fill, .meter-fill {
  display: block;
  height: 100%;
  border-radius: 5px;
  background: var(--accent);
}
.bar-fill.ok, .meter-fill.ok { background: var(--ok); }
.bar-fill.warn, .meter-fill.warn { background: var(--warn); }
.bar-fill.bad, .meter-fill.bad { background: var(--bad); }

.bar-val, .meter-val {
  font-family: var(--mono);
  color: var(--ink);
  text-align: right;
  white-space: nowrap;
}

/* 刻度线要探出轨道一点，才看得出「条越过它了」。所以轨道不能裁剪。 */
.meter-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
}
.meter-tick.hard { background: var(--bad); }
.meter-tick.warn { background: var(--warn); }

.stack {
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--line);
}
.stack-seg { display: block; height: 100%; }
.stack + .legend { margin-top: 6px; }

/* 散点图不拉伸：圆点得是圆的，标签不能被压扁。高度由 JS 按 viewBox 比例写进
   style 的 aspect-ratio，窄屏换窄 viewBox 时比例会自动跟着变。 */
.chart.scatter { height: auto; }
.chart .pt { stroke: var(--surface); stroke-width: 1.5; }
.chart .pt.dominated { stroke: var(--bad); stroke-width: 2; fill-opacity: .3; }
.chart .pt-label { font-size: 9.5px; fill: var(--ink-2); font-family: var(--mono); }
.chart .pt-leader { stroke: var(--faint); stroke-width: .6; }
.chart .axis-title { font-size: 10px; fill: var(--muted); }

.perf { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.perf th {
  text-align: left; font-weight: 600; color: var(--muted);
  padding: 5px 8px 5px 0; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
.perf td { padding: 5px 8px 5px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.perf td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perf td.bad { color: var(--bad); font-weight: 600; }
.perf td.empty { color: var(--faint); text-align: center; padding: 16px 0; }

/* 回复气泡里的模型标记 */
.msg-head .who.model-tag {
  padding: 0 6px; border-radius: 4px;
  background: var(--accent-wash); color: var(--accent-ink); font-weight: 600;
}

/* ---------- 会话管理 ---------- */

.rail-ops { display: inline-flex; align-items: center; gap: 10px; }
.link.danger { color: var(--bad); }
.link.off { opacity: .4; pointer-events: none; }

.sessions .pick { flex: none; margin: 0 2px 0 0; cursor: pointer; }
.sessions input.rename {
  flex: 1; min-width: 0;
  padding: 2px 6px; font-size: 12.5px;
  border: 1px solid var(--accent); border-radius: 5px;
  background: var(--surface); color: var(--ink);
}
.sessions input.rename:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-wash); }

/* 单条消息的删除键：hover 才显形，平时不抢视线。 */
.msg-head { display: flex; align-items: center; gap: 8px; }
.msg-head .msg-del {
  margin-left: auto; opacity: 0; transition: opacity .12s;
  border: 0; background: transparent; color: var(--faint);
  font-size: 14px; line-height: 1; padding: 0 4px; cursor: pointer;
}
.msg:hover .msg-del { opacity: 1; }
.msg-head .msg-del:hover { color: var(--bad); }

#chat-default.on { color: var(--accent-ink); font-weight: 600; }

/* 表格容器：桌面端不产生滚动条，窄屏时让表格自己横向滑而不是把页面撑宽。 */
.tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 0; }

/* ---------- 手机端 ----------

   窄屏不是「把桌面版缩小」，而是换一套外壳：左栏收成抽屉、视图切换挪到底部、
   所有靠 hover 才显形的删除键改成常显（触屏没有 hover）。桌面端不渲染这三个元素。 */

.mtop, .mnav, .drawer-backdrop { display: none; }

@media (max-width: 820px) {
  /* 100vh 在手机浏览器里把地址栏也算进去，会把底部导航顶出屏幕。 */
  .app {
    height: 100vh;
    height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "mtop" "main" "mnav";
  }

  .mtop {
    grid-area: mtop;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }
  .m-burger {
    width: 40px; height: 40px; flex: none;
    display: grid; align-content: center; gap: 4px;
    padding: 0 10px;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
  }
  .m-burger span { display: block; height: 1.5px; border-radius: 1px; background: var(--ink-2); }
  .m-brand {
    flex: 1; min-width: 0;
    font-size: 13.5px; font-weight: 650;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .m-safety { display: inline-flex; align-items: center; gap: 8px; flex: none; font-size: 11px; color: var(--muted); }
  /* 两个指示各自成组；熔断器那组平时是 hidden，只有告警才占位。 */
  .m-ind { display: inline-flex; align-items: center; gap: 5px; }
  .m-ind[hidden] { display: none; }
  .m-ind span:last-child { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .main { grid-area: main; }

  .mnav {
    grid-area: mnav;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mnav button {
    min-height: 46px;
    padding: 6px 2px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit; font-size: 11px;
    cursor: pointer;
    box-shadow: inset 0 2px 0 transparent;
  }
  .mnav button.on {
    color: var(--accent-ink); font-weight: 650;
    box-shadow: inset 0 2px 0 var(--accent);
  }

  /* 左栏变抽屉。注意这里必须重新声明 display:flex —— 上面 820px 那条规则把它设成了 none。 */
  .rail {
    display: flex;
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(300px, 86vw);
    z-index: 40;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .04);
  }
  body.drawer-open .rail { transform: none; }

  .drawer-backdrop {
    display: block;
    position: fixed; inset: 0;
    z-index: 39;
    background: rgba(20, 22, 26, .34);
  }
  .drawer-backdrop[hidden] { display: none; }

  /* 抽屉里留会话、安全阀，以及管理区的模块入口。使用类视图在底部导航里，
     不在两处重复同一组入口；管理区四个模块底部再塞就点不准了，交给抽屉。 */
  .rail .nav { display: block; }
  .rail .nav > li:not(.nav-admin) { display: none; }
  .rail .brand { padding-top: calc(14px + env(safe-area-inset-top)); }
  .rail-sessions { margin-top: 0; border-top: 0; }

  /* 触控尺寸：桌面端的 mini 按钮约 20px 高，够鼠标点，够不着手指。 */
  .btn { min-height: 40px; padding: 8px 14px; }
  .btn.mini { min-height: 36px; padding: 6px 12px; font-size: 12.5px; }
  .link { padding: 6px 2px; }
  .chip { padding: 8px 14px; }
  .nav button { min-height: 44px; padding: 10px; }

  /* 触屏没有 hover，「悬停才显形」的删除键必须常显，否则手机上根本删不掉。 */
  .sessions li { padding: 11px 10px; }
  .docs li { padding: 11px 10px; }
  .sessions .x, .docs .x { opacity: 1; padding: 4px 8px; font-size: 16px; }
  .msg-head .msg-del { opacity: 1; padding: 4px 8px; font-size: 16px; }

  /* iOS 在输入框字号小于 16px 时会自动放大整个页面，把布局顶乱且退不回来。 */
  input[type=text], input[type=number], select, textarea { font-size: 16px; }

  .view-head { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .view-head h1 { font-size: 14.5px; }
  .head-actions { flex-wrap: wrap; gap: 6px; width: 100%; }
  .head-actions .field.inline { flex: 1 1 auto; min-width: 0; }
  .head-actions .field.inline select { flex: 1; min-width: 0; max-width: 100%; }
  .head-actions .field.inline.narrow { flex: none; }

  .thread { padding: 14px; gap: 14px; }
  .msg { max-width: none; }

  /* 上下文条在窄屏折成一行「80% · 1.03GB」，点一下展开。 */
  .ctxbar { padding: 7px 14px; }
  /* 窄屏竖向更紧张：横幅内边距跟 ctxbar 对齐，列表上限再压低一档，
     不然 667px 高的手机上告警会吃掉一半屏幕。 */
  .alert-banner { padding: 10px 14px 0; margin-bottom: 10px; }
  .alert-list { max-height: 26vh; }
  .ctxbar-head { cursor: pointer; }
  .ctxbar-label, .ctxbar-num, .ctxbar-meter { display: none; }
  .ctxbar-mini { display: inline; }
  .ctxbar-body { display: none; }
  .ctxbar.open .ctxbar-body { display: grid; }
  .composer { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  .composer.slim { flex-direction: column; align-items: stretch; }
  .composer-bar { gap: 8px; }
  .composer-bar .hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .cmp-models { flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 14px; }
  .cmp-models .label { padding-top: 0; }
  .cmp-grid { padding: 14px; gap: 12px; grid-template-columns: minmax(0, 1fr); }
  .vis-drop { margin: 12px 14px 0; padding: 16px 12px; }
  .vis-results { padding: 12px 14px 16px; grid-template-columns: minmax(0, 1fr); }

  .kb-body, .tpl-body { grid-template-columns: minmax(0, 1fr); }
  .kb-docs, .tpl-list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 34vh; }
  .tpl-editor, .tpl-run { padding: 14px; }
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-actions { flex-wrap: wrap; }

  /* 批量运行行原本五列（324px + 间距），窄屏放不下：拆成两行，模型名退到第二行。 */
  .run-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "id nm st" "md md pg";
    gap: 4px 10px;
    padding: 10px;
  }
  .run-row .id { grid-area: id; }
  .run-row .nm { grid-area: nm; }
  .run-row .status { grid-area: st; }
  .run-row .md { grid-area: md; font-size: 11.5px; }
  .run-row .pg { grid-area: pg; text-align: right; }

  .sched-scroll { padding: 14px 14px 20px; gap: 18px; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .events { max-height: none; }
  .ev { grid-template-columns: 50px 62px minmax(0, 1fr); gap: 6px; padding: 8px 9px; }
  .membar { height: 26px; }
  .perf { min-width: 460px; }

  /* toast 原本贴在右下角，窄屏会盖住底部导航。 */
  .toasts {
    left: 12px; right: 12px;
    bottom: calc(62px + env(safe-area-inset-bottom));
    max-width: none;
  }
}

/* ---------- 导航分组：使用 / 管理 ---------- */

.nav-group {
  margin: 12px 0 3px;
  padding: 0 10px;
  font-size: 10.5px;
  font-weight: 650;
  color: var(--faint);
  letter-spacing: .06em;
}
.nav-group:first-child { margin-top: 2px; }

/* 管理区是密集内容，右侧那栏在这里是重复信息，把宽度让给表格。
   只在宽屏生效：1180px 以下右侧栏本来就已隐藏，820px 以下是单列抽屉布局。 */
@media (min-width: 1181px) {
  body.zone-admin .app { grid-template-columns: 216px minmax(0, 1fr); }
  body.zone-admin .inspector { display: none; }
}
body.zone-admin #mnav-admin { color: var(--accent-ink); font-weight: 600; }

/* ---------- 子页签 ---------- */

.tabs {
  display: flex; flex-wrap: wrap; gap: 2px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}
.tabs button {
  padding: 9px 12px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }

.tabpane { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.tabpane[hidden] { display: none; }

/* ---------- 通用小标签 ---------- */

.tag { padding: 1px 6px; border-radius: 4px; color: #fff; font-size: 10.5px; font-weight: 650; }
.pill.bad { background: var(--bad-wash); color: var(--bad); }

/* ---------- 密集表格（模型管理 / 评测） ---------- */

.dense { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.dense th {
  text-align: left; font-weight: 600; color: var(--muted);
  padding: 6px 8px; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
.dense td { padding: 6px 8px; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.dense td:first-child { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dense tr:hover td { background: var(--bg); }
.dense td.bad { color: var(--bad); font-weight: 600; }
.dense td.warn { color: var(--warn); font-weight: 600; }
.row-off td { color: var(--faint); }

/* ---------- Markdown 渲染（模型回复） ---------- */
/*
 * 只作用于带 .md 的容器。渲染后的块级元素自己管间距，所以必须把
 * pre-wrap 关掉——否则 <p> 之间的换行会变成多余空行，行内 <br> 也会翻倍。
 * 用户消息不挂 .md：他们敲的就是原文，原样显示才不会意外。
 */

.msg-body.md, .cmp-col-body.md { white-space: normal; }
.msg-body.md > :first-child, .cmp-col-body.md > :first-child { margin-top: 0; }
.msg-body.md > :last-child, .cmp-col-body.md > :last-child { margin-bottom: 0; }

.md p { margin: 0 0 8px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 14px 0 6px;
  font-weight: 650;
  line-height: 1.35;
  color: var(--ink);
}
.md h1 { font-size: 17px; }
.md h2 { font-size: 15.5px; }
.md h3 { font-size: 14.5px; }
.md h4, .md h5, .md h6 { font-size: 13.5px; }

.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md li { margin: 2px 0; }
.md li > ul, .md li > ol { margin: 2px 0; }

.md code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}
.md .md-pre {
  margin: 0 0 10px;
  padding: 10px 12px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre;
  word-break: normal;
}
.md .md-pre code {
  background: none; border: 0; padding: 0;
  font-size: 12px; line-height: 1.55; color: var(--ink-2);
}

.md blockquote {
  margin: 0 0 10px;
  padding: 2px 0 2px 11px;
  border-left: 2px solid var(--line-2);
  color: var(--muted);
}
.md blockquote > :last-child { margin-bottom: 0; }

.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md strong { font-weight: 650; }
.md del { color: var(--muted); }

.md .md-tablewrap { overflow-x: auto; margin: 0 0 10px; }
.md table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.md th, .md td {
  border: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
  vertical-align: top;
}
.md th { background: var(--sunken); font-weight: 650; }
.md .md-c { text-align: center; }
.md .md-r { text-align: right; }

/* ---------- thinking（默认折叠） ---------- */
/*
 * 为什么要有这一块：thinking 模型会把输出预算花在思考上，用户只看到「生成中」
 * 很久然后要么出答案要么空。折叠起来正好解释这段等待，也不占版面。
 */

.think {
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sunken);
}
.think > summary {
  cursor: pointer;
  padding: 5px 10px;
  font-size: 11.5px;
  color: var(--muted);
  list-style: none;
  user-select: none;
}
.think > summary::-webkit-details-marker { display: none; }
.think > summary::before { content: "▸ "; color: var(--faint); }
.think[open] > summary::before { content: "▾ "; }
.think-body {
  padding: 0 10px 8px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 角色与参数面板 ---------- */
/*
 * 默认折叠：它是「设定一次就不动」的东西。但必须摆在聊天页里——写一句 system
 * 会整体替换模型的出厂人设（实测），这件事不能发生在用户看不见的地方。
 */

.persona {
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.persona-head {
  cursor: pointer;
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 12px;
  list-style: none;
  user-select: none;
}
.persona-head::-webkit-details-marker { display: none; }
.persona-head::before { content: "▸"; color: var(--faint); font-size: 10px; }
.persona[open] > .persona-head::before { content: "▾"; }
.persona-title { font-weight: 650; font-size: 12.5px; color: var(--ink-2); }
.persona-state { font-size: 11.5px; color: var(--muted); }

.persona-body { padding: 4px 12px 12px; display: grid; gap: 10px; }
.persona-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}
.persona .field { display: grid; gap: 4px; min-width: 0; }
.persona .field > span { font-size: 11px; color: var(--muted); }
.persona textarea {
  width: 100%;
  resize: vertical;
  font: 12.5px/1.55 var(--sans);
  padding: 7px 9px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--sunken);
  color: var(--ink);
}
.persona-factory {
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  padding: 7px 9px;
  background: var(--sunken);
  min-width: 0;
}
.persona-factory-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--muted);
  margin-bottom: 5px;
}
.persona-factory-text {
  font-size: 12px; line-height: 1.55; color: var(--ink-2);
  max-height: 132px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}
.persona-warn {
  font-size: 11.5px; line-height: 1.5;
  color: var(--warn);
  background: var(--warn-wash);
  border-radius: var(--radius);
  padding: 6px 9px;
}
.persona-params {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px 10px;
}
.persona-num input, .persona-num select {
  width: 100%;
  font: 12px/1.4 var(--mono);
  padding: 5px 7px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--sunken);
  color: var(--ink);
}
.persona-num input:disabled, .persona-num select:disabled {
  color: var(--faint); background: var(--bg); cursor: not-allowed;
}
.persona-actions { display: flex; align-items: center; gap: 8px; }
.persona-actions .hint { flex: 1; font-size: 11.5px; color: var(--muted); }

@media (max-width: 900px) {
  .persona-grid { grid-template-columns: minmax(0, 1fr); }
}
