@font-face { font-family: "Plex Mono"; src: url(fonts/plex-mono-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url(fonts/plex-mono-500.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url(fonts/plex-mono-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }

:root {
  /* 数据手册纸面 + 墨色 + PCB 材质色 */
  --paper: #e8ecef;
  --sheet: #fbfcfd;
  --sheet-2: #f3f5f7;
  --line: #cfd6dc;
  --line-strong: #aab4bd;
  --ink: #14202b;
  --graphite: #5a6875;
  --muted: #8693a0;
  --copper: #b06a2b;
  --copper-soft: #f2e2d2;
  --body-ic: #26323d;
  --mask: #1c6a4f;      /* 阻焊绿：直接替换 */
  --mask-soft: #dcefe5;
  --amber: #925f0e;     /* 需复核 */
  --amber-soft: #f6ead0;
  --trace: #33509c;     /* 需改板 */
  --trace-soft: #e0e6f4;
  --fault: #b3302a;     /* 不可替代 / 陷阱 */
  --fault-soft: #f7e0dc;

  --sans: "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --mono: "Plex Mono", "Cascadia Mono", Consolas, "Microsoft YaHei UI", monospace;
  --r: 6px;
  --gap: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--copper); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-glyph { width: 34px; height: 26px; }
.brand-glyph rect { fill: var(--body-ic); }
.brand-glyph .pad { fill: var(--copper); }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: 0.08em; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--graphite); letter-spacing: 0.04em; }

.job {
  display: flex;
  align-items: center;
  gap: 6px 16px;
  flex-wrap: wrap;
  margin-left: auto;
  font-size: 13px;
  color: var(--graphite);
}
.job label { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.job input[type="number"] {
  width: 64px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--sheet);
  font-family: var(--mono);
  color: var(--ink);
}
.job .check input { accent-color: var(--mask); }

.agent-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--graphite);
  background: var(--sheet-2);
}
.agent-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.agent-pill.ready .dot { background: var(--mask); }
.agent-pill.busy .dot { background: var(--copper); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------------------------------------------------------------- 三栏工作台 */
.view-tabs { display: none; }
.workbench {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(380px, 1fr) minmax(380px, 470px);
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
  height: calc(100vh - 92px);
}
.pane {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.pane-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 11px 14px 9px;
  border-bottom: 1px solid var(--line);
}
.pane-head h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.12em; }
.pane-meta { font-size: 12px; color: var(--graphite); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-head .btn { margin-left: auto; }

/* ---------------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 5px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--sheet); }
.btn-primary:not(:disabled):hover { background: #24384a; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:not(:disabled):hover { background: var(--sheet-2); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------------------------------------------------------------- BOM 栏 */
.bom-start { padding: 18px 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.bom-start p { margin: 0; color: var(--graphite); }
.bom-start .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.risk-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}
.risk-strip div { padding: 8px 12px; border-right: 1px solid var(--line); }
.risk-strip div:last-child { border-right: 0; }
.risk-strip b { display: block; font: 600 18px/1.2 var(--mono); }
.risk-strip span { font-size: 11px; color: var(--graphite); }
.risk-strip .high b { color: var(--fault); }
.risk-strip .med b { color: var(--amber); }

.bom-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.bom-line {
  display: grid;
  grid-template-columns: 4px 1fr;
  border-bottom: 1px solid var(--sheet-2);
  cursor: pointer;
}
.bom-line:hover { background: var(--sheet-2); }
.bom-line.selected { background: var(--copper-soft); }
.bom-line .rail { background: transparent; }
.bom-line.risk-high .rail { background: var(--fault); }
.bom-line.risk-medium .rail { background: var(--amber); }
.bom-line .body { padding: 8px 12px 8px 10px; min-width: 0; }
.bom-line .row1 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.refdes {
  font: 500 11px/1 var(--mono);
  padding: 3px 5px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mpn { font: 500 13px/1.3 var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bom-line .desc { font-size: 12px; color: var(--graphite); margin-top: 2px; }
.bom-line .risks { font-size: 12px; color: var(--fault); margin-top: 2px; }
.bom-line.risk-medium .risks { color: var(--amber); }
.swap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--mask-soft);
  color: var(--mask);
  font: 500 12px/1.4 var(--mono);
}
.swap.lvl-L2 { background: var(--amber-soft); color: var(--amber); }
.swap.lvl-L3 { background: var(--trace-soft); color: var(--trace); }
.bom-foot { padding: 8px 12px; border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------- 智能体栏 */
.feed { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.feed-empty { color: var(--graphite); max-width: 52ch; }
.feed-empty .lead { color: var(--ink); font-weight: 600; }

.msg { max-width: 100%; }
.msg-user {
  align-self: flex-end;
  max-width: 80%;
  background: var(--ink);
  color: var(--sheet);
  padding: 8px 12px;
  border-radius: 8px 8px 2px 8px;
  white-space: pre-wrap;
}
.msg-agent { padding: 2px 0; }
.msg-error { color: var(--fault); background: var(--fault-soft); padding: 8px 12px; border-radius: 5px; }

.tool {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--copper);
  border-radius: 4px;
  background: var(--sheet-2);
  font-size: 12px;
  animation: slidein 0.25s ease-out;
}
.tool-name { font: 600 12px/1.3 var(--mono); color: var(--copper); }
.tool-args { font-family: var(--mono); color: var(--graphite); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tool-out { color: var(--ink); white-space: nowrap; }
.tool-out.pending { color: var(--muted); }
.tool-out .trap { color: var(--fault); font-weight: 600; }
.tool .open-ev {
  grid-column: 1 / -1;
  justify-self: start;
  border: 0;
  background: none;
  padding: 0;
  color: var(--trace);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
@keyframes slidein { from { opacity: 0; transform: translateY(4px); } }

.thinking { font-size: 12px; color: var(--graphite); }
.thinking summary { cursor: pointer; color: var(--muted); }
.thinking pre { white-space: pre-wrap; font: 12px/1.5 var(--sans); margin: 6px 0 0; padding: 8px 10px; background: var(--sheet-2); border-radius: 4px; max-height: 240px; overflow: auto; }
.status-line { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.status-line::before { content: ""; width: 10px; height: 10px; border: 2px solid var(--line-strong); border-top-color: var(--copper); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.composer { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.prompts { display: flex; gap: 6px; flex-wrap: wrap; }
.prompts button {
  border: 1px solid var(--line);
  background: var(--sheet-2);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--graphite);
}
.prompts button:not(:disabled):hover { border-color: var(--copper); color: var(--ink); }
.prompts button:disabled { opacity: 0.5; cursor: not-allowed; }
.composer-row { display: flex; gap: 8px; align-items: stretch; }
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 7px 10px;
  background: var(--sheet);
}

/* Markdown（智能体回复、ECN） */
.md { font-size: 13.5px; line-height: 1.65; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1 { font-size: 18px; margin: 14px 0 8px; }
.md h2 { font-size: 15px; margin: 16px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.md h3 { font-size: 14px; margin: 12px 0 4px; }
.md p { margin: 6px 0; }
.md ul, .md ol { padding-left: 20px; margin: 6px 0; }
.md code { font-family: var(--mono); font-size: 12px; background: var(--sheet-2); padding: 1px 4px; border-radius: 3px; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 12.5px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--sheet-2); font-weight: 600; white-space: nowrap; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--copper); color: var(--graphite); background: var(--sheet-2); }

/* ---------------------------------------------------------------- 证据栏 */
.evidence { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.evidence > *, .feed > * { flex-shrink: 0; }
.ev-empty { color: var(--graphite); }

.orig-card { border: 1px solid var(--line); border-radius: 5px; padding: 10px 12px; background: var(--sheet-2); }
.orig-card .mpn { font-size: 15px; }
.orig-card .meta { font-size: 12px; color: var(--graphite); margin-top: 2px; }
.orig-card .risks { font-size: 12px; color: var(--fault); margin-top: 4px; }

.ctx-form { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; font-size: 12px; color: var(--graphite); }
.ctx-form label { display: inline-flex; align-items: center; gap: 4px; }
.ctx-form input { width: 58px; padding: 2px 5px; border: 1px solid var(--line); border-radius: 3px; font-family: var(--mono); background: var(--sheet); }
.ctx-form .note { flex-basis: 100%; color: var(--amber); }

.section-label { font-size: 11px; font-weight: 700; letter-spacing: 0.14em; color: var(--graphite); margin: 4px 0 -4px; }

.cand { border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.cand-head { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; padding: 9px 12px; align-items: center; }
.lvl {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  white-space: nowrap;
  letter-spacing: 0.04em;
}
.lvl-L1 { background: var(--mask-soft); color: var(--mask); }
.lvl-L2 { background: var(--amber-soft); color: var(--amber); }
.lvl-L3 { background: var(--trace-soft); color: var(--trace); }
.lvl-rejected { background: var(--fault-soft); color: var(--fault); }
.cand-title { min-width: 0; }
.cand-title .mpn { font-size: 14px; }
.cand-title .mfr { font-size: 12px; color: var(--graphite); }
.tag-cn { font-size: 10.5px; padding: 0 4px; border: 1px solid var(--mask); color: var(--mask); border-radius: 2px; margin-left: 4px; vertical-align: 1px; }
.cand-price { text-align: right; font-family: var(--mono); font-size: 12px; }
.cand-price .down { color: var(--mask); }
.cand-price .up { color: var(--fault); }
.cand-supply { grid-column: 2 / -1; font-size: 12px; color: var(--graphite); }
.cand-supply .short { color: var(--fault); }
.cand-notes { list-style: none; margin: 0; padding: 0 12px 8px 12px; font-size: 12px; }
.cand-notes li { padding-left: 14px; position: relative; color: var(--graphite); }
.cand-notes li::before { content: "·"; position: absolute; left: 4px; }
.cand-notes li.review { color: var(--amber); }
.cand-notes li.layout { color: var(--trace); }
.cand-actions { display: flex; gap: 6px; padding: 0 12px 10px; }
.cand.chosen { border-color: var(--mask); box-shadow: inset 3px 0 0 var(--mask); }

.compare { border-top: 1px dashed var(--line); padding: 10px 12px; background: var(--sheet-2); }
.ptable { width: 100%; border-collapse: collapse; font-size: 12px; }
.ptable th { text-align: left; font-weight: 600; color: var(--graphite); padding: 3px 4px; border-bottom: 1px solid var(--line); }
.ptable td { padding: 4px; border-bottom: 1px solid var(--sheet); vertical-align: top; }
.ptable td.v { font-family: var(--mono); white-space: nowrap; }
.ptable .st { font-size: 11px; font-weight: 600; white-space: nowrap; }
.st-ok { color: var(--mask); }
.st-better { color: var(--mask); }
.st-note { color: var(--graphite); }
.st-review { color: var(--amber); }
.st-fail { color: var(--fault); }
.st-info { color: var(--muted); }
.ptable .why { color: var(--graphite); font-size: 11.5px; }

/* 引脚对照图（标志元素） */
.pinmap { margin: 4px 0 10px; }
.pinmap svg { width: 100%; height: auto; display: block; }
.pinmap .ic { fill: var(--body-ic); }
.pinmap .ic-dot { fill: #56636f; }
.pinmap .pad { fill: var(--copper); }
.pinmap .pad.bad { fill: var(--fault); }
.pinmap .pad.warn { fill: #c98b1c; }
.pinmap .pno { font: 600 9px var(--mono); fill: var(--sheet); text-anchor: middle; }
.pinmap .lbl { font: 500 10.5px var(--mono); text-anchor: middle; fill: var(--graphite); }
.pinmap .lbl.new { fill: var(--mask); }
.pinmap .lbl.new.bad { fill: var(--fault); font-weight: 600; }
.pinmap .lbl.new.warn { fill: var(--amber); font-weight: 600; }
.pinmap .row-tag { font: 600 9.5px var(--sans); fill: var(--muted); }
.pinmap .pkg { font: 500 10px var(--mono); fill: #c4ccd3; text-anchor: middle; }
.pin-verdict { font-size: 12px; margin-top: 4px; }
.pin-verdict.bad { color: var(--fault); font-weight: 600; }
.pin-verdict.ok { color: var(--mask); }
.pin-verdict.warn { color: var(--amber); }

.traps { border: 1px solid var(--fault-soft); background: #fdf4f2; border-radius: 5px; padding: 9px 12px; }
.traps h3 { margin: 0 0 4px; font-size: 12px; color: var(--fault); letter-spacing: 0.06em; }
.traps ul { margin: 0; padding-left: 16px; font-size: 12px; }
.traps li { margin: 2px 0; }
.traps .mpn { font-size: 12px; display: inline; }

.decision-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--graphite);
}

.datanote { padding: 0 18px 10px; font-size: 11.5px; color: var(--muted); }

/* ---------------------------------------------------------------- ECN 对话框 */
.ecn {
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--sheet);
  color: var(--ink);
}
.ecn::backdrop { background: rgba(20, 32, 43, 0.45); }
.ecn-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
}
.ecn-head h2 { margin: 0; font-size: 15px; }
.ecn-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.ecn-body { padding: 8px 22px 22px; }

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 1240px) {
  body { height: auto; }
  .workbench { grid-template-columns: minmax(260px, 300px) 1fr; grid-template-rows: 1fr 1fr; height: auto; }
  .pane-bom { grid-row: 1 / 3; max-height: calc(200vh - 200px); }
  .pane-chat, .pane-evidence { min-height: 460px; }
}
@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 10px 16px; }
  .job { margin-left: 0; width: 100%; }
  .agent-pill { order: -1; margin-left: auto; }
  .view-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 8px 16px 0;
  }
  .view-tabs button {
    padding: 7px 0;
    border: 1px solid var(--line);
    background: var(--sheet);
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
  }
  .view-tabs button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); border-color: var(--ink); }
  .workbench { display: block; padding: 10px 16px; height: auto; }
  .workbench .pane { display: none; height: auto; min-height: 60vh; }
  .workbench .pane-chat { height: 78vh; }
  .bom-list, .evidence { overflow: visible; }
  .workbench[data-view="bom"] .pane-bom,
  .workbench[data-view="chat"] .pane-chat,
  .workbench[data-view="evidence"] .pane-evidence { display: flex; }
  .msg-user { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
