:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --other: #b9b8b0;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  /* entities */
  --house: var(--s1); --solar: var(--s2); --battery: var(--s3); --grid-c: var(--s7); --gen: var(--s4);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --wash: rgba(255, 255, 255, 0.05);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --other: #55544f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --wash: rgba(255, 255, 255, 0.05);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --other: #55544f;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 24px; max-width: 1280px; margin: 0 auto; }
.status { display: flex; gap: 8px; flex-wrap: wrap; }
.title-row { display: flex; align-items: baseline; gap: 14px; }
.pages { display: flex; gap: 6px; }
.pages a { font-size: 13px; color: var(--ink-2); text-decoration: none; border: 1px solid var(--border); border-radius: 8px; padding: 2px 10px; }
.pages a:hover { background: var(--wash); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--ink-2); font-size: 12.5px; white-space: nowrap; }
.chip b { color: var(--ink); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.good { background: var(--good); }
.dot.warning { background: var(--warning); }
.dot.critical { background: var(--critical); }

main { max-width: 1280px; margin: 0 auto; padding: 0 24px 48px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sub { margin: -2px 0 10px; color: var(--ink-2); font-size: 12.5px; }
.label { color: var(--ink-2); font-size: 13px; }

/* Live */
.now { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 2.4fr); gap: 16px; align-items: start; }
.hero { display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.hero-value { font-size: 56px; line-height: 1.05; font-weight: 600; letter-spacing: -0.01em; }
.hero-sub { color: var(--ink-2); }
.split { display: flex; gap: 2px; height: 10px; margin-top: 14px; }
.split span { display: block; height: 100%; min-width: 2px; }
.split span:first-child { border-radius: 4px 0 0 4px; }
.split span:last-child { border-radius: 0 4px 4px 0; }
.split span:only-child { border-radius: 4px; }
.split-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.split-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }

/* Power-flow topology */
.flow-note { font-size: 12px; }
.flow-canvas {
  border-radius: 10px; padding: 6px;
  background-color: var(--page);
  background-image: radial-gradient(var(--grid) 1px, transparent 1.2px);
  background-size: 18px 18px;
}
.flow-svg { display: block; width: 100%; height: auto; font-family: var(--font); }
.flow-svg.narrow { max-width: 520px; margin: 0 auto; }

/* links: a faint tinted pipe, a soft glow, and moving dots */
.fl-base, .fl-glow, .fl-dots { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fl-base { stroke: var(--axis); }
.fl-link.on .fl-base { stroke-opacity: 0.16; }
.fl-glow, .fl-dots { display: none; stroke-dasharray: 0 12; animation: fl-move 1.6s linear infinite; }
.fl-link.on .fl-glow, .fl-link.on .fl-dots { display: inline; }
.fl-glow { stroke-opacity: 0.14; }
.fl-glow.rev, .fl-dots.rev { animation-direction: reverse; }
@keyframes fl-move { to { stroke-dashoffset: -12; } }
@media (prefers-reduced-motion: reduce) { .fl-glow, .fl-dots { animation: none; } }
.fl-link.ghost .fl-base { stroke-dasharray: 2 5; stroke-opacity: 0.5; }

/* buses */
.fl-bus { fill: none; stroke: var(--grid); stroke-width: 12; stroke-linecap: round; }
.fl-bus.on.solar { stroke: var(--solar); stroke-opacity: 0.13; }
.fl-bus.on.grid { stroke: var(--grid-c); stroke-opacity: 0.13; }
.fl-bustag { fill: var(--ink-2); font-size: 9.5px; font-weight: 700; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.fl-junction { stroke: var(--surface); stroke-width: 2.5; }
.fl-ct circle { fill: var(--surface); stroke: var(--grid-c); stroke-width: 1.4; }
.fl-ct text { fill: var(--ink-2); font-size: 8.5px; font-weight: 700; }
.fl-port { fill: var(--muted); font-size: 8.5px; font-weight: 700; letter-spacing: 0.06em; }

/* cards */
.fl-card { fill: var(--surface); stroke: var(--border); filter: url(#fl-shadow); }
.fl-node.dim { opacity: 0.55; }
.fl-card.outlined { stroke-width: 2; }
.fl-badge { fill-opacity: 0.14; }
.fl-icon { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fl-title { fill: var(--ink); font-size: 13px; font-weight: 600; }
.fl-kicker { fill: var(--muted); font-size: 9.5px; font-weight: 600; letter-spacing: 0.08em; }
.fl-value { fill: var(--ink); font-size: 22px; font-weight: 650; letter-spacing: -0.015em; }
.flow-svg.wide .fl-value { font-size: 30px; }
.fl-sub.big { font-size: 13px; }
.fl-timer { fill: var(--ink); font-size: 15px; font-weight: 600; }
.fl-sub { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.fl-sub.strong { fill: var(--ink); font-weight: 600; }
.fl-chip rect { fill: var(--page); stroke: var(--border); }
.fl-chip text { fill: var(--ink-2); font-size: 10.5px; font-weight: 600; }
.fl-pill rect { fill: var(--surface); stroke-opacity: 0.55; stroke-width: 1.2; }
.fl-pill text { fill: var(--ink); font-size: 10.5px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* bars and the battery gauge */
.fl-track { fill: var(--grid); }
.fl-fill { fill: var(--ink-2); }
.fl-fill.solar { fill: var(--solar); }
.fl-fill.battery { fill: var(--battery); }
.fl-floor { fill: url(#fl-hatch); }
.fl-hatch { stroke: var(--muted); stroke-width: 1.5; }
.fl-tick { stroke: var(--ink-2); stroke-width: 1.2; }
.fl-ticklabel { fill: var(--muted); font-size: 9px; font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.tile { display: flex; flex-direction: column; gap: 2px; }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; }
.tile .value small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.tile .detail { color: var(--ink-2); font-size: 12.5px; }
.tile .key { display: inline-flex; align-items: center; gap: 6px; }
.meter { height: 6px; border-radius: 3px; background: var(--grid); margin: 6px 0 2px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--battery); }

/* Devices table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num { white-space: nowrap; }
.dev-name { display: flex; align-items: center; gap: 8px; min-width: 180px; }
.dev-name .sw { width: 10px; height: 10px; }
.supply { display: inline-flex; align-items: center; gap: 5px; margin-left: 8px; padding: 0 7px; border: 1px solid var(--border); border-radius: 999px; font-size: 11.5px; color: var(--ink-2); vertical-align: 1px; white-space: nowrap; }
.supply i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.supply.solar i { background: var(--solar); }
.supply.grid i { background: var(--grid-c); }
.dev-name.child { padding-left: 22px; position: relative; }
.dev-name.child::before { content: ""; position: absolute; left: 4px; top: -4px; width: 10px; height: 14px; border-left: 1px solid var(--axis); border-bottom: 1px solid var(--axis); border-bottom-left-radius: 4px; }
.dev-meta { color: var(--muted); font-size: 12px; }
.dev-power { font-weight: 600; color: var(--ink); }
.share { width: 100%; min-width: 90px; height: 8px; display: flex; align-items: center; }
.share span { display: block; height: 8px; border-radius: 0 4px 4px 0; min-width: 2px; }
tr.inactive td { color: var(--muted); }
tr.inactive .dev-power { color: var(--muted); font-weight: 400; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); }
.spark-col, .share-col { width: 140px; }
svg.spark { display: block; width: 120px; height: 24px; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.filters-label { font-weight: 600; font-size: 15px; margin-right: 8px; }
.filters button, .table-toggle { font: inherit; font-size: 13px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 12px; cursor: pointer; }
.filters button:hover, .table-toggle:hover { background: var(--wash); }
.filters button[aria-checked="true"] { color: var(--ink); border-color: var(--ink-2); font-weight: 600; }
.table-toggle { font-size: 12px; padding: 3px 10px; }
.table-toggle[aria-pressed="true"] { color: var(--ink); border-color: var(--ink-2); }
button:focus-visible, svg:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }

/* Charts */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card.wide { grid-column: 1 / -1; }
.plot { position: relative; transition: opacity 0.2s; }
.plot.loading { opacity: 0.5; }
.plot svg { display: block; width: 100%; overflow: visible; }
.plot .gridline { stroke: var(--grid); stroke-width: 1; }
.plot .baseline { stroke: var(--axis); stroke-width: 1; }
.plot .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.plot .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .area { stroke: none; opacity: 0.1; }
.plot .cross { stroke: var(--ink-2); stroke-width: 1; }
.plot .hover-dot { stroke: var(--surface); stroke-width: 2; }
.plot .col.dim { opacity: 0.45; }
.plot table { font-size: 12.5px; }
.plot .table-scroll { max-height: 320px; overflow: auto; }
.plot .table-scroll th { position: sticky; top: 0; background: var(--surface); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 6px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .lk { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.legend b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.bars { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 12px; align-items: center; }
.bars .name { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.bars .track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bars .bar { height: 14px; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 2px; }
.bars .val { font-size: 12.5px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }

.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); font-size: 12.5px; min-width: 150px; }
.tooltip .t-head { color: var(--muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 64px; }
.tooltip .t-row span:last-child { color: var(--ink-2); }
.tooltip .lk { width: 12px; height: 2px; border-radius: 1px; display: inline-block; flex: none; }

@media (max-width: 860px) {
  .now, .charts { grid-template-columns: minmax(0, 1fr); }
  .top, main { padding-left: 16px; padding-right: 16px; }
  .hero-value { font-size: 48px; }
  .spark-col, .share-col, td.spark, td.share-cell { display: none; }
}
.fl-link.unsure .fl-dots, .fl-link.unsure .fl-glow { opacity: 0.45; }
.fl-link.unsure .fl-base { stroke-dasharray: 3 4; }
.fl-fill.floor { fill: var(--muted); }
.fl-fill.battery.reserve { fill-opacity: 0.5; }
.fl-source { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.fl-source.big { font-size: 15px; }
.fl-source.pv { fill: var(--solar); }
.fl-source.grid { fill: var(--grid-c); }
.fl-sub.strong.muted { fill: var(--muted); font-weight: 400; }
.fl-value.inline { font-size: 20px; }
.fl-value.mini { font-size: 15px; }

/* Who is signed in, sign-out and the install button (session.js) */
.account { display: flex; align-items: baseline; gap: 10px; margin-left: 4px; font-size: 13px; color: var(--ink-2); }
.link-btn { appearance: none; background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.link-btn:hover { color: var(--ink); }
.install-btn { appearance: none; font: 500 12.5px var(--font); color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px 10px; cursor: pointer; }
.install-btn:hover { background: var(--wash); }
