:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --raised: #ffffff;
  --text: #0b0b0b; --text-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,.10);
  --accent: #1c5cab; --accent-ink: #ffffff; --wash: rgba(11,11,11,.05);
  /* series: colour follows the entity everywhere */
  --s-grid: #2a78d6; --s-feedin: #eb6834; --s-battery: #1baf7a; --s-pv: #eda100;
  --s-load: #e87ba4; --s-meter: #008300; --s-est: #c3c2b7; --s-nodata: #e1e0d9;
  --seq-lo: #cde2fb; --seq-hi: #0d366b;
  --yr-0: #86b6ef; --yr-1: #2a78d6; --yr-2: #104281;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300; --crit-text: #a82a2a; --warn-bg: #fff6de; --warn-text: #5c4300;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --raised: #222221;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
    --accent: #6da7ec; --accent-ink: #0b0b0b; --wash: rgba(255,255,255,.06);
    --s-grid: #3987e5; --s-feedin: #d95926; --s-battery: #199e70; --s-pv: #c98500;
    --s-load: #d55181; --s-meter: #0ca30c; --s-est: #52514e; --s-nodata: #2c2c2a;
    --seq-lo: #0d366b; --seq-hi: #b7d3f6;
    --yr-0: #184f95; --yr-1: #3987e5; --yr-2: #9ec5f4;
    --good-text: #0ca30c; --crit-text: #e66767; --warn-bg: #33290c; --warn-text: #fbe3a3;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; text-wrap: balance; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); } .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; text-wrap: pretty; }
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
  padding: 12px max(16px, calc((100vw - 1240px) / 2)) 0; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; }
.brand p { font-size: 12px; line-height: 1.2; }
.sun { width: 22px; height: 22px; border-radius: 50%; background: var(--s-pv);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--s-pv) 25%, transparent); }
.tabs { display: flex; gap: 2px; overflow-x: auto; margin-left: auto; align-self: flex-end; }
.tabs button {
  border: 0; background: none; padding: 9px 14px 11px; cursor: pointer; white-space: nowrap;
  color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 550;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 12px max(16px, calc((100vw - 1240px) / 2)) 0; font-size: 13px; color: var(--text-2);
}
.filters[hidden] { display: none; }
.filters label { display: inline-flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg[hidden] { display: none; }
.seg button { border: 0; background: none; padding: 6px 11px; cursor: pointer; color: var(--text-2); font-size: 13px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--wash); }
.seg button.on { background: var(--text); color: var(--surface); }

main { padding: 16px max(16px, calc((100vw - 1240px) / 2)) 64px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.card > header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 8px 16px; margin-bottom: 12px; }
.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.chart { width: 100%; height: 320px; }
.chart.tall { height: 380px; } .chart.short { height: 190px; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; margin-top: 2px; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--text-2); letter-spacing: 0; margin-left: 3px; }
.tile .n { font-size: 12px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }

.notice { border-radius: 12px; padding: 12px 16px; display: flex; gap: 12px; align-items: flex-start;
  background: var(--warn-bg); color: var(--warn-text); border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent); }
.notice strong { font-weight: 650; }
.notice .ico { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--warning); color: #0b0b0b;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; margin-top: 1px; }
.notice.info { background: var(--wash); color: var(--text-2); border-color: var(--border); }
.notice.info .ico { background: var(--axis); }
.notice p + p { margin-top: 4px; }

.tablewrap { overflow-x: auto; margin: 0 -18px -6px; padding: 0 18px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
td.wrap { white-space: normal; min-width: 180px; }
th { font-weight: 600; color: var(--text-2); font-size: 12px; position: sticky; top: 0; background: var(--surface); }
th[data-sort] { cursor: pointer; } th[data-sort]:hover { color: var(--text); }
tbody tr:hover { background: var(--wash); }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 650; border-bottom: 0; border-top: 1px solid var(--axis); }
.scrolly { max-height: 420px; overflow: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px 2px 6px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--raised); color: var(--text); white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.ok::before { background: var(--good); } .badge.gap::before { background: var(--warning); }
.badge.bad::before { background: var(--critical); }
.pos { color: var(--crit-text); } .neg { color: var(--good-text); }

.btn { border: 1px solid var(--border); background: var(--raised); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 550; font-size: 14px; }
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.danger { color: var(--crit-text); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.form { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: start; }
.form .wide { grid-column: 1 / -1; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
.field input, .field select, .field textarea, .filters input {
  border: 1px solid var(--axis); border-radius: 8px; padding: 7px 10px; background: var(--raised); color: var(--text); width: 100%; min-width: 0;
}
.filters input { width: auto; padding: 5px 8px; }
.field input:focus-visible, .field select:focus-visible, .btn:focus-visible, .tabs button:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.field .hint { font-size: 12px; color: var(--muted); min-height: 18px; }
.err { color: var(--crit-text); font-size: 13px; }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin-bottom: 4px; } dialog .sub { margin-bottom: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 9px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
.login { max-width: 360px; margin: 12vh auto 0; }
.empty { color: var(--text-2); padding: 12px 0; }
.legendline { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legendline span { display: inline-flex; align-items: center; gap: 6px; }
.drop { border: 1.5px dashed var(--axis); border-radius: 10px; padding: 18px; text-align: center; color: var(--text-2); }
.drop.over { border-color: var(--accent); background: var(--wash); }
@media (max-width: 640px) {
  .tabs { margin-left: 0; width: 100%; } .tile .v { font-size: 22px; } .chart { height: 280px; }
}

.stats { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-bottom: 12px; }
.stat .k { font-size: 12px; color: var(--text-2); }
.stat .v { font-size: 21px; font-weight: 650; letter-spacing: -.02em; line-height: 1.25; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--text-2); letter-spacing: 0; margin-left: 3px; }
.stat .n { font-size: 12px; color: var(--muted); }
th.grp, td.grp { border-left: 1px solid var(--grid); }
thead th.grp[colspan] { text-align: center; color: var(--text); }
