/* ── tokens ────────────────────────────────────────────────────────────── */
:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f0f2f5;
  --line:      #dfe3e8;
  --line-soft: #eaedf1;
  --ink:       #16191d;
  --ink-2:     #545c66;
  --ink-3:     #858e99;
  --accent:    #1f6feb;
  --accent-ink:#ffffff;

  --solar:     #e8a33d;
  --solar-2:   #f2c877;
  --grid:      #5a6b7d;
  --grid-2:    #9aa8b6;
  --good:      #1f9254;
  --warn:      #b57314;
  --bad:       #c0392b;

  --radius:    10px;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --mono:      ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1115;
    --surface:   #171a20;
    --surface-2: #1e222a;
    --line:      #2a2f39;
    --line-soft: #22262e;
    --ink:       #e8eaed;
    --ink-2:     #a4adb9;
    --ink-3:     #6f7885;
    --accent:    #4c8dff;
    --solar:     #f0b354;
    --solar-2:   #6b5124;
    --grid:      #8fa2b5;
    --grid-2:    #3b4753;
    --good:      #3ec87c;
    --warn:      #e0a33f;
    --bad:       #f0705f;
    --shadow:    0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }

/* The browser hides [hidden] with display:none, but that comes from the user-agent
   stylesheet and any author rule setting display beats it. .banner sets display:flex,
   so a hidden banner still occupied a strip on every page. Declared once here rather
   than per component, because the next element given a display and a hidden attribute
   would have the same bug. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 21px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 14px; font-weight: 650; margin: 0; letter-spacing: .01em; }
h3.sub { font-size: 13px; font-weight: 650; margin: 22px 0 4px; color: var(--ink-2); }

/* ── chrome ────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; }
.brand-mark {
  width: 16px; height: 16px; border-radius: 50%;
  background: linear-gradient(135deg, var(--solar), #d4791f);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--solar) 18%, transparent);
}
.brand-name { letter-spacing: -.01em; }

.tabs { display: flex; gap: 2px; margin-right: auto; }
.tabs a {
  padding: 7px 12px; border-radius: 7px;
  color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500;
}
.tabs a:hover { background: var(--surface-2); color: var(--ink); }
.tabs a.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }

.who { font-size: 13px; color: var(--ink-3); display: flex; align-items: center; gap: 10px; }
.who a { color: var(--ink-2); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }

.view-head {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.view-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stamp { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ── banner ────────────────────────────────────────────────────────────── */
.banner {
  padding: 10px 20px; font-size: 14px;
  background: color-mix(in srgb, var(--bad) 12%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  color: var(--ink);
  display: flex; align-items: center; gap: 12px;
}
.banner.info { background: color-mix(in srgb, var(--accent) 12%, var(--surface));
               border-bottom-color: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ── cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
  margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 12px; margin-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { color: var(--ink-2); text-transform: uppercase; font-size: 11.5px; letter-spacing: .06em; }
.split-2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .split-2 { grid-template-columns: 1fr; } }

.note { font-size: 12.5px; color: var(--ink-3); margin: 12px 0 0; line-height: 1.55; }
.hint { font-size: 12.5px; color: var(--ink-3); margin: 2px 0 10px; line-height: 1.55; }
.empty { color: var(--ink-3); font-size: 14px; padding: 24px 0; text-align: center; }

/* ── tiles ─────────────────────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
}
.tiles.compact .tile { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.tile-label { font-size: 11.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tile-value { font-size: 25px; font-weight: 600; margin-top: 5px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile-value .unit { font-size: 13px; color: var(--ink-3); font-weight: 500; margin-left: 3px; }
.tile-sub { font-size: 12px; color: var(--ink-3); margin-top: 3px; font-variant-numeric: tabular-nums; }
.tile.solar .tile-value { color: var(--solar); }
.tile.grid  .tile-value { color: var(--grid); }

/* ── forms ─────────────────────────────────────────────────────────────── */
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row.mt { margin-top: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--ink-2); }
.field.grow { flex: 1 1 220px; }
.field.inline { flex-direction: row; align-items: center; gap: 7px; }
.field span em { font-style: normal; color: var(--ink-3); font-weight: 400; }

input, .select, select, textarea {
  font: inherit; font-size: 14px;
  padding: 7px 10px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: -1px; border-color: var(--accent);
}
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
input:invalid:not(:placeholder-shown) { border-color: var(--bad); }

.form-actions { display: flex; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-soft); }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 7px 14px; border-radius: 7px; cursor: pointer;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line);
}
/* Scoped away from .primary: the generic hover sets a near-white background and
   out-specifies .btn.primary, so a primary button's white label landed on white
   and the button appeared to vanish under the cursor. */
.btn:not(.primary):hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.12); }
.btn.ghost { background: transparent; }
.btn.sm { font-size: 12.5px; padding: 5px 10px; }
.btn.icon { padding: 4px 8px; color: var(--ink-3); border-color: transparent; background: transparent; }
.btn.icon:hover { color: var(--bad); background: var(--surface-2); }

/* ── tables ────────────────────────────────────────────────────────────── */
.scroll-x { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 600; padding: 7px 8px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.grid td { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid input, table.grid select { width: 100%; padding: 5px 8px; font-size: 13.5px; }
table.grid tr:last-child td { border-bottom: none; }

/* ── result panel ──────────────────────────────────────────────────────── */
.party { padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.party:last-of-type { border-bottom: none; }
.party-head { display: flex; align-items: baseline; gap: 10px; }
.party-name { font-weight: 650; font-size: 15px; }
.party-total { margin-left: auto; font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.party-lines { margin-top: 8px; display: grid; grid-template-columns: 1fr auto; gap: 3px 16px; font-size: 13px; color: var(--ink-2); }
.party-lines .v { font-variant-numeric: tabular-nums; text-align: right; }
.party-lines .credit { color: var(--good); }

.total-check {
  margin-top: 14px; padding: 9px 12px; border-radius: 7px;
  background: color-mix(in srgb, var(--good) 12%, var(--surface));
  color: var(--ink); font-size: 12.5px;
  display: flex; align-items: center; gap: 8px;
}
.total-check.bad { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }

.warnings { margin-top: 12px; }
.warning {
  font-size: 12.5px; padding: 8px 11px; border-radius: 7px; margin-bottom: 6px;
  background: color-mix(in srgb, var(--warn) 13%, var(--surface));
  border-left: 2px solid var(--warn); line-height: 1.5;
}

/* ── settings ──────────────────────────────────────────────────────────── */
.setting {
  display: grid; grid-template-columns: 1fr 220px; gap: 6px 24px;
  padding: 14px 0; border-bottom: 1px solid var(--line-soft); align-items: start;
}
.setting:last-child { border-bottom: none; }
.setting-label { font-weight: 550; font-size: 14px; }
.setting-desc { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; line-height: 1.55; grid-column: 1; }
.setting-control { grid-row: 1 / span 2; grid-column: 2; display: flex; flex-direction: column; gap: 5px; }
.setting-control input { width: 100%; }
.setting-error { font-size: 12px; color: var(--bad); }
.setting.dirty .setting-label::after {
  content: "changed"; margin-left: 8px; font-size: 10.5px; font-weight: 600;
  color: var(--warn); text-transform: uppercase; letter-spacing: .05em;
}
@media (max-width: 720px) {
  .setting { grid-template-columns: 1fr; }
  .setting-control { grid-row: auto; grid-column: 1; }
}

.range-row { display: flex; align-items: center; gap: 9px; }
.range-row input[type="range"] { flex: 1; padding: 0; }
.range-val { font-variant-numeric: tabular-nums; font-size: 13px; min-width: 44px; text-align: right; color: var(--ink-2); }

/* ── charts ────────────────────────────────────────────────────────────── */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; min-width: 520px; }
.legend { margin-left: auto; display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.axis text { font-size: 10px; fill: var(--ink-3); }
.axis line { stroke: var(--line); }
.gridline { stroke: var(--line-soft); }

/* ── quality ───────────────────────────────────────────────────────────── */
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar { height: 6px; border-radius: 3px; background: var(--good); min-width: 2px; }
.bar.warn { background: var(--warn); }
.bar.bad  { background: var(--bad); }
.bar-track { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); max-width: 160px; }

.pill {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.pill.ok   { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad  { background: color-mix(in srgb, var(--bad) 18%, transparent);  color: var(--bad); }

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* Attached bill documents */
.doc-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; font-size: 13px; color: var(--ink-2);
}
.doc-row span { flex: 1; }

/* Chart tooltip. Positioned against .chart-wrap, which is why that is relative. */
.chart-wrap { position: relative; }

.chart-tip {
  position: fixed; z-index: 60; pointer-events: none;
  min-width: 190px; padding: 9px 11px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(16,24,40,.14);
  font-size: 12.5px; line-height: 1.5;
  opacity: 0; transition: opacity .08s ease;
}
.chart-tip.on { opacity: 1; }
.chart-tip .tip-when { font-weight: 650; margin-bottom: 5px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 7px; }
.chart-tip .tip-row i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.chart-tip .tip-row span { flex: 1; color: var(--ink-2); }
.chart-tip .tip-row b { font-variant-numeric: tabular-nums; font-weight: 600; }
.chart-tip .tip-total {
  margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--line-soft);
  display: flex; gap: 7px;
}
.chart-tip .tip-total span { flex: 1; color: var(--ink-2); }
.chart-tip .tip-total b { font-variant-numeric: tabular-nums; }
/* Exported solar sits under the consumed total without its own rule, because it
   is a footnote to the figure above rather than a second total. */
.chart-tip .tip-sub { display: flex; gap: 7px; color: var(--ink-3); }
.chart-tip .tip-sub span { flex: 1; }
.chart-tip .tip-sub b { font-variant-numeric: tabular-nums; font-weight: 600; }
.chart-tip .tip-none { color: var(--ink-3); }
/* Sits above the figures: it changes how they should be read, so it has to be
   seen before them, not after. */
.chart-tip .tip-partial {
  margin-bottom: 4px; padding: 3px 6px; border-radius: 4px;
  background: var(--warn-bg, #fdf3e3); color: var(--warn-ink, #8a5a12);
  font-size: 11.5px;
}

.hover-band { fill: var(--ink); opacity: 0; }
.hover-band.on { opacity: .06; }

/* Live tile figures update in place, so they get a gentle transition instead of
   the whole tile being replaced. */
.tile-num { transition: color .25s ease; }

/* The staleness pill sits between the tiles and the chart card and was touching
   both; give it room of its own. */
#live-basis { display: flex; }
#live-basis .pill, #live-basis .tile-sub { margin: 2px 0 6px; }

/* The front page for anyone who arrives without access. Centred and roomy: it is
   a destination in its own right now, not an error squeezed into a corner. */
.card.locked { max-width: 520px; margin: 48px auto; text-align: center; padding: 32px 28px; }
.card.locked h2 { margin: 0 0 10px; }
.card.locked .note { margin: 0 0 20px; }
.card.locked a.btn { display: inline-block; text-decoration: none; }

/* ── day-of-week picker on a tariff band ───────────────────────────────────── */
.daypick { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.daypick-day { position: relative; cursor: pointer; user-select: none; }
.daypick-day input { position: absolute; opacity: 0; width: 0; height: 0; }
.daypick-day span {
  display: grid; place-items: center; width: 22px; height: 24px;
  border: 1px solid var(--line); border-radius: 5px;
  font-size: 11px; font-weight: 600; color: var(--ink-3); background: var(--surface);
}
.daypick-day input:checked + span {
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
}
.daypick-day input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.daypick-presets { display: flex; gap: 2px; margin-left: 4px; }
.daypick-presets .btn { padding: 3px 6px; font-size: 10.5px; line-height: 1; }

/* ── bill vs our meters ────────────────────────────────────────────────────── */
/* A number says how far apart they are; the bar says whether that is a lot. */
.xbar-track { width: 90px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.xbar { height: 100%; border-radius: 3px; background: var(--ink-3); transition: width .2s ease; }
.xbar.good { background: var(--good); }
.xbar.warn { background: var(--warn); }
.xbar.bad  { background: var(--bad); }
td.num.good { color: var(--good); }
td.num.warn { color: var(--warn); }
td.num.bad  { color: var(--bad); font-weight: 600; }

/* ── derived money ─────────────────────────────────────────────────────────── */
/* Read-only rather than disabled: the value still submits, and it stays legible
   instead of greying out to the point of looking absent. */
input.derived {
  background: var(--surface-2); border-color: transparent;
  color: var(--ink-2); font-weight: 600; cursor: default;
}
input.derived:focus { outline: none; }

.billtot {
  display: flex; gap: 12px; font-size: 13px;
  padding: 4px 0; color: var(--ink-2);
}
.billtot span { flex: 1; }
.billtot b { font-variant-numeric: tabular-nums; color: var(--ink); }
.billtot.grand {
  margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 15px; font-weight: 650; color: var(--ink);
}
.billtot.grand b { font-size: 17px; }
