/* 数字工厂 dashboard 样式。复用 style.css 设计 token。 */
.factory { display: flex; flex-direction: column; gap: var(--sp-sm); }

/* ── beaver 工位配色：随暗色模式适配（JS 从 computed value 读取） ── */
/* life 是当前唯一的活阶段；egg/boot/grow/butler 保留给 DB 里的遗留任务，
   同场渲染时靠颜色区分。 */
:root {
  --beaver-life: #4a8a5a;
  --beaver-egg: #c79a3a;
  --beaver-boot: #8a6d3b;
  --beaver-grow: #6f8a4a;
  --beaver-butler: #5a7aa8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --beaver-life: oklch(72% 0.12 150);
    --beaver-egg: oklch(78% 0.11 80);
    --beaver-boot: oklch(70% 0.06 75);
    --beaver-grow: oklch(74% 0.10 120);
    --beaver-butler: oklch(74% 0.09 250);
  }
}

/* ── 货流漏斗：单行紧凑流（异常融入主流）── */
.factory-funnel {
  display: flex; align-items: center; gap: var(--sp-sm); flex-wrap: wrap;
  padding: 10px var(--sp-md); background: var(--surface);
  border: 1px solid var(--rule-subtle); border-radius: var(--radius-md);
}
.funnel-main { display: flex; align-items: center; gap: var(--sp-sm); flex-wrap: wrap; }
.funnel-branch { display: none; } /* 隐藏分支，异常直接放主流 */
.funnel-stage { display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 8px; }
.funnel-n { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); line-height: 1; }
.funnel-l { font-size: 11px; color: var(--ink-dim); font-weight: 500; letter-spacing: 0.01em; }
.funnel-sub { color: var(--ink-faded); font-size: 10px; font-weight: 400; margin-left: 3px; }
.funnel-arrow { color: var(--ink-faded); font-size: 13px; flex: none; margin: 0 2px; }
.funnel-done .funnel-n { color: var(--success); }
.funnel-problem { margin-left: auto; padding-left: 12px; border-left: 2px solid var(--danger-soft); }
.funnel-problem .funnel-n { color: var(--danger); }
.funnel-problem .funnel-l { color: var(--danger); font-weight: 600; }

/* ── 可点击元素统一为按钮（无障碍）：去掉原生按钮外观 ── */
.beaver, .crate, .wbox, .fo-page {
  font: inherit; color: inherit; background: none; border: 0; padding: 0;
  -webkit-appearance: none; appearance: none;
}
.beaver:focus-visible, .crate:focus-visible, .wbox:focus-visible, .fo-page:focus-visible,
.ft-help:focus-visible, .wh-toggle:focus-visible, .factory-detail .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm);
}
.wbox:disabled { cursor: default; }

/* 运行进度 N/M 页 */
.beaver-prog {
  font-size: 9px; color: var(--accent-ink); display: block; text-align: center;
  font-variant-numeric: tabular-nums; line-height: 1.2;
}
.ship-fly { will-change: transform, opacity; }

/* 触控目标 ≥44px（仅粗指针设备的交互元素） */
@media (pointer: coarse) {
  .ft-help, .wh-toggle, .crate, .fm-range-btn { min-height: 44px; }
  .fm-range-btn { min-width: 44px; }
  .problem-job { min-height: 44px; align-items: center; }
  .fo-page { min-height: 44px; }
}

/* ── 顶栏 ── */
.factory-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px var(--sp-md); background: var(--surface);
  border-bottom: 1px solid var(--rule-subtle);
}
.ft-title {
  font-weight: 600; font-size: 15px; margin: 0; color: var(--ink);
  display: flex; align-items: center; gap: 6px;
}
.ft-help { display: none; } /* 隐藏"角色"按钮 */
.ft-stat {
  font-size: 11px; color: var(--ink-dim); font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; background: var(--paper);
  border: 1px solid var(--rule-subtle); border-radius: var(--radius-full);
  white-space: nowrap;
}
.ft-stat b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
.ft-conn {
  margin-left: auto; font-size: 10px; color: var(--success);
  display: flex; align-items: center; gap: 4px; font-weight: 500;
}
.ft-conn::before { content: '●'; font-size: 8px; animation: pulse-dot 2s ease-in-out infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* 角色介绍卡片 */
.factory-roles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--sp-sm); padding: var(--sp-sm);
  background: var(--surface); border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-md);
}
.role-card { display: flex; gap: 10px; align-items: flex-start; padding: 8px; }
.role-emoji { font-size: 28px; flex: none; line-height: 1; }
.role-name { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.role-desc { font-size: 12px; color: var(--ink-dim); line-height: 1.6; }
#ft-overseer.active { border-color: var(--warning); }
#ft-overseer.active b { color: var(--warning); }

/* ── 主舞台：纵向布局，流水线居顶 ── */
.factory-stage { display: flex; flex-direction: column; gap: var(--sp-sm); }

/* ── 流水线：全宽主舞台 ── */
.factory-line {
  background: var(--surface); border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-md); padding: var(--sp-sm);
}
.overseer-track { position: relative; height: 28px; margin-bottom: 4px; }
.overseer { position: absolute; left: 0; font-size: 20px; transition: left .6s var(--ease-out, ease-out); cursor: help; }
.overseer::after { content: "🦦"; animation: overseer-bob 1.8s ease-in-out infinite; display: inline-block; }
.overseer { font-size: 0; }  /* 隐藏原 emoji，用 ::after 带动画 */
.overseer::after { font-size: 20px; }
@keyframes overseer-bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-3px) rotate(3deg); } }

/* 单工位：占满整行（原来四工位并排 + 传送带的布局已下线） */
.workstations { display: flex; align-items: stretch; gap: 0; }
.workstation {
  flex: 1 1 auto; background: var(--paper);
  border: 1px solid var(--rule-subtle); border-radius: 3px; padding: 8px;
  transition: border-color var(--dur-fast, .15s), box-shadow var(--dur-fast, .15s);
}
.ws-head { display: flex; align-items: center; gap: 5px; font-size: 12px; margin-bottom: 8px; }
.ws-icon { font-size: 15px; }
.ws-name { color: var(--ink-dim); }
/* 遗留阶段副标：只在真有旧任务在跑时才有内容 */
.ws-sub { font-size: 10px; color: var(--ink-faded); cursor: help; }
.ws-count {
  margin-left: auto; font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 1px 6px; border-radius: var(--radius-full);
  background: var(--rule-subtle); color: var(--ink-dim);
}
.ws-count.active { background: var(--accent-soft); color: var(--accent-ink); }
.ws-count.problem { background: var(--danger-soft); color: var(--danger); }
.ws-review { font-size: 12px; margin-left: 4px; }
.ws-review.pass { color: var(--success); }
.ws-review.warn { color: var(--warning); }
.ws-review.fail { color: var(--danger); }
/* 单工位横向铺满后每行能放十几只海狸，放宽高度上限少出滚动条 */
.ws-floor {
  display: flex; flex-wrap: wrap; gap: 8px 6px; min-height: 96px; max-height: 280px;
  overflow-y: auto; align-content: flex-start; padding: 2px;
}

/* ── beaver 工人 ── */
.beaver {
  position: relative; width: 72px; cursor: pointer; text-align: center;
  transition: transform var(--dur-fast, .15s);
}
.beaver:hover { transform: scale(1.1); z-index: 1; }
.beaver:active { transform: scale(0.96); }
.beaver-svg { width: 38px; height: 38px; display: block; margin: 0 auto; }
/* 槽位加宽到 72px：54px 放不下书名，长标题会和邻居视觉重叠 */
.beaver-label {
  display: block; width: 100%; max-width: 100%;
  font-size: 9px; color: var(--ink-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
/* lifecycle 阶段标签（如 GRW 22/120），完整链条进度在 title 里 */
.beaver-stage {
  display: block; font-size: 9px; line-height: 1.25; font-weight: 600;
  color: var(--accent-ink); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 72px;
  font-variant-numeric: tabular-nums;
}
.beaver-prog { display: block; font-size: 9px; color: var(--ink-faded); font-variant-numeric: tabular-nums; }
.beaver-dur { font-size: 9px; color: var(--ink-faded); display: block; text-align: center; font-variant-numeric: tabular-nums; }
.beaver-dur-total { font-size: 8px; color: var(--ink-faded); display: block; text-align: center; font-variant-numeric: tabular-nums; opacity: 0.8; }
/* 遗留阶段任务的角标 */
.beaver-old {
  position: absolute; top: -3px; left: 2px;
  font-size: 8px; font-weight: 700; padding: 0 3px;
  border-radius: var(--radius-full);
  background: var(--rule-subtle); color: var(--ink-faded);
}
.beaver.legacy .beaver-svg { opacity: .85; }
.beaver.working .beaver-svg { animation: beaver-bob .65s ease-in-out infinite; }
.beaver.idle .beaver-svg { animation: beaver-bob 2.6s ease-in-out infinite; opacity: .7; }
.beaver.problem .beaver-svg { animation: beaver-flash .5s steps(2) infinite; }
.beaver .beaver-badge { position: absolute; top: -4px; right: 2px; font-size: 11px; }
.float-token { position: absolute; font-size: 10px; color: var(--accent-ink); font-weight: 600; pointer-events: none; }
@keyframes beaver-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes beaver-flash { 0% { filter: none; } 100% { filter: drop-shadow(0 0 4px var(--danger)); } }

/* ── 辅助区：今日产出改成书级折叠后信息更密，再加宽一档 ── */
.factory-aux {
  display: grid;
  grid-template-columns: minmax(160px, 0.85fr) minmax(320px, 1.35fr) minmax(300px, 1.8fr);
  gap: 10px; align-items: start;
}
.factory-zone {
  background: var(--surface); border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-md); padding: 10px;
}
.factory-zone h2 {
  font-size: 12px; color: var(--ink-dim); margin: 0 0 8px;
  font-weight: 600;
  display: flex; align-items: center; gap: 5px;
}
.aux-count {
  font-size: 10px; font-weight: 700; padding: 1px 6px;
  background: var(--rule-subtle); color: var(--ink-dim);
  border-radius: var(--radius-full); font-variant-numeric: tabular-nums;
}

/* 原料区 */
.raw-crates { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; }
.crate {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: var(--paper); border: 1px solid var(--rule-subtle);
  border-radius: 3px; font-size: 12px; cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.crate { width: 100%; text-align: left; }
.crate:hover { border-color: var(--accent); transform: translateX(2px); box-shadow: var(--shadow-sm); }
.crate:active { transform: scale(0.96); }
.crate-icon { font-size: 14px; }

/* 异常队列：历史失败与实时工位分离，避免把失败库存误读为当前堵塞 */
.aux-count.danger { background: var(--danger-soft); color: var(--danger); }
.problem-mini {
  font-size: 10px; color: var(--ink-faded); font-weight: 500;
  padding: 1px 6px; border: 1px solid var(--rule-subtle); border-radius: var(--radius-full);
}
.problem-mini b { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.problem-groups { display: flex; flex-direction: column; gap: 5px; max-height: 340px; overflow-y: auto; }
.problem-card {
  background: var(--paper); border: 1px solid var(--rule-subtle); border-radius: 3px;
  padding: 7px 9px; box-shadow: var(--shadow-xs, none);
}
.problem-card.retryable { border-color: var(--warning); }
.problem-card.review { border-color: var(--danger); }
.problem-head { display: flex; align-items: center; gap: 8px; }
.problem-title { font-size: 12px; font-weight: 700; color: var(--ink); }
.problem-count {
  margin-left: auto; font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--danger); background: var(--danger-soft); border-radius: var(--radius-full); padding: 1px 7px;
}
.problem-meta { font-size: 10px; color: var(--ink-faded); margin-top: 3px; }
.problem-suggestion { font-size: 11px; color: var(--ink-dim); line-height: 1.45; margin-top: 5px; }
.problem-jobs { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.problem-job {
  display: inline-flex; gap: 5px; align-items: center; max-width: 170px;
  padding: 3px 7px; border: 1px solid var(--rule-subtle); border-radius: var(--radius-full);
  color: var(--accent-ink); background: var(--surface); font-size: 10px; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.problem-job span { color: var(--ink-faded); }
.problem-job:hover { border-color: var(--accent); }
.problem-empty { font-size: 12px; color: var(--ink-faded); padding: 10px; background: var(--paper); border-radius: var(--radius-sm); }

/* ── 今日产出：内容口径的产出（真实新建/更新的页面）── */
.factory-output h2 { flex-wrap: wrap; }
.aux-count.success { background: var(--accent-soft); color: var(--success); }
.fo-mini {
  font-size: 10px; color: var(--ink-faded); font-weight: 500;
  padding: 1px 6px; border: 1px solid var(--rule-subtle); border-radius: var(--radius-full);
}
.fo-mini b { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.fo-trend { margin-left: auto; line-height: 0; cursor: help; }
.fo-list { display: flex; flex-direction: column; gap: 4px; max-height: 340px; overflow-y: auto; }

/* 书级汇总行（第一层）：点击就地展开该书的页面明细 */
.fo-book {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  padding: 6px 8px; cursor: pointer;
  background: var(--paper); border: 1px solid var(--rule-subtle); border-radius: 3px;
  font-size: 12px; color: var(--ink);
  transition: border-color .15s, background .15s;
}
.fo-book:hover { border-color: var(--accent); }
.fo-book.expanded { border-color: var(--accent); background: var(--accent-soft); }
.fo-book-caret { flex: none; font-size: 9px; color: var(--ink-faded); width: 9px; }
.fo-book-title {
  font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fo-book-wikis, .fo-book-split {
  flex: none; font-size: 9px; color: var(--ink-faded);
  padding: 0 5px; border: 1px solid var(--rule-subtle); border-radius: var(--radius-full);
}
.fo-book-split { margin-left: auto; font-variant-numeric: tabular-nums; }
.fo-book-wikis + .fo-book-split { margin-left: 0; }
.fo-book-wikis { margin-left: auto; }
.fo-book-n {
  flex: none; font-weight: 700; color: var(--success);
  font-variant-numeric: tabular-nums;
}
/* 书内明细：左侧竖线示意层级 */
.fo-book-detail {
  display: flex; flex-direction: column; gap: 3px;
  margin: 2px 0 4px 10px; padding-left: 8px;
  border-left: 2px solid var(--accent-soft);
}
.fo-loading { font-size: 11px; color: var(--ink-faded); padding: 6px 2px; }

/* wiki 分组标题：一书多 wiki 时才出现 */
.fo-wiki {
  display: flex; align-items: baseline; gap: 6px; font-size: 11px;
  padding: 5px 2px 2px; color: var(--ink-dim);
}
.fo-wiki:not(:first-child) { border-top: 1px solid var(--rule-subtle); margin-top: 3px; }
.fo-wiki-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fo-wiki-n {
  margin-left: auto; font-weight: 700; color: var(--success);
  font-variant-numeric: tabular-nums; flex: none;
}
.fo-page {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  padding: 5px 8px; cursor: pointer;
  background: var(--paper); border: 1px solid var(--rule-subtle); border-radius: 3px;
  font-size: 12px; color: var(--accent-ink);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.fo-page:hover { border-color: var(--accent); transform: translateX(2px); box-shadow: var(--shadow-sm); }
.fo-page:active { transform: scale(0.98); }
.fo-page.loading { opacity: .6; cursor: progress; }
.fo-page-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fo-page-time {
  margin-left: auto; flex: none; font-size: 10px;
  color: var(--ink-faded); font-variant-numeric: tabular-nums;
}
.fo-badge {
  flex: none; font-size: 9px; font-weight: 700;
  padding: 0 5px; border-radius: var(--radius-full);
}
.fo-badge.new { background: var(--accent-soft); color: var(--accent-ink); }
.fo-badge.upd { background: var(--rule-subtle); color: var(--ink-dim); }
.fo-empty {
  font-size: 12px; color: var(--ink-faded); padding: 10px;
  background: var(--paper); border-radius: var(--radius-sm);
}
/* 仓库累计降级为底部一行：产出区的主体是今日清单，累计只作参照 */
.fo-warehouse {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
  padding-top: 7px; border-top: 1px solid var(--rule-subtle);
  font-size: 10px; color: var(--ink-faded);
}
.fo-warehouse #wh-count { color: var(--ink-dim); font-variant-numeric: tabular-nums; font-weight: 600; }

/* 仓库：折叠态（容器已并入今日产出区，仅保留展开后的盒子样式） */
.factory-output .warehouse-boxes { margin-top: var(--sp-sm); }
.wh-toggle {
  margin-left: auto; background: none; border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-full); cursor: pointer; font-size: 11px;
  color: var(--ink-dim); padding: 1px 8px; line-height: 1.6;
  transition: border-color .15s, color .15s;
}
.wh-toggle:hover { border-color: var(--accent); color: var(--accent-ink); }
.warehouse-boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; max-height: 240px; overflow-y: auto; }
.wbox {
  padding: 8px 10px; background: var(--paper); border: 1px solid var(--rule-subtle);
  border-radius: 3px; font-size: 12px; cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.wbox { width: 100%; text-align: left; }
.wbox:hover:not(:disabled) { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.wbox:active:not(:disabled) { transform: scale(0.96); }
.wbox-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wbox-meta { color: var(--ink-dim); font-size: 11px; margin-top: 2px; }

/* ── 详情面板：右侧固定滑入 ── */
.factory-detail {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(420px, 100vw);
  z-index: 50; background: var(--surface); border-left: 1px solid var(--rule);
  box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; padding: var(--sp-md);
  animation: slide-in-right .2s ease-out;
}
@keyframes slide-in-right { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-out-right { from { transform: none; opacity: 1; } to { transform: translateX(20px); opacity: 0; } }
.factory-detail.closing { animation: slide-out-right .15s ease-in forwards; }
.fd-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; margin-bottom: 10px; font-size: 14px;
}

/* 阶段时间线 */
.fd-timeline {
  display: flex; align-items: center; gap: 3px; flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px solid var(--rule-subtle); margin-bottom: 8px;
  min-height: 32px;
}
.fd-tphase {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11px;
  padding: 3px 8px; border-radius: var(--radius-full);
  background: var(--paper); border: 1px solid var(--rule-subtle); color: var(--ink-dim);
  white-space: nowrap;
}
.fd-tphase.done { border-color: var(--success); color: var(--success); }
.fd-tphase.active {
  border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft);
  font-weight: 600;
}
.fd-tphase.failed { border-color: var(--danger); color: var(--danger); }
.fd-tarrow { color: var(--ink-faded); font-size: 10px; }

/* 日志流 */
.fd-feed {
  flex: 1; overflow-y: auto; font-size: 12px;
  font-family: var(--font-mono, monospace); line-height: 1.55;
}
.fd-feed .fd-supervise { color: var(--warning); }
.fd-feed .fd-token { color: var(--accent-ink); }
.fd-feed .fd-phase { color: var(--info); font-weight: 600; }
.fd-feed .fd-error { color: var(--danger); }
.fd-feed .fd-review { color: var(--success); font-weight: 600; }
.fd-feed .fd-review-issue { color: var(--ink-dim); padding-left: 6px; }
.fd-feed .fd-noise { color: var(--ink-faded); font-size: 11px; font-style: italic; }
.fd-feed .fd-system { color: var(--ink-dim); font-size: 11px; }
.fd-feed .fd-raw { color: var(--ink-faded); font-size: 10px; font-family: monospace; }
.ws-review { cursor: help; }

/* ══ 生产观测 ══════════════════════════════════════════════════════════════
   图表色不复用页面的 --success/--danger 等语义色：那几个是按「彩字压 soft 底」
   的徽标场景调的（深色模式 L 到 0.72~0.75），当图表填充用时超出可读的明度带。
   这里用 dataviz 参考调色板的 slot 1/2，两个模式各自选值、都过了六项校验：
     浅色 #2a78d6/#eb6834 on #ffffff — CVD ΔE 24.7，正常视觉 33.6
     深色 #3987e5/#d95926 on #1b1b19 — CVD ΔE 26.8，正常视觉 31.8
   （node scripts/validate_palette.js 实测，2026-09-10） */
.factory-metrics {
  --fm-series-1: #2a78d6;      /* 新建 / 单系列默认 */
  --fm-series-2: #eb6834;      /* 更新 */
  --fm-grid: var(--rule-subtle);
  margin-bottom: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .factory-metrics {
    --fm-series-1: #3987e5;
    --fm-series-2: #d95926;
  }
}
:root[data-theme="dark"] .factory-metrics {
  --fm-series-1: #3987e5;
  --fm-series-2: #d95926;
}

.fm-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.fm-head h2 { margin: 0; }
.fm-status { min-width: 0; font-size: 10px; color: var(--ink-faded); }
.fm-status.is-error { color: var(--danger); }
/* 筛选控件在图表上方一行（interaction.md） */
.fm-range { display: flex; gap: 2px; margin-left: auto; }
.fm-range-btn {
  font: inherit; font-size: 11px; line-height: 1;
  padding: 4px 8px; cursor: pointer;
  background: var(--paper); color: var(--ink-dim);
  border: 1px solid var(--rule-subtle); border-radius: var(--radius-sm);
}
.fm-range-btn:hover { background: var(--raised); color: var(--ink); }
.fm-range-btn.is-active {
  background: var(--accent-soft); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600;
}

/* KPI 行。头条数字刻意用比例数字而不是 tabular-nums：等宽数字在 22px 这种
   展示字号下会让「177」显得松垮。等宽只留给需要纵向对齐的地方（轴刻度、
   数据表），那里对齐才有意义。 */
.fm-kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px; margin-bottom: 12px;
}
.fm-kpi {
  background: var(--paper); border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.fm-kpi-v {
  font-size: 22px; font-weight: 700; color: var(--ink);
  line-height: 1.1;
}
.fm-kpi-l { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.fm-kpi-n { font-size: 10px; color: var(--ink-faded); margin-top: 1px; }

.fm-charts {
  display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 12px;
  align-items: end;
}
.fm-chart { margin: 0; min-width: 0; }
.fm-chart figcaption {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin-bottom: 4px;
}
.fm-chart-title { font-size: 11px; font-weight: 600; color: var(--ink-dim); }
.fm-chart-note { font-size: 10px; color: var(--ink-faded); }
.fm-plot { min-width: 0; }
.fm-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.fm-empty {
  font-size: 11px; color: var(--ink-faded); text-align: center;
  padding: 28px 0; background: var(--paper); border-radius: var(--radius-sm);
}

/* 轴与标签一律走文字色，不穿系列色（dataviz：text wears text tokens） */
.fm-axis-label { font-size: 9px; fill: var(--ink-faded); }
.fm-peak-label {
  font-size: 10px; font-weight: 700; fill: var(--ink-dim);
}

/* 图例：≥2 系列常在，色块只作为身份的辅助，文字自带标签 */
.fm-legend { display: inline-flex; gap: 10px; }
.fm-li { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; color: var(--ink-dim); }
.fm-sw {
  display: inline-block; width: 8px; height: 8px; border-radius: 2px;
  vertical-align: middle; margin-right: 3px; flex: 0 0 auto;
}

.fm-hit { cursor: crosshair; }
.fm-tip {
  position: fixed; z-index: 80; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 6px 8px; font-size: 11px; line-height: 1.5;
  max-width: 220px; font-variant-numeric: tabular-nums;
}

/* 表格视图：图表的等价文本形式，默认折叠 */
.fm-table-wrap { margin-top: 10px; }
.fm-table-wrap summary {
  font-size: 11px; color: var(--ink-dim); cursor: pointer;
  padding: 2px 0; width: fit-content;
}
.fm-table-wrap summary:hover { color: var(--ink); }
.fm-table-scroll { max-height: 240px; overflow-y: auto; margin-top: 6px; }
.fm-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.fm-table th, .fm-table td {
  text-align: right; padding: 3px 8px;
  border-bottom: 1px solid var(--rule-subtle);
  font-variant-numeric: tabular-nums;
}
.fm-table th:first-child, .fm-table td:first-child { text-align: left; }
.fm-table thead th {
  position: sticky; top: 0; background: var(--surface);
  color: var(--ink-dim); font-weight: 600;
}

/* ── 响应式 ── */
@media (max-width: 1024px) {
  .factory-aux { grid-template-columns: 1fr 1.5fr 1fr; }
  .fm-charts { grid-template-columns: 1fr 1fr; }
  /* 页面产出是主图，窄屏下独占一行 */
  #fm-chart-pages { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .factory-aux { grid-template-columns: 1fr; }
  .fm-charts { grid-template-columns: 1fr; }
  /* 单工位不再横向滚动，但监工是 %定位的巡逻轨，窄屏下意义不大 */
  .overseer-track { display: none; }
  .factory-detail { width: 100vw; top: auto; height: 55vh; border-left: none; border-top: 1px solid var(--rule); animation: slide-in-up .2s ease-out; }
  @keyframes slide-in-up { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
}
@media (prefers-reduced-motion: reduce) {
  .beaver .beaver-svg { animation: none !important; }
  .overseer { transition: none; }
  .factory-detail, .factory-detail.closing { animation: none; }
}
