/* energy dashboard. Colors are the dataviz reference palette (validated light + dark). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  /* categorical slots, fixed order */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  /* status (never used for series) */
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --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-1: #1a1a19;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --good-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --good-text: #0ca30c;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text-primary); font: 15px/1.45 var(--font); }
a { color: var(--accent); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
header.top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
header.top h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
header.top .meta { color: var(--text-secondary); font-size: 13px; }
header.top .right { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: 13px; }
.badge { border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; color: var(--text-secondary); }
h2.section { font-size: 15px; font-weight: 600; margin: 26px 0 10px; color: var(--text-secondary); }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-height: 92px; }
.tile .label { font-size: 13px; color: var(--text-secondary); }
.tile .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .value .unit { font-size: 15px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.tile .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.tile.hero { grid-column: span 2; }
.tile.hero .value { font-size: 48px; line-height: 1.05; }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; }
.status.on .dot { background: var(--serious); }
.status.off .dot { background: var(--text-muted); }
.status.good .dot { background: var(--good); }
.status.critical .dot { background: var(--critical); }
.meter { height: 8px; border-radius: 4px; background: var(--grid); margin-top: 8px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }

/* filters: one row, above the charts they scope */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 22px 0 4px; }
.filters .label { font-size: 13px; color: var(--text-secondary); margin-right: 4px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--text-primary);
  padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
.seg button:hover:not([aria-pressed="true"]) { background: var(--grid); }

/* chart cards */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } .tile.hero { grid-column: span 1; } }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 14px 10px; margin-top: 12px; position: relative; min-width: 0; }
.grid2 .card { margin-top: 0; }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card .desc { margin: 2px 0 6px; font-size: 13px; color: var(--text-secondary); }
.card .tools { position: absolute; top: 12px; right: 12px; }
.linkbtn { font: inherit; font-size: 12.5px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-secondary); margin: 4px 0 2px; }
.legend .key { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 5px; border-radius: 1px; }
.legend .key.dot { width: 8px; height: 8px; border-radius: 50%; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: var(--font); }
.chart .tick { font-size: 11px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.chart .endlabel { font-size: 11.5px; fill: var(--text-secondary); }
.chart .empty { font-size: 13px; fill: var(--text-muted); }
.tooltip { position: absolute; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,.12);
  min-width: 140px; z-index: 5; display: none; }
.tooltip .when { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tooltip .row strong { font-variant-numeric: tabular-nums; }
.tooltip .row .name { color: var(--text-secondary); }
.tooltip .key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.note { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }

/* table view */
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
table.data th, table.data td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }
.tablewrap { max-height: 320px; overflow: auto; }

/* forms */
form.entry { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }
form.entry label { font-size: 12.5px; color: var(--text-secondary); display: grid; gap: 3px; }
input, select { font: inherit; font-size: 14px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--page); color: var(--text-primary); width: 100%; }
button.primary { font: inherit; font-weight: 600; background: var(--accent); color: #fff; border: 0; border-radius: 7px; padding: 8px 14px; cursor: pointer; }
.msg { font-size: 13px; margin-top: 6px; }
.msg.ok { color: var(--good-text); }
.msg.err { color: var(--critical); }

/* login */
.login { max-width: 360px; margin: 12vh auto 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 16px; color: var(--text-secondary); font-size: 13.5px; }
.login form { display: grid; gap: 12px; }
.login .err { color: var(--critical); font-size: 13.5px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--text-secondary); }
