:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #16202e;
  --muted: #5b6878;
  --border: #e1e6ed;
  --primary: #1d4ed8;
  --primary-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --warn: #b45309;
  --warn-bg: #fff8eb;
  --bad: #c62828;
  --bad-bg: #fdf0f0;
  --info: #1d4ed8;
  --info-bg: #eef4ff;
  --l1: #2563eb;
  --l2: #d97706;
  --l3: #059669;
  --s1: #7c3aed;
  --s2: #0891b2;
  --s3: #db2777;
  --s4: #a16207;
  --s5: #4f46e5;
  --s6: #65a30d;
  --rest: #94a3b8;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1f2833;
    --text: #e6ebf1;
    --muted: #93a0b1;
    --border: #2b3542;
    --primary: #4f80f0;
    --ok: #4ade80;
    --ok-bg: #12261a;
    --warn: #fbbf24;
    --warn-bg: #2a2111;
    --bad: #f87171;
    --bad-bg: #2c1717;
    --info: #7aa2f7;
    --info-bg: #172036;
    --l1: #60a5fa;
    --l2: #fbbf24;
    --l3: #34d399;
    --s1: #a78bfa;
    --s2: #22d3ee;
    --s3: #f472b6;
    --s4: #d4a54a;
    --s5: #818cf8;
    --s6: #a3e635;
    --rest: #64748b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0.2rem 0; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Topbalk */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem max(16px, calc((100vw - 1140px) / 2));
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: var(--text); text-decoration: none; font-weight: 700; }
.brand svg { color: var(--primary); }
.brand small { font-weight: 500; color: var(--muted); margin-left: 0.25rem; }
nav { display: flex; gap: 1.25rem; align-items: center; }
nav a, .link { color: var(--muted); text-decoration: none; font-weight: 500; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
nav a.active, nav a:hover, .link:hover { color: var(--text); }

.container { max-width: 1140px; margin: 0 auto; padding: 1.5rem 16px 4rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: 0.25rem 0 0; }
.back { font-size: 0.9rem; text-decoration: none; }

/* Kaarten */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 420px; margin: 3rem auto; }
.empty { text-align: center; padding: 2.5rem 1.25rem; }

/* Knoppen */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1rem; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn.danger-outline { color: var(--bad); border-color: currentColor; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Formulieren */
.stack { display: flex; flex-direction: column; gap: 1rem; }
fieldset { border: 0; padding: 0; margin: 0 0 0.5rem; display: flex; flex-direction: column; gap: 0.9rem; }
legend { font-weight: 700; font-size: 1.05rem; margin-bottom: 0.75rem; }
label, .label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 500; font-size: 0.9rem; }
label.inline { flex-direction: row; align-items: center; gap: 0.5rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.65rem; width: 100%;
}
label.inline select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.grid2, .grid3 { display: grid; gap: 0.9rem; }
.grid2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: start; }
.preview { margin: 0; padding: 0.6rem 0.8rem; background: var(--surface-2); border-radius: 8px; }
.search { margin-bottom: 0.75rem; max-width: 420px; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented label { flex-direction: row; font-weight: 600; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { padding: 0.4rem 0.9rem; border-radius: 7px; color: var(--muted); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); }
.segmented.small span { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

.copy-row { display: flex; gap: 0.5rem; }
.copy-row input { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.65rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover, .table.clickable tbody tr:focus { background: var(--surface-2); outline: none; }
.table tr.current td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.table tr.recommended td { background: var(--ok-bg); }

.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; }
.tag.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }

.pill { display: inline-block; font-size: 0.8rem; font-weight: 700; padding: 0.15rem 0.6rem; border-radius: 99px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.soft { font-weight: 500; }

.meter { display: inline-block; width: 64px; height: 6px; border-radius: 3px; background: var(--surface-2); margin-right: 0.5rem; vertical-align: middle; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 3px; }
.meter.ok span { background: var(--ok); }
.meter.warn span { background: var(--warn); }
.meter.bad span { background: var(--bad); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.4rem; vertical-align: middle; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.stale { background: var(--warn); }
.dot.idle { background: var(--border); }

/* Advies */
.controls { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.verdict { border-radius: var(--radius); padding: 1.25rem 1.4rem; margin: 0.75rem 0 1rem; border: 1px solid transparent; }
.verdict h2 { font-size: 1.4rem; margin: 0.15rem 0 0.4rem; }
.verdict p { margin: 0.25rem 0; }
.verdict-label { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.verdict.ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.verdict.ok .verdict-label, .verdict.ok h2 { color: var(--ok); }
.verdict.neutral { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.verdict.neutral .verdict-label, .verdict.neutral h2 { color: var(--info); }
.verdict.bad { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.verdict.bad .verdict-label, .verdict.bad h2 { color: var(--bad); }
.savings { font-size: 1.05rem; }

.notice { border-radius: 10px; padding: 0.8rem 1rem; margin: 0 0 1rem; }
.notice ul { margin: 0; padding-left: 1.2rem; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.warn { background: var(--warn-bg); color: var(--text); border-left: 4px solid var(--warn); }
.notice.info { background: var(--info-bg); color: var(--text); border-left: 4px solid var(--info); }

.stats { display: grid; gap: 1rem; margin-bottom: 0; }
.stats.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats.one { grid-template-columns: minmax(240px, 420px); }
.stat { border-top: 4px solid var(--accent); }
.stat-head { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.stat-main { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-main small { font-size: 1rem; color: var(--muted); font-weight: 500; }
.stat dl { margin: 0.75rem 0 0; display: grid; gap: 0.2rem; }
.stat dl div { display: flex; justify-content: space-between; font-size: 0.9rem; }
.stat dt { color: var(--muted); }
.stat dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

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

/* Deelmetingen */
h3 { font-size: 1rem; margin: 0; }
.split { display: grid; gap: 0.5rem; margin: 0.75rem 0 1rem; }
.split-row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr auto; gap: 0.75rem; align-items: center; }
.split-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-bar { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.split-bar span { display: block; height: 100%; border-radius: 6px; }
.split-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.swatch.inline { display: inline-block; margin-right: 0.45rem; vertical-align: middle; }
.origin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1.25rem 0 0.5rem; }
.meter-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.meter-head h2 { margin-bottom: 0.15rem; }
.meter-head p { margin: 0; }

/* Batterij */
#battery-section h3 { margin: 1.25rem 0 0.5rem; }
.battery-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin: 0 0 0.75rem; }
.kpis div { background: var(--surface-2); border-radius: 10px; padding: 0.6rem 0.8rem; display: flex; flex-direction: column; }
.kpis span { font-size: 0.8rem; color: var(--muted); }
.kpis strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }

/* Shelly */
.steps { padding-left: 1.2rem; margin: 0 0 1rem; }
.steps li { margin-bottom: 0.3rem; }
.code-block { position: relative; }
.code-block pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; overflow-x: auto; font-size: 0.8rem; line-height: 1.45; margin: 0.5rem 0; }
.code-block .copy { position: absolute; top: 0.5rem; right: 0.5rem; }
details { margin: 1rem 0; }
summary { cursor: pointer; font-weight: 600; }

.tariff-table td, .tariff-table th { padding: 0.4rem 0.5rem; }
.tariff-table input { min-width: 90px; text-align: right; padding: 0.35rem 0.5rem; }

#toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.6rem 1.1rem; border-radius: 10px;
  font-weight: 600; box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); z-index: 50; max-width: calc(100vw - 32px);
}
#toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .brand small { display: none; }
  nav { gap: 0.9rem; }
  h1 { font-size: 1.35rem; }
  .table th, .table td { padding: 0.55rem 0.6rem; }
  .chart-box.tall { height: 300px; }
  .split-row { grid-template-columns: 1fr auto; }
  .split-bar { grid-column: 1 / -1; grid-row: 2; }
}

@media print {
  :root { --bg: #fff; --surface: #fff; }
  .topbar nav, .no-print, #toast { display: none !important; }
  .topbar { position: static; }
  .card, .verdict { break-inside: avoid; box-shadow: none; }
  .container { padding-top: 0.5rem; }
}
.lead-msg { max-width: 360px; white-space: pre-wrap; color: var(--muted); margin-top: 0.25rem; }

/* Uitklapmenu (gegevens downloaden) */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: " ▾"; }
.menu-items { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; box-shadow: 0 10px 30px rgb(0 0 0 / 0.15); display: grid; gap: 0.5rem; width: 260px; }
.menu-items p { margin: 0; }
nav[hidden] { display: none; }
@media (max-width: 640px) {
  .menu-items { left: 0; right: auto; width: min(260px, calc(100vw - 32px)); }
}
/* Knoppenrij: alle knoppen (ook het uitklapmenu) even hoog en verticaal gecentreerd */
.actions { align-items: center; }
.menu > summary.btn { height: 100%; }
.member-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 16px; max-height: 320px; overflow: auto; padding: 4px; }
.member-pick .check { flex-direction: row; align-items: flex-start; gap: 0.5rem; font-weight: 400; }
.member-pick input { width: auto; margin-top: 0.3rem; }
.group-kpis { margin-top: 0.5rem; }
.group-kpis strong small { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
