: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); --accent: #2a78d6; --wash: rgba(42,120,214,0.08);
  /* entity colours (fixed per entity, see app.js COLORS) */
  --house: #2a78d6; --car: #eb6834; --battery: #1baf7a; --solar: #eda100; --gas: #e87ba4; --export: #6250d6;
  --neutral: #c3c2b7; --offpeak: #86b6ef; --peak: #1c5cab;
  --good: #006300; --bad: #d03b3b;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    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); --accent: #3987e5; --wash: rgba(57,135,229,0.14);
    --house: #3987e5; --car: #d95926; --battery: #199e70; --solar: #c98500; --gas: #d55181; --export: #9085e9;
    --neutral: #55544f; --offpeak: #9ec5f4; --peak: #256abf;
    --good: #0ca30c; --bad: #e66767;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font-size: 15px; line-height: 1.4; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 4px; font-weight: 600; }
button, input, select { font: inherit; color: inherit; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(340px, 100%); display: grid; gap: 10px; }
.login input { padding: 10px 12px; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface); }
.login button { padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.error { color: var(--bad); margin: 0; }

/* header + tabs */
.top { display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.tabs button:hover { background: var(--wash); }
.tabs button[aria-selected="true"] { color: var(--ink); background: var(--wash); font-weight: 600; }
.logout { color: var(--muted); text-decoration: none; font-size: 13px; white-space: nowrap; }

/* filters: one row above everything they scope */
.filters { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding: 12px 20px; }
.presets { display: flex; flex-wrap: wrap; gap: 4px; }
.presets button { border: 1px solid var(--border); background: var(--surface); padding: 5px 10px; border-radius: 999px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.presets button:hover { background: var(--wash); }
.presets button.on { border-color: var(--accent); color: var(--ink); font-weight: 600; }
.custom { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; color: var(--ink-2); }
.custom input[type=date], .custom select { padding: 4px 6px; border: 1px solid var(--axis); border-radius: 6px; background: var(--surface); }
.check { display: flex; gap: 6px; align-items: center; }

main#app { padding: 0 20px 32px; transition: opacity .15s; }
main#app.busy { opacity: .55; }
.panel { display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 16px 8px; min-width: 0; }
.note { color: var(--muted); font-size: 13px; margin: 0 0 6px; }
.chart { height: 340px; width: 100%; }
.chart.tall { height: 420px; }
.status { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile .k { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tile .k i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.tile .v { font-size: 24px; font-weight: 650; }
.tile .s { font-size: 13px; color: var(--muted); }

/* tables */
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--ink-2); font-weight: 600; font-size: 13px; }
td .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; vertical-align: -1px; }
.table-wrap { overflow-x: auto; }
a.btn { display: inline-block; padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; text-decoration: none; color: var(--accent); font-size: 13px; }
a.btn:hover { background: var(--wash); }
.muted { color: var(--muted); }

.device-pick { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--ink-2); margin: 4px 0 6px; }
.device-pick label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.device-pick i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .logout { margin-left: auto; }
  .filters { padding: 10px 12px; }
  main#app { padding: 0 12px 24px; }
  .card { padding: 12px 10px 4px; }
  .chart { height: 280px; }
  .chart.tall { height: 360px; }
  .tile .v { font-size: 20px; }
}
