:root {
  --bg: #f2f6f5;
  --surface: #ffffff;
  --surface-2: #e8efed;
  --text: #11201d;
  --muted: #5d706b;
  --line: #d5dfdc;
  --kwh: #0f9d76;
  --cost: #c47a0a;
  --rate: #6a5acd;
  --danger: #c0392b;
  --bar: var(--kwh);
  --tab-h: 62px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a18;
    --surface: #17262a;
    --surface-2: #213539;
    --text: #e6f1ee;
    --muted: #93aaa4;
    --line: #2a4044;
    --kwh: #35d6a4;
    --cost: #f0b04a;
    --rate: #9d90f5;
    --danger: #ff8a7a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom));
}

/* header */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px;
}
.top img { border-radius: 7px; }
.top h1 { margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: .01em; }
/* Blazor focuses the h1 after navigation for screen readers; don't draw a box around it. */
.top h1:focus { outline: none; }

/* bottom tab bar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.tabbar a {
  flex: 1;
  max-width: 270px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: .78rem;
  min-height: 48px;
}
.tabbar a span { font-size: 1.15rem; line-height: 1.2; }
.tabbar a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }

/* segmented control */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 4px;
  min-height: 44px;
  border-radius: 10px;
  font-weight: 550;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.seg.small button { min-height: 36px; padding: 6px 4px; font-size: .88rem; }

/* period stepper */
.stepper {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  margin: 12px 0;
}
.stepper .icon {
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.6rem;
  line-height: 1;
}
.stepper .icon:disabled { opacity: .3; cursor: default; }
.stepper-title {
  border: 0;
  background: none;
  font-weight: 650;
  font-size: 1.05rem;
  padding: 10px 4px;
  min-height: 48px;
}
.stepper-title:disabled { cursor: default; }

/* cards */
.card {
  background: var(--surface);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.card h2 { margin: 0 0 8px; font-size: 1rem; }
.count {
  font-weight: 500;
  font-size: .8rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 4px;
}

/* totals */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.total { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.big { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.big.kwh, .s-val .kwh { color: var(--kwh); }
.big.cost, .s-val .cost { color: var(--cost); }
.totals .sub { grid-column: 1 / -1; margin: 4px 0 0; font-size: .85rem; color: var(--muted); }

/* chart */
.chart .seg { margin-bottom: 8px; }
.chart.m-kwh { --bar: var(--kwh); }
.chart.m-cost { --bar: var(--cost); }
.chart.m-rate { --bar: var(--rate); }
.readout { margin: 6px 0; min-height: 2.6em; font-size: .88rem; color: var(--muted); }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--bar); opacity: .8; }
.chart .bar.sel { opacity: 1; stroke: var(--text); stroke-width: 1.5; }
.chart .hit { fill: transparent; cursor: pointer; }

/* date range */
.range-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.range-pick label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.range-pick input[type=date] {
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  font-size: .88rem;
}

/* sessions */
.sessions { list-style: none; margin: 0; padding: 0; }
.sessions li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.sessions li:first-child { border-top: 0; }
.s-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.s-sub { font-size: .8rem; color: var(--muted); }
.s-val { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.s-val .cost { font-size: .9rem; }
.badge {
  font-size: .7rem;
  border: 1px solid var(--kwh);
  color: var(--kwh);
  border-radius: 999px;
  padding: 0 6px;
  margin-left: 4px;
}
abbr { text-decoration: none; cursor: help; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }
.error { color: var(--danger); background: var(--surface); border: 1px solid var(--danger); border-radius: 12px; padding: 10px 14px; }

/* splash + Blazor error bar */
.splash { display: grid; place-items: center; gap: 8px; min-height: 100vh; color: var(--muted); }
.splash img { border-radius: 20px; }

#blazor-error-ui {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: #ffe9a8;
  color: #3a2c00;
  z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 12px; }

@media (prefers-reduced-motion: no-preference) {
  .chart .bar { transition: opacity .15s; }
}
