:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1d232a;
  --muted: #6b7380;
  --line: #e2ded6;
  --accent: #0f6e6e;      /* grid */
  --solar: #d98e04;       /* solar */
  --gas: #6a5acd;         /* gas */
  --warn: #b4441f;
  --side: #1b2a2f;
  --side-ink: #c9d4d6;
  --radius: 10px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-feature-settings: "tnum" 1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171a; --panel: #1a2125; --ink: #e6eaec; --muted: #8e9aa3; --line: #2a3338;
    --side: #0c1012; --side-ink: #a9b6ba;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; text-decoration: none; margin-bottom: 28px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: linear-gradient(135deg, var(--solar) 0 45%, var(--accent) 45%); }
.brand small { display: block; color: var(--side-ink); font-size: 12px; }
.nav-group h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d8d92; margin: 18px 8px 6px; }
.nav-group a { display: block; padding: 7px 10px; border-radius: 7px; color: var(--side-ink); text-decoration: none; font-size: 14px; }
.nav-group a:hover { background: rgba(255,255,255,.06); }
.nav-group a.active { background: rgba(15,110,110,.35); color: #fff; }
.content { padding: 28px 36px; max-width: 1400px; min-width: 0; }
.page-head h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.01em; }
.lede { color: var(--muted); margin: 0 0 22px; max-width: 80ch; }
h2 { font-size: 16px; margin: 28px 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 22px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.tile-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile-value { font-size: 30px; font-weight: 650; margin: 6px 0 4px; }
.tile-value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.tile-note { font-size: 13px; color: var(--muted); }
.tile.pending { border-style: dashed; background: transparent; }
.tile.pending .tile-value { color: var(--muted); }
.delta { font-weight: 600; color: var(--accent); }
.delta.up { color: var(--warn); }
.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 20px; }
.chart-card figcaption { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.chart { min-height: 380px; width: 100%; }
.chart .empty { color: var(--muted); padding: 40px; text-align: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.toolbar input, .toolbar select, .toolbar button { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.toolbar button { background: var(--accent); color: #fff; border: 0; padding: 6px 16px; cursor: pointer; }
.channels { border: 0; padding: 0; margin: 0; display: flex; gap: 12px; flex-wrap: wrap; }
.check { display: flex; gap: 5px; align-items: center; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
code { font-size: 12px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); white-space: nowrap; }
.badge.suspected_outage, .badge.gap { background: #f6d7cc; color: #7a2a10; }
.badge.step_change { background: #e5defa; color: #3b2d84; }
.u-legend { font-size: 13px; }
@media (max-width: 800px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .content { padding: 18px 16px; }
}
.num.warn { color: var(--warn); font-weight: 600; }

/* ---- Plant calendar ---------------------------------------------------- */
:root {
  --c-production: #2a8a7e; --c-weekend_catch_up: #e0a100; --c-breakdown: #c8402a;
  --c-planned_maintenance: #7a5cc4; --c-planned_shutdown: #8aa0b4; --c-unexplained_stop: #f07a2a;
  --c-idle_weekend: #dcd8cf; --c-no_data: transparent;
}
@media (prefers-color-scheme: dark) { :root { --c-idle_weekend: #2b3439; --c-planned_shutdown: #5c7286; } }
.years { display: flex; gap: 6px; margin-bottom: 14px; }
.years a { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 14px; }
.years a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.drawer { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; font-size: 14px; }
.drawer h2 { margin: 0 0 6px; } .drawer h3 { font-size: 14px; margin: 16px 0 6px; }
.heatmap { display: grid; grid-template-columns: 30px 1fr; grid-template-rows: auto auto; gap: 4px 6px; overflow-x: auto; }
.heatmap .months { grid-column: 2; display: grid; grid-template-columns: repeat(var(--weeks), 1fr); font-size: 11px; color: var(--muted); }
.heatmap .weekday-labels { display: grid; grid-template-rows: repeat(7, 1fr); font-size: 10px; color: var(--muted); }
.heatmap .grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); grid-template-columns: repeat(var(--weeks), 1fr); gap: 2px; min-width: 640px; }
.cell { aspect-ratio: 1; border: 0; border-radius: 2px; padding: 0; cursor: pointer; background: var(--c-no_data); outline: 1px solid var(--line); outline-offset: -1px; }
.cell.pad, .cell.empty { visibility: hidden; }
.cell:hover { outline: 2px solid var(--ink); }
.cell.overridden { box-shadow: inset 0 0 0 2px var(--ink); }
.cell.production, .swatch.production, .badge.production { background: var(--c-production); color: #fff; }
.cell.weekend_catch_up, .swatch.weekend_catch_up, .badge.weekend_catch_up { background: var(--c-weekend_catch_up); color: #1d232a; }
.cell.breakdown, .swatch.breakdown, .badge.breakdown { background: var(--c-breakdown); color: #fff; }
.cell.planned_maintenance, .swatch.planned_maintenance, .badge.planned_maintenance { background: var(--c-planned_maintenance); color: #fff; }
.cell.planned_shutdown, .swatch.planned_shutdown, .badge.planned_shutdown { background: var(--c-planned_shutdown); color: #fff; }
.cell.unexplained_stop, .swatch.unexplained_stop, .badge.unexplained_stop { background: var(--c-unexplained_stop); color: #fff; }
.cell.idle_weekend, .swatch.idle_weekend, .badge.idle_weekend { background: var(--c-idle_weekend); }
.cell.no_data { background: repeating-linear-gradient(45deg, transparent 0 2px, var(--line) 2px 3px); }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.legend strong { color: var(--ink); }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; outline: 1px solid var(--line); }
.swatch.no_data { background: repeating-linear-gradient(45deg, transparent 0 2px, var(--line) 2px 3px); }
.area-card { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.area-card h3 { margin: 0 0 6px; }
.small { font-size: 13px; margin: 4px 0; }
.override-note { color: var(--accent); }
.override-form { display: grid; gap: 6px; margin-top: 8px; }
.override-form select, .override-form input, .override-form button, button.secondary { font: inherit; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.override-form button { background: var(--accent); color: #fff; border: 0; cursor: pointer; }
button.secondary { cursor: pointer; margin: 4px 0; }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); margin-top: 6px; }
table.compact { font-size: 12px; } table.compact td, table.compact th { padding: 4px 6px; }
tr.clickable { cursor: pointer; } tr.clickable:hover { background: var(--bg); }
.flash { padding: 6px 10px; border-radius: 6px; font-size: 13px; }
.flash.ok { background: #d6efe9; color: #0b4d47; } .flash.error { background: #f6d7cc; color: #7a2a10; }
@media (max-width: 1100px) { .calendar-layout { grid-template-columns: 1fr; } .drawer { position: static; max-height: none; } }
.muted-row td { color: var(--muted); }
.warn-text { color: var(--warn); }
.signature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 16px; }
.chart.small-chart { min-height: 300px; }
.chart.mini-chart { min-height: 230px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.chart-grid.two { grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); }
.chart-grid > div { min-width: 0; }
.chart-grid h4 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.donuts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.donut { text-align: center; }
.donut svg { width: 100%; max-width: 200px; height: auto; color: var(--ink, #222); }
.donut h4 { margin: 0 0 6px; font-size: 13px; font-weight: 600; }
.donut ul { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
.donut .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
@media (max-width: 600px) { .signature-grid { grid-template-columns: 1fr; } }

/* ---- Energy flows ------------------------------------------------------- */
.flow-columns { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; }
.flow-row { display: grid; grid-template-columns: 200px 1fr 110px; gap: 10px; align-items: center; margin: 8px 0; font-size: 14px; }
.flow-track { background: var(--bg); border-radius: 4px; height: 18px; overflow: hidden; }
.flow-bar { height: 100%; border-radius: 4px; position: relative; display: flex; justify-content: flex-end; }
.flow-bar.grid, .flow-bar.consumer { background: var(--accent); }
.flow-bar.solar { background: var(--solar); }
.flow-bar.export { background: color-mix(in srgb, var(--solar) 45%, transparent); }
.flow-bar.gas { background: var(--gas); }
.flow-est { height: 100%; background: repeating-linear-gradient(45deg, rgba(255,255,255,.55) 0 3px, transparent 3px 6px); }
.flow-value { text-align: right; white-space: nowrap; }
@media (max-width: 1000px) { .flow-columns { grid-template-columns: 1fr; } .flow-row { grid-template-columns: 1fr; } }

/* ---- Opportunities ------------------------------------------------------ */
.opportunity-list { display: grid; gap: 10px; margin-bottom: 18px; }
.opportunity { display: grid; grid-template-columns: 36px 1fr 180px; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.op-rank { font-size: 22px; font-weight: 700; color: var(--muted); }
.op-head { display: flex; gap: 8px; align-items: center; }
.opportunity h3 { margin: 6px 0; font-size: 16px; }
.opportunity h3 a { color: var(--ink); text-decoration: none; }
.opportunity h3 a:hover { text-decoration: underline; }
.op-figures { text-align: right; font-size: 14px; display: grid; gap: 4px; align-content: start; }
.op-figures strong { font-size: 18px; }
.confidence { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.confidence.high { background: #d6efe9; color: #0b4d47; }
.confidence.medium { background: #fbecc9; color: #6b4a00; }
.confidence.low { background: #ececec; color: #555; }
@media (max-width: 700px) { .opportunity { grid-template-columns: 1fr; } .op-figures { text-align: left; } }

/* ---- Scenarios ---------------------------------------------------------- */
.button-row { display: flex; gap: 10px; align-items: center; margin: 12px 0 16px; }
.button-row button, .scenario-form button[type=submit] { font: inherit; padding: 6px 14px; border-radius: 6px; border: 0; background: var(--accent); color: #fff; cursor: pointer; }
.levers { margin: 0; padding-left: 18px; font-size: 13px; }
.scenario-form { display: grid; gap: 12px; margin-top: 12px; font-size: 14px; }
.scenario-form fieldset { border: 1px solid var(--line); border-radius: 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 14px; padding: 10px 12px; }
.scenario-form legend { font-weight: 600; padding: 0 4px; }
.scenario-form label { display: grid; gap: 3px; font-size: 13px; color: var(--muted); }
.scenario-form label:has(input[type=checkbox]) { display: flex; gap: 6px; align-items: center; color: var(--ink); }
.scenario-form input, .scenario-form select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.scenario-form .wide input { max-width: 480px; }
td.good { color: var(--accent); font-weight: 600; }
.badge.status-simulated { background: #d6efe9; color: #0b4d47; }
.badge.status-draft { background: #fbecc9; color: #6b4a00; }
.htmx-indicator { display: none; } .htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
a.button { display: inline-block; font: inherit; padding: 6px 14px; border-radius: 6px; text-decoration: none; }
a.button.secondary, .button-row button.secondary { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }

/* ---- Login & account ---------------------------------------------------- */
.login-body { display: grid; place-items: center; grid-template-columns: 1fr; background: var(--side); }
.login-card { background: var(--panel); border-radius: 12px; padding: 28px; width: min(380px, calc(100vw - 32px)); }
.login-card .brand { color: var(--ink); margin-bottom: 20px; display: flex; gap: 10px; align-items: center; }
.login-card .brand small { display: block; color: var(--muted); }
.login-card form, .stack-form { display: grid; gap: 12px; max-width: 420px; }
.login-card label, .stack-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input, .stack-form input, .stack-form select, .inline-form input { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.login-card button, .stack-form button { font: inherit; padding: 8px 14px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
.sidebar-user { position: absolute; bottom: 18px; left: 14px; right: 14px; font-size: 13px; }
.me { display: grid; gap: 6px; border-top: 1px solid rgba(255,255,255,.1); padding-top: 12px; }
.me strong { color: #fff; }
.me a, .me button.link { color: var(--side-ink); text-align: left; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input { padding: 4px 6px; width: 150px; }
@media (max-width: 800px) { .sidebar-user { position: static; margin-top: 16px; } }

.zone-green, .zone-yellow, .zone-red { padding: 0 .4em; border-radius: 3px; white-space: nowrap; }
.zone-green { background: #d6efe0; color: #135a32; }
.zone-yellow { background: #fbf0c4; color: #6b5300; }
.zone-red { background: #f6d7cc; color: #7a2a10; }

.lang-switch { display: flex; gap: .6em; padding: .4rem 1rem; font-size: .85rem; }
.lang-switch a { color: inherit; opacity: .7; }
.lang-switch strong { opacity: 1; }

.svg-chart svg { width: 100%; height: auto; max-height: 340px; color: var(--ink, #222); }
.svg-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 1rem; padding: 0; margin: .3rem 0 0; font-size: .85rem; }
.svg-legend .swatch { display: inline-block; width: .8em; height: .8em; margin-right: .35em; vertical-align: -0.05em; }

/* Heat maps (steam per quality): one sequential blue ramp, light = low. Dark mode has its own
   steps, low = near the surface. Text switches to light ink where the fill is dark. */
.heat-map { border-collapse: separate; border-spacing: 2px; }
.heat-map td { border-radius: 3px; padding: 4px 6px; min-width: 3.2em; }
.heat-map td small { opacity: 0.85; }
.heat-hours td { min-width: 2.1em; padding: 3px 2px; font-size: 0.8em; }
.heat-1 { background: #cde2fb; color: #1d2329; }
.heat-2 { background: #9ec5f4; color: #1d2329; }
.heat-3 { background: #6da7ec; color: #1d2329; }
.heat-4 { background: #3987e5; color: #10161b; }
.heat-5 { background: #256abf; color: #fff; }
.heat-6 { background: #184f95; color: #fff; }
.heat-7 { background: #0d366b; color: #fff; }
.heat-thin { background: repeating-linear-gradient(45deg, var(--line) 0 3px, transparent 3px 7px); color: var(--muted); }
.heat-legend { display: flex; gap: 2px; align-items: center; font-size: 0.85em; margin: 0.4em 0 1em; }
.heat-legend .muted { margin: 0 0.4em; }
.heat-swatch { width: 22px; height: 12px; border-radius: 2px; display: inline-block; }
p.warning { border-left: 3px solid var(--solar); padding: 0.5em 0.9em; background: var(--panel); }
@media (prefers-color-scheme: dark) {
  .heat-1 { background: #104281; color: #e6eaec; }
  .heat-2 { background: #184f95; color: #e6eaec; }
  .heat-3 { background: #1c5cab; color: #fff; }
  .heat-4 { background: #2a78d6; color: #fff; }
  .heat-5 { background: #5598e7; color: #10161b; }
  .heat-6 { background: #86b6ef; color: #10161b; }
  .heat-7 { background: #b7d3f6; color: #10161b; }
}
/* Uniform time series: dense table, flagged labels stand out. */
table.timeseries { font-size: 12px; }
table.timeseries th, table.timeseries td { white-space: nowrap; }
table.timeseries thead th { position: sticky; top: 0; background: var(--panel); }
table.timeseries th.fallback, table.timeseries td.fallback { background: #fbf1d9; }
.badge.flag { background: #f6e3b4; color: #6b4a00; }
