: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;
  --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;
    --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;
  --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; }
.user { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-2); }
.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%; 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: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.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); }

/* lifetime / events */
.life { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 14px; }
.life .k { font-size: 13px; color: var(--text-2); }
.life .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.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; }
