/* 嵌入式上位机平台 · Web 控制台
 * 调色：仪器青 + 越限橙红，深色主题由 tokens 切换。
 * 不依赖任何外部字体与脚本：离线双击即可打开。 */

:root {
  --ground: #f2f5f4;
  --panel: #ffffff;
  --panel-2: #f7f9f8;
  --ink: #15201d;
  --muted: #5a6964;
  --rule: #d6dedb;
  --faint: #e8eeec;
  --accent: #0e7c6b;
  --accent-soft: #d4ece7;
  --alert: #b8430f;
  --alert-soft: #f8e3d8;
  --warn: #9a6a00;
  --warn-soft: #f6ecd2;
  --pass: #2d7a4c;
  --series-2: #7a8f88;
  --hex-head: #0e7c6b;
  --hex-meta: #6b4fa0;
  --hex-len: #9a6a00;
  --hex-crc: #b8430f;
  --sans: "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0d1311; --panel: #141c19; --panel-2: #18221f; --ink: #e2e9e6; --muted: #8e9f99;
    --rule: #28332f; --faint: #1c2622; --accent: #3cc0a6; --accent-soft: #173a33;
    --alert: #f08352; --alert-soft: #3d241a; --warn: #e0b54a; --warn-soft: #3a3016; --pass: #5cc389;
    --series-2: #6f837c; --hex-head: #3cc0a6; --hex-meta: #b39ae6; --hex-len: #e0b54a; --hex-crc: #f08352;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #0d1311; --panel: #141c19; --panel-2: #18221f; --ink: #e2e9e6; --muted: #8e9f99;
  --rule: #28332f; --faint: #1c2622; --accent: #3cc0a6; --accent-soft: #173a33;
  --alert: #f08352; --alert-soft: #3d241a; --warn: #e0b54a; --warn-soft: #3a3016; --pass: #5cc389;
  --series-2: #6f837c; --hex-head: #3cc0a6; --hex-meta: #b39ae6; --hex-len: #e0b54a; --hex-crc: #f08352;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 14.5px/1.6 var(--sans); padding-inline: 16px; padding-block: 0 40px;
}
.wrap { max-width: 1240px; margin: 0 auto; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- 顶栏 ---------- */
header.bar {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between;
  padding-block: 18px 12px;
}
.brand { display: grid; gap: 4px; }
.frame { display: flex; gap: 4px; font: 11px/1 var(--mono); letter-spacing: .1em; }
.frame span { border: 1px solid var(--accent); color: var(--accent); padding: 3px 4px; border-radius: 2px; }
.frame span.dim { border-color: var(--rule); color: var(--muted); }
h1 { font-size: 20px; line-height: 1.25; margin: 0; font-weight: 800; letter-spacing: -.01em; }
.source { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; background: var(--faint); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.live { background: var(--accent-soft); color: var(--accent); }
.badge.live::before { animation: pulse 1.6s ease-in-out infinite; }
.badge.replay { background: var(--warn-soft); color: var(--warn); }
.badge.down { background: var(--alert-soft); color: var(--alert); }
@keyframes pulse { 50% { opacity: .25; } }
.btn {
  border: 1px solid var(--rule); background: var(--panel); padding: 4px 11px; border-radius: 4px;
  cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
a.btn { color: inherit; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.field {
  border: 1px solid var(--rule); background: var(--panel); padding: 4px 9px; border-radius: 4px; font-size: 13px;
  min-width: 0;
}

/* 回放条 */
.replay-bar {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--rule); border-left: 3px solid var(--warn);
  border-radius: 6px; margin-bottom: 10px; font-size: 13px;
}
.replay-bar .grow { flex: 1 1 220px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.replay-bar input[type="range"] { flex: 1; min-width: 80px; accent-color: var(--warn); }
.replay-bar .note { color: var(--muted); font-size: 12px; flex-basis: 100%; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; padding: 3px 10px; cursor: pointer; font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--panel); font-weight: 600; }

/* ---------- 标签页 ---------- */
nav.tabs {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--ground);
  display: flex; gap: 2px; border-bottom: 1px solid var(--rule); overflow-x: auto; scrollbar-width: none;
}
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button {
  border: 0; background: none; padding: 11px 14px 9px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; font-size: 14px;
}
nav.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 700; border-bottom-color: var(--accent); }
nav.tabs .count { font: 11px var(--mono); margin-left: 4px; color: var(--alert); }

section.view { padding-top: 16px; display: grid; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 14px 16px; min-width: 0; }
.panel > h2, .panel-head h2 { font-size: 14px; margin: 0; font-weight: 700; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.hint { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 18px 0; text-align: center; }

/* ---------- 监测 ---------- */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 820px) { .cards { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 12px 14px; display: grid; gap: 6px; }
.card.alarm { border-color: var(--alert); box-shadow: inset 0 0 0 1px var(--alert); }
.card .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .label { font-weight: 700; }
.card .value { font: 700 34px/1.1 var(--mono); font-variant-numeric: tabular-nums; }
.card .value small { font-size: 15px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.card .stats { display: grid; grid-template-columns: repeat(4, auto); justify-content: space-between; gap: 4px; font-size: 12px; color: var(--muted); }
.card .stats b { display: block; font: 600 13px var(--mono); color: var(--ink); }
/* 仪表刻度：本次记录的最低—最高区间、当前值、报警阈值，画在同一把尺子上。
 * 离阈值还有多远不必心算——这是整个页面上唯一刻意加重的元素。 */
.scale { position: relative; height: 34px; margin: 4px 0 2px; }
.scale .track { position: absolute; left: 0; right: 0; top: 11px; height: 6px; border-radius: 3px; background: var(--faint); }
.scale .band { position: absolute; top: 11px; height: 6px; border-radius: 3px; background: var(--accent); opacity: .32; }
.scale .limit { position: absolute; top: 4px; width: 2px; height: 20px; margin-left: -1px; background: var(--alert); }
.scale .limit span {
  position: absolute; top: 20px; transform: translateX(-50%); font: 10.5px/1.4 var(--mono);
  color: var(--alert); white-space: nowrap;
}
.scale .limit.edge-r span { transform: translateX(-100%); }
.scale .limit.edge-l span { transform: none; }
.scale .now {
  position: absolute; top: 6px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%;
  background: var(--panel); border: 3px solid var(--accent); transition: left .4s ease;
}
.card.alarm .scale .now { border-color: var(--alert); }
.margin-note { font-size: 12px; color: var(--muted); }
.margin-note b { font: 600 12px var(--mono); color: var(--ink); }
.card.alarm .margin-note b { color: var(--alert); }
@media (prefers-reduced-motion: reduce) { .scale .now { transition: none; } }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--alert-soft); color: var(--alert); }
.pill.idle { background: var(--faint); color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid-main { grid-template-columns: 1fr; } }
.side { display: grid; gap: 16px; }
.chart { position: relative; }
.chart canvas { display: block; width: 100%; cursor: crosshair; touch-action: pan-y; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--panel);
  font: 12px/1.5 var(--mono); padding: 6px 8px; border-radius: 4px; white-space: pre; z-index: 3;
  transform: translate(12px, -50%);
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.fan-state { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.fan-state strong { font-size: 18px; }
.fan-reason { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; min-height: 1.6em; }
.fan-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: end; margin-top: 10px; }
.fan-form label { font-size: 12px; color: var(--muted); display: grid; gap: 3px; }
.fan-form input { width: 100%; }
.toast { font-size: 12px; min-height: 1.5em; margin-top: 6px; color: var(--muted); }
.toast.err { color: var(--alert); }
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.devices li { display: flex; justify-content: space-between; gap: 8px; }

/* ---------- 链路 ---------- */
.counters { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
@media (max-width: 820px) { .counters { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.counter { background: var(--panel); padding: 10px 12px; display: grid; gap: 2px; }
.counter b { font: 700 22px/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.counter span { font-size: 12px; color: var(--muted); }
.counter.bad b { color: var(--alert); }
.counter.good b { color: var(--pass); }
.inactive {
  padding: 14px 16px; border: 1px dashed var(--rule); border-radius: 6px; color: var(--muted); font-size: 13.5px;
}
.inactive code { font-family: var(--mono); background: var(--faint); padding: 1px 5px; border-radius: 3px; }
.link-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .link-grid { grid-template-columns: 1fr; } }
.table-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--rule); border-radius: 6px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--faint); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 600; font-size: 12px; z-index: 1; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr[aria-selected="true"] { background: var(--accent-soft); }
tr.bad td:first-child { box-shadow: inset 3px 0 var(--alert); }
tr.warn td:first-child { box-shadow: inset 3px 0 var(--warn); }
td.hex { font-family: var(--mono); max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.hex-bytes { font: 12.5px/1.9 var(--mono); word-break: break-all; }
.hex-bytes .h { color: var(--hex-head); font-weight: 700; }
.hex-bytes .m { color: var(--hex-meta); font-weight: 700; }
.hex-bytes .l { color: var(--hex-len); font-weight: 700; }
.hex-bytes .c { color: var(--hex-crc); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin: 8px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.fields { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 13px; margin-top: 8px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; font-family: var(--mono); word-break: break-all; }

/* ---------- 问答 ---------- */
.qa-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .qa-grid { grid-template-columns: 1fr; } }
.chat { display: grid; gap: 10px; max-height: 560px; overflow-y: auto; padding-right: 4px; }
.msg { max-width: 88%; padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.msg.q { justify-self: end; background: var(--accent); color: var(--panel); border-bottom-right-radius: 3px; }
.msg.a { justify-self: start; background: var(--panel-2); border: 1px solid var(--rule); border-bottom-left-radius: 3px; cursor: pointer; }
.msg.a[aria-selected="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.msg.a .src { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.msg.pending { opacity: .6; font-style: italic; }
.ask { display: flex; gap: 8px; margin-top: 12px; }
.ask input { flex: 1; }
.chip-groups { display: grid; gap: 10px; margin-top: 12px; }
.chip-group > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button.boundary { border-style: dashed; }
.verdict-line { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 13px; }
.boundary-sum { font: 12px/1.6 var(--mono); color: var(--muted); }
.chips button { border: 1px solid var(--rule); background: var(--panel); border-radius: 999px; padding: 3px 11px; font-size: 12.5px; cursor: pointer; }
.chips button:hover { border-color: var(--accent); }
.trace { display: grid; gap: 12px; }
.trace h3 { font-size: 12.5px; margin: 0 0 4px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.facts { font: 12.5px/1.7 var(--mono); background: var(--panel-2); border: 1px solid var(--faint); border-radius: 4px; padding: 8px 10px; white-space: pre-wrap; margin: 0; }
.attempt { border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; display: grid; gap: 4px; font-size: 13px; }
.attempt.accepted { border-color: var(--accent); }
.attempt.refused { border-color: var(--alert); }
.attempt .row { display: grid; grid-template-columns: 56px 1fr; gap: 8px; }
.attempt .row span:first-child { color: var(--muted); font-size: 12px; }
.attempt .verdict { font-size: 12.5px; font-weight: 600; }
.attempt.accepted .verdict { color: var(--accent); }
.attempt.refused .verdict { color: var(--alert); }
.flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; }
.flow span { padding: 2px 8px; border-radius: 4px; background: var(--faint); }
.flow span.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.flow i { color: var(--muted); font-style: normal; }

/* 实时流程：左侧时间，竖线串起每一步；颜色只标三件事——模型参与、代码拦下、最终答案 */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.timeline li { display: grid; grid-template-columns: 58px 1fr; gap: 10px; padding: 6px 0 8px; border-left: 2px solid var(--rule); margin-left: 58px; padding-left: 12px; position: relative; font-size: 13px; }
.timeline li .at { position: absolute; left: -64px; width: 56px; text-align: right; top: 6px; font: 11.5px/1.6 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline li > div { grid-column: 1 / -1; display: grid; gap: 3px; min-width: 0; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 11px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--rule); }
.timeline li strong { font-weight: 600; font-size: 13px; }
.timeline li p { margin: 0; overflow-wrap: anywhere; }
.timeline li .quote { padding: 4px 8px; background: var(--panel-2); border-radius: 4px; }
.timeline li.model::before { border-color: var(--hex-meta); }
.timeline li.model strong { color: var(--hex-meta); }
.timeline li.ok::before { border-color: var(--accent); }
.timeline li.warn::before { border-color: var(--warn); }
.timeline li.warn strong { color: var(--warn); }
.timeline li.bad::before { border-color: var(--alert); background: var(--alert); }
.timeline li.bad strong { color: var(--alert); }
.timeline li.idle strong { color: var(--muted); }
.timeline li.final::before { border-color: var(--accent); background: var(--accent); }
.timeline li.final strong { color: var(--accent); }
.timeline li.waiting::before { border-style: dashed; }
.timeline li.waiting strong { color: var(--muted); }
.checks { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 2px; font-size: 12.5px; }
.checks li { display: grid; grid-template-columns: 16px 64px 1fr; gap: 6px; border: 0; margin: 0; padding: 0; }
.checks li::before { display: none; }
.checks .mark { font-weight: 700; }
.checks .pass .mark { color: var(--pass); }
.checks .fail .mark, .checks .fail span { color: var(--alert); }
.checks .detail { font-family: var(--mono); overflow-wrap: anywhere; }
.timeline .verdict { font-weight: 600; font-size: 12.5px; }
.timeline .verdict.ok { color: var(--accent); }
.timeline .verdict.bad { color: var(--alert); }

/* ---------- 历史 ---------- */
.hist-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

footer { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--muted); display: grid; gap: 3px; }
@media (prefers-reduced-motion: reduce) { .badge.live::before { animation: none; } }
