:root {
  /* Saverick brand (saverick.africa): violet + ember on deep ink */
  --bg: #faf8ff;
  --panel: #ffffff;
  --panel-2: #f6f2ff;
  --line: #e7e1f7;
  --line-strong: #d5c4ff;
  --text: #17112e;
  --muted: #6b6488;
  --accent: #5b2bd6;
  --accent-soft: #efe7ff;
  --brand: #8c52ff;
  --ember: #ff8a4c;
  --ember-text: #d9601f;
  --grad: linear-gradient(120deg, #5b2bd6 0%, #8c52ff 40%, #d35be8 75%, #ff8a4c 100%);
  --ok: #17845a;
  --ok-soft: #dcf3e8;
  --warn: #b35a12;
  --warn-soft: #ffeadf;
  --bad: #c42b3c;
  --bad-soft: #fde4e7;
  --idle: #8a84a3;
  --idle-soft: #f0edf7;
  --s-volt: #5b2bd6;
  --s-curr: #d9601f;
  --s-soc: #17845a;
  --s-temp: #c42b3c;
  --replay: #1f7fd1;
  --band: rgba(140, 82, 255, 0.16);
  --grid: #f0edf7;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: Sora, Inter, system-ui, sans-serif;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 17, 46, .04), 0 12px 40px -18px rgba(91, 43, 214, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0919; --panel: #151027; --panel-2: #1b1433; --line: #2a2248; --line-strong: #4a3a85;
    --text: #f4f1ff; --muted: #a39cc4; --accent: #b795ff; --accent-soft: #251a4d; --brand: #8c52ff;
    --ember: #ff8a4c; --ember-text: #ffa878;
    --ok: #4fd08f; --ok-soft: #123326; --warn: #ffa878; --warn-soft: #3a2218;
    --bad: #ff6b7d; --bad-soft: #3d1621; --idle: #8c84ad; --idle-soft: #231c3d;
    --s-volt: #b795ff; --s-curr: #ffa878; --s-soc: #4fd08f; --s-temp: #ff6b7d;
    --replay: #5cb8ff; --band: rgba(183, 149, 255, 0.2); --grid: #211a3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 18px 50px -18px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0c0919; --panel: #151027; --panel-2: #1b1433; --line: #2a2248; --line-strong: #4a3a85;
    --text: #f4f1ff; --muted: #a39cc4; --accent: #b795ff; --accent-soft: #251a4d; --brand: #8c52ff;
    --ember: #ff8a4c; --ember-text: #ffa878;
    --ok: #4fd08f; --ok-soft: #123326; --warn: #ffa878; --warn-soft: #3a2218;
    --bad: #ff6b7d; --bad-soft: #3d1621; --idle: #8c84ad; --idle-soft: #231c3d;
    --s-volt: #b795ff; --s-curr: #ffa878; --s-soc: #4fd08f; --s-temp: #ff6b7d;
    --replay: #5cb8ff; --band: rgba(183, 149, 255, 0.2); --grid: #211a3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 18px 50px -18px rgba(0, 0, 0, .7);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased;
  min-height: 100vh; display: flex; flex-direction: column; }
body > main { flex: 1 0 auto; width: 100%; align-content: start; }
h2, h3 { margin: 0; font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; margin-bottom: 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }

/* ---- top bar ---- */
.topbar { position: relative; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 10px 24px; background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--grad); flex: none; position: relative; }
.logo::after { content: ""; position: absolute; inset: 7px 9px; background: #fff; clip-path: polygon(60% 0, 10% 58%, 45% 58%, 35% 100%, 90% 38%, 55% 38%); }
.brand-name { font-family: var(--display); font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.price { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.price-input { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 2px 6px; background: var(--panel); color: var(--text); }
.price input { width: 52px; border: 0; background: transparent; outline: none; font-family: var(--mono); font-size: 12px; }
.loc select { appearance: none; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238c52ff' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 9px center / 10px 6px; padding: 5px 28px 5px 10px; font-size: 13px; font-weight: 550; cursor: pointer; max-width: 230px; }
.loc select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.detail-id { display: flex; align-items: center; gap: 12px; }
.stepper { display: flex; gap: 4px; }
.btn.icon { width: 30px; height: 30px; padding: 0; font-size: 18px; line-height: 1; }
#map .node.dim { opacity: 0.25; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.conn.live i { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.conn.down i { background: var(--bad); }
.clock { font-family: var(--mono); font-size: 12px; color: var(--muted); }

main { max-width: 1480px; margin: 0 auto; padding: 18px 24px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

/* ---- KPIs ---- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-family: var(--display); font-size: 22px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.alert { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); background: var(--bad-soft); }
.kpi.alert .kpi-value { color: var(--bad); }
.good { color: var(--ok); }

/* ---- panels ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.grid-top { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(320px, 1fr); gap: 16px; }
.map-panel { display: flex; flex-direction: column; }
#map { width: 100%; flex: 1; min-height: 260px; max-height: 380px; }
#map .land { fill: var(--panel-2); stroke: var(--line-strong); stroke-width: 0.35; stroke-linejoin: round; }
#map .grat { stroke: var(--grid); stroke-width: 0.2; }
#map .city { fill: var(--muted); }
#map text { font-family: var(--sans); font-size: calc(2.9px * var(--s, 1)); fill: var(--muted); }
#map .lbl { fill: var(--text); font-weight: 600; font-size: calc(3.1px * var(--s, 1)); paint-order: stroke; stroke: var(--panel-2); stroke-width: calc(0.8px * var(--s, 1)); }
#map .node { cursor: pointer; }
#map .node circle.core { stroke: var(--panel); stroke-width: 0.6; }
#map .node.sel circle.ring { stroke: var(--accent); stroke-width: 0.5; fill: none; }
#map .pulse { animation: pulse 1.6s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { from { opacity: 0.6; transform: scale(1); } to { opacity: 0; transform: scale(3); } }
@media (prefers-reduced-motion: reduce) { #map .pulse { animation: none; opacity: 0.3; } }
.map-legend { display: flex; gap: 10px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }
.dot.online { background: var(--ok); } .dot.stale { background: var(--warn); } .dot.trip { background: var(--bad); } .dot.offline { background: var(--idle); }
.bw-wide { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }

.stations tbody tr { cursor: pointer; }
.stations tbody tr:hover { background: var(--panel-2); }
.stations tbody tr.sel { background: var(--accent-soft); }
.stations tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.m-only { display: none; }
.stations .node-id { color: var(--accent); font-weight: 600; margin-right: 4px; }
.stations .pill + .st-region { margin-top: 3px; }
.st-name { font-weight: 550; }
.st-region { font-size: 12px; color: var(--muted); }
.node-id { font-family: var(--mono); font-size: 12px; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; letter-spacing: 0.03em; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.online { color: var(--ok); background: var(--ok-soft); }
.pill.stale { color: var(--warn); background: var(--warn-soft); }
.pill.offline, .pill.never { color: var(--idle); background: var(--idle-soft); }
.pill.trip { color: var(--bad); background: var(--bad-soft); }
.chip { display: inline-block; font-size: 10.5px; font-weight: 600; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 4px; background: var(--idle-soft); color: var(--muted); margin-right: 3px; }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.replay { background: color-mix(in srgb, var(--replay) 16%, transparent); color: var(--replay); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.link-name { font-size: 12px; }
.link-down { color: var(--bad); font-weight: 600; }

.soc { display: flex; align-items: center; gap: 6px; }
.soc-bar { width: 54px; height: 6px; border-radius: 3px; background: var(--idle-soft); overflow: hidden; }
.soc-bar i { display: block; height: 100%; background: var(--ok); }
.soc-bar i.low { background: var(--bad); }
.soc-bar i.mid { background: var(--warn); }

/* ---- bandwidth ---- */
.bw-hero { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.bw-hero b { font-family: var(--display); background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: 30px; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.bw-rows { display: grid; gap: 10px; margin: 14px 0 12px; }
.bw-row { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; }
.bw-bars { display: grid; gap: 3px; }
.bw-bar { height: 9px; border-radius: 3px; min-width: 2px; }
.bw-bar.ste { background: var(--grad); }
.bw-bar.json { background: var(--line-strong); }
.bw-meta { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bw-cost { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bw-cost div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.bw-cost b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.bw-key { display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.bw-key i { display: inline-block; width: 10px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.fineprint { font-size: 11px; color: var(--muted); margin: 10px 0 0; }

/* ---- detail ---- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: -14px -16px 14px; padding: 14px 16px 0; }
.detail-title { font-family: var(--display); font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.detail-head > div:first-child { padding-bottom: 12px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 550; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); }

.toolbar { display: flex; justify-content: flex-start; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 4px 10px; cursor: pointer; font-size: 12px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--accent); color: var(--panel); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); margin-left: auto; }
.legend i { display: inline-block; vertical-align: middle; margin-right: 5px; }
.lg-line { width: 14px; height: 2px; background: var(--s-volt); }
.lg-replay { width: 7px; height: 7px; border-radius: 50%; background: var(--replay); }
.lg-band { width: 14px; height: 8px; background: var(--band); border-top: 1px solid var(--s-volt); }
.lg-trip { width: 14px; height: 0; border-top: 1.5px dashed var(--bad); }

.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.chart { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 4px; position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; }
.chart-head b { font-size: 16px; font-variant-numeric: tabular-nums; }
.chart svg { display: block; width: 100%; height: 150px; overflow: visible; touch-action: pan-y; }
.chart .axis text { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); }
.chart .empty { font-size: 12px; fill: var(--muted); }

/* ---- frames ---- */
.frames-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
.frames-wrap { max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.frames th { position: sticky; top: 0; background: var(--panel); }
.frames td { font-size: 12.5px; padding: 6px 8px; }
.frames tbody tr { cursor: pointer; }
.frames tbody tr:hover { background: var(--panel-2); }
.frames tbody tr.sel { background: var(--accent-soft); }
.frames tr.dup td { color: var(--muted); }
.dir-up { color: var(--s-volt); }
.dir-down { color: var(--ember-text); }
.inspector textarea { width: 100%; min-height: 64px; resize: vertical; font: 12px/1.5 var(--mono); padding: 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel-2); }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.hexview { font: 12px/1.9 var(--mono); word-break: break-all; }
.hexview span { padding: 1px 2px; border-radius: 3px; margin-right: 1px; cursor: default; }
.hexview .f-hdr { background: color-mix(in srgb, var(--brand) 22%, transparent); }
.hexview .f-rec0 { background: color-mix(in srgb, var(--s-soc) 16%, transparent); }
.hexview .f-rec1 { background: color-mix(in srgb, var(--s-soc) 30%, transparent); }
.hexview .f-crc { background: color-mix(in srgb, var(--ember) 30%, transparent); }
.hex-key { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin: 6px 0; }
.hex-key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.decoded { font: 11.5px/1.5 var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 300px; overflow: auto; margin: 8px 0 0; white-space: pre-wrap; }
.decoded:empty { display: none; }
.err-text { color: var(--bad); }

/* ---- config ---- */
.config-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 24px; }
.cfg-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; align-content: start; }
.field { display: grid; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; }
.field input, .field select { padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--panel); font-variant-numeric: tabular-nums; }
.field input:focus, .field select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 0; }
.field .hint { font-size: 11px; color: var(--muted); }
.field.full { grid-column: 1 / -1; }
.field.bad input { border-color: var(--bad); }
.cfg-status { grid-column: 1 / -1; font-size: 12.5px; border-radius: 8px; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--line); }
.cfg-status.pending { background: var(--warn-soft); border-color: transparent; }
.cfg-status.rejected, .cfg-status.error { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.cfg-actions { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.history td { font-size: 12.5px; }
.history td:last-child { white-space: normal; color: var(--muted); font-size: 12px; }

.btn { border: 1px solid var(--line-strong); background: var(--panel); border-radius: 7px; padding: 6px 12px; cursor: pointer; font-weight: 550; font-size: 13px; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--grad); color: #fff; border-color: transparent; }
.btn.primary:hover { opacity: 0.88; }
.btn.warn { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- sim ---- */
.sim-note { margin: 0 0 14px; }
.sim-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px; }
.btn-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.gauge { height: 10px; border-radius: 5px; background: var(--idle-soft); overflow: hidden; margin: 6px 0 4px; }
.gauge i { display: block; height: 100%; background: var(--grad); transition: width 0.4s; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.stat span { display: block; font-size: 11px; color: var(--muted); }
.stat b { font-variant-numeric: tabular-nums; }
.autonomy { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.autonomy div { border-radius: 8px; padding: 8px 10px; border: 1px solid var(--line); }
.autonomy b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.autonomy .ours { background: var(--ok-soft); border-color: transparent; }
.log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; max-height: 330px; overflow: auto; }
.log li { display: grid; grid-template-columns: 64px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.log time { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* ---- feed ---- */
.feed { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; font-size: 12.5px; }
.feed li { display: grid; grid-template-columns: 70px 70px 1fr auto; gap: 10px; padding: 5px 2px; border-bottom: 1px solid var(--line); align-items: center; }
.feed li.err { color: var(--bad); }
.feed li.muted { display: block; }
.feed time, .feed .node-id { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.feed .hex { font-family: var(--mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tip { position: fixed; pointer-events: none; z-index: 20; background: var(--text); color: var(--panel); font-size: 12px; padding: 6px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }



/* ================================================================ workspaces */
.ver { font-family: var(--mono); font-size: 10.5px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 5px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }
.top-stats { display: flex; gap: 22px; padding: 0 18px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.top-stats div { display: grid; line-height: 1.25; }
.top-stats span { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.top-stats b { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.top-stats b.good { color: var(--ok); }

.viewnav { position: sticky; top: 0; z-index: 4; display: flex; gap: 2px; padding: 0 24px; overflow-x: auto; scrollbar-width: none;
  background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.viewnav::-webkit-scrollbar { display: none; }
.viewnav button { flex: none; display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; padding: 11px 14px 12px; cursor: pointer;
  color: var(--muted); font-weight: 550; font-size: 13.5px; border-bottom: 2px solid transparent; white-space: nowrap; }
.viewnav button:hover { color: var(--text); }
.viewnav button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); background: linear-gradient(to top, var(--accent-soft), transparent 70%); }
.viewnav .vi { color: var(--brand); font-size: 12px; }

.nodebar[hidden] { display: none; }
.nodebar { max-width: 1480px; margin: 14px auto 0; padding: 0 24px; display: flex; align-items: center; gap: 8px; }
.node-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.node-chips::-webkit-scrollbar { display: none; }
.node-chip { flex: none; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 999px; padding: 5px 12px 5px 9px; cursor: pointer; font-size: 12.5px; font-weight: 550; }
.node-chip:hover { background: var(--panel-2); }
.node-chip[aria-pressed="true"] { border-color: var(--brand); background: var(--accent-soft); }
.node-chip .dot { margin: 0; }
.node-chip .node-id { color: var(--accent); font-family: var(--mono); font-size: 11.5px; }
.view[hidden] { display: none !important; }
.view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.mb { margin-bottom: 12px; }
.mt { margin-top: 18px; }
.intro p { margin: 6px 0 0; max-width: 980px; font-size: 13.5px; }

/* ---- digital twin ---- */
.twin-head { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; }
.twin-title { font-family: var(--display); font-size: 19px; font-weight: 650; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.twin-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 85%, black); }
.cmd-status { grid-column: 1 / -1; color: var(--muted); }
.cmd-status:empty { display: none; }
.cmd-status b { color: var(--text); }
.gauges { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.g-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.g-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.g-tag { color: var(--ok); }
.g-tag.warn { color: var(--warn); } .g-tag.bad { color: var(--bad); } .g-tag.idle { color: var(--muted); }
.g-val { font-family: var(--display); font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.g-val small { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.g-bar { position: relative; height: 6px; border-radius: 3px; background: var(--idle-soft); overflow: visible; }
.g-bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--ok); transition: width .5s ease; }
.g-bar i.warn { background: var(--warn); } .g-bar i.bad { background: var(--bad); } .g-bar i.brand { background: var(--grad); }
.g-bar s { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--bad); border-radius: 1px; text-decoration: none; }
.g-foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }
.twin-grid { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.tb-title { margin-right: auto; }
.lg-alarm { width: 3px; height: 8px; background: var(--bad); }
.legend { margin-bottom: 10px; }
.sandbox .ctl { display: grid; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sandbox .ctl:last-child { border-bottom: 0; }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.ctl-head b { font-family: var(--mono); font-size: 13px; color: var(--accent); }
.sandbox select { padding: 7px 8px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--panel); }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--brand) var(--fill, 50%), var(--idle-soft) var(--fill, 50%)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--idle-soft); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--brand); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: #fff; border: 3px solid var(--brand); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--brand); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sandbox .note { font-size: 11.5px; color: var(--muted); margin: 0; }

/* ---- serialization lab ---- */
.lab-grid { display: grid; grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.6fr); gap: 16px; align-items: start; }
.lab-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.lab-form .full { grid-column: 1 / -1; }
.enc-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.enc { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.enc-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 8px 10px; background: var(--panel-2); border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; }
.enc-h b { font-family: var(--mono); font-size: 13px; }
.enc.json .enc-h b { color: var(--bad); } .enc.ascii .enc-h b { color: var(--warn); } .enc.ste .enc-h b { color: var(--ok); }
.enc pre { margin: 0; padding: 10px; font: 11.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-all; flex: 1; min-height: 110px; }
.enc .miss { padding: 6px 10px 9px; font-size: 11px; color: var(--muted); border-top: 1px dashed var(--line); }
.layout { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; }
.lay { border: 1px solid var(--line); border-radius: 8px; padding: 6px 4px; text-align: center; background: var(--panel-2); min-width: 0; }
.lay span { display: block; font-size: 9.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lay b { display: block; font-family: var(--mono); font-size: 12px; margin: 2px 0; }
.lay code { font-size: 10px; color: var(--accent); }
.wire { width: 100%; }
.wire td, .wire th { padding: 7px 8px; }
.wire .bar { height: 8px; border-radius: 3px; background: var(--line-strong); min-width: 2px; }
.wire .bar.ste { background: var(--grad); }
.wire td.w-bar { width: 38%; }

/* ---- edge ---- */
.edge-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.edge-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.edge-top .spacer { flex: 1; }
.edge-stats { display: flex; gap: 18px; font-size: 13px; flex-wrap: wrap; }
.edge-stats b { font-family: var(--mono); color: var(--accent); }
.det { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.det:last-child { border-bottom: 0; }
.det-name { font-weight: 600; font-size: 13px; }
.det-val { font-family: var(--mono); font-size: 13px; text-align: right; }
.det-desc { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); }
.det.hot .det-val { color: var(--bad); font-weight: 700; }
.console { background: #07050f; color: #cfc7ee; border-radius: 10px; padding: 10px 12px; font: 12px/1.6 var(--mono); max-height: 360px; min-height: 240px; overflow: auto; border: 1px solid var(--line); }
.console div { display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.console time { color: #7d74a8; }
.console .hot { color: #ff8f9c; } .console .warn { color: #ffb37d; } .console .ok { color: #7fe3a8; }

/* ---- OTA ---- */
.ota-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; align-items: start; }
.img-list { display: grid; gap: 8px; }
.img { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.img:hover { background: var(--panel-2); }
.img.sel { border-color: var(--brand); background: var(--accent-soft); }
.img input { margin: 0; accent-color: var(--brand); }
.img-name { font-weight: 600; font-size: 13px; }
.img-meta { grid-column: 2 / -1; font-size: 11.5px; color: var(--muted); }
.img-size { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ota-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0 4px; }
.rollout { width: 100%; margin-top: 10px; }
.rollout td { font-size: 12.5px; }
.prog { height: 6px; border-radius: 3px; background: var(--idle-soft); overflow: hidden; min-width: 70px; }
.prog i { display: block; height: 100%; background: var(--grad); transition: width .4s; }
.prog i.ok { background: var(--ok); } .prog i.bad { background: var(--bad); }
.ota-steps { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; font-size: 11px; color: var(--muted); }
.ota-steps span { border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }

/* ---- misc ---- */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 30; background: var(--text); color: var(--panel); padding: 9px 14px; border-radius: 9px; font-size: 13px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
#edge { display: grid; gap: 16px; }

/* ---- footer ---- */
.site-foot { margin-top: 24px; position: relative; background: color-mix(in srgb, var(--panel) 70%, var(--bg)); border-top: 1px solid var(--line); }
.site-foot::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: var(--grad); opacity: .85; }
.foot-inner { max-width: 1480px; margin: 0 auto; padding: 32px 24px 24px; display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr)); gap: 28px; }
.foot-logo { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 650; font-size: 15px; }
.foot-logo .logo { width: 26px; height: 26px; border-radius: 8px; }
.foot-logo .logo::after { inset: 6px 8px; }
.foot-brand p { color: var(--muted); font-size: 13px; margin: 10px 0 14px; max-width: 360px; }
.foot-status { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 10px; background: var(--panel); }
.foot-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.foot-status i.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.foot-status i.down { background: var(--bad); }
.foot-col h4 { margin: 2px 0 12px; font-family: var(--display); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.foot-col button, .foot-fleet { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 4px 0; font-size: 13px; color: var(--text); cursor: pointer; text-align: left; }
.foot-col button:hover { color: var(--accent); }
.foot-col .node-id { color: var(--accent); font-family: var(--mono); font-size: 11.5px; }
.foot-col .dot { flex: none; }
.foot-facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 12.5px; color: var(--muted); }
.foot-facts li { padding-left: 14px; position: relative; }
.foot-facts li::before { content: ""; position: absolute; left: 0; top: 7px; width: 6px; height: 6px; border-radius: 2px; background: var(--grad); }
.foot-bar { max-width: 1480px; margin: 0 auto; padding: 14px 24px 22px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.foot-bar a { color: var(--accent); text-decoration: none; }
.foot-bar a:hover { text-decoration: underline; }
#f-build { font-family: var(--mono); font-size: 11.5px; }
@media (max-width: 1100px) { .foot-inner { grid-template-columns: 1fr 1fr; } .foot-brand { grid-column: 1 / -1; } }
@media (max-width: 560px) { .foot-inner { grid-template-columns: minmax(0, 1fr); padding: 24px 16px 16px; gap: 22px; } .foot-bar { padding: 12px 16px 20px; } }

/* ---- preloader ---- */
body.loading { overflow: hidden; }
.preload { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--brand) 22%, transparent), transparent 60%), var(--bg);
  transition: opacity .45s ease, visibility .45s; }
.preload.out { opacity: 0; visibility: hidden; }
.preload-card { width: min(360px, 100%); text-align: center; }
.preload-mark { position: relative; display: inline-flex; align-items: flex-end; gap: 10px; margin-bottom: 18px; }
.logo.big { width: 56px; height: 56px; border-radius: 16px; box-shadow: 0 12px 40px -10px color-mix(in srgb, var(--brand) 70%, transparent); }
.logo.big::after { inset: 13px 17px; }
.signal { display: inline-flex; align-items: flex-end; gap: 3px; height: 26px; }
.signal i { width: 5px; border-radius: 2px; background: var(--line-strong); animation: bar 1.4s ease-in-out infinite; }
.signal i:nth-child(1) { height: 25%; } .signal i:nth-child(2) { height: 50%; animation-delay: .15s; }
.signal i:nth-child(3) { height: 75%; animation-delay: .3s; } .signal i:nth-child(4) { height: 100%; animation-delay: .45s; }
@keyframes bar { 0%, 100% { background: var(--line-strong); } 40% { background: var(--ember); } }
.preload-title { font-family: var(--display); font-weight: 650; font-size: 19px; letter-spacing: -0.01em; }
.preload-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.preload-steps { list-style: none; padding: 0; margin: 22px auto 16px; display: grid; gap: 8px; text-align: left; width: fit-content; font-size: 13px; color: var(--muted); }
.preload-steps li { display: flex; align-items: center; gap: 10px; transition: color .2s; }
.preload-steps li::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--line-strong); box-sizing: border-box; flex: none; }
.preload-steps li.active { color: var(--text); }
.preload-steps li.active::before { border-color: var(--brand); border-right-color: transparent; animation: spin .8s linear infinite; }
.preload-steps li.done { color: var(--text); }
.preload-steps li.done::before { border: 0; background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M4 7.2l2 2 4-4.4' stroke='white' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") center / 14px no-repeat; }
@keyframes spin { to { transform: rotate(360deg); } }
.preload-bar { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.preload-bar i { display: block; height: 100%; width: 40%; background: var(--grad); border-radius: 2px; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.preload-note { min-height: 18px; margin-top: 12px; font-size: 12px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  .signal i, .preload-bar i, .preload-steps li.active::before { animation: none; }
  .preload-bar i { width: 100%; opacity: .5; }
}

@media (max-width: 1320px) {
  .grid-top, .twin-grid { grid-template-columns: minmax(0, 1fr); }
  .top-stats { display: none; }
}
@media (max-width: 1100px) {
  .lab-grid, .ota-grid, .edge-grid { grid-template-columns: minmax(0, 1fr); }
  .gauges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bw-wide { display: block; }
  .frames-layout, .config-layout, .sim-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  body { font-size: 14px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; row-gap: 8px; }
  .brand { flex: 1 1 auto; }
  .brand-sub, .price > span:first-child { display: none; }
  .topbar-right { flex: 1 1 100%; justify-content: space-between; gap: 8px; flex-wrap: nowrap; }
  .loc { flex: 1 1 auto; min-width: 0; }
  .loc select { width: 100%; max-width: none; }
  .clock { display: none; }
  main { padding: 12px 12px 32px; gap: 12px; }
  .panel { padding: 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 20px; }

  /* stations become cards */
  .stations thead { display: none; }
  .stations, .stations tbody { display: block; }
  .stations tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; padding: 12px 10px; border-bottom: 1px solid var(--line); border-radius: 10px; }
  .stations tbody tr:last-child { border-bottom: 0; }
  .stations td { padding: 0; border: 0; white-space: normal; text-align: left; }
  .stations td.c-name { grid-column: 1 / 3; }
  .stations td.c-status { grid-column: 3; text-align: right; }
  .stations td[data-label]::before { content: attr(data-label); display: block; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 2px; }
  .stations .soc-bar { width: 34px; }
  .stations .m-only { display: inline; }
  .stations td.c-seen { display: none; }
  .stations tbody tr { padding: 10px 8px; }
  .stations tbody tr.sel td:first-child { box-shadow: none; }
  .stations tbody tr.sel { box-shadow: inset 3px 0 0 var(--accent); }

  #map { min-height: 220px; }
  .bw-row { grid-template-columns: 34px 1fr; }
  .bw-cost { grid-template-columns: 1fr 1fr; }
  .bw-hero b { font-size: 26px; }

  .detail-head { margin: -12px -12px 12px; padding: 12px 12px 0; }
  .detail-head > div:first-child { padding-bottom: 8px; }
  .detail-id { align-items: flex-start; }
  .detail-title { font-size: 15px; }
  .tabs { width: 100%; }
  .tabs button { padding: 8px 10px 10px; }
  .toolbar { gap: 8px; }
  .legend { margin-left: 0; gap: 10px; }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .chart svg { height: 140px; }

  .frames .c-dir, .frames .c-recs { display: none; }
  .frames-wrap { max-height: 360px; }
  .btn-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .btn-grid .btn { padding: 9px 8px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .autonomy b { font-size: 16px; }
  .cfg-form { grid-template-columns: minmax(0, 1fr); }
  .cfg-actions .btn { flex: 1 1 auto; }
  .field input, .field select, .sandbox select { font-size: 16px; } /* stops iOS zoom-on-focus */
  .viewnav { padding: 0 8px; }
  .viewnav button { padding: 10px 10px 11px; font-size: 13px; }
  .nodebar { padding: 0 12px; margin-top: 12px; }
  .twin-head { grid-template-columns: minmax(0, 1fr); }
  .twin-actions { justify-content: flex-start; }
  .twin-actions .btn { flex: 1 1 auto; }
  .g-val { font-size: 24px; }
  .gauges { gap: 8px; }
  .g-card { padding: 10px 12px; }
  .enc-grid { grid-template-columns: minmax(0, 1fr); }
  .enc pre { min-height: 0; }
  .layout { grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lab-form { grid-template-columns: 1fr 1fr; }
  .wire td.w-bar { width: 30%; }

  .feed li { grid-template-columns: 58px 1fr; }
  .feed li .node-id { grid-column: 2; grid-row: 1; }
  .feed li > span:nth-child(3) { grid-column: 1 / -1; }
  .feed .hex { display: none; }
}
@media (max-width: 380px) {
  .kpi-value { font-size: 18px; }
  .stations td.c-name { grid-column: 1 / -1; }
  .stations td.c-status { grid-column: 1 / -1; text-align: left; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .stations td.c-status .st-region { margin: 0; }
}
