:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efea;
  --border: #e3e1da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7d7b75;
  --grid: #e7e5df;
  --accent: #1c5cab;
  --load: #2a78d6;
  --solar: #eb6834;
  --battery: #1baf7a;
  --grid-c: #eda100;
  --genset: #e87ba4;
  --export: #6250d6;
  --good: #1f8a4c;
  --warn: #b26a00;
  --crit: #c22f2e;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8d86; --grid: #2c2c29; --accent: #6da7ec;
    --load: #3987e5; --solar: #d95926; --battery: #199e70; --grid-c: #c98500; --genset: #d55181; --export: #9085e9;
    --good: #3fb96f; --warn: #e0a030; --crit: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8d86; --grid: #2c2c29; --accent: #6da7ec;
  --load: #3987e5; --solar: #d95926; --battery: #199e70; --grid-c: #c98500; --genset: #d55181; --export: #9085e9;
  --good: #3fb96f; --warn: #e0a030; --crit: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, select { font: inherit; color: inherit; }

/* header */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.top-in { max-width: 1280px; margin: 0 auto; padding: 12px 20px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.logo { height: 38px; width: auto; display: block; }
.logo-lg { height: 96px; width: auto; display: block; }
picture { display: contents; }
/* installed app: keep content clear of the phone's notch / status bar */
.top-in { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
footer { padding-bottom: max(30px, env(safe-area-inset-bottom)); }
.ios-tip { position: fixed; left: 12px; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 20; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: 0 10px 30px rgb(0 0 0 / .18); font-size: 14px; }
.ios-tip b { color: var(--text); }
.ios-tip button { float: right; border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--text-3); margin: -6px -6px 0 8px; }
.site-pick { display: flex; align-items: center; gap: 10px; margin-left: 8px; }
.site-pick select { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 7px 12px; font-weight: 600; max-width: 320px; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 99px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.pill.ok .dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.pill.bad { color: var(--crit); } .pill.bad .dot { background: var(--crit); }
.spacer { flex: 1; }
.updated { color: var(--text-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.btn { background: transparent; border: 1px solid var(--border); border-radius: 9px; padding: 6px 12px; cursor: pointer; color: var(--text-2); text-decoration: none; font-size: 14px; }
.btn:hover { background: var(--surface-2); color: var(--text); }

/* layout */
main { max-width: 1280px; margin: 0 auto; padding: 20px; display: grid; gap: 16px;
  grid-template-columns: repeat(12, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.span-8 { grid-column: span 8; } .span-4 { grid-column: span 4; } .span-12 { grid-column: span 12; }
.span-6 { grid-column: span 6; }
@media (max-width: 1000px) { .span-8, .span-4, .span-6 { grid-column: span 12; } }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin: 0 0 12px; font-weight: 650; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.muted { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }

/* power flow */
.flow svg { width: 100%; max-width: 820px; margin: 0 auto; height: auto; display: block; }
.flow .node-bg { fill: var(--surface-2); stroke: var(--border); }
.flow .node-ring { fill: none; stroke-width: 3; }
.flow .lbl { fill: var(--text-2); font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.flow .val { fill: var(--text); font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.flow .sub { fill: var(--text-3); font-size: 12px; }
.flow .wire { stroke: var(--grid); stroke-width: 3; fill: none; }
.flow .pulse { stroke-width: 3; fill: none; stroke-dasharray: 2 14; stroke-linecap: round; }
.flow .pulse.fwd { animation: dash 1.1s linear infinite; }
.flow .pulse.rev { animation: dash 1.1s linear infinite reverse; }
@keyframes dash { to { stroke-dashoffset: -32; } }
@media (prefers-reduced-motion: reduce) { .flow .pulse { animation: none !important; stroke-dasharray: none; opacity: .6; } }

/* battery */
.bat-big { display: flex; align-items: baseline; gap: 6px; }
.bat-big .v { font-size: 46px; font-weight: 750; letter-spacing: -0.02em; line-height: 1; }
.bat-big .u { font-size: 20px; color: var(--text-2); font-weight: 600; }
.bat-bar { height: 12px; border-radius: 99px; background: var(--surface-2); margin: 14px 0 6px; overflow: hidden; border: 1px solid var(--border); }
.bat-bar > div { height: 100%; background: var(--battery); border-radius: 99px; transition: width .6s ease; }
.bat-state { font-weight: 600; color: var(--text-2); margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; font-size: 14px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* stat tiles */
#tiles { display: flex; flex-direction: column; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles > .tile:last-child:nth-child(odd) { grid-column: span 2; }
}
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile .k { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.tile .k i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.tile .v { font-size: 26px; font-weight: 720; margin-top: 4px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v small { font-size: 14px; color: var(--text-2); font-weight: 600; margin-left: 3px; }
.tiles-wrap { grid-column: span 12; }
.tiles-wrap h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin: 4px 2px 10px; font-weight: 650; }

/* charts */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.datenav { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.datenav button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; }
.datenav button:disabled { opacity: .35; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); margin: 4px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.sq { width: 10px; height: 10px; border-radius: 3px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--text-3); stroke-width: 1; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .xh { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; font-size: 13px; box-shadow: 0 6px 20px rgb(0 0 0 / .12); min-width: 160px; z-index: 5; display: none; }
.tip .tt { font-weight: 650; margin-bottom: 5px; color: var(--text); }
.tip .tr { display: flex; align-items: center; gap: 7px; color: var(--text-2); justify-content: space-between; }
.tip .tr b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 650; }
.tip .tr i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 2px; }
.note { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.empty { padding: 40px 0; text-align: center; color: var(--text-3); }

/* events */
.events { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; }
.events li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 6px; margin-right: 6px; background: var(--surface-2); color: var(--text-2); }
.tag.alarm, .tag.offline { background: color-mix(in srgb, var(--crit) 15%, transparent); color: var(--crit); }
.tag.cleared, .tag.online { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.alarms { margin: 0 0 10px; padding: 0; list-style: none; }
.alarms li { color: var(--crit); font-weight: 600; font-size: 14px; padding: 3px 0; }
.alarms li::before { content: "⚠ "; }
.status-lines div { font-size: 14px; color: var(--text-2); padding: 2px 0; }

/* overview (admin, many sites) */
.ov { width: 100%; border-collapse: collapse; font-size: 14px; }
.ov th { text-align: left; color: var(--text-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.ov td { padding: 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.ov tr { cursor: pointer; } .ov tbody tr:hover { background: var(--surface-2); }
footer { max-width: 1280px; margin: 0 auto; padding: 10px 20px 30px; color: var(--text-3); font-size: 12px; }

/* period selector on the summary tiles */
.tiles-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 2px 10px; }
.tiles-head h2 { margin: 0 !important; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* technical battery panel */
.tech { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1000px) { .tech { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tech .t { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tech .k { font-size: 13px; color: var(--text-2); }
.tech .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tech .v small { font-size: 13px; color: var(--text-2); font-weight: 600; margin-left: 3px; }
.tech .s { font-size: 12.5px; color: var(--text-3); margin-top: 2px; font-variant-numeric: tabular-nums; }
.tech .meter { height: 6px; border-radius: 99px; background: var(--border); margin-top: 8px; overflow: hidden; }
.tech .meter > div { height: 100%; background: var(--battery); border-radius: 99px; }
.tech .flag { color: var(--crit); font-weight: 600; }
.tech-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1000px) { .tech-charts { grid-template-columns: 1fr; } }
.sub-h { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 4px 0 2px; }

/* phones: never wider than the screen; charts own sideways drags, no text selection */
html, body { overflow-x: hidden; overflow-x: clip; max-width: 100%; }
main { overflow-x: clip; }
.chart { touch-action: pan-y; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.chart svg text { pointer-events: none; }
.ov-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 560px) { .tip { min-width: 0; max-width: 78%; font-size: 12.5px; } }
@media (max-width: 560px) {
  .ov th, .ov td { padding: 7px 4px; font-size: 12.5px; }
  .ov th { letter-spacing: 0; }
  #overview .ov th:nth-child(4), #overview .ov td:nth-child(4) { display: none; }   /* Load column */
}
@media (max-width: 700px) {
  .top { position: static; }           /* phones: header scrolls away instead of covering the charts */
  .top-in { gap: 10px 12px; }
}

/* alerts dialog */
#notifdlg, #newsdlg, #ctldlg { border: 1px solid var(--border); border-radius: 16px; padding: 20px 22px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .25); }
#notifdlg::backdrop, #newsdlg::backdrop, #ctldlg::backdrop { background: rgb(0 0 0 / .35); }
#notifdlg h3, #newsdlg h3, #ctldlg h3 { margin: 0 0 6px; font-size: 18px; }
#notifdlg .chk { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-size: 14px; cursor: pointer; }
#notifdlg .chk input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
#notifdlg .chk small { color: var(--text-3); }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.btn-primary { background: var(--text); color: var(--surface); border-color: var(--text); font-weight: 600; }
.btn-primary:hover { background: var(--text); color: var(--surface); opacity: .88; }
#notifbtn.on { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }

/* header actions: big, well-spaced touch targets; sign out lives in the menu */
.top-in { position: relative; }
.hdr-actions { display: flex; gap: 12px; align-items: center; }
.btn.tap { min-height: 44px; min-width: 44px; padding: 8px 14px; display: inline-flex; align-items: center; gap: 8px; border-radius: 12px; font-weight: 600; }
.menu { position: absolute; right: 20px; top: calc(100% + 6px); z-index: 30; min-width: 250px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 14px 40px rgb(0 0 0 / .18); padding: 8px; }
.menu-who { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-who small { color: var(--text-3); }
.menu-item { display: flex; align-items: center; width: 100%; min-height: 48px; padding: 0 12px; border: 0; background: none;
  border-radius: 10px; color: var(--text); text-decoration: none; font: inherit; font-size: 15px; cursor: pointer; text-align: left; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.danger { color: var(--crit); font-weight: 600; }
.menu-sep { height: 1px; background: var(--border); margin: 8px 4px; }
@media (max-width: 700px) {
  .hdr-actions { margin-left: auto; }
  .menu { left: 16px; right: 16px; min-width: 0; }
}

/* version / what's new */
.menu-ver { margin-left: auto; color: var(--text-3); font-size: 13px; font-variant-numeric: tabular-nums; }
#newsdlg { width: min(520px, calc(100vw - 32px)); }
.news { max-height: 60vh; overflow-y: auto; margin: 4px 0 8px; }
.news h4 { margin: 14px 0 6px; font-size: 15px; display: flex; gap: 8px; align-items: baseline; }
.news h4 small { color: var(--text-3); font-weight: 500; }
.news h4 .cur { font-size: 11px; font-weight: 700; color: var(--ok, #12805c); text-transform: uppercase; letter-spacing: .05em; }
.news ul { margin: 0; padding-left: 20px; } .news li { margin: 4px 0; font-size: 14px; line-height: 1.45; color: var(--text-2); }

/* BYD battery modules (installer view) */
.byd-sum { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 14px; color: var(--text-2); margin: 2px 0 12px; }
.byd-sum b { color: var(--text); font-variant-numeric: tabular-nums; }
.byd-towers { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.byd-towers th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.byd-towers td { padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.byd-towers tr.sel td { background: var(--surface-2); }
.byd-towers tr { cursor: pointer; }
.byd-towers .bad { color: var(--crit); font-weight: 650; }
.byd-towers .warn { color: var(--warn, #b7791f); font-weight: 650; }
.byd-maphead { margin-top: 16px; gap: 12px; flex-wrap: wrap; }
.byd-maphead .seg button { min-width: 44px; }
.byd-map { display: flex; flex-direction: column; gap: 6px; user-select: none; -webkit-user-select: none; }
.byd-mod { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 4px 8px; align-items: center; }
.byd-mod .ml { font-size: 12px; font-weight: 650; color: var(--text-2); grid-row: span 2; }
.byd-cells { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 2px; }
.byd-temps { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 2px; max-width: 60%; }
.byd-cells .c, .byd-temps .c { height: 22px; border-radius: 4px; background: var(--surface-2); font-size: 10px; line-height: 22px; text-align: center;
  color: var(--text-2); font-variant-numeric: tabular-nums; overflow: hidden; cursor: pointer; }
.byd-temps .c { height: 16px; line-height: 16px; }
.byd-cells .c.on, .byd-temps .c.on { outline: 2px solid var(--text); outline-offset: -1px; }
.byd-cells .c span, .byd-temps .c span { display: none; }
@media (min-width: 1100px) { .byd-cells .c span, .byd-temps .c span { display: inline; } }
.byd-read { min-height: 22px; margin: 10px 0 4px; font-size: 14px; font-variant-numeric: tabular-nums; }
.byd-key { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
.byd-key span { display: inline-flex; align-items: center; gap: 6px; }
.byd-key i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); display: inline-block; border: 1px solid var(--border); }
.byd-key i.lo { background: color-mix(in srgb, var(--load) 70%, var(--surface-2)); }
.byd-key i.hi { background: color-mix(in srgb, var(--solar) 70%, var(--surface-2)); }
@media (max-width: 700px) { .byd-temps { max-width: none; } .byd-cells .c { height: 18px; } .byd-mod { grid-template-columns: 28px minmax(0, 1fr); gap: 3px 6px; } }
@media (max-width: 700px) {
  .byd-towers th:nth-child(3), .byd-towers td:nth-child(3), .byd-towers th:nth-child(4), .byd-towers td:nth-child(4) { display: none; }
  .byd-towers td, .byd-towers th { padding: 8px 6px; }
  .byd-maphead .seg button { min-width: 0; padding: 6px 9px; white-space: nowrap; }
}

/* battery modules: summary in the tech panel + separate full-page view */
.byd-summary { display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap; margin-top: 16px; padding: 14px 16px;
  background: var(--surface-2); border-radius: 12px; }
.byd-summary-text { flex: 1 1 260px; min-width: 0; }
.byd-brief { font-size: 14px; color: var(--text-2); margin-top: 4px; font-variant-numeric: tabular-nums; }
.byd-brief .bad { color: var(--crit); font-weight: 650; } .byd-brief .warn { color: var(--warn); font-weight: 650; }
.byd-summary .btn { min-height: 44px; }
.byd-viewhead { display: flex; align-items: center; gap: 14px; }
.byd-title { font-size: 22px; margin: 0; }
@media (max-width: 700px) { .byd-summary .btn { width: 100%; } }
main[hidden] { display: none; }

/* cell voltage history (BYD group + admins) */
.ch-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; margin: 4px 0 12px; }
.ch-wrap { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 8px; }
.ch-mods { display: grid; font-size: 12px; font-weight: 650; color: var(--text-2); }
.ch-mods div { display: flex; align-items: center; }
.ch-plot { position: relative; height: 432px; border-radius: 8px; overflow: hidden; background: var(--surface-2); touch-action: pan-y; cursor: crosshair; }
.ch-plot canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.ch-plot::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(100% / var(--mods, 9) - 1px), var(--surface) calc(100% / var(--mods, 9) - 1px), var(--surface) calc(100% / var(--mods, 9))); }
.ch-cursor { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--text); pointer-events: none; z-index: 1; }
.ch-axis { position: relative; height: 18px; margin: 4px 0 0 42px; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ch-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ch-scale { display: flex; align-items: center; gap: 8px; margin: 10px 0 0 42px; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ch-scale i { flex: 0 1 220px; height: 10px; border-radius: 3px; display: block; }
.ch-snaphead { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.ch-snaphead .sub-h { margin: 0; }
.ch-slider { width: 100%; margin: 8px 0 12px; accent-color: var(--text); }
@media (max-width: 700px) { .ch-plot { height: 324px; } .ch-wrap { grid-template-columns: 28px minmax(0, 1fr); } .ch-axis, .ch-scale { margin-left: 36px; } }
.ch-hint { font-size: 12.5px; margin: 6px 0 0; }
#ch-msel button { min-width: 40px; }
@media (max-width: 700px) { #ch-msel { flex-wrap: wrap; } #ch-msel button { min-width: 0; padding: 6px 8px; } }

/* clickable legends: hide/show a series */
.legend button.lg { font: inherit; color: inherit; background: none; border: 0; padding: 4px 6px; margin: -4px -2px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.legend button.lg:hover { background: var(--surface-2); }
.legend button.lg:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.legend button.lg.off { opacity: .45; text-decoration: line-through; }
.legend button.lg.off i { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--text-3); }
.map-when { font-size: 13.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.map-when b { color: var(--text); }
#mapcard .ch-slider { margin-top: 0; }
.datenav[hidden], .seg[hidden] { display: none; }

/* battery page: state of charge */
.byd-soc { margin: 4px 0 14px; max-width: 520px; }
.byd-soc-v { display: flex; align-items: baseline; gap: 4px; }
.byd-soc-v b { font-size: 40px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.byd-soc-v small { font-size: 18px; color: var(--text-2); font-weight: 650; }
.byd-soc-v span { margin-left: 14px; font-size: 14px; color: var(--text-2); }
.byd-soc-bar { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.byd-soc-bar > div { height: 100%; background: var(--battery); border-radius: 99px; transition: width .4s; }
.tech-charts .chart-wide { grid-column: 1 / -1; }
.tech.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* status: per-phase meter readings */
details.phases { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
details.phases summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--text-2); padding: 4px 0; list-style-position: inside; }
details.phases .ph { margin-top: 10px; }
details.phases h4 { margin: 6px 0 4px; font-size: 13px; font-weight: 650; }
details.phases h4 small { font-weight: 500; color: var(--text-3); }
details.phases table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
details.phases th, details.phases td { padding: 5px 6px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
details.phases thead th { font-size: 11.5px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
details.phases tbody th { text-align: left; font-weight: 500; color: var(--text-2); }
details.phases td:last-child { font-weight: 650; }

/* controls (admin, writes to the controller) */
.ctl-banner { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); background: color-mix(in srgb, var(--warn) 8%, var(--surface)); font-size: 14px; line-height: 1.5; }
.ctl-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.ctl-card h2 { margin-bottom: 4px; }
.ctl-help { color: var(--text-3); font-size: 13px; margin: 0 0 12px; }
.ctl-now { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.ctl-now b { font-size: 20px; }
.ctl-now small { color: var(--text-3); }
.ctl-now .diff { color: var(--warn); }
.ctl-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.ctl-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-3); }
.ctl-form input { width: 96px; min-height: 40px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 15px; }
.ctl-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.ctl-seg button { min-height: 40px; min-width: 64px; border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; padding: 0 12px; }
.ctl-seg button + button { border-left: 1px solid var(--border); }
.ctl-seg button.on { background: var(--text); color: var(--surface); font-weight: 600; }
.ctl-foot { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ctl-card[aria-busy="true"] { opacity: .6; pointer-events: none; }
.ctl-off { color: var(--text-3); font-size: 14px; }
.ctl-dbody { font-size: 15px; margin: 10px 0; }
.ctl-dbody .arrow { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin-top: 8px; }
.ctl-dbody .arrow span { color: var(--text-3); }
.ctl-rev { display: flex; flex-direction: column; gap: 6px; font-size: 14px; margin-top: 10px; }
.ctl-rev select { min-height: 40px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); font: inherit; padding: 0 8px; }
.ctl-log td { font-size: 13px; vertical-align: top; }
.ctl-log .bad { color: var(--crit); font-weight: 600; }
.ctl-log .okk { color: var(--good); font-weight: 600; }
.ctl-log button { min-height: 32px; }
.ctl-log { min-width: 680px; }
.ctl-group { grid-column: 1 / -1; margin: 8px 0 -6px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.ctl-chk { flex-direction: row !important; align-items: center; gap: 8px !important; min-height: 40px; font-size: 15px !important; color: var(--text) !important; }
.ctl-chk input { width: 20px !important; height: 20px; min-height: 0 !important; }
.ctl-chk { flex-basis: 100%; }
.ctl-grid { display: block; }
.ctl-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.ctl-tabs button { min-height: 44px; padding: 0 18px; border: 1px solid var(--border); border-radius: 22px; background: var(--surface); color: var(--text); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
.ctl-tabs button[aria-selected="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.ctl-sec { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.ctl-sec[hidden] { display: none; }
/* balancing markers (admins and the BYD group) */
.byd-cells .c { position: relative; }
.byd-cells .c.bal::after, .byd-key i.bal::after { content: ""; position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--text); box-shadow: 0 0 0 1.5px var(--surface); }
.byd-key i.bal { position: relative; }
.bal-tag { display: inline-block; padding: 1px 7px; border-radius: 9px; font-size: 12px; font-weight: 600; background: color-mix(in srgb, var(--solar) 25%, var(--surface-2)); color: var(--text); }
#key-bal[hidden] { display: none; }
