/* Battery planner dashboard. Colours are tokens; dark mode has its own
   validated steps (chart series from the dataviz reference palette). */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --accent: #2a78d6;
  --grid: #e7e6e1;
  --good: #0e7a3a;
  --good-bg: #e3f4e8;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  /* series: one colour per thing, the same on every chart */
  --s-battery: #2a78d6;  /* blue */
  --s-import: #eb6834;   /* orange: grid import and prices */
  --s-usage: #1baf7a;    /* aqua: house usage */
  --s-solar: #eda100;    /* yellow */
  --s-export: #4a3aa7;   /* violet */
  --s-free: #e87ba4;     /* magenta: free sessions */
  --s-agile: #1baf7a;    /* aqua: Agile smart charging (savings only) */
  --s-neutral: #b9b8b2;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #3987e5;
    --grid: #2c2c29;
    --good: #6fd29a;
    --good-bg: #173322;
    --warn: #f0c060;
    --warn-bg: #3a2e12;
    --bad: #ff8a80;
    --bad-bg: #3d1a17;
    --s-battery: #3987e5;
    --s-import: #d95926;
    --s-usage: #199e70;
    --s-solar: #c98500;
    --s-export: #9085e9;
    --s-free: #d55181;
    --s-agile: #199e70;
    --s-neutral: #55554f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #2f2f2c;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #9a998f; --accent: #3987e5; --grid: #2c2c29;
  --good: #6fd29a; --good-bg: #173322; --warn: #f0c060; --warn-bg: #3a2e12; --bad: #ff8a80; --bad-bg: #3d1a17;
  --s-battery: #3987e5; --s-import: #d95926; --s-usage: #199e70; --s-solar: #c98500;
  --s-export: #9085e9; --s-free: #d55181; --s-agile: #199e70; --s-neutral: #55554f;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.15rem; margin-bottom: 4px; }
h3 { font-size: .95rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { font-variant-numeric: tabular-nums; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 650; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  padding: 7px 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; white-space: nowrap;
  font-weight: 500;
}
.tabs a:hover { background: var(--surface-2); }
.tabs a.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.user { display: flex; align-items: center; gap: 8px; }
.user form { margin: 0; }
.avatar { border-radius: 50%; }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 60px; }

/* building blocks */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 16px; min-width: 0;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid > .panel { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile-label { color: var(--text-2); font-size: .82rem; }
.tile-value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile-value.long { font-size: 1.05rem; line-height: 1.3; margin-top: 6px; }
.tile-sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.hero { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.chart-box { position: relative; height: 260px; }
.chart-box.short { height: 190px; }
.chart-box.tall { height: 320px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--text-2); margin: 0 0 8px; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.line { height: 3px; border-radius: 2px; width: 16px; }
.swatch.dash { height: 0; width: 16px; border-top: 3px dashed; background: none !important; border-radius: 0; }

.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: .78rem;
  font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }

.notice { border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: .9rem; }
.notice-bad { background: var(--bad-bg); color: var(--bad); }
.notice-warn { background: var(--warn-bg); color: var(--warn); }
.notice-info { background: var(--surface-2); color: var(--text-2); }

table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; }
td:first-child { white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
details > summary { cursor: pointer; color: var(--text-2); font-size: .86rem; margin-top: 8px; }

.timeline { display: flex; flex-direction: column; gap: 6px; }
.block { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.block .when { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: .86rem; }
.block .what { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.block .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-2); padding: 5px 8px; }
input[type="date"] { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); }

.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--s-battery); border-radius: 999px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .9rem; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px;
  width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: 1.4rem; margin-top: 12px; }
.login-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.btn-provider { padding: 10px 14px; font-weight: 600; }

@media (max-width: 820px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 10px 16px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; flex-wrap: wrap; }
  .tabs a { padding: 6px 9px; }
  .user-email { display: none; }
  main { padding: 16px 16px 48px; }
  .block { grid-template-columns: 1fr; gap: 2px; }
  .hero { font-size: 2rem; }
  .chart-box { height: 220px; }
}
