/* PB service 0.2: a light, clinical look of its own (the bed's world), dark when the system or the operator wants
   it. No inline styles anywhere: the site is served with a CSP that allows none. */

:root {
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --bg: #f2f5f7;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #edf1f4;
  --border: #e1e7ec;
  --border-strong: #cdd6de;
  --text: #15202b;
  --text-2: #3f4d5c;
  --muted: #6a7887;
  --accent: #0b7a83;
  --accent-hover: #086870;
  --accent-soft: #e2f2f3;
  --on-accent: #ffffff;
  --ok: #18834a;
  --ok-soft: #e3f3ea;
  --warn: #a8640a;
  --warn-soft: #fbf0dc;
  --err: #c53636;
  --err-soft: #fbe6e6;
  --rt: #0b7a83;
  --cfg: #5554d1;
  --stat: #b0700f;
  --rt-soft: #e2f2f3;
  --cfg-soft: #ebebfb;
  --stat-soft: #f8eedc;
  --mark: #fff0a8;
  --shadow: 0 1px 2px rgba(16, 28, 40, .05), 0 2px 6px rgba(16, 28, 40, .05);
  --shadow-lg: 0 10px 40px rgba(16, 28, 40, .18);
  --radius: 14px;
  --radius-sm: 9px;
  --rail: 208px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1115;
  --surface: #141a20;
  --surface-2: #192027;
  --surface-3: #202931;
  --border: #26303a;
  --border-strong: #34414d;
  --text: #e6ecf1;
  --text-2: #b9c5cf;
  --muted: #8a99a6;
  --accent: #2fb3ae;
  --accent-hover: #4fc6c1;
  --accent-soft: #11302f;
  --on-accent: #05201f;
  --ok: #43cf7f;
  --ok-soft: #10301e;
  --warn: #efb04a;
  --warn-soft: #332610;
  --err: #f27070;
  --err-soft: #3a1818;
  --rt: #2fb3ae;
  --cfg: #9a99f3;
  --stat: #e6a948;
  --rt-soft: #10302f;
  --cfg-soft: #22223f;
  --stat-soft: #33270f;
  --mark: #5c4f0b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1115;
    --surface: #141a20;
    --surface-2: #192027;
    --surface-3: #202931;
    --border: #26303a;
    --border-strong: #34414d;
    --text: #e6ecf1;
    --text-2: #b9c5cf;
    --muted: #8a99a6;
    --accent: #2fb3ae;
    --accent-hover: #4fc6c1;
    --accent-soft: #11302f;
    --on-accent: #05201f;
    --ok: #43cf7f;
    --ok-soft: #10301e;
    --warn: #efb04a;
    --warn-soft: #332610;
    --err: #f27070;
    --err-soft: #3a1818;
    --rt: #2fb3ae;
    --cfg: #9a99f3;
    --stat: #e6a948;
    --rt-soft: #10302f;
    --cfg-soft: #22223f;
    --stat-soft: #33270f;
    --mark: #5c4f0b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: "tnum" 0;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
svg { flex: none; }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 34px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text); font-weight: 550; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
.btn.danger:hover { background: var(--err-soft); border-color: var(--err); color: var(--err); }
.btn.ghost { background: transparent; border-color: var(--border-strong); }
.btn.sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn.lg { height: 42px; padding: 0 22px; font-size: 15px; }
.btn:disabled, .btn:disabled:hover { opacity: .45; cursor: default; border-color: var(--border-strong); color: var(--text); background: var(--surface); }
.btn.primary:disabled { background: var(--accent); color: var(--on-accent); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); color: var(--muted);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg path.filled { fill: currentColor; stroke: none; }

.input, .select {
  height: 34px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  min-width: 0;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.select.sm { height: 30px; padding: 0 6px; font-size: 13px; font-weight: 600; }
.input.shake { animation: shake .35s; border-color: var(--err); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-2); font-size: 12.5px; font-weight: 550;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-count { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .chip-count { color: inherit; }
.chip.unknown .chip-label { font-style: italic; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px;
  background: transparent; border: 0; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 13px;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg .n { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.rt { background: var(--rt); }
.dot.cfg { background: var(--cfg); }
.dot.stat { background: var(--stat); }

.tag {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .01em; white-space: nowrap;
}
.tag.rt { background: var(--rt-soft); color: var(--rt); }
.tag.cfg { background: var(--cfg-soft); color: var(--cfg); }
.tag.stat { background: var(--stat-soft); color: var(--stat); }
.tag.svc, .tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.err { background: var(--err-soft); color: var(--err); }
.tag.muted { background: var(--surface-3); color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 650; background: var(--surface-3); color: var(--muted);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }

kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
  font: 600 11px var(--mono); color: var(--muted); background: var(--surface-2);
}

.bar { position: relative; height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; min-width: 40px; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 99px; transition: width .35s ease; }
.bar.stat > i { background: var(--stat); }
.bar.cfg > i { background: var(--cfg); }
.bar.warn > i { background: var(--warn); }
.bar.err > i { background: var(--err); }

.spark { display: block; overflow: visible; }
.spark path { fill: none; stroke: var(--rt); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }

.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* ---------------------------------------------------------------- top bar */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: 58px; padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; }
.logo { width: 30px; height: 30px; }
.logo rect { fill: var(--accent); }
.logo path { fill: none; stroke: var(--on-accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.ver { font-size: 11.5px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 6px; }

.unit-strip {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  margin-left: 8px; padding-left: 16px; border-left: 1px solid var(--border);
}
.unit-name { font-weight: 700; white-space: nowrap; }
.unit-meta { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.beat { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex: none; }
.beat.on { animation: beat .9s ease-out; }
@keyframes beat { 0% { background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); } 100% { background: var(--border-strong); box-shadow: 0 0 0 8px transparent; } }
.sim-badge { font-size: 11.5px; font-weight: 700; color: var(--cfg); background: var(--cfg-soft); padding: 2px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: calc(100vh - 58px); }
body.offline .shell { grid-template-columns: minmax(0, 1fr); }
body.offline .rail { display: none; }

.rail {
  position: sticky; top: 58px; align-self: start; height: calc(100vh - 58px);
  display: flex; flex-direction: column; gap: 3px; padding: 16px 12px;
  border-right: 1px solid var(--border); background: var(--surface);
}
.rail button {
  display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px;
  background: transparent; border: 0; border-radius: 10px; color: var(--text-2); font-weight: 600; text-align: left;
}
.rail button:hover { background: var(--surface-3); color: var(--text); }
.rail button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.rail svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

main { min-width: 0; padding: 22px 28px 40px; }
.view { max-width: 1240px; margin: 0 auto; }
.view-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.view-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -.015em; }
.sub { color: var(--muted); font-size: 13px; }
.view-head .sub { margin-top: 3px; }
.foot { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.sub.ok-text { color: var(--ok); }
.sub.err { color: var(--err); }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.text { color: var(--text-2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row.end { justify-content: flex-end; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; min-width: 0;
}
.card-h { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.card-h h2 { font-size: 13px; font-weight: 700; color: var(--text-2); letter-spacing: .02em; text-transform: uppercase; }
.card-h .sub { margin-left: auto; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.def-note { display: block; color: var(--warn); font-weight: 500; font-size: 12.5px; }

.empty { padding: 42px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text-2); font-size: 15px; margin-bottom: 4px; }

.note { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------------------------------------------------------------- connect */
.connect { display: grid; place-items: start center; padding-top: 4vh; }
.connect-card {
  width: min(620px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow); padding: 34px 38px; text-align: left;
}
.connect-art { width: 100%; max-width: 330px; height: auto; display: block; margin: 0 auto 22px; }
.connect-art .a-box { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.connect-art .a-led { fill: var(--ok); }
.connect-art .a-lines, .connect-art .a-cable, .connect-art .a-base { fill: none; stroke: var(--border-strong); stroke-width: 3; stroke-linecap: round; }
.connect-art .a-lines { stroke: var(--accent); stroke-width: 2.5; opacity: .5; }
.connect-art .a-plug { fill: var(--surface-3); stroke: var(--border-strong); stroke-width: 2; }
.connect-art .a-laptop { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 2.5; }
.connect-art .a-pulse { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 60; animation: pulse 2.4s linear infinite; }
@keyframes pulse { from { stroke-dashoffset: 120; } to { stroke-dashoffset: 0; } }
.connect-card h1 { font-size: 24px; font-weight: 750; letter-spacing: -.02em; margin-bottom: 8px; }
.lead { color: var(--text-2); font-size: 15px; margin-bottom: 18px; }
.steps { margin: 0 0 22px; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 10px; }
.steps li { counter-increment: step; position: relative; padding-left: 36px; min-height: 24px; color: var(--text-2); }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12.5px;
}
.steps b { color: var(--text); }
.connect-row { display: flex; gap: 10px; }
.connect-row .select { flex: 1; height: 42px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12.5px; margin: 22px 0 14px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#simBtn { width: 100%; height: 40px; }
.fine { color: var(--muted); font-size: 12.5px; margin-top: 8px; text-align: center; }
.connect .note { margin-top: 12px; }

/* ---------------------------------------------------------------- overview */
.ov-grid { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-flow: dense; align-items: start; }
.sep { height: 1px; background: var(--border); margin: 14px 0 6px; }
.flag-group + .flag-group { margin-top: 16px; }
.flag-head { color: var(--muted); font-size: 12px; font-weight: 650; margin-bottom: 7px; }
.now { font-size: 20px; font-weight: 750; letter-spacing: -.01em; color: var(--accent); margin-bottom: 10px; }
.now.idle { color: var(--muted); font-weight: 600; font-size: 17px; }
.ov-grid > .card { grid-column: span 4; }
.ov-grid > .card.w6 { grid-column: span 6; }
.ov-grid > .card.w8 { grid-column: span 8; }
.ov-grid > .card.w12 { grid-column: span 12; }

.unit-hero { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.unit-hero .big { font-size: 30px; font-weight: 750; letter-spacing: -.02em; }
.unit-hero .sub { font-family: var(--mono); }

.flagset { display: grid; gap: 7px; }
.flag { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.flag .led { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--border-strong); flex: none; }
.flag.on .led { background: var(--accent); border-color: var(--accent); }
.flag.bad .led { background: var(--err); border-color: var(--err); }
.flag.bad { color: var(--err); font-weight: 600; }
.flag.off { color: var(--muted); }
details.more { margin-top: 10px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 12.5px; list-style: none; }
details.more summary::before { content: "▸ "; }
details.more[open] summary::before { content: "▾ "; }
details.more .flagset { margin-top: 8px; }

.op { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.op:last-child { border-bottom: 0; }
.op .k { color: var(--muted); }
.op .v { font-weight: 600; text-align: right; }
.op.active .v { color: var(--accent); }
.op.alert .v { color: var(--warn); }

.weight { display: flex; align-items: baseline; gap: 8px; }
.weight .big { font-size: 40px; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.weight .u { color: var(--muted); font-size: 16px; font-weight: 600; }
.scale-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 10px 0 14px; font-size: 13px; }
.scale-row .k { color: var(--muted); }
.scale-row .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.scale-viz { display: grid; grid-template-columns: 1fr 150px; gap: 16px; align-items: center; }
.cells { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.cell .k { font-size: 11.5px; color: var(--muted); }
.cell .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.cog { width: 150px; height: 110px; }
.cog .bed { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1.5; }
.cog .axis { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.cog .head { fill: var(--border-strong); }
.cog .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; transition: cx .4s, cy .4s; }
.cog text { font-size: 9px; fill: var(--muted); }

.meter { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(50px, 1fr) 84px 72px; gap: 12px; align-items: center; padding: 6px 0; font-size: 13.5px; }
.meter .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.meter .v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter .spark { width: 72px; }

.angles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.angle { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: center; }
.angle svg { width: 64px; height: 40px; display: block; margin: 0 auto 4px; }
.angle .track { fill: none; stroke: var(--surface-3); stroke-width: 6; stroke-linecap: round; }
.angle .needle { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; transition: transform .4s; transform-origin: 32px 36px; }
.angle .hub { fill: var(--accent); }
.angle .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.angle .k { font-size: 11.5px; color: var(--muted); }
.angle.none .needle, .angle.none .hub { opacity: .25; }

.periph { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.periph .p { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--surface-2); }
.periph .p .k { font-size: 11.5px; color: var(--muted); }
.periph .p .v { font-weight: 650; }
.periph .p.off .v { color: var(--muted); font-weight: 500; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; min-width: 0; }
.kpi .v { font-size: 22px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-left: 4px; letter-spacing: 0; }
.kpi .k { font-size: 12px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.kpi.warn .v { color: var(--warn); }

.fw { display: grid; gap: 4px; }
.fw .op .v { font-family: var(--mono); font-size: 12.5px; }

/* ---------------------------------------------------------------- data */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search {
  flex: 1 1 340px; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 11px; min-width: 0;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; height: 100%; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.filters { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }

.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 290px); min-height: 220px; }
table.vt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.vt th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left; white-space: nowrap;
  padding: 9px 12px; color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: .02em;
  border-bottom: 1px solid var(--border);
}
.vt th.sortable { cursor: pointer; user-select: none; }
.vt th.sortable:hover { color: var(--text); }
.vt th[aria-sort="ascending"]::after { content: " ↑"; color: var(--accent); }
.vt th[aria-sort="descending"]::after { content: " ↓"; color: var(--accent); }
.vt td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.vt tbody tr:last-child td { border-bottom: 0; }
.vt tbody tr:hover td { background: var(--surface-2); }
.vt tr.pinned td { background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.vt .c-pin { width: 34px; padding-right: 0; }
.vt .c-src { width: 96px; }
.vt .c-id { width: 56px; color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
.vt .c-name { min-width: 220px; }
.vt td.c-name .unnamed { color: var(--muted); font-style: italic; }
.vt .c-val { min-width: 150px; font-weight: 600; }
.vt td.c-val .u { color: var(--muted); font-weight: 500; }
.vt .c-raw { width: 90px; color: var(--muted); font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.vt .c-trend { width: 110px; }
.vt .c-grp { width: 150px; color: var(--muted); font-size: 12.5px; }
.values:not(.show-raw) .c-raw { display: none; }
.vt td.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.flags-inline { display: flex; flex-wrap: wrap; gap: 4px; }
.flags-inline span { font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--muted); font-weight: 500; }
.flags-inline span.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.pin {
  display: grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 6px; background: transparent;
  color: var(--border-strong);
}
.pin svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.pin:hover { color: var(--accent); background: var(--surface-3); }
.pin[aria-pressed="true"] { color: var(--accent); }
.pin[aria-pressed="true"] svg { fill: currentColor; }
tr.detail td { background: var(--surface-2); padding: 14px 16px 16px 58px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px 24px; }
.detail-grid .kv { font-size: 13px; }
.detail-chart { grid-column: 1 / -1; }
.detail-chart svg.spark { width: 100%; height: 64px; }
.vt tbody tr.vrow { cursor: pointer; }
.vt tbody tr.vrow.open td { background: var(--surface-2); }

/* ---------------------------------------------------------------- usage */
.usage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.usage-grid .card.wide { grid-column: 1 / -1; }
.ranked { display: grid; gap: 2px; }
.rank { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(60px, 1fr) 70px; gap: 12px; align-items: center; padding: 5px 0; font-size: 13.5px; }
.rank .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.rank .v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.rank.zero .k, .rank.zero .v { color: var(--muted); font-weight: 500; }
.ranked + .btn { margin-top: 10px; }
.hist { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.hist .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.hist .bar-v { width: 100%; max-width: 46px; background: var(--warn); border-radius: 7px 7px 3px 3px; min-height: 3px; transition: height .35s; }
.hist .bar-v.zero { background: var(--surface-3); }
.hist .v { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.hist .k { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.act { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(80px, 1.4fr) 72px 70px; gap: 12px; align-items: center; padding: 6px 0; font-size: 13.5px; }
.act.head { color: var(--muted); font-size: 12px; font-weight: 650; padding-top: 0; }
.act .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.act .v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.act .ah { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- logs */
.tabs { display: inline-flex; gap: 2px; background: var(--surface-3); border-radius: 10px; padding: 3px; margin-left: 10px; }
.tabs button { height: 30px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 650; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.log-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; margin-bottom: 14px; }
.log-progress { flex: 1; display: grid; gap: 6px; min-width: 200px; }
.timeline { display: flex; align-items: flex-end; gap: 2px; height: 64px; margin-bottom: 14px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.timeline .d { flex: 1; min-width: 2px; background: var(--accent); opacity: .75; border-radius: 2px 2px 0 0; min-height: 2px; }
.timeline .d:hover { opacity: 1; }
.timeline .d.none { background: var(--border); opacity: 1; }
.dates { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.types { margin-bottom: 14px; }
.vt .c-idx { width: 64px; color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
.vt .c-time { width: 170px; font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.vt .c-cat { width: 130px; }
.vt td.c-ev { font-weight: 600; }
.vt td.c-ev.unknown { color: var(--muted); font-style: italic; font-weight: 500; }
.records:not(.with-cat) .c-cat { display: none; }
.undated { color: var(--muted); font-style: italic; }

/* ---------------------------------------------------------------- service */
.mode { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.mode-state { display: flex; gap: 14px; align-items: flex-start; flex: 1; min-width: 260px; }
.mode-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 5px; background: var(--muted); flex: none; }
.mode-dot.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.mode-dot.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.mode-dot.err { background: var(--err); box-shadow: 0 0 0 4px var(--err-soft); }
.svc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.flags { display: grid; gap: 8px; }
.flag-byte { display: grid; grid-template-columns: 58px repeat(8, minmax(0, 1fr)) 44px; gap: 4px; align-items: center; }
.flag-byte .name { font-size: 12px; font-weight: 700; color: var(--muted); }
.flag-byte .hex { font-family: var(--mono); font-size: 12.5px; text-align: right; color: var(--text-2); }
.bit {
  height: 30px; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--surface);
  font: 600 12px var(--mono); color: var(--muted);
}
.bit[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.bit.changed { box-shadow: 0 0 0 2px var(--warn); }
.bit:disabled { cursor: default; opacity: .55; }
.bit-legend { display: grid; grid-template-columns: 58px repeat(8, minmax(0, 1fr)) 44px; gap: 4px; font-size: 10.5px; color: var(--muted); text-align: center; }

/* ---------------------------------------------------------------- toasts and dialog */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: grid; gap: 8px; width: min(420px, calc(100vw - 36px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 12px 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 11px; box-shadow: var(--shadow-lg); animation: rise .2s ease-out;
}
.toast span { flex: 1; overflow-wrap: anywhere; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast-x { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

dialog {
  width: min(500px, calc(100vw - 32px)); padding: 22px 22px 18px; border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(10, 18, 26, .45); backdrop-filter: blur(2px); }
dialog h2 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
#askText { color: var(--text-2); white-space: pre-line; overflow-wrap: anywhere; }
#askKeywordRow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; color: var(--text-2); }
#askKeywordRow b { font-family: var(--mono); color: var(--err); }
#askKeywordRow .input { flex: 1; min-width: 140px; }
dialog .row { margin-top: 18px; }

/* ---------------------------------------------------------------- narrow screens */
@media (max-width: 1100px) {
  .ov-grid > .card, .ov-grid > .card.w6, .ov-grid > .card.w8 { grid-column: span 6; }
  .ov-grid > .card.w12 { grid-column: span 12; }
}

@media (max-width: 900px) {
  :root { --rail: 0px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 40; height: auto;
    flex-direction: row; justify-content: space-around; gap: 0; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
  }
  .rail button { flex-direction: column; gap: 2px; height: auto; padding: 6px 4px; font-size: 11px; flex: 1; justify-content: center; }
  main { padding: 16px 16px 96px; }
  body.offline main { padding-bottom: 40px; }
  .usage-grid, .svc-grid { grid-template-columns: minmax(0, 1fr); }
  .ov-grid > .card, .ov-grid > .card.w6, .ov-grid > .card.w8, .ov-grid > .card.w12 { grid-column: span 12; }
  .unit-meta { display: none; }
  .table-card { max-height: none; }
  .toasts { bottom: 84px; }
}

@media (max-width: 640px) {
  .top { gap: 8px; padding: 0 12px; }
  .brand-name, .ver, .beat { display: none; }
  .unit-strip { margin-left: 0; padding-left: 10px; gap: 8px; min-width: 0; }
  .unit-name { overflow: hidden; text-overflow: ellipsis; }
  .unit-strip .pill { font-size: 0; gap: 0; padding: 0 8px; height: 20px; } /* the dot says the mode */
  .sim-badge { display: none; }
  #disconnectBtn { padding: 0 9px; }
  .connect-card { padding: 24px 18px; border-radius: 16px; }
  .connect-row { flex-direction: column; }
  .view-head h1 { font-size: 20px; }
  .scale-viz { grid-template-columns: 1fr; }
  .cog { margin: 0 auto; }
  .vt .c-src, .vt .c-grp, .vt .c-trend, .vt .c-id { display: none; }
  .vt .c-name { min-width: 150px; }
  .vt .c-val { min-width: 110px; }
  .flag-byte, .bit-legend { grid-template-columns: 46px repeat(8, minmax(0, 1fr)) 34px; }
  .rank { grid-template-columns: minmax(0, 1.4fr) minmax(40px, 1fr) 56px; }
  .act { grid-template-columns: minmax(0, 1fr) 60px 56px; }
  .act .bar { display: none; }
  tr.detail td { padding-left: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
