/* OpenInverter Web Interface — "Blend" design (doc/REDESIGN.md)
   Homestead's layouts and glass components carrying OpenInverter's
   cyan + mint identity. Dark-first; full light mode. */

/* Bundled so the UI looks the same with no internet (AP mode in a car).
   Latin subsets, variable weight; SIL OFL (THIRD_PARTY_NOTICES.md) */
@font-face {
  font-family: "Inter Tight"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("fonts/intertight.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("fonts/jbmono.woff2") format("woff2");
}

:root {
  /* light theme (default when system prefers light) */
  --bg: #ececed;
  --bg-glow1: rgba(2,132,199,.06);
  --bg-glow2: rgba(15,157,99,.05);
  --surface: #ffffff;
  --surface2: #f6f6f7;
  --surface3: #ebebee;
  --glass: rgba(255,255,255,.82);
  --card: rgba(255,255,255,.88);
  --text: #16161a;
  --text2: #5c5c66;
  --text3: #686872;
  --accent: #0369a1;   /* 5.0:1 on the light ground (#0284c7 was 3.5:1) */
  --accent2: #075985;
  --accent-glow: rgba(2,132,199,.12);
  --green: #0f9d63;
  --green2: #0c7d4f;
  --red: #c8232c;
  --amber: #9a5b00;
  /* state tones */
  --tone-info: #0369a1;     --tone-info-bg: rgba(2,132,199,.1);
  --tone-active: #0b7a48;   --tone-active-bg: rgba(15,157,99,.12);
  --tone-warn: #9a5b00;     --tone-warn-bg: rgba(217,119,6,.12);
  --tone-danger: #c8232c;   --tone-danger-bg: rgba(220,38,38,.1);
  --grad-edge: linear-gradient(120deg, rgba(2,132,199,.45) 0%, rgba(2,132,199,.06) 30%, rgba(0,0,0,.04) 55%, rgba(15,157,99,.32) 100%);
  --grad-signature: linear-gradient(90deg, var(--accent), var(--green));
  --border: rgba(0,0,0,.09);
  --border2: rgba(0,0,0,.16);
  --radius: 20px;
  --radius-sm: 14px;
  --radius-xs: 9px;
  --shadow: 0 1px 3px rgba(0,0,0,.05), 0 8px 28px rgba(0,0,0,.07);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --on-bg: #16161a; --on-fg: #ffffff;   /* selected nav/segment, primary button */
  --card-bg: rgba(255,255,255,.88);
  --ctl-bg: #ffffff; --ctl-hover: #f2f2f4;
  --row-hover: rgba(0,0,0,.025);
  --pill-ok-fg: #ffffff;
  --pill-ok-a: #0b7a48; --pill-ok-b: #096b3f; /* white text at 5.4:1 */
  --glow-pri: 0 8px 26px rgba(2,132,199,.18);
  --font: "Inter Tight", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", "Consolas", monospace;
  --num: var(--mono); /* telemetry numerals: tabular figures, clean zeros */
  --navbar-w: 238px;
  --navbar-w-min: 60px;
  --transition: .2s cubic-bezier(.22,.61,.36,1);
}

/* Dark theme: the primary design target */
:root[data-theme="dark"] {
  --bg: #070708;
  --bg-glow1: rgba(76,201,240,.08);
  --bg-glow2: rgba(84,230,164,.06);
  --surface: #111113;
  --surface2: #161618;
  --surface3: #1d1d20;
  --glass: rgba(17,17,19,.72);
  --card: rgba(255,255,255,.04);
  --text: #e8ecf1;
  --text2: #9aa3b2;
  --text3: #8a93a3;
  --accent: #4cc9f0;
  --accent2: #2eb4e0;
  --accent-glow: rgba(76,201,240,.13);
  --green: #54e6a4;
  --green2: #36c987;
  --red: #ff6b6b;
  --amber: #ffb454;
  --tone-info: #4cc9f0;    --tone-info-bg: rgba(76,201,240,.12);
  --tone-active: #54e6a4;  --tone-active-bg: rgba(84,230,164,.12);
  --tone-warn: #ffb454;    --tone-warn-bg: rgba(255,180,84,.12);
  --tone-danger: #ff6b6b;  --tone-danger-bg: rgba(255,107,107,.12);
  --grad-edge: linear-gradient(120deg, rgba(76,201,240,.7) 0%, rgba(76,201,240,.08) 30%, rgba(255,255,255,.06) 55%, rgba(84,230,164,.45) 100%);
  --border: rgba(255,255,255,.07);
  --border2: rgba(255,255,255,.13);
  --shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 10px 34px rgba(0,0,0,.45);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --on-bg: #ffffff; --on-fg: #0a0a0b;
  --card-bg: linear-gradient(158deg, rgba(255,255,255,.085) 0%, rgba(255,255,255,.028) 42%, rgba(255,255,255,.012) 100%);
  --ctl-bg: rgba(255,255,255,.055); --ctl-hover: rgba(255,255,255,.11);
  --row-hover: rgba(255,255,255,.025);
  --pill-ok-fg: #03251a;
  --pill-ok-a: var(--green); --pill-ok-b: var(--green2);
  --glow-pri: 0 8px 26px rgba(76,201,240,.22), 0 2px 10px rgba(84,230,164,.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070708;
    --bg-glow1: rgba(76,201,240,.08);
    --bg-glow2: rgba(84,230,164,.06);
    --surface: #111113;
    --surface2: #161618;
    --surface3: #1d1d20;
    --glass: rgba(17,17,19,.72);
    --card: rgba(255,255,255,.04);
    --text: #e8ecf1;
    --text2: #9aa3b2;
    --text3: #8a93a3;
    --accent: #4cc9f0;
    --accent2: #2eb4e0;
    --accent-glow: rgba(76,201,240,.13);
    --green: #54e6a4;
    --green2: #36c987;
    --red: #ff6b6b;
    --amber: #ffb454;
    --tone-info: #4cc9f0;    --tone-info-bg: rgba(76,201,240,.12);
    --tone-active: #54e6a4;  --tone-active-bg: rgba(84,230,164,.12);
    --tone-warn: #ffb454;    --tone-warn-bg: rgba(255,180,84,.12);
    --tone-danger: #ff6b6b;  --tone-danger-bg: rgba(255,107,107,.12);
    --grad-edge: linear-gradient(120deg, rgba(76,201,240,.7) 0%, rgba(76,201,240,.08) 30%, rgba(255,255,255,.06) 55%, rgba(84,230,164,.45) 100%);
    --border: rgba(255,255,255,.07);
    --border2: rgba(255,255,255,.13);
    --shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 10px 34px rgba(0,0,0,.45);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --on-bg: #ffffff; --on-fg: #0a0a0b;
    --card-bg: linear-gradient(158deg, rgba(255,255,255,.085) 0%, rgba(255,255,255,.028) 42%, rgba(255,255,255,.012) 100%);
    --ctl-bg: rgba(255,255,255,.055); --ctl-hover: rgba(255,255,255,.11);
    --row-hover: rgba(255,255,255,.025);
    --pill-ok-fg: #03251a;
    --pill-ok-a: var(--green); --pill-ok-b: var(--green2);
    --glow-pri: 0 8px 26px rgba(76,201,240,.22), 0 2px 10px rgba(84,230,164,.12);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  font-family: var(--font); font-size: 15px; line-height: 1.55; letter-spacing: -.006em;
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: none; -webkit-font-smoothing: antialiased;
}
/* ambient glow layers — the tech-telemetry backdrop */
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 500px at 85% -5%, var(--bg-glow1), transparent 65%),
    radial-gradient(800px 600px at -10% 105%, var(--bg-glow2), transparent 60%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

select.styled {
  font-size: .85rem; padding: 6px 28px 6px 10px;
  border-radius: var(--radius-xs);
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--accent);
  appearance: none; cursor: pointer;
  background-image: url('data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%235f6672%22 stroke-width=%222%22><polyline points=%226 9 12 15 18 9%22/></svg>');
  background-repeat: no-repeat; background-position: right 8px center;
}

h2 { font-size: 1.4rem; font-weight: 700; margin: 0 0 .75rem; letter-spacing: -.01em; }
h3 { font: 600 .7rem/1.4 var(--mono); color: var(--text3); margin: 1.5rem 0 .55rem; text-transform: uppercase; letter-spacing: .11em; }
.underline { border-bottom: 1px solid var(--border2); padding-bottom: .5rem; margin-bottom: .75rem; }

p { margin: 0 0 .5rem; color: var(--text2); line-height: 1.6; }

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ===== KEYFRAMES ===== */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.8); }
}

/* ===== NAVBAR ===== */
#navbar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--navbar-w); z-index: 50;
  background: var(--glass); backdrop-filter: blur(22px) saturate(140%); -webkit-backdrop-filter: blur(22px) saturate(140%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  transition: width var(--transition);
  scrollbar-width: none; /* scrollbar steals width from the slim bar */
}
#navbar::-webkit-scrollbar { display: none; }

#logo { padding: 1.5rem 1.25rem .75rem; flex-shrink: 0; }
#logo svg, #logo img { width: 40px; height: 40px; display: block; margin: 0 auto; cursor: pointer; opacity: .9; transition: opacity var(--transition), transform var(--transition); }
#logo svg:hover, #logo img:hover { opacity: 1; transform: scale(1.06); }

.tablink {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 13px; margin: 1px 10px;
  border-radius: 12px; cursor: pointer;
  color: var(--text2); font-size: .86rem; font-weight: 600;
  transition: all var(--transition); white-space: nowrap;
}
.tablink:hover { background: var(--ctl-bg); color: var(--text); transform: translateX(2px); }
/* Homestead's selected pill, lit by the cyan/mint signature */
.tablink.active { background: var(--on-bg); color: var(--on-fg); box-shadow: var(--glow-pri); }
.tablink.active .tab-icon { color: var(--on-fg); }

.tab-icon { display: flex; align-items: center; flex-shrink: 0; color: var(--text3); transition: color var(--transition); }
.tab-dot { display: none; }

.btn-ic { display: inline-flex; align-items: center; flex-shrink: 0; }

.navbar-text { overflow: hidden; text-overflow: ellipsis; }

#spinner-div { display: flex; align-items: center; gap: 8px; padding: 8px 16px; font-size: .75rem; color: var(--text3); }
.css-spinner { width: 14px; height: 14px; flex-shrink: 0; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.css-spinner-lg { width: 32px; height: 32px; border-width: 3px; margin: 1rem auto; }

#version { margin: auto 10px 0; padding: 10px 12px; font-size: .7rem; color: var(--text3); background: var(--surface2); border-radius: var(--radius-xs); line-height: 1.6; }
/* device nickname (Settings → Device Name); takes over #version's auto-margin when present */
#device-name { margin: auto 10px 0; padding: 6px 10px; font-size: .78rem; font-weight: 700; color: var(--accent); background: var(--accent-glow); border-radius: var(--radius-xs); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* preset dry-run / file-compare diff tables: matching rows fade back */
tr.diff-same td { color: var(--text3); }

/* Password managers (LastPass especially) ignore the data-lpignore hints on
   the Settings fields and inject in-field icon overlays anyway — mispositioned
   by the multi-column card layout. Nothing on these pages is a credential
   (WiFi config, device name), so suppress the injected overlay elements. */
[data-lastpass-icon-root], [data-lastpass-root], [data-lastpass-infield],
#onepassword-button, com-1password-button { display: none !important; }
input::-webkit-credentials-auto-fill-button { visibility: hidden; pointer-events: none; }
#data-age { position: relative; margin: 8px 10px 10px; padding: 6px 12px; font-size: .75rem; font-weight: 600; color: var(--accent); background: var(--accent-glow); border-radius: var(--radius-xs); text-align: center; font-variant-numeric: tabular-nums; }

/* refresh indicator: a glowing stroke circling the badge outline (no layout shift) */
@property --da-angle { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
#data-age.fetching::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; padding: 1.5px;
  background: conic-gradient(from var(--da-angle),
    transparent 0turn .68turn, var(--accent) .86turn, transparent 1turn);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  animation: da-orbit 1.1s linear infinite;
  filter: drop-shadow(0 0 3px var(--accent));
  pointer-events: none;
}
@keyframes da-orbit { to { --da-angle: 360deg; } }
@media (prefers-reduced-motion: reduce) { #data-age.fetching::before { animation: none; } }
.fast-badge { background: var(--accent); color: #04222e; padding: 2px 8px; border-radius: 10px; font-size: .65rem; font-weight: 700; letter-spacing: .03em; white-space: nowrap; }

.control { padding: 4px 16px; display: flex; align-items: center; gap: 8px; font-size: .75rem; color: var(--text3); }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border2); border-radius: 20px; transition: var(--transition); cursor: pointer; }
.slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; bottom: 2px; background: #fff; border-radius: 50%; transition: var(--transition); }
input:checked + .slider { background: var(--accent); }
input:checked + .slider::before { transform: translateX(14px); }

/* compact switch variant */
.switch.sm { width: 30px; height: 18px; }
.switch.sm .slider::before { width: 14px; height: 14px; }
.switch.sm input:checked + .slider::before { transform: translateX(12px); }

/* labeled toggle row for action panels */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 8px 12px; margin: 0;
  background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-xs);
  cursor: pointer; user-select: none;
  font-size: .8rem; font-weight: 500; color: var(--text2);
  transition: border-color var(--transition), color var(--transition), transform var(--transition);
}
.toggle-row:hover { border-color: var(--accent); color: var(--text); transform: translateY(-1px); }
.toggle-row:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }
.toggle-row.disabled { opacity: .45; pointer-events: none; }
.toggle-row .toggle-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* the same row holding a compact select instead of a switch */
/* neither part truncates here: in a narrow column the select wraps onto
   its own line instead of squeezing the label (or its own text) */
.toggle-row.select-row { cursor: default; flex-wrap: wrap; row-gap: 6px; }
.toggle-row.select-row .toggle-label { flex-shrink: 0; overflow: visible; }
.toggle-row.select-row select { width: auto; flex: none; margin: 0 0 0 auto; padding: 3px 22px 3px 6px; font-size: .75rem; }

/* navbar CAN node selector: full select on desktop, compact #N on slim rail */
.can-node-select { position: relative; width: 100%; }
.can-node-select .can-node-short { display: none; }

/* responsive actions expander: desktop renders the group inline,
   slim layouts collapse it behind a clearly-labelled Actions button */
.actions-expander { display: none; }
.collapsible-actions { display: contents; }
@media (max-width: 900px) {
  .actions-expander {
    display: inline-flex; align-items: center; gap: 6px;
    width: auto; font-weight: 600;
  }
  .collapsible-actions { display: none; }
  .collapsible-actions.open { display: contents; }
}

/* accent colour swatches */
.accent-swatches { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.accent-swatches .swatch {
  width: 26px; height: 26px; border-radius: 50%; padding: 0;
  border: 2px solid var(--border2); cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
}
.accent-swatches .swatch:hover { transform: scale(1.15); border-color: var(--text2); }
.accent-swatches .swatch.sel { border-color: var(--text); transform: scale(1.12); box-shadow: 0 0 0 3px var(--accent-glow); }
.accent-swatches .swatch.reset {
  background: var(--surface3); color: var(--text2);
  display: flex; align-items: center; justify-content: center; font-size: .85rem;
}
.accent-swatches input[type=color] {
  width: 26px; height: 26px; padding: 0; border: 2px dashed var(--border2);
  border-radius: 50%; background: none; cursor: pointer;
}

/* ===== CONTENT ===== */
#content-wrapper { position: fixed; top: 0; right: 0; bottom: 0; left: var(--navbar-w); overflow: hidden; transition: left var(--transition); }
/* top bar above, the page below it scrolls */
#content-wrapper-inner { display: flex; flex-direction: column; height: 100%; }
#content-wrapper-inner > .tabdiv { min-height: 0; padding-top: .5rem; }
#content { display: flex; height: 100%; }

.tabdiv { display: none; flex: 1; padding: 2rem; overflow-y: auto; }

/* ===== LAYOUT ===== */
.main-content { display: flex !important; gap: 2.5rem; position: relative; }
.main-left { flex: 1; min-width: 0; overflow-y: auto; padding-right: 12px; scrollbar-gutter: stable; }
.main-right { width: 220px; min-width: 180px; flex-shrink: 0; display: flex; flex-direction: column; gap: .35rem; padding-top: .25rem; transition: width var(--transition), min-width var(--transition), opacity var(--transition), padding var(--transition); }
#content-wrapper-inner[data-panel="closed"] .main-right { width: 0; min-width: 0; opacity: 0; overflow: hidden; padding: 0; margin: 0; }
.panel-toggle { display: none; }

/* ===== CARDS (glass) ===== */
.dash-row { display: flex; gap: 1rem; margin-bottom: 1rem; }
.dash-box {
  flex: 1; min-width: 0; padding: 1.25rem 1.5rem;
  position: relative;
  /* No backdrop blur: an in-flow card only has the page behind it, and
     Chrome's blur samples past the card's edge, so a card below another
     showed a flickering light band along its top on every repaint.
     Floating chrome (navbar, top bar, modals, toasts) keeps its blur */
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-height: 160px; display: flex; flex-direction: column;
  transition: box-shadow var(--transition), transform var(--transition);
  animation: rise .3s ease both;
}
/* luminous edge — the OpenInverter signature, kept for hero cards only
   (.edge), so it marks what matters instead of every card */
.dash-box.edge::before, .hero-card::before, .gauge-tile.edge::before {
  content: '';
  position: absolute; inset: 0;
  padding: 1px;
  border-radius: inherit;
  background: var(--grad-edge);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none;
}
.dash-box:hover { border-color: var(--border2); transform: translateY(-2px); }
.hero-card { border-color: transparent; }
/* running: a mint/cyan aurora inside the hero card */
.hero-card:has(.hero-top .pill.active)::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(520px 220px at 12% 120%, rgba(84,230,164,.16), transparent 70%),
              radial-gradient(420px 200px at 100% -30%, rgba(76,201,240,.14), transparent 70%);
}
.hero-card > * { position: relative; z-index: 1; }
.dash-box.compact { min-height: 0; }
.dash-box.compact h3 { margin-top: 0; }
.dash-box h3 { margin: 0 0 .5rem; }
.dash-box table { width: 100%; font-size: .9rem; }
.dash-box td { padding: 4px 0; border: none; background: transparent; }
.dash-box td:first-child { color: var(--text2); padding-right: 1rem; white-space: nowrap; }
.dash-box tbody tr, .dash-box tbody tr:nth-child(even), .dash-box tbody tr:hover { background: transparent; }

/* ===== HERO STATUS CARD ===== */
.hero-card { min-height: 0; gap: .9rem; }
.hero-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hero-state { font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.hero-sub { color: var(--text2); font-size: .85rem; margin: 0; overflow-wrap: anywhere; }
.hero-metrics { display: flex; gap: 2.2rem; flex-wrap: wrap; margin-top: .35rem; }
.metric { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }
.metric-label { font: 600 .64rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: .11em; color: var(--text3); }
.metric-value { font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 1.7rem; font-weight: 600; line-height: 1.2; }
.metric-unit { font-size: .85rem; color: var(--text2); font-weight: 500; margin-left: 2px; }
.metric .spark { margin-top: 4px; color: var(--accent); opacity: .85; }
.metric.tone-active .spark { color: var(--green); }

/* ===== STATE PILL ===== */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 13px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; letter-spacing: .01em;
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse-dot 2s ease infinite; }
.pill.info    { color: var(--tone-info);   background: var(--tone-info-bg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone-info) 32%, transparent); }
.pill.active  { color: var(--pill-ok-fg); background: linear-gradient(135deg, var(--pill-ok-a), var(--pill-ok-b)); box-shadow: 0 3px 14px color-mix(in srgb, var(--green) 30%, transparent); }
.pill.warn    { color: var(--tone-warn);   background: var(--tone-warn-bg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone-warn) 34%, transparent); }
.pill.danger  { color: var(--tone-danger); background: var(--tone-danger-bg); }
.pill.muted   { color: var(--text2);       background: var(--surface3); }
.pill.muted .dot { animation: none; }

/* sparkline svg */
.spark { display: block; }
.spark polyline { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }

/* ===== BUTTONS ===== */
button, .butt {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px; font-size: .86rem; font-weight: 620; font-family: var(--font);
  background: var(--ctl-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
  line-height: 1.4;
}
button:hover, .butt:hover { background: var(--ctl-hover); border-color: var(--border2); transform: translateY(-1px); }
button:active, .butt:active { transform: translateY(0) scale(.98); }
button:focus-visible, .butt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.main-right button, .main-right .butt { width: 100%; justify-content: flex-start; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:hover { background: var(--ctl-bg); border-color: var(--border); color: var(--text); transform: none; }
.flex-break { display: none; }

/* ===== SETTINGS ===== */
/* Boxes pack into responsive newspaper columns under full-width section
   headers: unlike a row-based grid, short cards don't leave holes — the
   next card flows straight up beneath them */
.settings-grid { columns: 2 380px; column-gap: 12px; }
.settings-grid > .dash-box {
  margin: 0 0 12px; break-inside: avoid;
  display: block; /* flex column boxes mis-measure inside CSS columns */
}
.settings-subhead {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text3); margin: .6rem 0 .35rem;
}
/* preset rows in the Parameters action rail: each preset is its own boxed
   card (name + button row) so it's obvious which buttons belong to which,
   with uniform-height compact buttons */
.preset-row {
  display: flex; align-items: center; gap: 4px; width: 100%; flex-wrap: wrap;
  padding: 6px 8px; background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius-xs);
}
.preset-row .preset-name {
  flex: 1 1 100%; min-width: 0; font-size: .8rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preset-row button {
  width: auto; height: 24px; padding: 0 9px; font-size: .7rem;
  line-height: 1; justify-content: center;
}

/* action gauge tile: a button that fills its tile and flashes the outcome.
   Minimal padding (the base button's 8/15px ate a third of a phone tile)
   and labels may wrap onto two clamped lines before ellipsising. */
.action-tile-btn {
  width: 100%; height: 100%; min-height: 0; justify-content: center;
  font-weight: 650; overflow: hidden; padding: 2px 4px;
  border: 1.5px solid var(--accent); color: var(--accent); background: var(--accent-glow);
  transition: background .15s, border-color .15s, color .15s;
}
.action-tile-btn .action-label {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-clamp: 2;
  overflow: hidden; text-align: center; line-height: 1.15; word-break: break-word; max-width: 100%;
}
.action-tile-btn:hover { transform: none; }
.action-tile-btn.busy { opacity: .6; }
.action-tile-btn.ok { border-color: var(--green); color: var(--green); background: color-mix(in srgb, var(--green) 18%, transparent); }
.action-tile-btn.fail { border-color: var(--red); color: var(--red); background: color-mix(in srgb, var(--red) 18%, transparent); }

/* bar gauge: a tile-filling linear meter, level or column */
.bar-gauge { position: relative; border: 1px solid var(--border2); border-radius: var(--radius-xs); background: var(--surface); overflow: hidden; }
.bar-gauge .bar-fill { position: absolute; transition: width .3s ease, height .3s ease, left .3s ease, bottom .3s ease; }
.bar-gauge.horiz .bar-fill { top: 0; bottom: 0; }
.bar-gauge.vert .bar-fill { left: 0; right: 0; }
/* centre-point tick: marks the pivot a centred bar fills from */
.bar-gauge .bar-center-tick { position: absolute; background: var(--text3); opacity: .7; }
.bar-gauge.horiz .bar-center-tick { top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.bar-gauge.vert .bar-center-tick { left: 0; right: 0; height: 2px; margin-bottom: -1px; }
.bar-gauge .bar-fill.over { background: var(--red); }
.bar-gauge .bar-val { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 4px rgba(0,0,0,.35); overflow: hidden; }
.bar-gauge .bar-end { position: absolute; font-size: .62rem; color: var(--text2); }
.bar-gauge.horiz .bar-lo { left: 6px; bottom: 2px; }
.bar-gauge.horiz .bar-hi { right: 6px; bottom: 2px; }
.bar-gauge.vert .bar-lo { left: 50%; transform: translateX(-50%); bottom: 2px; }
.bar-gauge.vert .bar-hi { left: 50%; transform: translateX(-50%); top: 2px; }
/* peak-hold marker: where the session's highest (lowest) value reached */
.bar-gauge .bar-peak-tick { position: absolute; background: var(--text); opacity: .5; }
/* Segmented: LED blocks with a small gap; lit ones take their --seg colour.
   The blocks and bands sit in full-size wrappers (one per style) */
.bar-gauge .bar-segs, .bar-gauge .bar-zones { position: absolute; inset: 0; }
.bar-gauge.bar-segmented { background: transparent; border-color: transparent; }
.bar-gauge .bar-seg { position: absolute; border-radius: 3px; background: color-mix(in srgb, var(--text) 13%, transparent); transition: background .2s; }
.bar-gauge.horiz .bar-seg { top: 0; bottom: 0; border-left: 2px solid transparent; border-right: 2px solid transparent; background-clip: padding-box; }
.bar-gauge.vert .bar-seg { left: 0; right: 0; border-top: 2px solid transparent; border-bottom: 2px solid transparent; background-clip: padding-box; }
.bar-gauge .bar-seg.on { background-color: var(--seg); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
/* A tall horizontal segmented bar puts its blocks in the lower half and the
   value and end labels above them, clear of the bright blocks */
.bar-gauge.seg-split .bar-seg { top: 50%; }
.bar-gauge.seg-split .bar-val { bottom: 50%; }
.bar-gauge.seg-split .bar-end { bottom: auto; top: 2px; }
.bar-gauge.bar-segmented:not(.seg-split) .bar-val { text-shadow: 0 0 4px var(--bg), 0 0 10px var(--bg); }
/* Zones: caution/danger bands along the top (or left) edge, a marker at the value */
.bar-gauge .bar-zone { position: absolute; opacity: .75; }
.bar-gauge.horiz .bar-zone { top: 0; height: 22%; }
.bar-gauge.vert .bar-zone { left: 0; width: 22%; }
.bar-gauge .bar-marker { position: absolute; background: var(--text); border-radius: 2px; transition: left .3s ease, bottom .3s ease; }
.bar-gauge.horiz .bar-marker { top: 0; bottom: 0; width: 4px; margin-left: -2px; }
.bar-gauge.vert .bar-marker { left: 0; right: 0; height: 4px; margin-bottom: -2px; }
.bar-gauge.horiz .bar-peak-tick { top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.bar-gauge.vert .bar-peak-tick { left: 0; right: 0; height: 2px; margin-bottom: -1px; }

/* value alarm: the tile pulses in the warn colour while the value is in the zone */
.gauge-tile.alarming { animation: alarm-pulse .9s ease-in-out infinite; }
@keyframes alarm-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 0 3px var(--alarmc, #ef4444); }
}

/* full-screen mode: gauges own the whole screen, chrome hidden */
body.kiosk #navbar { display: none; }
body.kiosk #content-wrapper { left: 0; }
body.kiosk #gauges-head { display: none !important; } /* beats the row's inline flex */
body.kiosk .gauges-view.tabdiv { padding: .5rem .6rem; }
body.kiosk #communication-error-bar { display: none !important; }
.kiosk-exit {
  position: fixed; top: 10px; right: 10px; z-index: 500;
  width: 34px; height: 34px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem; opacity: .5;
}
.kiosk-exit:hover { opacity: 1; }

/* toggle gauge tile: a scaled switch, red ring flash on failure */
.toggle-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%; height: 100%; cursor: pointer; user-select: none;
}
.toggle-tile.fail .slider { box-shadow: 0 0 0 2px var(--red); }

/* slider gauge tile; .row = short tiles put the value beside the slider */
.slider-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; max-width: 100%; overflow: hidden; }
.slider-tile input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; min-width: 0; }
.slider-tile.row { flex-direction: row; gap: 6px; }
.slider-tile.row input[type="range"] { flex: 1; }
.slider-tile.row .g-val { flex: none; white-space: nowrap; }
.slider-tile.ok .g-val { color: var(--green); }
.slider-tile.fail .g-val { color: var(--red); }

/* wifi signal bars */
.wifi-bars { display: inline-flex; align-items: flex-end; gap: 1.5px; line-height: 1; }
.wifi-bars i { display: inline-block; width: 3px; border-radius: 1px; background: var(--border2); }
.wifi-bars i.on { background: var(--green); }
.wifi-bars .wifi-dbm { font-size: .7rem; color: var(--text3); margin-left: 5px; align-self: center; }

/* navbar update-available badge */
.update-badge {
  display: flex; align-items: center; gap: 2px; margin: 6px 8px 0;
  padding: 2px 4px 2px 10px; border-radius: 12px;
  background: var(--accent-glow); border: 1px solid var(--accent);
  color: var(--accent); font-size: .66rem; font-weight: 700; letter-spacing: .02em;
}
.update-badge span { cursor: pointer; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.update-badge button { border: none; background: none; box-shadow: none; color: var(--accent); font-size: .8rem; padding: 0 4px; }
.update-badge button:hover { background: none; border: none; transform: none; }

/* segmented picker (UART | CAN Bus) */
/* segmented controls (.seg, defined with the page switchers below): every
   button inside is a rounded segment; the chosen one is the selected pill */
.seg button { border: 1px solid transparent; border-radius: 10px; background: transparent; font-size: .82rem; font-weight: 620;
  padding: 6px 14px; color: var(--text2); width: auto; }
.seg button:hover { transform: none; background: var(--ctl-bg); color: var(--text); border-color: transparent; }
.seg button.sel, .seg button.active { background: var(--on-bg); color: var(--on-fg); border-color: var(--on-bg); box-shadow: var(--glow-pri); }

/* ===== FORMS ===== */
input[type=number], input[type=text], input[type=password], select, textarea {
  padding: 8px 12px; font-size: .9rem; font-family: var(--font);
  background: var(--ctl-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  transition: border-color var(--transition), box-shadow var(--transition); outline: none;
}
input[type=number] { font-family: var(--num); font-variant-numeric: tabular-nums; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
select { padding-right: 30px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 12 12%22%3E%3Cpath fill=%22%239ca0a8%22 d=%22M6 8L1 3h10z%22/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
input[type=number] { width: 8em; }
textarea { width: 100%; resize: vertical; min-height: 80px; }

/* ===== TABLES ===== */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th {
  position: sticky; top: 0; z-index: 2;
  padding: 10px 14px; font: 600 .64rem/1.4 var(--mono);
  text-transform: uppercase; letter-spacing: .11em;
  color: var(--text3); background: var(--surface2);
  border-bottom: 1px solid var(--border2); text-align: left;
}
tbody td { padding: 8px 14px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--row-hover); }
td { font-variant-numeric: tabular-nums; }

/* Spot values columns */
#spotValues td.sv-name { font-weight: 500; overflow-wrap: anywhere; }
#spotValues td.sv-val { font-family: var(--num); font-weight: 600; color: var(--accent); overflow-wrap: anywhere; }
#spotValues td.sv-unit { color: var(--text3); font-size: .78rem; }
#spotValues td.sv-spark { color: var(--accent); opacity: .75; padding: 2px 8px; }
#spotValues td.sv-spark .spark { display: block; }

/* Parameters: [fav][i][name][value][unit][min][max][default] */
#params td:nth-child(2) { color: var(--text3); font-size: .72rem; font-family: var(--num); }
#params td:nth-child(3) { font-weight: 500; }
#params td:nth-child(4) { font-family: var(--num); }
#params td:nth-child(5) { color: var(--text3); font-size: .78rem; }
#params td:nth-child(6), #params td:nth-child(7), #params td:nth-child(8) {
  color: var(--text3); font-family: var(--num); font-size: .8rem;
}
/* Category section rows */
#params td[colspan] { padding: 16px 4px 4px; border-bottom: none; }
#params td[colspan] button {
  color: var(--accent); font-size: .74rem; font-weight: 700 !important;
  text-transform: uppercase; letter-spacing: .08em; padding: 2px 8px;
}
#params tr:has(td[colspan]):hover { background: transparent; }

.fullheight { max-height: calc(100vh - 220px); overflow-y: auto; padding-right: 10px; scrollbar-gutter: stable; }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.small-modal-container, .large-modal-container, .can-mapping-modal-container {
  position: relative;
  background: var(--glass); backdrop-filter: blur(24px) saturate(140%); -webkit-backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--border2);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 85vh; overflow-y: auto;
  animation: rise .25s ease both;
}
.small-modal-container { width: 400px; padding: 1.5rem 1.75rem; }
.large-modal-container { width: 640px; padding: 2rem; }
.can-mapping-modal-container { width: 560px; padding: 2rem; }
/* modal header: title left, close X pinned top-right (float dropped the X
   below the block heading — "down by the content") */
#large-modal-header-div { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#large-modal-header-div h2 { margin: 0; }
.modal-close { flex: none; font-size: 1.5rem; color: var(--text3); cursor: pointer; transition: color var(--transition); line-height: 1; }
.modal-close:hover { color: var(--red); }
.modal-content { margin-top: 1rem; }

/* ===== COMMAND ===== */
#commandoutput {
  flex: 1; min-height: 120px; max-height: 400px; overflow-y: auto;
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-xs);
  font-family: var(--mono); font-size: .82rem; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere;
}
#commandinput { width: 100%; flex-shrink: 0; font-family: var(--mono); }

/* data logger output: terminal styling */
#data-logger-text-area {
  width: 100%; min-height: 60vh;
  font-family: var(--mono); font-size: .8rem; line-height: 1.5;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 10px 12px; white-space: pre; overflow: auto;
}

/* ===== PROGRESS ===== */
.graph { width: 100%; height: 26px; background: var(--surface2); border-radius: 13px; overflow: hidden; position: relative; margin-top: .5rem; }
#upload-firmware-bar, #bar {
  height: 100%; border-radius: 13px; transition: width .3s ease;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
}
#progress-label {
  position: absolute; inset: 0; margin: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
}
#progress-msg { font-size: .7rem; color: var(--text2); margin: 4px 0 0; text-align: center; }

/* ===== ERROR ===== */
.communication-error-bar {
  /* centered over the content area — the navbar paints above this
     element's stacking context, so never slide underneath it */
  position: fixed; top: 14px; left: calc(50% + var(--navbar-w) / 2); transform: translateX(-50%); z-index: 200;
  padding: 9px 20px;
  background: var(--glass); backdrop-filter: blur(20px) saturate(140%); -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--tone-danger); color: var(--tone-danger);
  font-weight: 600; font-size: .82rem;
  border-radius: 999px;
  box-shadow: var(--shadow), 0 0 20px var(--tone-danger-bg);
  /* dedicated keyframes: a generic transform animation would override
     the translateX(-50%) centering */
  animation: toast-rise .25s ease both;
  white-space: nowrap;
  max-width: calc(100vw - var(--navbar-w) - 24px);
}
@keyframes toast-rise {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@media (max-width: 600px) {
  .communication-error-bar { white-space: normal; text-align: center; border-radius: var(--radius); width: max-content; }
}
.communication-error-bar p { margin: 0; color: inherit; display: flex; align-items: center; gap: 9px; }
.communication-error-bar p::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: currentColor; animation: pulse-dot 1.6s ease infinite;
}

/* ===== GAUGES ===== */
.gauge-wrapper canvas { display: block; }
.hover-row { transition: background var(--transition); }
.hover-row:hover { background: var(--accent-glow); }

/* SVG arc gauge */
.svg-gauge { position: relative; width: 230px; height: 230px; margin: 0 auto; }
.svg-gauge svg { display: block; }
.g-track { fill: none; stroke: var(--surface3); stroke-width: 13; stroke-linecap: round; }
/* Segmented and Zone track radials: blocks and bands are plain arcs */
.g-seg { transition: stroke .2s; }
/* unlit blocks: a faint tint of the text colour, visible in either theme */
.g-seg:not(.on) { stroke: color-mix(in srgb, var(--text) 13%, transparent); }
.g-zone { opacity: .75; }
.g-value {
  fill: none; stroke-width: 13; stroke-linecap: round;
  transition: stroke-dasharray .14s linear, stroke-dashoffset .14s linear, opacity .2s;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}
/* centre-point tick: marks the pivot a centred gauge sweeps from */
.g-center-tick { stroke: var(--text3); stroke-width: 2; opacity: .8; }
/* peak-hold tick: hugs the track's inner edge at the session's extreme */
.g-peak-tick { stroke: var(--text); stroke-width: 2; opacity: .55; }
/* needle dial: the pointer rotates smoothly to the value; a hub covers its pivot */
.g-needle { transition: transform .25s cubic-bezier(.4, 0, .2, 1); }
.g-hub { fill: var(--surface3); stroke: var(--border2); stroke-width: 1.5; }
.g-value.over { stroke: var(--red) !important; filter: drop-shadow(0 0 8px var(--tone-danger-bg)); }
.g-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.g-val { font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 2.1rem; font-weight: 650; line-height: 1.1; }
.g-unit { font-size: .8rem; color: var(--text2); margin-top: 2px; }
/* peak-hold lows and highs under the value */
.g-peaks { display: flex; gap: .7em; justify-content: center; margin-top: 2px; font-family: var(--num); color: var(--text3); white-space: nowrap; line-height: 1.1; }
.bar-gauge .bar-val .g-peaks { position: absolute; left: 0; right: 0; bottom: 3px; margin: 0; }
.g-enum { color: var(--accent); font-weight: 600; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-min, .g-max {
  position: absolute; bottom: 22px;
  font-size: .68rem; color: var(--text3);
  font-family: var(--num); font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.g-min { left: 40px; } .g-max { right: 40px; }

/* ===== TOOLTIP ===== */
.tooltip { position: relative; display: inline-block; border-bottom: 1px dotted var(--text3); cursor: help; }
.tooltiptext {
  visibility: hidden; width: 180px; bottom: 100%; left: 0; max-width: calc(100vw - 24px);
  background: var(--surface3); color: var(--text); text-align: left;
  padding: 8px 12px; border-radius: var(--radius-xs); font-size: .75rem; font-weight: 400;
  position: absolute; z-index: 10; margin-bottom: 6px;
  box-shadow: var(--shadow); border: 1px solid var(--border2);
}
.tooltip:hover .tooltiptext { visibility: visible; }
.tooltiptext-empty { color: var(--text3); font-style: italic; }
.tooltip.tip-below .tooltiptext { top: 100%; bottom: auto; margin-top: 6px; margin-bottom: 0; }

.beta-feature { display: none; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  :root { --navbar-w: var(--navbar-w-min); }
  .navbar-text { display: none; }
  .tablink { justify-content: center; padding: 10px 6px; }
  #logo { padding: 1rem .5rem .5rem; }
  #logo svg, #logo img { width: 30px; height: 30px; }
  #spinner-div { justify-content: center; padding: 6px 4px; }
  #spinner-div span { display: none; }
  .control { flex-wrap: wrap; justify-content: center; padding: 4px 6px; text-align: center; }
  .control span { width: 100%; text-align: center; font-size: .65rem; }
  #version { text-align: center; font-size: .6rem; padding: 4px 6px; line-height: 1.4; }
  #device-name { font-size: .55rem; padding: 3px 4px; margin: auto 4px 0; }
  #data-age { text-align: center; font-size: .6rem; padding: 2px 4px; margin: 2px 4px 0; }
  .fast-badge { font-size: .55rem; padding: 2px 4px; letter-spacing: 0; }
  /* slim rail: show just the node number; the native dropdown still opens with full labels */
  .can-node-select select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
  .can-node-select .can-node-short {
    display: flex; align-items: center; justify-content: center;
    padding: 4px 2px; font-size: .7rem; font-weight: 700;
    color: var(--accent); background: var(--accent-glow); border-radius: var(--radius-xs);
    pointer-events: none; font-variant-numeric: tabular-nums;
  }
  .main-content { flex-direction: column !important; gap: .5rem; }
  /* touch overlay scrollbars don't need the desktop gutter */
  .main-left, .fullheight { padding-right: 0; scrollbar-gutter: auto; }
  .main-right { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 4px; padding: .5rem 0; position: static; box-shadow: none; min-width: auto; }
  .main-right button, .main-right .butt { width: auto; font-size: .75rem; padding: 5px 10px; }
  .main-right .toggle-row { width: auto; min-width: 0; font-size: .72rem; padding: 5px 10px; }
  /* force a wrap in the responsive flex-row so following buttons start a new line */
  .main-right .flex-break { display: block; flex-basis: 100%; width: 100%; height: 0; }
  .main-right h3 { margin: .5rem 0 2px; font-size: .7rem; display: block; width: 100%; }
  .main-right h3:first-child { margin-top: 0; }
  /* reclaim vertical space on Spot Values: drop the item count and View header */
  .sv-count, .sv-view-head { display: none; }
  .dash-row { flex-direction: column; }
  .tabdiv { padding: .75rem; }
  .panel-toggle { display: none; }
  #content-wrapper-inner[data-panel="closed"] .main-right { display: none; }
  .hero-state { font-size: 1.6rem; }
  .hero-metrics { gap: 1.2rem; }
  .metric-value { font-size: 1.35rem; }
}
/* new CAN mappings and virtual values: each row is a labelled grid that
   wraps to the width it has, so no window size scrolls it sideways */
table.canmap-new, table.canmap-new tbody { display: block; width: 100% !important; }
table.canmap-new thead { display: none; }
table.canmap-new tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 124px)); gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
table.canmap-new td { display: block; padding: 0; border: 0; }
table.canmap-new td:first-child { grid-column: span 2; }
table.canmap-new td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 3px; font-size: .65rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text3); }
table.canmap-new input:not([type=checkbox]), table.canmap-new select { width: 100% !important; box-sizing: border-box; }
table.canmap-new td { text-align: left !important; }
table.canmap-new td.canmap-del { align-self: end; justify-self: end; }

@media (max-width: 600px) {
  .small-modal-container, .large-modal-container, .can-mapping-modal-container { width: 95vw; }
  /* the device's mappings: six columns plus remove fit at phone width */
  table.canmap-list th, table.canmap-list td { padding-left: 4px; padding-right: 4px; }
  table.canmap-list th:first-child { min-width: 0 !important; }
  /* the gauge editor's actions bar wraps to a full-width row on phones and
     eats most of the screen — drop the explanatory help text there */
  .edit-help { display: none; }
  table { font-size: .8rem; }
  /* full width whatever the layout, so long names wrap instead of
     stretching the table past the screen */
  #spotValues { font-size: .9rem; width: 100% !important; }
  thead th, tbody td { padding: 6px 6px; }
  /* compact fixed columns so names get the space (!important beats the
     inline header widths) */
  #spotValues th.h-fav { width: 26px !important; }
  #spotValues th.h-val { width: 70px !important; min-width: 70px !important; }
  #spotValues th.h-spark { width: 58px !important; }
  #spotValues th.h-unit { width: 34px !important; min-width: 34px !important; }
  #spotValuesWrap.multi-col #spotValues th:first-child,
  #spotValuesWrap.multi-col #spotValues td:first-child { width: 26px; }
  #spotValuesWrap.multi-col #spotValues td.sv-val { width: 70px; }
  #spotValuesWrap.multi-col #spotValues td.sv-spark { width: 58px; }
  #spotValuesWrap.multi-col #spotValues td.sv-unit { width: 34px; }
  #spotValuesWrap.multi-col #spotValues td.sv-val.sv-wide { width: 162px; }
  #spotValues td.sv-spark { padding: 2px 2px; }
  #spotValues td.sv-spark .spark { width: 100%; height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .dash-box, .small-modal-container, .large-modal-container, .can-mapping-modal-container { animation: none; }
  .pill .dot { animation: none; }
}

/* Wide screens: split spot values into multiple columns when content overflows vertically */
#spotValuesWrap.multi-col {
  column-width: 350px;
  column-gap: 2rem;
  max-height: none;
}
#spotValuesWrap.multi-col #spotValues { width: 100% !important; }
#spotValuesWrap.multi-col #spotValues tbody { display: block; }
#spotValuesWrap.multi-col #spotValues tr { break-inside: avoid; display: table; width: 100%; table-layout: fixed; }
#spotValuesWrap.multi-col #spotValues thead { display: table; width: 100%; table-layout: fixed; }
/* fixed layout needs explicit widths or every column gets an equal share
   (long names then overflow into the value column) */
#spotValuesWrap.multi-col #spotValues th:first-child,
#spotValuesWrap.multi-col #spotValues td:first-child { width: 30px; }
#spotValuesWrap.multi-col #spotValues td.sv-val { width: 100px; }
#spotValuesWrap.multi-col #spotValues td.sv-spark { width: 76px; }
#spotValuesWrap.multi-col #spotValues td.sv-unit { width: 44px; }
/* enum/bitmask text spans the value, sparkline and unit columns */
#spotValuesWrap.multi-col #spotValues td.sv-val.sv-wide { width: 220px; }

/* ==================== Gauges grid (GridStack) ==================== */
.gauges-view .grid-stack { min-height: 220px; }
.gauge-tile {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  overflow: hidden;
}
.gauge-tile-name { font-weight: 600; font-size: .82rem; margin: 2px 0; max-width: 95%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* transparent tiles: the gauge floats on the page with no card chrome
   (the edit-mode dashed outline still shows, so they stay manipulable) */
.gauge-tile.tile-clear { background: transparent; border-color: transparent; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
/* Badge text tile: a small frosted pill in theme colours (it keeps them even
   over a picture with "Text on it" set, since it brings its own card; these
   resolve at the root, so a tile's ink override doesn't reach them) */
:root { --badge-text: var(--text); --badge-text2: var(--text2); --badge-text3: var(--text3); }
.tile-badge { display: inline-flex; flex-direction: column; align-items: center; gap: 1px; padding: .3em .8em .35em;
  border-radius: .7em; line-height: 1.1; max-width: 100%; overflow: hidden; text-shadow: none;
  background: color-mix(in srgb, var(--surface) 82%, transparent); border: 1px solid var(--border2);
  backdrop-filter: blur(10px) saturate(130%); -webkit-backdrop-filter: blur(10px) saturate(130%);
  box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.tile-badge .tb-name { font: 600 .48em/1.2 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--text3); white-space: nowrap; }
.tile-badge .tb-val { font-family: var(--num); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.tile-badge .tb-unit { font-size: .55em; font-weight: 500; color: var(--text2); margin-left: .25em; }
.gauge-tile.on-bg.ink-light .tile-badge, .gauge-tile.on-bg.ink-dark .tile-badge {
  --text: var(--badge-text); --text2: var(--badge-text2); --text3: var(--badge-text3); }
/* Clear tiles over a page background picture: text gets a soft halo so live
   readouts stay legible on it; the background's "Text on it" can pin light
   or dark text (a dark photo needs light text in either theme) */
.gauge-tile.tile-clear.on-bg { text-shadow: 0 0 3px var(--bg), 0 0 8px var(--bg), 0 0 14px var(--bg); }
.gauge-tile.tile-clear.on-bg.ink-light { --text: #f4f7fb; --text2: #d8dee7; --text3: #c2c9d4; color: var(--text);
  text-shadow: 0 0 3px rgba(0,0,0,.85), 0 0 8px rgba(0,0,0,.6), 0 0 14px rgba(0,0,0,.45); }
.gauge-tile.tile-clear.on-bg.ink-dark { --text: #111216; --text2: #3a3c44; --text3: #4a4d56; color: var(--text);
  text-shadow: 0 0 3px rgba(255,255,255,.9), 0 0 8px rgba(255,255,255,.65), 0 0 14px rgba(255,255,255,.45); }
/* Page background: behind the tiles, pinned to the grid's box (full width,
   bg.rows x --gs-cell tall) so it moves and scales with them */
.grid-stack > .page-bg { position: absolute; top: 0; left: 0; right: 0; z-index: 0; pointer-events: none; }
.page-bg img { display: block; width: 100%; height: 100%; }
.grid-stack > .page-bg-missing { position: absolute; top: 0; left: 0; margin: 4px 6px; font-size: .72rem; color: var(--text3); pointer-events: none; }
/* view-mode gauge area: no text selection, so a mouse/touch page-swipe drag
   doesn't highlight tile labels/values as it moves. touch-action: pan-y keeps
   vertical scrolling but hands HORIZONTAL touch gestures to our swipe handler
   — without it the browser claims the drag as a scroll and fires
   pointercancel (not pointerup), so swipe worked with a mouse but not on touch. */
.gauge-swipe { user-select: none; -webkit-user-select: none; touch-action: pan-y; position: relative; }
/* Android Chrome doesn't reliably honour an ancestor's touch-action on inline
   SVG/canvas, so set it directly on the swipe surfaces (leaving interactive
   tiles to their own handling) */
.gauge-swipe .grid-stack, .gauge-swipe .grid-stack-item, .gauge-swipe .gauge-tile,
.gauge-swipe .svg-gauge, .gauge-swipe .bar-gauge, .gauge-swipe svg, .gauge-swipe canvas,
.gauge-swipe .ind-wrap { touch-action: pan-y; } /* none here blocked scrolling a page taller than the screen */
.gauge-swipe .toggle-tile, .gauge-swipe .slider-tile, .gauge-swipe .action-tile-btn { touch-action: auto; }
/* swipe feedback: a gradient that grows from the edge being dragged toward.
   Opacity is set live from JS during the drag; pointer-events none so it never
   intercepts the gesture it's visualising. */
.swipe-hint {
  position: absolute; inset: 0; z-index: 6; pointer-events: none; opacity: 0;
  transition: opacity .12s ease;
}
.swipe-hint.left  { background: linear-gradient(to left,  transparent 55%, color-mix(in srgb, var(--accent) 40%, transparent)); }
.swipe-hint.right { background: linear-gradient(to right, transparent 55%, color-mix(in srgb, var(--accent) 40%, transparent)); }
/* gauge settings modal: section headers group the (long) option list */
.modal-sect {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text3); margin: 6px 0 -4px; padding-bottom: 3px;
  border-bottom: 1px solid var(--border2);
}
.modal-sect:first-child { margin-top: 0; }
/* Keep the first-column labels rigid so a long helper description wraps
   instead of squeezing the label narrower (Centre/Peak were drifting left) */
#gauge-config-modal-overlay label[style*="4.5em"],
#gauge-config-modal-overlay span[style*="4.5em"] { flex-shrink: 0; }
/* edit mode affordances: dashed outline + grab cursor, like a layout editor */
.gauges-editing .gauge-tile { outline: 1.5px dashed var(--accent); cursor: grab; }
.gauges-editing .grid-stack-item.ui-draggable-dragging .gauge-tile { cursor: grabbing; opacity: .85; }
/* Resize grip: a small corner affordance. gridstack's default 20px handle
   covers the centre of a 1x1 tile on a phone and intercepts the
   tap-to-configure gesture (!important: gridstack.min.css loads after us) */
.grid-stack-item > .ui-resizable-se { width: 22px !important; height: 22px !important; background-image: none !important; transform: none !important; }
/* drawn in the accent colour, set in from the corner so it clears the
   rounded dashed outline (14px radius) instead of sitting on it */
.grid-stack-item > .ui-resizable-se::after {
  content: ''; position: absolute; right: 7px; bottom: 7px; width: 11px; height: 11px;
  background: var(--accent);
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 11" fill="none" stroke="black" stroke-width="1.8" stroke-linecap="round"><path d="M10 1 1 10M10 5.5 5.5 10"/></svg>') center / contain no-repeat;
          mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 11" fill="none" stroke="black" stroke-width="1.8" stroke-linecap="round"><path d="M10 1 1 10M10 5.5 5.5 10"/></svg>') center / contain no-repeat;
}
.grid-stack-item > .ui-resizable-se:hover::after { background: var(--text); }
/* 1x1-on-phone tiles: the grip would cover the whole tile — settings modal
   has a Size control instead */
.grid-stack-item.tile-tiny > .ui-resizable-se { display: none; }
/* page pills */
/* page switchers: Homestead's segmented control (.seg holds the pills) */
.seg { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 4px;
  border-radius: var(--radius-sm); background: var(--ctl-bg); border: 1px solid var(--border); max-width: 100%; }
.page-pill {
  width: auto; font-size: .82rem; font-weight: 620; padding: 6px 14px;
  border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--text2);
}
.page-pill:hover { background: var(--ctl-bg); color: var(--text); border-color: transparent; }
.page-pill.active { background: var(--on-bg); color: var(--on-fg); border-color: var(--on-bg); box-shadow: var(--glow-pri); }
.page-pill.draggable { cursor: grab; }
.page-pill.draggable:active { cursor: grabbing; }
/* pills are tabs, not action buttons — no lift on hover/active/select
   (the generic button transform was nudging the selected pill up a pixel) */
.page-pill:hover, .page-pill:active { transform: none; }

/* ===== USERS & SIGN-IN ===== */
/* Permission gate: transparent to layout; dims and disables what the
   signed-in role can't use (the device refuses it anyway) */
.perm-gate { display: contents; }
.perm-gate[inert] > *, .perm-gate[inert] label, .perm-gate[inert] button { opacity: .45; cursor: not-allowed; }
.perm-gate[inert] .perm-gate[inert] > * { opacity: 1; } /* don't dim twice */
.settings-grid[inert] > * { opacity: .55; }
.perm-note {
  margin: 0 0 .75rem; padding: 8px 12px; border-radius: var(--radius-xs);
  font-size: .8rem; line-height: 1.45; color: var(--tone-warn); background: var(--tone-warn-bg);
}
/* Read-only indicator: a small pill pinned to the bottom of the content
   area (the tab container is a flex row, so it can't sit in the flow) */
.readonly-bar {
  position: fixed; z-index: 150; left: calc(var(--navbar-w) + 10px); bottom: max(10px, env(safe-area-inset-bottom));
  max-width: calc(100vw - var(--navbar-w) - 20px); box-sizing: border-box;
  padding: 5px 12px; border-radius: 999px; font-size: .74rem; line-height: 1.35; pointer-events: none;
  color: var(--tone-warn); background: var(--glass); border: 1px solid var(--tone-warn);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: var(--shadow-sm);
}
.readonly-bar .ro-long { margin-left: 4px; }
body.kiosk .readonly-bar { left: 10px; }
.role-viewer .whoami .user-avatar { box-shadow: 0 0 0 2px var(--tone-warn); }
.auth-loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.user-avatar {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; letter-spacing: .02em;
  color: var(--accent); background: var(--accent-glow);
}
.user-avatar.lg { width: 44px; height: 44px; font-size: .9rem; }
.role-pill {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .65rem; font-weight: 700;
  letter-spacing: .03em; color: var(--text2); background: var(--surface3); white-space: nowrap;
}
.role-pill.role-viewer { color: var(--tone-warn); background: var(--tone-warn-bg); }

/* Sidebar: who is signed in, and sign-out */
.whoami {
  display: flex; align-items: center; gap: 8px; margin: 8px 10px 0; padding: 6px 8px;
  border-radius: var(--radius-xs); background: var(--surface2); cursor: pointer; min-width: 0;
}
.whoami:hover { background: var(--surface3); }
.whoami-text { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.whoami-name { font-size: .78rem; font-weight: 600; color: var(--text); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#navbar .signout { margin: 6px 10px 12px; width: auto; justify-content: center; font-size: .72rem; padding: 5px 8px; }

/* Forms on the sign-in screen and in Settings → Users & Access */
.auth-form { display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.auth-field { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; font-weight: 600; color: var(--text2); }
.auth-field input, .auth-field select { width: 100%; font-size: 16px; padding: 10px 12px; min-height: 44px; box-sizing: border-box; }
.auth-form button, .login-btn { min-height: 44px; justify-content: center; }
button.primary { background: var(--on-bg); border-color: var(--on-bg); color: var(--on-fg); font-weight: 650; box-shadow: var(--glow-pri); }
button.primary:hover { background: var(--on-bg); color: var(--on-fg); filter: brightness(.94); }
button.primary:hover { background: var(--accent2); color: #fff; }
button.danger { color: var(--red); background: color-mix(in srgb, var(--red) 7%, transparent); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.auth-lead { font-size: .8rem; color: var(--text2); margin: 0 0 .5rem; line-height: 1.5; }
.auth-hint { font-size: .72rem; color: var(--text3); margin: .75rem 0 0; line-height: 1.5; max-width: 420px; }
.auth-err { margin: 0; font-size: .8rem; font-weight: 600; color: var(--red); }
.auth-ok { margin: 0; font-size: .8rem; font-weight: 600; color: var(--green); }
.role-guide { margin: .25rem 0 .75rem; padding-left: 1.1rem; font-size: .76rem; color: var(--text2); line-height: 1.6; }

.me-row { display: flex; align-items: center; gap: 12px; margin-bottom: .5rem; flex-wrap: wrap; }
.me-name { font-weight: 700; font-size: 1rem; margin-bottom: 2px; overflow-wrap: anywhere; }
.user-rows { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.user-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px; border-radius: var(--radius-xs); background: var(--surface2);
}
.user-name { flex: 1 1 120px; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.user-name .you { font-weight: 400; color: var(--text3); font-size: .75rem; }
.user-row select { width: auto; min-height: 40px; font-size: 16px; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.user-actions button { width: auto; min-height: 40px; font-size: .75rem; padding: 6px 10px; }

/* Sign-in screen */
.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 16px; box-sizing: border-box;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.login-card {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px;
  padding: 28px 22px; border-radius: var(--radius); background: var(--card);
  border: 1px solid var(--border); box-shadow: var(--shadow); box-sizing: border-box;
}
.login-card h1 { margin: 0; font-size: 1.4rem; text-align: center; }
.login-logo { width: 48px; height: 48px; margin: 0 auto; color: var(--text3); }
.login-sub { margin: -6px 0 4px; text-align: center; font-size: .82rem; color: var(--text3); }
.login-note { margin: 0; padding: 8px 10px; border-radius: var(--radius-xs); font-size: .8rem; color: var(--tone-info); background: var(--tone-info-bg); }
.login-remember { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--text2); min-height: 44px; }
.login-remember input { width: 20px; height: 20px; margin: 0; flex-shrink: 0; }
.login-btn { width: 100%; font-size: 1rem; }
.login-card .auth-hint { margin: 4px 0 0; text-align: center; }

/* Toasts: bottom centre, clear of the phone's home indicator */
#oi-toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 1000;
  bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px); pointer-events: none;
}
.oi-toast {
  padding: 10px 14px; border-radius: var(--radius-xs); font-size: .85rem; line-height: 1.4;
  background: var(--surface); color: var(--text); border: 1px solid var(--border2); box-shadow: var(--shadow);
  transition: opacity .3s, transform .3s;
}
.oi-toast.bad { border-color: var(--red); }
.oi-toast.ok { border-color: var(--green); }
.oi-toast.out { opacity: 0; transform: translateY(6px); }

@media (max-width: 900px) {
  /* slim rail: the avatar alone opens the account; sign-out shrinks to an icon */
  .whoami { justify-content: center; margin: 6px 4px 0; padding: 4px; background: none; }
  .whoami-text { display: none; }
  #navbar .signout { margin: 4px 4px 10px; padding: 6px 4px; }
  .readonly-bar .ro-long { display: none; }
}

/* Respect motion and transparency preferences; the blur is also costly on
   older phones */
@media (prefers-reduced-motion: reduce) {
  .dash-box:hover, button:hover, .butt:hover, .tablink:hover { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .dash-box, #navbar, .gauge-tile { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* ===== DASHBOARD WIDGETS (panel tiles on the gauge grid) ===== */
.gauge-tile.widget-tile { align-items: stretch; justify-content: flex-start; padding: 14px 16px; overflow: auto; }
.widget-body { display: flex; flex-direction: column; gap: .6rem; flex: 1; min-height: 0; width: 100%; }
.widget-body h3 { margin: 0; }
.widget-body .hero-state { font-size: clamp(1.4rem, 2.6vw, 2.1rem); }
.widget-body { align-items: stretch; text-align: left; }
.widget-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-start; }
.widget-actions button { width: auto; margin: 0; }
.wt-terminal #commandoutput { flex: 1; min-height: 3em; overflow: auto; }
.widget-pre { margin: 0; overflow: auto; }
.widget-note { font-size: .78rem; color: var(--text3); margin: 0; }
.widget-metric .metric-value { font-size: clamp(1.3rem, 2.2vw, 1.9rem); }
.widget-metric .spark { color: var(--accent); }
/* The status tile fits its grid cell instead of scrolling: grid rows scale
   with the page width, so the card sizes its type to the tile (cq units)
   and drops the extras (sub line, sparklines) when it gets short */
.gauge-tile.widget-tile.hero-card { container-type: size; overflow: hidden; padding: 12px 14px; }
.wt-status { gap: clamp(.25rem, 3cqh, .6rem); }
.wt-status .hero-top { gap: 8px; }
.wt-status .hero-state { font-size: clamp(1.05rem, min(11cqh, 7cqw), 2.1rem); }
/* metrics wrap into a grid; StatusTile hides whole rows that don't fit */
.wt-status .hero-metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.2rem, 1fr)); align-content: start;
  gap: clamp(.3rem, 2.5cqh, .8rem) clamp(.8rem, 3cqw, 1.6rem); margin-top: 0; flex: 1; min-height: 0; overflow: hidden; }
.wt-status .metric { min-width: 0; }
.wt-status .metric.clipped { visibility: hidden; }
.wt-status .metric-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wt-status .metric-value { font-size: clamp(1rem, 8cqh, 1.7rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wt-status .spark { width: 100%; max-width: 90px; height: auto; }
@container (max-height: 250px) { .wt-status .hero-sub { display: none; } }
@container (max-height: 190px) { .wt-status .spark { display: none; } }
/* Actions: icon-only buttons once the labels would wrap to a second row */
.gauge-tile.widget-tile:has(.wt-actions) { container-type: inline-size; padding: 6px 12px; }
.wt-actions { justify-content: center; }
@container (max-width: 760px) {
  .wt-actions .widget-actions { flex-wrap: nowrap; }
  .wt-actions .widget-actions button { font-size: 0; gap: 0; padding: 6px 12px; }
  .wt-actions .widget-actions .btn-ic svg { width: 16px; height: 16px; }
}
/* Image tiles: the picture takes the cell's size (zero flex basis, so it
   never stretches the tile or makes it scroll, grid or phone stack alike)
   and object-fit letterboxes or crops it into that box */
.gauge-tile.widget-tile:has(.wt-image) { padding: 4px; overflow: hidden; }
/* Clear: just the picture, edge to edge */
.gauge-tile.widget-tile.tile-clear:has(.wt-image) { padding: 0; }
.wt-image { gap: 4px; align-items: center; justify-content: center; }
.wt-image .img-link { display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; width: 100%; }
.wt-image .img-pic { display: block; flex: 1 1 0; min-height: 0; width: 100%; height: 0; }
.wt-image .img-caption { flex: none; max-width: 100%; font-size: .75rem; color: var(--text3); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wt-image .img-empty { text-align: center; }
/* Dashboard/gauge header: Record is a dot in a ring, in the text colour
   while idle; recording turns the button red and the ring pulses */
#rec-btn.recording { color: var(--red); border-color: var(--red); }
#rec-btn.recording .btn-ic svg { animation: pulse-dot 1.6s ease infinite; }
/* stack layout: on phones a 'stack' page lists its tiles in reading order,
   two per row, wide tiles across both (gridstack's absolute positions off) */
.grid-stack.stacked { display: grid !important; grid-template-columns: 1fr 1fr; gap: 10px; height: auto !important; max-width: none !important; }
.grid-stack.stacked > .grid-stack-item { position: relative !important; left: auto !important; top: auto !important;
  width: auto !important; height: auto !important; min-height: calc(var(--h, 2) * 60px); grid-column: span var(--span, 1); }
.grid-stack.stacked > .grid-stack-item > .grid-stack-item-content { position: relative !important; inset: auto !important; height: 100%; min-height: inherit; }

/* ===== APP CHROME (doc/REDESIGN.md phase 4) ===== */
#logo { display: flex; align-items: center; gap: 12px; padding: 1.1rem 1.25rem .9rem; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
#logo svg, #logo img { margin: 0; width: 36px; height: 36px; }
.brand-name { font-weight: 700; font-size: .95rem; letter-spacing: .02em; color: var(--text); white-space: nowrap; }
.navlbl { font: 700 .62rem/1 var(--mono); letter-spacing: .13em; text-transform: uppercase; color: var(--text3); padding: 14px 23px 7px; }
button.tablink { background: transparent; border: 1px solid transparent; width: calc(100% - 20px); justify-content: flex-start; text-align: left; font-family: var(--font); line-height: 1.4; }
button.tablink:hover { border-color: transparent; }
/* slim rail (tablets, phones in landscape): the icon alone, centred */
@media (max-width: 900px) { button.tablink { justify-content: center; } }
#topbar { position: relative; flex: 0 0 auto; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: 64px; padding: 10px 24px; margin: 0 0 14px; border-bottom: 1px solid var(--border);
  background: var(--glass); backdrop-filter: blur(26px) saturate(125%); -webkit-backdrop-filter: blur(26px) saturate(125%); }
.crumb { font: 650 .66rem/1.3 var(--mono); letter-spacing: .11em; text-transform: uppercase; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbsep { color: var(--border2); margin: 0 6px; }
.crumb-cur { color: var(--accent); }
.page-title { margin: 2px 0 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* the top bar carries the page title now */
.main-left > h2:first-child, #gauges-head > h2 { display: none; }
#gauges-head { justify-content: flex-end !important; }
body.kiosk #topbar, body.kiosk #bottombar { display: none !important; }
/* parameters set live but not saved to flash */
/* a slim strip that can fold into a pill: tweaking without saving is normal */
.savebar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px 10px; padding: 4px 6px 4px 10px; margin-bottom: 8px;
  max-width: 640px; font-size: .8rem; border-radius: 99px; border: 1px solid color-mix(in srgb, var(--amber) 34%, transparent); background: color-mix(in srgb, var(--amber) 9%, var(--surface)); }
.savebar.min { padding: 0; border: 0; background: none; margin-bottom: 4px; }
.savebar-pill { width: auto; display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; font-size: .72rem; font-weight: 600; border-radius: 99px;
  border: 1px solid color-mix(in srgb, var(--amber) 34%, transparent); background: color-mix(in srgb, var(--amber) 12%, var(--surface)); color: var(--text); }
.savebar-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); flex: 0 0 auto; }
.savebar-text { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.savebar-sub { color: var(--text2); }
.savebar-actions { margin-left: auto; display: flex; gap: 4px; flex: 0 0 auto; }
.savebar-actions button { width: auto; padding: 2px 10px; font-size: .74rem; min-height: 0; border-radius: 99px; }
.savebar-actions .savebar-hide { padding: 2px 8px; font-size: .9rem; line-height: 1; background: none; border-color: transparent; color: var(--text2); }
/* bitmask parameters: set flags, opening to a checkbox per bit */
.bitmask { display: inline-flex; flex-direction: column; gap: 4px; max-width: 18em; }
.bitmask-sum { width: auto; display: inline-flex; align-items: center; gap: 8px; padding: 3px 8px; font: inherit; font-size: .8rem; text-align: left;
  border: 1.5px solid var(--accent); border-radius: var(--radius-xs); background: var(--surface); color: var(--text); }
.bitmask-names { overflow-wrap: anywhere; }
.bitmask-num { color: var(--text3); font-size: .72rem; margin-left: auto; }
.bitmask-list { display: flex; flex-direction: column; gap: 2px; padding: 4px 2px; }
.bitmask-flag { display: flex; align-items: center; gap: 6px; font-size: .8rem; cursor: pointer; }
.bitmask-flag input { margin: 0; }
.bitmask-bit { color: var(--text3); font-size: .7rem; margin-left: auto; padding-left: 8px; }
/* phone: a bottom tab bar; the sidebar becomes a drawer behind More */
#bottombar, #nav-scrim { display: none; }
.bb-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 48px; padding: 4px 0;
  background: transparent; border: 0; border-radius: 10px; color: var(--text2); font: 600 .66rem/1.2 var(--font); position: relative; }
.bb-item:hover { background: transparent; border: 0; transform: none; color: var(--text); }
.bb-item.active { color: var(--text); }
.bb-item.active::before { content: ''; position: absolute; top: -6px; left: 50%; width: 22px; height: 3px; margin-left: -11px; border-radius: 0 0 3px 3px;
  background: var(--grad-signature); box-shadow: 0 0 10px rgba(76,201,240,.6); }
.bb-item .tab-icon { color: inherit; }
@media (max-width: 599px) {
  :root { --navbar-w: 0px; }
  /* closed: off-screen AND hidden, so keyboard focus can't land in it */
  #navbar { width: min(280px, 86vw); bottom: calc(62px + env(safe-area-inset-bottom)); transform: translateX(-105%); visibility: hidden;
    transition: transform var(--transition), visibility 0s linear .2s; z-index: 60; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  body.nav-open #navbar { transform: none; visibility: visible; transition: transform var(--transition); }
  #navbar .tablink:hover { transform: none; }
  #navbar .navbar-text { display: inline; }
  #navbar .tablink { justify-content: flex-start; padding: 10px 13px; }
  #nav-scrim { display: block; position: fixed; left: 0; right: 0; top: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 55;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity var(--transition); }
  body.nav-open #nav-scrim { opacity: 1; pointer-events: auto; }
  #bottombar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border);
    background: var(--glass); backdrop-filter: blur(26px) saturate(125%); -webkit-backdrop-filter: blur(26px) saturate(125%); }
  #content-wrapper { bottom: calc(62px + env(safe-area-inset-bottom)); }
  #topbar { padding: 8px 14px; min-height: 52px; margin-bottom: 10px; }
  .page-title { font-size: 1.1rem; }
  .savebar { top: 0; padding: 2px 4px 2px 8px; font-size: .74rem; }
  .savebar-sub { display: none; }
  .savebar-actions button { padding: 2px 8px; font-size: .7rem; }
  /* gauge/dashboard header actions: icons only, so they stay on one row
     (the labels remain as aria-label and tooltip) */
  #gauges-head .hd-label { display: none; }
  #gauges-head > div { flex-wrap: nowrap !important; gap: 6px !important; }
  #gauges-head button { min-width: 40px; min-height: 36px; justify-content: center; padding: 4px 10px !important; }
  .readonly-bar { bottom: calc(70px + env(safe-area-inset-bottom)); }
}

/* Native controls (a select's popup list, scrollbars, date pickers) follow
   the theme: without this the browser draws a light popup with the dark
   theme's light text, so the options read washed out */
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }
option { background: var(--surface2); color: var(--text); }
/* Group headings in the list (e.g. "Dashboard widgets"): a muted label on
   the list's own background, not the browser's white strip */
optgroup { background: var(--surface2); color: var(--text3); font-style: normal; font-weight: 600; }
/* Chrome builds a select's popup from the select's own background colour: the
   dark theme's translucent --ctl-bg made it fall back to its light palette
   (white group headings, a pale highlight behind light text). A solid colour
   that looks the same (the tint over the surface) keeps the popup dark */
:root[data-theme="dark"] select:not(.styled) { background-color: color-mix(in srgb, #fff 5.5%, var(--surface)); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) select:not(.styled) { background-color: color-mix(in srgb, #fff 5.5%, var(--surface)); }
}

/* Files page: a compact list, Download beside Delete */
.files-table tbody td { padding: 3px 10px; }
.files-table .file-actions { display: flex; gap: 6px; justify-content: flex-start; white-space: nowrap; }
.files-table .file-actions .butt, .files-table .file-actions button { padding: 3px 10px; font-size: .75rem; gap: 4px; text-decoration: none; }
.files-table .files-group-head th { padding: 10px 10px 4px; background: transparent; border-bottom: 1px solid var(--border2); position: static; }
.files-table .files-count { color: var(--text3); font-weight: 500; margin-left: 4px; }
.files-table .file-size { color: var(--text2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.file-badge { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; font: 600 .62rem/1.6 var(--mono); letter-spacing: .04em; vertical-align: 1px; }
.file-badge.original { color: var(--text3); background: color-mix(in srgb, var(--text) 7%, transparent); }
.file-badge.modified { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
.file-badge.missing { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.files-table tr.file-missing td:first-child { color: var(--text3); }
