/* Lime green on dark blue.
   --accent is the lime fill (buttons, borders, focus rings: >= 3:1 against the page; navy text on it >= 4.5:1).
   --accent-fill is the bright lime behind primary buttons (always with navy text).
   --accent-text is for links and icons, which need text contrast: bright lime on white fails, so light mode darkens it.
   Chart series (off-peak / peak / solar / battery) are validated for colour-blind separation and contrast
   against --surface in both themes - change them only after re-running the dataviz palette validator. */
:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #e9eef7;
  --border: #d6deec;
  --grid: #e4eaf4;
  --text: #0b1f3a;
  --text-2: #3c4f6e;
  --muted: #5b6b88;
  --accent: #5c970b;
  --accent-fill: #a3e635;
  --accent-ink: #0b1f3a;
  --accent-text: #3f6212;
  --brand: #0b1f3a;

  --series-offpeak: #2a78d6;
  --series-peak: #eb6834;
  --series-solar: #1baf7a;
  --series-battery: #eda100;
  --series-muted: #b3bfd4;

  --good: #0ca30c;
  --critical: #d03b3b;

  --radius: 16px;
  --shadow: 0 1px 2px rgb(11 31 58 / 0.06), 0 4px 16px rgb(11 31 58 / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a1628;
    --surface: #112240;
    --surface-2: #1a2f52;
    --border: #243b63;
    --grid: #1d3358;
    --text: #ffffff;
    --text-2: #d0dcf0;
    --muted: #93a7c6;
    --accent: #a3e635;
    --accent-fill: #a3e635;
    --accent-ink: #0a1628;
    --accent-text: #a3e635;
    --brand: #a3e635;
    --series-offpeak: #3987e5;
    --series-peak: #d95926;
    --series-solar: #199e70;
    --series-battery: #c98500;
    --series-muted: #3a4d70;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1628;
  --surface: #112240;
  --surface-2: #1a2f52;
  --border: #243b63;
  --grid: #1d3358;
  --text: #ffffff;
  --text-2: #d0dcf0;
  --muted: #93a7c6;
  --accent: #a3e635;
  --accent-fill: #a3e635;
  --accent-ink: #0a1628;
  --accent-text: #a3e635;
  --brand: #a3e635;
  --series-offpeak: #3987e5;
  --series-peak: #d95926;
  --series-solar: #199e70;
  --series-battery: #c98500;
  --series-muted: #3a4d70;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
/* Served from this site (vendor/fonts, copied by `npm run vendor`): the CSP allows no third-party fonts. */
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(../vendor/fonts/plus-jakarta-sans-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(../vendor/fonts/plus-jakarta-sans-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.4rem, 3.5vw, 2rem); font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0.25rem 0 0; }
.muted { color: var(--muted); }
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar & tabs ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  max-width: 1200px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; letter-spacing: -0.01em; }
.brand strong { font-weight: 800; color: var(--accent-text); }
.brand-mark { width: 32px; height: 32px; flex: none; color: var(--accent-text); }
.brand-name { font-weight: 600; letter-spacing: -0.02em; }
.brand-tagline { font-size: 0.8rem; color: var(--muted); padding-left: 10px; border-left: 1px solid var(--border); }
.brand-name { white-space: nowrap; }
@media (max-width: 960px) { .brand-tagline { display: none; } } /* room for the top-bar buttons on tablets */
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: end; margin-left: auto; }
.topbar #theme-toggle { flex: none; }

/* Feedback email link: full label on wide screens, "Feedback" on tablets, icon only on phones. */
.feedback-link { display: inline-flex; align-items: center; gap: 6px; flex: none; text-decoration: none; color: inherit; white-space: nowrap; }
.feedback-link svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.feedback-short { display: none; }
@media (max-width: 1180px) {
  .feedback-long { display: none; }
  .feedback-short { display: inline; }
}

/* "Data" menu: storage status, backup and restore (in-browser backend only). */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: " ▾"; font-size: 0.75em; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  width: min(300px, calc(100vw - 32px)); display: grid; gap: 8px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.menu-panel .btn { width: 100%; text-align: left; border-radius: 10px; }
.menu-heading {
  margin: 6px 0 0; padding-top: 12px; border-top: 1px solid var(--grid);
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.menu-group { display: grid; gap: 8px; }

/* First-run panel, shown on Overview until a bill is imported. */
.empty-state {
  max-width: 560px; margin: clamp(16px, 8vh, 72px) auto; padding: 36px 28px;
  display: grid; justify-items: center; gap: 12px; text-align: center;
}
.empty-state h1 { font-size: clamp(1.3rem, 3.5vw, 1.7rem); }
.empty-state p { margin: 0; max-width: 46ch; }
.empty-icon { width: 48px; height: 48px; color: var(--accent-text); }
.welcome .empty-state { margin-bottom: 32px; }

/* Supplier logos inside the import panel. */
.suppliers { width: 100%; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--grid); display: grid; gap: 10px; justify-items: center; }
.suppliers-title { margin: 0; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.supplier-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.supplier { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; line-height: 0; }
.supplier img { display: block; width: 88px; height: 64px; object-fit: cover; }

/* Feature tiles under the first-run panel. */
.features { margin-bottom: 16px; }
.features h2 { text-align: center; margin-bottom: 14px; }
.feature-grid {
  list-style: none; margin: 0; padding: 0;
  /* Columns of at least 300px: three on desktop, two on tablets, one on phones, so six tiles fill evenly. */
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 12px;
}
.feature { display: grid; align-content: start; gap: 6px; }
/* The privacy promise: a full-width banner between the import panel and the feature tiles. */
.feature.feature-wide {
  grid-template-columns: auto 1fr; column-gap: 14px; align-items: center;
  border-color: var(--accent); margin-bottom: 32px;
}
.feature.feature-wide svg { grid-row: span 2; margin-bottom: 0; }
.feature svg {
  width: 40px; height: 40px; padding: 8px; border-radius: 12px; margin-bottom: 4px;
  background: var(--surface-2); color: var(--accent-text);
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.feature h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.feature p { margin: 0; font-size: 0.88rem; color: var(--text-2); }
.btn.btn-accent { background: var(--accent-fill); border-color: var(--accent); color: var(--accent-ink); padding: 11px 22px; font-size: 0.95rem; }
.btn.btn-accent:hover { filter: brightness(1.08); }
.btn.btn-outline { background: transparent; border: 2px solid var(--accent); color: var(--text); padding: 9px 20px; font-size: 0.95rem; }
.btn.btn-outline:hover { background: var(--surface-2); }
.empty-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 14px; margin-top: 8px; }
.empty-or { color: var(--muted); font-size: 0.9rem; }
@media (max-width: 480px) {
  .empty-actions { flex-direction: column; gap: 6px; }
  .empty-actions .btn { width: 100%; max-width: 260px; }
}
#features-title { scroll-margin-top: 72px; } /* clear the sticky tab bar */
#features-title:focus { outline: none; }
.status a { color: var(--accent-text); font-weight: 600; }

/* Shown while files are dragged over the page. */
body.dragging main { outline: 3px dashed var(--accent); outline-offset: -6px; border-radius: 16px; }

.tabs {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  padding: 8px 16px; margin: 0 auto; max-width: 1200px;
  background: var(--bg);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 8px 14px; border-radius: 999px;
  color: var(--text-2); text-decoration: none; font-weight: 600; font-size: 0.92rem;
}
.tabs a:hover { background: var(--surface-2); }
.tabs a[aria-current="page"] { background: var(--text); color: var(--bg); }

main { max-width: 1200px; margin: 0 auto; padding: 8px 16px 32px; }
.view { display: grid; gap: 16px; }
.view-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; padding: 8px 0 4px; }

/* ---------- buttons & fields ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 0.88rem;
}
.btn:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-icon { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; }
.btn-icon svg { width: 18px; height: 18px; }
.btn:disabled { opacity: 0.6; cursor: progress; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 999px;
  font-weight: 600; font-size: 0.85rem; color: var(--text-2); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.field { display: grid; gap: 6px; font-size: 0.88rem; font-weight: 600; color: var(--text-2); }
.field output { float: right; color: var(--text); }
.field input[type="number"], .field-inline select {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); font-weight: 500;
}
.field input:focus-visible, .field-inline select:focus-visible, .btn:focus-visible,
.seg button:focus-visible, .tabs a:focus-visible, input[type="range"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field input[type="text"], .field input[type="time"] {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); font-weight: 500;
}
.field input[type="text"]:focus-visible, .field input[type="time"]:focus-visible, .check input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.check { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.compare-fields { border: 0; padding: 0; margin: 0; display: grid; gap: 14px; min-width: 0; }
.compare-fields:disabled { display: none; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
tr.best td { font-weight: 700; }

/* ---------- configurations ---------- */
.field select {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); font-weight: 600;
}
.field select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.config-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.config-actions .btn { flex: 1; }
.btn-danger:hover { border-color: var(--critical); color: var(--critical); }
.pill {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 0.72rem; font-weight: 700; vertical-align: middle;
}
#configs-table tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.link-btn {
  border: 0; background: none; padding: 0; font: inherit; color: var(--accent-text); cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#cost-config-name { font-weight: 500; font-size: 0.9rem; }

/* ---------- install cost line items ---------- */
.cost-list { display: grid; gap: 8px; }
.cost-row, .cost-head {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: minmax(0, 1fr) 104px 72px 112px 96px 36px;
}
.cost-head { font-size: 0.78rem; font-weight: 600; color: var(--muted); padding: 0 2px; }
.cost-head span:nth-child(n+3) { text-align: right; }
.cost-row input, .cost-row select {
  width: 100%; min-width: 0; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); font-weight: 500;
}
.cost-row input[type="number"] { text-align: right; }
.cost-row input:focus-visible, .cost-row select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cost-row input[aria-invalid="true"] { border-color: var(--critical); }
.cost-line { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.cost-del, .cost-open { width: 36px; height: 36px; border-radius: 10px; color: inherit; }
.cost-del svg, .cost-open svg { width: 16px; height: 16px; }
.cost-row .c-url { grid-column: 1 / 6; font-size: 0.85rem; padding: 6px 10px; }
.cost-row { padding-bottom: 10px; border-bottom: 1px solid var(--grid); }
.cost-row:last-child { border-bottom: 0; }
.cost-empty { color: var(--muted); font-size: 0.9rem; padding: 8px 0; }
.cost-totals { display: flex; justify-content: flex-end; gap: 24px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--grid); font-size: 0.9rem; color: var(--text-2); }
.cost-totals strong { color: var(--text); font-size: 1.05rem; margin-left: 6px; }
input[readonly] { opacity: 0.75; cursor: not-allowed; }

@media (max-width: 640px) {
  .cost-head { display: none; }
  .cost-row {
    grid-template-columns: 1fr 1fr 36px;
    grid-template-areas: "name name del" "cat qty qty" "unit line line" "url url open";
    padding: 10px; border: 1px solid var(--grid); border-radius: 12px;
  }
  .cost-row:last-child { border-bottom: 1px solid var(--grid); }
  .cost-row .c-name { grid-area: name; } .cost-row .c-cat { grid-area: cat; }
  .cost-row .c-qty { grid-area: qty; } .cost-row .c-unit { grid-area: unit; }
  .cost-row .cost-line { grid-area: line; } .cost-row .cost-del { grid-area: del; }
  .cost-row .c-url { grid-area: url; } .cost-row .cost-open { grid-area: open; }
}
.field-inline { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 600; color: var(--text-2); }
.field-inline select { width: auto; padding: 6px 10px; }
.hint { font-size: 0.85rem; color: var(--muted); }
.hint:empty { display: none; }

/* ---------- cards, tiles ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head p { font-size: 0.85rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.tile-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; overflow-wrap: anywhere; }
.tile-sub { font-size: 0.8rem; color: var(--text-2); margin-top: 2px; }
.tile.hero { background: var(--text); color: var(--bg); border-color: transparent; }
.tile.hero .tile-label, .tile.hero .tile-sub { color: inherit; opacity: 0.8; }
/* Hero figure scales with its tile so "4.8 years" stays on one line in a narrow tile. */
.tile.hero { container-type: inline-size; }
.tile.hero .tile-value { font-size: clamp(1.6rem, 16cqi, 2.5rem); white-space: nowrap; overflow-wrap: normal; }
.delta-good::before { content: "▲ "; color: var(--good); }
.delta-bad::before { content: "▼ "; color: var(--critical); }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 360px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }

.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: baseline; }

/* ---------- planner layout ---------- */
.planner { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: 16px; align-items: start; }
.inputs { display: grid; gap: 14px; }
.inputs h2:not(:first-child) { margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--grid); }
.results { display: grid; gap: 16px; min-width: 0; }

.status {
  padding: 12px 16px; border-radius: 12px; background: var(--surface-2); color: var(--text-2);
  margin-bottom: 16px; font-size: 0.9rem; white-space: pre-line; /* import results list one failed file per line */
}
.status.error { border-left: 4px solid var(--critical); }

.foot { text-align: center; font-size: 0.8rem; padding: 16px; }
.foot p { margin: 0 0 4px; }
.foot .disclaimer { max-width: 70ch; margin-inline: auto; font-size: 0.75rem; }
.foot a { color: var(--accent-text); font-weight: 600; }

@media (max-width: 820px) {
  .planner { grid-template-columns: 1fr; }
  .chart-box { height: 260px; }
  .chart-box.tall { height: 300px; }
  .tile-value { font-size: 1.35rem; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 10px; }
  .topbar-actions .btn-ghost { padding: 7px 10px; }
}
@media (max-width: 720px) {
  /* Logo, feedback and theme buttons on the first row, data controls on the second. */
  .topbar { flex-wrap: wrap; }
  .topbar #theme-toggle { order: 1; }
  /* Icon-only beside the theme button, so the data controls keep the second row to themselves. */
  .topbar .feedback-link { order: 1; margin-left: auto; width: 38px; height: 38px; padding: 0; justify-content: center; }
  .feedback-short { display: none; }
  .topbar-actions { order: 2; width: 100%; justify-content: flex-start; gap: 6px; flex-wrap: nowrap; }
  .topbar-actions .menu { margin-left: auto; }
  .topbar-actions .seg button { padding: 5px 9px; white-space: nowrap; }
  .topbar-actions .btn-ghost { padding: 7px 10px; white-space: nowrap; }
  .menu-panel { position: fixed; left: 16px; right: 16px; top: auto; width: auto; margin-top: 6px; }
}
#configs-table td:first-child { white-space: normal; min-width: 160px; }
