:root {
  color-scheme: light;
  --surface-0: #f3f3f1;
  --surface-1: #ffffff;
  --surface-2: #f7f7f5;
  --border: #d4d4d0;
  --grid: #e6e6e3;
  --text-primary: #191919;
  --text-secondary: #666666;
  --input-yellow: #ffff99;
  --input-yellow-border: #d8d86a;
  --input-mt1: #dcebfb;
  --input-mt1-border: #8fb6e0;
  --header-bg: #eceae4;
  --accent: #257de0;
  --good: #0a7d23;
  --bad: #c62828;
  --warn-bg: #fff4d6;
  --err-bg: #fde7e7;
  /* chart series (reference palette, light steps) */
  --s-heat: #f47230;
  --s-dhw: #00b894;
  --s-cool: #257de0;
  --s-elec: #6a4ce2;
  --s-pv: #008a17;
  --s-pvself: #f2a600;
  --s-temp: #8a8a8a;
  --cls-A: #1a9641; --cls-B: #73c06b; --cls-C: #c4e687; --cls-D: #ffffbf;
  --cls-E: #fdc980; --cls-F: #f07c4a; --cls-G: #d7191c;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #121212; --surface-1: #191919; --surface-2: #202020;
    --border: #3a3a3a; --grid: #2c2c2c;
    --text-primary: #efefef; --text-secondary: #9c9c9c;
    --input-yellow: #4a4718; --input-yellow-border: #77722a;
    --input-mt1: #1b3450; --input-mt1-border: #3c6a9c;
    --header-bg: #262626; --accent: #338ced;
    --good: #4cc464; --bad: #ff6b6b; --warn-bg: #3a3014; --err-bg: #3d1c1c;
    --s-heat: #e76624; --s-dhw: #00a888; --s-cool: #338ced; --s-elec: #9887ef;
    --s-pv: #0aac23; --s-pvself: #d28e05; --s-temp: #8c8c8c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121212; --surface-1: #191919; --surface-2: #202020;
  --border: #3a3a3a; --grid: #2c2c2c;
  --text-primary: #efefef; --text-secondary: #9c9c9c;
  --input-yellow: #4a4718; --input-yellow-border: #77722a;
  --input-mt1: #1b3450; --input-mt1-border: #3c6a9c;
  --header-bg: #262626; --accent: #338ced;
  --good: #4cc464; --bad: #ff6b6b; --warn-bg: #3a3014; --err-bg: #3d1c1c;
  --s-heat: #e76624; --s-dhw: #00a888; --s-cool: #338ced; --s-elec: #9887ef;
  --s-pv: #0aac23; --s-pvself: #d28e05; --s-temp: #8c8c8c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--surface-0); color: var(--text-primary);
  font: 13px/1.35 "Segoe UI", Calibri, system-ui, -apple-system, sans-serif;
}
.layout { display: grid; grid-template-columns: 1fr 1fr; height: 100vh; }
.pane { overflow: auto; padding: 14px 16px 40px; }
.pane-left { background: var(--surface-1); border-right: 1px solid var(--border); }
.pane-right { background: var(--surface-0); }
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .pane { overflow: visible; }
}

h1 { font-size: 16px; margin: 0 0 2px; }
h2 { font-size: 13px; margin: 18px 0 6px; text-transform: none; }
.sub { color: var(--text-secondary); font-size: 12px; }
.legend-row { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 4px; font-size: 12px; color: var(--text-secondary); }
.swatch { display: inline-block; width: 14px; height: 12px; border: 1px solid var(--border); vertical-align: -2px; margin-right: 4px; }
.swatch.yellow { background: var(--input-yellow); border-color: var(--input-yellow-border); }
.swatch.mt1 { background: var(--input-mt1); border-color: var(--input-mt1-border); }

/* Excel-like grids */
table.xl { border-collapse: collapse; width: 100%; background: var(--surface-1); }
table.xl th, table.xl td { border: 1px solid var(--grid); padding: 2px 5px; vertical-align: middle; }
table.xl th { background: var(--header-bg); font-weight: 600; text-align: left; font-size: 12px; }
table.xl td.num, table.xl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.xl td.unit { color: var(--text-secondary); font-size: 11px; }
table.xl tr.sum td { font-weight: 600; background: var(--surface-2); }
table.xl td.in { padding: 0; }
table.xl td.lbl { white-space: nowrap; }
.mt1-head { background: var(--input-mt1) !important; }

input.cell, select.cell {
  width: 100%; min-width: 0; border: 0; padding: 3px 5px; font: inherit; color: var(--text-primary);
  background: var(--input-yellow); border-radius: 0; outline: none;
}
input.cell.num { text-align: right; font-variant-numeric: tabular-nums; }
input.cell.mt1, select.cell.mt1 { background: var(--input-mt1); }
input.cell:focus, select.cell:focus { box-shadow: inset 0 0 0 2px var(--accent); }
input.cell.invalid { box-shadow: inset 0 0 0 2px var(--bad); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }

/* results table */
table.res th.col { cursor: pointer; text-align: center; min-width: 108px; }
table.res th.col select.cell { font-size: 11px; padding: 2px 2px; }
table.res th.col.sel { background: var(--accent); color: #fff; }
table.res td.sel { background: color-mix(in srgb, var(--accent) 10%, transparent); }
table.res select.cell { font-weight: 600; }
.pass { color: var(--good); font-weight: 600; }
.fail { color: var(--bad); font-weight: 600; }
.cls-chip { display: inline-block; min-width: 22px; text-align: center; font-weight: 700; border-radius: 3px; color: #111; padding: 0 4px; }

/* messages */
.msg { border-radius: 4px; padding: 6px 10px; margin: 6px 0; font-size: 12px; }
.msg.err { background: var(--err-bg); }
.msg.warn { background: var(--warn-bg); }
.msg ul { margin: 2px 0 0 16px; padding: 0; }

/* right pane */
.topbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.status { font-size: 12px; color: var(--text-secondary); }
.status.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
button { font: inherit; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); border-radius: 4px; padding: 3px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; margin-bottom: 12px; }
.class-card { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.big-class { width: 86px; height: 86px; border-radius: 8px; display: grid; place-items: center; font-size: 52px; font-weight: 800; color: #111; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 14px; }
.kpi .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 11px; color: var(--text-secondary); }
.scale { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.scale-row { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.scale-bar { height: 15px; color: #111; font-weight: 700; padding-left: 5px; border-radius: 0 3px 3px 0; display: flex; align-items: center; }
.scale-row .marker { font-weight: 700; color: var(--text-primary); }

.chart { margin-bottom: 10px; }
.chart-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.chart-head .t { font-weight: 600; }
.chart-head .s { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.chart-wrap { position: relative; }
.chart-wrap canvas { display: block; width: 100%; }
.chart-wrap canvas.ov { position: absolute; inset: 0; pointer-events: none; }
.tip { position: absolute; top: 2px; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; display: none; }
.chart-legend { font-size: 11px; color: var(--text-secondary); display: flex; gap: 12px; }
.chart-legend i { display: inline-block; width: 12px; height: 3px; vertical-align: 3px; margin-right: 4px; border-radius: 2px; }

details.acc { background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 8px; }
details.acc > summary { cursor: pointer; padding: 8px 12px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 8px; }
details.acc > summary::after { content: "▸"; color: var(--text-secondary); }
details.acc[open] > summary::after { content: "▾"; }
details.acc .acc-body { padding: 0 12px 12px; }
pre.json { margin: 0; max-height: 520px; overflow: auto; background: var(--surface-2); border: 1px solid var(--grid); border-radius: 4px; padding: 8px; font: 11.5px/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre; }
.acc-tools { display: flex; gap: 6px; margin-bottom: 6px; }
.note { font-size: 11.5px; color: var(--text-secondary); }
table.mini { border-collapse: collapse; font-size: 12px; width: 100%; }
table.mini td, table.mini th { border-bottom: 1px solid var(--grid); padding: 3px 6px; text-align: left; }
table.mini td.num { text-align: right; font-variant-numeric: tabular-nums; }
