/* Touch-first, dark by default: these pages live in dim electrical rooms and get
   operated with gloves on. Light scheme follows the device preference. */
:root {
  --bg:#11161c; --tile:#1a222b; --tile2:#151c24; --fg:#e9eef4; --muted:#8fa0b3;
  --ok:#37b24d; --warn:#f59f00; --bad:#e03131; --info:#3b8ed0; --accent:#4dabf7;
  --edge:#2b3642; --radius:12px;

  /* Palette the inlined diagram SVG reads. Same variable names in both themes, so
     the drawing needs no dark-mode logic of its own. */
  --dg-line:#7d8fa3; --dg-bus:#c3ccd6; --dg-label:#8fa0b3; --dg-text:#e9eef4;
  --dg-box:#12181f;  --dg-arrow-fill:#1a222b; --dg-off:#38434f;
  --dg-ok:#37b24d;   --dg-warn:#f59f00; --dg-bad:#e03131; --dg-flow:#4dabf7;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg:#f4f6f8; --tile:#fff; --tile2:#eef1f5; --fg:#11161c; --muted:#5b6b7c; --edge:#d8dee6;
    --dg-line:#4a5764; --dg-bus:#26303a; --dg-label:#5b6b7c; --dg-text:#11161c;
    --dg-box:#ffffff;  --dg-arrow-fill:#ffffff; --dg-off:#d7dee6;
  }
}
* { box-sizing: border-box; }
/* An author `display:` rule beats the UA stylesheet's [hidden]{display:none}, so a
   hidden overlay stays laid out and swallows every click on the page. This one line
   is what keeps `el.hidden = true` actually meaning hidden. */
[hidden] { display: none !important; }
body {
  margin:0; background:var(--bg); color:var(--fg);
  font:16px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#topbar {
  display:flex; align-items:center; justify-content:space-between; gap:8px;
  padding:10px 12px; background:var(--tile2); border-bottom:1px solid var(--edge);
  position:sticky; top:0; z-index:5;
}
.brand { display:flex; align-items:baseline; gap:8px; min-width:0; }
#app-title { font-size:1.05rem; margin:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.site { color:var(--muted); font-size:.75rem; text-transform:uppercase; letter-spacing:.06em; }
.topright { display:flex; align-items:center; gap:8px; flex-shrink:0; }
.whoami { color:var(--muted); font-size:.8rem; }
@media (max-width:520px) { .whoami { display:none; } #app-title { font-size:.95rem; } }
.conn { font-size:.72rem; padding:4px 8px; border-radius:999px; border:1px solid var(--edge); white-space:nowrap; }
.conn[data-state="live"]        { color:var(--ok);   border-color:var(--ok); }
.conn[data-state="reconnecting"]{ color:var(--warn); border-color:var(--warn); }
.conn[data-state="down"]        { color:var(--bad);  border-color:var(--bad); }

.banner { padding:10px 12px; background:var(--warn); color:#231a00; font-weight:600; }
.banner[data-kind="bad"] { background:var(--bad); color:#fff; }

.tabs { display:flex; gap:6px; overflow-x:auto; padding:8px 12px; border-bottom:1px solid var(--edge); }
.tabs button {
  background:var(--tile); color:var(--fg); border:1px solid var(--edge);
  border-radius:999px; padding:8px 14px; min-height:44px; font-size:.9rem;
}
.tabs button[aria-selected="true"] { border-color:var(--accent); color:var(--accent); }

.page { display:grid; gap:12px; padding:12px; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); }
@media (min-width:900px) { .page { grid-template-columns:repeat(auto-fit,minmax(210px,1fr)); } }

.tile {
  background:var(--tile); border:1px solid var(--edge); border-radius:var(--radius);
  padding:12px; min-height:104px; display:flex; flex-direction:column; gap:8px;
}
.tile.wide { grid-column:1 / -1; }
.tile .label { color:var(--muted); font-size:.75rem; text-transform:uppercase; letter-spacing:.05em; }
.tile .hint  { color:var(--muted); font-size:.7rem; }
.tile .val   { font-size:2rem; font-variant-numeric:tabular-nums; line-height:1.1; }
.tile .val .unit { font-size:.9rem; color:var(--muted); margin-left:4px; }
.tile.stale { opacity:.45; border-style:dashed; }
.tile.pending { outline:2px solid var(--accent); outline-offset:-2px; }

.led { display:flex; align-items:center; gap:10px; }
.led .dot { width:26px; height:26px; border-radius:50%; background:var(--muted); border:2px solid var(--edge); }
.led.on  .dot { background:var(--ok);  border-color:var(--ok); }
.led.off .dot { background:transparent; border-color:var(--bad); }
.led .txt { font-weight:600; letter-spacing:.04em; }

button, .switch, input[type=range] { touch-action:manipulation; -webkit-tap-highlight-color:transparent; }
button { min-height:48px; border-radius:10px; border:1px solid var(--edge); background:var(--tile2); color:var(--fg); font-size:.95rem; }
button.primary { background:var(--accent); border-color:var(--accent); color:#06121d; font-weight:600; }
button.ghost   { background:transparent; min-height:40px; padding:0 10px; }
button:disabled { opacity:.45; }

.switch { display:flex; align-items:center; gap:10px; cursor:pointer; }
.switch .track { width:64px; height:36px; border-radius:999px; background:var(--tile2); border:1px solid var(--edge); position:relative; transition:background .15s; }
.switch .knob  { position:absolute; top:3px; left:3px; width:28px; height:28px; border-radius:50%; background:var(--muted); transition:left .15s, background .15s; }
.switch.on  .track { background:color-mix(in srgb, var(--ok) 35%, transparent); border-color:var(--ok); }
.switch.on  .knob  { left:33px; background:var(--ok); }
.switch .state { font-size:.85rem; color:var(--muted); }

.sp { display:flex; flex-direction:column; gap:6px; }
.sp .cur { font-size:1.6rem; font-variant-numeric:tabular-nums; }
.sp .cur .unit { font-size:.85rem; color:var(--muted); margin-left:4px; }
.sp input[type=range] { width:100%; height:44px; accent-color:var(--accent); }
.sp .rowline { display:flex; gap:8px; align-items:center; }
.sp .rowline input[type=number] { flex:1; min-height:44px; font-size:1rem; padding:0 10px; border-radius:10px; border:1px solid var(--edge); background:var(--tile2); color:var(--fg); }
.sp select { min-height:44px; font-size:1rem; border-radius:10px; border:1px solid var(--edge); background:var(--tile2); color:var(--fg); padding:0 10px; }
.sp .dirty { color:var(--warn); font-size:.72rem; }
.sp .locked { color:var(--muted); font-size:.72rem; }

.gauge { width:100%; }
.gauge svg { width:100%; height:auto; display:block; }
.gauge .track { stroke:var(--tile2); }
.gauge .fill  { stroke:var(--accent); transition:stroke-dasharray .25s, stroke-dashoffset .25s; }
.gauge .fill.neg { stroke:var(--info); }
.gauge text { fill:var(--fg); font-variant-numeric:tabular-nums; }
.gauge text.small { fill:var(--muted); }

.bar { width:100%; height:26px; background:var(--tile2); border:1px solid var(--edge); border-radius:8px; overflow:hidden; }
.bar > span { display:block; height:100%; background:var(--ok); transition:width .25s; }

#footer { display:flex; justify-content:space-between; gap:8px; padding:10px 12px; color:var(--muted); font-size:.72rem; border-top:1px solid var(--edge); }

.overlay { position:fixed; inset:0; background:rgba(0,0,0,.6); display:grid; place-items:center; z-index:20; padding:16px; }
.panel { background:var(--tile); border:1px solid var(--edge); border-radius:var(--radius); padding:16px; width:min(360px,100%); display:flex; flex-direction:column; gap:8px; }
.panel h2 { margin:0; font-size:1.05rem; }
.panel label { font-size:.75rem; color:var(--muted); text-transform:uppercase; letter-spacing:.05em; }
.panel input { min-height:46px; font-size:1rem; padding:0 10px; border-radius:10px; border:1px solid var(--edge); background:var(--tile2); color:var(--fg); }
.panel .row { display:flex; gap:8px; margin-top:6px; }
.panel .row button { flex:1; }
.muted { color:var(--muted); font-size:.8rem; margin:0; }
.error { color:var(--bad); font-size:.85rem; }

/* --- single line diagram ---------------------------------------------------- */
.diagram-tile { min-height:0; padding:10px; }
.diagram-tile .dg { width:100%; overflow-x:auto; }
/* The drawing has a fixed aspect ratio and a lot of small text, so below tablet
   width it scrolls sideways rather than shrinking into illegibility. */
.diagram-tile .dg svg { width:100%; min-width:680px; height:auto; display:block; }
.dg-loading { color:var(--muted); font-size:.85rem; padding:24px 4px; }
