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

/* ── beaver 工位配色：随暗色模式适配（JS 从 computed value 读取） ── */
:root {
  --beaver-egg: #c79a3a;
  --beaver-boot: #8a6d3b;
  --beaver-grow: #4a8a5a;
  --beaver-butler: #5a7aa8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --beaver-egg: oklch(78% 0.11 80);
    --beaver-boot: oklch(70% 0.06 75);
    --beaver-grow: oklch(72% 0.12 150);
    --beaver-butler: oklch(74% 0.09 250);
  }
}

/* ── 货流漏斗：待处理 → 进行中 → 今日完成（异常单列告警） ── */
.factory-funnel {
  display: flex; align-items: center; gap: var(--sp-sm); flex-wrap: wrap;
  padding: var(--sp-sm) var(--sp-md); background: var(--surface);
  border: 1px solid var(--rule-subtle); border-radius: var(--radius-md);
}
.funnel-stage { display: inline-flex; align-items: baseline; gap: 7px; padding: 4px 10px; border-radius: var(--radius-md); }
.funnel-n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); line-height: 1; }
.funnel-l { font-size: 12px; color: var(--ink-dim); }
.funnel-sub { color: var(--ink-faded); font-size: 11px; }
.funnel-arrow { color: var(--ink-faded); font-size: 14px; flex: none; }
.funnel-done .funnel-n { color: var(--success); }
.funnel-problem { margin-left: auto; background: var(--danger-soft); }
.funnel-problem .funnel-n,
.funnel-problem .funnel-l { color: var(--danger); }

/* ── 可点击元素统一为按钮（无障碍）：去掉原生按钮外观 ── */
.beaver, .crate, .wbox {
  font: inherit; color: inherit; background: none; border: 0; padding: 0;
  -webkit-appearance: none; appearance: none;
}
.beaver:focus-visible, .crate:focus-visible, .wbox: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; }

/* 工位异常文字标签（不只靠颜色） */
.ws-alert {
  font-size: 10px; font-weight: 700; color: var(--danger);
  background: var(--danger-soft); padding: 0 5px; border-radius: var(--radius-full);
}
/* 运行进度 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 { min-height: 44px; }
  .problem-job { min-height: 44px; align-items: center; }
}

/* ── 顶栏 ── */
.factory-topbar {
  display: flex; align-items: center; gap: var(--sp-md); flex-wrap: wrap;
  padding: var(--sp-sm) var(--sp-md); background: var(--surface);
  border: 1px solid var(--rule-subtle); border-radius: var(--radius-md);
}
.ft-title { font-weight: 700; font-size: 16px; }
.ft-stat {
  font-size: 12px; color: var(--ink-dim);
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; background: var(--paper);
  border: 1px solid var(--rule-subtle); border-radius: var(--radius-full);
}
.ft-stat b { color: var(--accent-ink); font-variant-numeric: tabular-nums; font-weight: 700; }
.ft-conn { margin-left: auto; font-size: 12px; color: var(--ink-faded); }
.ft-help {
  font-size: 12px; color: var(--ink-dim); cursor: pointer;
  background: var(--paper); border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-full); padding: 3px 10px;
  transition: border-color .15s, color .15s;
}
.ft-help:hover { border-color: var(--accent); color: var(--accent-ink); }

/* 角色介绍卡片 */
.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-md); }

/* ── 流水线：全宽主舞台 ── */
.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; min-width: 0; background: var(--paper);
  border: 1px solid var(--rule-subtle); border-radius: var(--radius-sm); padding: 8px;
  transition: border-color var(--dur-fast, .15s), box-shadow var(--dur-fast, .15s);
}
.workstation.has-problem { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger-soft); }
.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-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: 6px; min-height: 100px; max-height: 180px;
  overflow-y: auto; align-content: flex-start; padding: 2px;
}

/* 传送带（工位之间动态小点） */
.ws-conveyor {
  flex: none; width: 28px; align-self: center;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  padding: 0 4px;
}
.ws-conveyor span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); opacity: 0.25;
  animation: conv-pulse 1.4s ease-in-out infinite;
}
.ws-conveyor span:nth-child(1) { animation-delay: 0s; }
.ws-conveyor span:nth-child(2) { animation-delay: .46s; }
.ws-conveyor span:nth-child(3) { animation-delay: .92s; }
@keyframes conv-pulse {
  0%, 100% { opacity: 0.15; transform: scale(0.75); }
  50% { opacity: 0.9; transform: scale(1.2); }
}

/* ── beaver 工人 ── */
.beaver {
  position: relative; width: 54px; cursor: pointer; text-align: center;
  transition: transform var(--dur-fast, .15s);
}
.beaver:hover { transform: scale(1.1); }
.beaver-svg { width: 38px; height: 38px; display: block; margin: 0 auto; }
.beaver-label {
  font-size: 9px; color: var(--ink-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 54px;
}
.beaver-dur { font-size: 9px; color: var(--ink-faded); display: block; text-align: center; font-variant-numeric: tabular-nums; }
.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); 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: 200px minmax(320px, 1fr) 1fr; gap: var(--sp-md); align-items: start;
}
.factory-zone {
  background: var(--surface); border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-md); padding: var(--sp-sm);
}
.factory-zone h2 {
  font-size: 12px; color: var(--ink-dim); margin: 0 0 var(--sp-sm);
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.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: 5px; max-height: 180px; overflow-y: auto; }
.crate {
  display: flex; align-items: center; gap: 6px; padding: 7px 9px;
  background: var(--paper); border: 1px solid var(--rule-subtle);
  border-radius: var(--radius-sm); 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-icon { font-size: 15px; }

/* 异常队列：历史失败与实时工位分离，避免把失败库存误读为当前堵塞 */
.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: 8px; max-height: 260px; overflow-y: auto; }
.problem-card {
  background: var(--paper); border: 1px solid var(--rule-subtle); border-radius: var(--radius-sm);
  padding: 9px 10px; box-shadow: var(--shadow-xs, none);
}
.problem-card.retryable { border-color: var(--warning); background: var(--warning-soft); }
.problem-card.review { border-color: var(--danger); background: var(--danger-soft); }
.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-warehouse h2 { margin-bottom: 0; }
.factory-warehouse .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: var(--radius-sm); font-size: 12px; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.wbox { width: 100%; text-align: left; }
.wbox:hover:not(:disabled) { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.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; } }
.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); }
.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; }
.ws-review { cursor: help; }

/* ── 响应式 ── */
@media (max-width: 860px) {
  .factory-aux { grid-template-columns: 1fr; }
  .workstations { overflow-x: auto; }
  .workstation { min-width: 120px; }
  /* 工位横向滚动后，%定位的监工会与工位错位 → 窄屏隐藏巡逻轨 */
  .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, .ws-conveyor span { animation: none !important; }
  .overseer { transition: none; }
  .factory-detail { animation: none; }
}
