:root {
  --bg: #f4f5f7; --surface: #ffffff; --border: #e3e6eb; --border-strong: #d5d9e0; --text: #14171c;
  --muted: #5b6472; --accent: #1d4ed8; --now: #dc2626; --grid: #e8eaee;
  --charge: #1d4ed8; --solar: #d97706; --auto: #0f766e; --discharge: #c2410c; --hold: #6b7280; --idle: #d5d9e0;
  --use: #94a3b8; --sun: #f59e0b; --price: #8b6be6; --soc: #047857;
  --mono: ui-monospace, "IBM Plex Mono", SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #1a1d23; --border: #2a2f37; --border-strong: #3a404a; --text: #e8eaee;
    --muted: #a1a9b6; --accent: #6b8cff; --grid: #2a2f37; --idle: #3a404a; --hold: #8b93a0; --use: #64748b;
    --soc: #34d399; --price: #a78bfa;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h2 { margin: 0; font-size: 15px; font-weight: 600; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); font-size: 12px; }
.error { color: #b42318; }
hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 12px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.brand { display: flex; align-items: center; gap: 10px; flex-grow: 1; }
.brand strong { font-size: 18px; }
.chip { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; border-radius: 4px; padding: 3px 8px; }
.chip-shadow { color: #3b2f7a; background: #ece8fd; }
.chip-live { color: #064e3b; background: #d1fae5; }
.chip-sim { color: #7c2d12; background: #ffedd5; }
nav { display: flex; flex-wrap: wrap; gap: 4px; }
nav a { text-decoration: none; color: var(--muted); padding: 10px 14px; border-radius: 6px; }
nav a[aria-current="page"] { color: var(--text); background: var(--bg); font-weight: 600; }
.seg { gap: 0; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.seg a { border-radius: 0; padding: 8px 12px; }

main { max-width: 1400px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-width: 0; }
.pad { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 20px; }
.grid-2.tight { gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.head-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.head-row h2 { flex-grow: 1; }
.scroll-x { overflow-x: auto; }

.now-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 20px; }
@media (max-width: 900px) { .now-grid { grid-template-columns: 1fr; } }
.now-main { border-top: 4px solid var(--idle); }
.now-action { font-size: 26px; font-weight: 700; }
.now-reason { margin: 0; font-size: 15px; }
.c-charge_grid { border-top-color: var(--charge); } .c-store_solar { border-top-color: var(--solar); }
.c-discharge { border-top-color: var(--discharge); } .c-hold { border-top-color: var(--hold); }
.c-export_solar, .c-idle { border-top-color: var(--idle); } .c-offline, .c-no_plan { border-top-color: var(--now); }
.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: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.tile .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.tile .value { font-family: var(--mono); font-size: 24px; font-weight: 500; }
.socbar { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.socbar div { height: 6px; background: var(--soc); }

.btn { min-height: 40px; padding: 0 14px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 6px; font: inherit; font-weight: 500; cursor: pointer; }
.btn:hover { background: var(--bg); }
.btn-primary { border: 0; background: var(--accent); color: #fff; font-weight: 600; }
.btn-danger { border-color: #f1c3c3; color: #b42318; }
.form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.form .grid-2 { width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.field input, .field select { height: 40px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 0 10px; font: inherit; font-weight: 400; background: var(--surface); color: var(--text); }
.days { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.days legend { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.chk { display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 6px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child, td.text, th.text { text-align: left; }
td.reason { white-space: normal; min-width: 320px; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td { font-family: var(--mono); }
td.text { font-family: inherit; }
tr.total td { font-weight: 600; }
.log { max-height: 520px; overflow-y: auto; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 5px; margin-right: 6px; background: var(--idle); vertical-align: -1px; }
.dot.c-charge_grid { background: var(--charge); } .dot.c-store_solar { background: var(--solar); }
.dot.c-discharge { background: var(--discharge); } .dot.c-hold { background: var(--hold); }
.dot.c-offline, .dot.c-no_plan { background: var(--now); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -2px; margin-right: 5px; }
.ln { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--soc); vertical-align: 3px; margin-right: 5px; }
.ln.soc-plan { border-top-style: dashed; }

/* SVG-tijdlijn */
.chart-svg { display: block; font-family: system-ui, sans-serif; }
.chart-svg .lbl { fill: var(--muted); font-size: 11px; }
.chart-svg .lbl.small { font-size: 9px; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .day { stroke: var(--border-strong); stroke-width: 1; }
.chart-svg .now { stroke: var(--now); stroke-width: 2; }
.chart-svg .now-lbl { fill: var(--now); font-weight: 600; }
.chart-svg .price { fill: var(--price); }
.chart-svg .use, .sw.use { fill: var(--use); background: var(--use); }
.chart-svg .sun, .sw.sun { fill: var(--sun); background: var(--sun); }
.chart-svg .fc { opacity: .45; }
.sw.fc { background: var(--use); opacity: .45; }
.chart-svg .soc { fill: none; stroke: var(--soc); stroke-width: 2; }
.chart-svg .soc-plan { fill: none; stroke: var(--soc); stroke-width: 2; stroke-dasharray: 4 3; opacity: .8; }
.a-charge { fill: var(--charge); background: var(--charge); }
.a-solar { fill: var(--solar); background: var(--solar); }
.a-auto { fill: var(--auto); background: var(--auto); }
.a-discharge { fill: var(--discharge); background: var(--discharge); }
.a-hold { fill: var(--hold); background: var(--hold); }
.a-idle { fill: var(--idle); background: var(--idle); }
.a-off { fill: var(--now); background: var(--now); }
.login { max-width: 380px; width: 100%; margin: 40px auto; }
.login .form { align-items: stretch; }
