/* Colour system — Voratide brand (same tokens as www.voratide.com, dark mode)
   - warm near-black neutrals for every surface and all text
   - Voratide gold for the brand mark, links, focus and selection
   - the primary action is a cream pill with navy text (www's .btn-fill)
   - data colours, muted, one meaning each, used the same everywhere
   - status colours only where something needs attention; "fine" stays neutral
   (app.js / results.js read the same values from THEME in shared.js) */
:root {
  --bg: #0f1116;
  --panel-bg: #14171d;
  --card-bg: #1a1d24;
  --input-bg: #1f232b;
  --surface-3: #282c35;
  --border: #2a2e37;
  --border-soft: #21242b;
  --text: #ede9e0;
  --text-dim: #a29e96;
  --text-faint: #6f6b64;

  --accent: #d4af37;
  --accent-strong: #d4af37;
  --accent-hover: #e5c158;
  --accent-text: #e5c158;
  --accent-soft: rgba(212, 175, 55, 0.1);
  --accent-soft-2: rgba(212, 175, 55, 0.2);
  --accent-line: rgba(212, 175, 55, 0.45);

  /* brand */
  --gold: #d4af37;
  --gold-dark: #b8962e;
  --navy: #1a1d23;
  --cream: #fafaf7;
  --parchment: #f0ede6;
  --font-h: "Playfair Display", Georgia, serif;
  --font-b: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --c-solar: #d4a94a;
  --c-battery: #3e9e96;
  --c-grid: #8e98aa;
  --c-load: #7a9cc9;
  --c-inverter: #b9c0cb;

  --ok: #5da880;
  --warn: #d08a3e;
  --bad: #d65f5a;
  --warn-soft: rgba(208, 138, 62, 0.1);
  --warn-line: rgba(208, 138, 62, 0.4);

  --accent2: var(--ok);
  --danger: var(--bad);
  --radius: 10px;
  --gap: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-b);
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* the columns scroll, not the page */
}
button, input, select { font-family: inherit; }
.hint { font-size: 13px; color: var(--text-dim); line-height: 1.45; margin: 6px 0; }

/* --- top bar --- */
.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 18px; }
.topbar h1 { margin: 0; font-size: 18px; letter-spacing: 0.01em; }
.tag {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
}
.sub { margin: 0; color: var(--text-dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- three-column layout filling the window --- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 400px;
  gap: var(--gap);
  padding: var(--gap);
}
.sidebar, .results {
  min-height: 0;
  overflow-y: auto;
}
.sidebar { display: flex; flex-direction: column; gap: var(--gap); }

.card, .results {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card h2, .results h2, .props h2 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

/* --- component palette: compact tiles --- */
.palette-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13.5px;
  line-height: 1.25;
  text-align: center;
  transition: border-color 0.15s, transform 0.1s;
}
.palette-item .pi-icon { font-size: 22px; }
.palette-item:hover { border-color: var(--accent); }
.palette-item:active { transform: scale(0.97); }
.palette-item:last-child:nth-child(odd) { grid-column: span 2; flex-direction: row; justify-content: center; gap: 8px; }

.howto { margin-top: 10px; }
.howto summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
}
.howto summary:hover { color: var(--text); }

/* --- form fields (site + properties) --- */
.site { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.site label, .props label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
}
.site input, .site select, .props input, .props select {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 7px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13.5px;
  color-scheme: dark;
}
.site input:focus, .site select:focus, .props input:focus, .props select:focus {
  outline: none;
  border-color: var(--accent);
}

/* --- centre column: sky, canvas, transport --- */
.canvas-wrap {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stage-area { position: relative; flex: 1; min-height: 300px; overflow: hidden; }
/* the circuit canvas is transparent so the sky shows through; faint dot grid on top */
#stage-container {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 22px 22px;
}

.zoom-controls {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  gap: 4px;
  z-index: 3;
}
.zoom-controls button {
  min-width: 34px;
  height: 32px;
  padding: 0 10px;
  background: rgba(27, 31, 40, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.zoom-controls button:hover { border-color: var(--accent); }

/* sky: fills the canvas area behind the circuit (colours are toned down in JS) */
.sky {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(to bottom, #0a0c16, #121524);
  transition: background 0.25s linear;
}
.stars {
  position: absolute;
  inset: 0;
  opacity: 0.6;
  background-image:
    radial-gradient(1px 1px at 6% 12%, #fff, transparent),
    radial-gradient(1px 1px at 14% 34%, #cfd6ff, transparent),
    radial-gradient(1.5px 1.5px at 23% 8%, #fff, transparent),
    radial-gradient(1px 1px at 31% 27%, #fff, transparent),
    radial-gradient(1px 1px at 39% 52%, #cfd6ff, transparent),
    radial-gradient(1.5px 1.5px at 47% 16%, #fff, transparent),
    radial-gradient(1px 1px at 55% 40%, #fff, transparent),
    radial-gradient(1px 1px at 63% 6%, #cfd6ff, transparent),
    radial-gradient(1.5px 1.5px at 71% 30%, #fff, transparent),
    radial-gradient(1px 1px at 79% 58%, #fff, transparent),
    radial-gradient(1px 1px at 87% 14%, #cfd6ff, transparent),
    radial-gradient(1.5px 1.5px at 94% 44%, #fff, transparent),
    radial-gradient(1px 1px at 10% 64%, #fff, transparent),
    radial-gradient(1px 1px at 51% 70%, #cfd6ff, transparent),
    radial-gradient(1px 1px at 83% 72%, #fff, transparent);
  transition: opacity 0.4s linear;
}
.sun {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffe27a;
  box-shadow: 0 0 30px 12px rgba(232, 210, 122, 0.22), 0 0 70px 30px rgba(232, 200, 110, 0.07);
  opacity: 0;
  transition: opacity 0.3s linear;
}
/* ground/horizon along the bottom of the canvas; the sun sets behind it */
.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 44px;
  z-index: 1;
  background: linear-gradient(to bottom, #1a2117, #121610);
  border-top: 1px solid #2f3a2a;
}
.sky-info {
  position: absolute;
  z-index: 2;
  left: 12px;
  top: 10px;
  max-width: calc(100% - 24px);
  padding: 5px 11px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(10, 12, 18, 0.55);
  border-radius: 999px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

/* date & time: its own card, same look as the other sidebar cards */
.datetime .dt-row { display: flex; align-items: center; gap: 10px; }
.dt-icon { font-size: 22px; line-height: 1; }
.dt-time {
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.dt-date { margin-top: 8px; font-size: 15px; font-weight: 600; color: var(--text); }
.dt-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.dt-chip {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}
.dt-chip.phase { color: var(--accent); border-color: var(--border); }

/* transport bar */
.transport {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
}
.transport button, .transport select {
  height: 36px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0 12px;
  font-size: 14.5px;
  cursor: pointer;
}
.transport button:hover:not(:disabled), .transport select:hover { border-color: var(--text-faint); }
.transport button:disabled { opacity: 0.4; cursor: default; }
.transport #play-btn { min-width: 38px; font-size: 14px; }
.transport input[type="range"] { flex: 1; min-width: 80px; accent-color: var(--accent); }
.transport .run-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
  padding: 0 14px;
  white-space: nowrap;
}
.transport .run-btn:hover { filter: brightness(1.07); border-color: var(--accent); }
.divider { width: 1px; align-self: stretch; margin: 2px 2px; background: var(--border); }
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 700;
  min-width: 84px;
  text-align: right;
  color: var(--text-dim);
}
.status {
  flex: none;
  margin: 0;
  padding: 0 12px 8px;
  min-height: 24px;
  font-size: 13.5px;
  color: var(--text-dim);
  background: var(--panel-bg);
}

/* flow tooltip */
.flow-tip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 17, 21, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13.5px;
  line-height: 1.4;
  z-index: 5;
}
.flow-tip span { color: var(--text-dim); font-size: 12.5px; }

/* properties: floating panel over the canvas */
.props {
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 10px;
  width: 330px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  background: rgba(22, 25, 32, 0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.props[hidden] { display: none; }
.props-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 0;
}
.props-head h2 { margin: 0; }
.props-x {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.props-x:hover { color: var(--text); }
.props-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  align-content: start;
}
.props-body label.wide { grid-column: span 2; }
.props-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border-soft);
}
.props-actions button {
  flex: 1;
  padding: 8px;
  font-size: 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}
.props-actions .danger { border-color: var(--danger); color: var(--danger); }

/* --- results column --- */
.results { padding: 14px; font-size: 13.5px; }
.results h2 { font-size: 13px; }
.results h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 14px 0 6px;
}
.results .verdict {
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left-width: 4px;
}
.site-line { font-size: 12.5px; color: var(--text-dim); margin: 0 0 6px; }
.load-list, .issue-list { list-style: none; margin: 0; padding: 0; }
.load-verdict {
  display: flex;
  gap: 7px;
  font-size: 13px;
  line-height: 1.35;
  padding: 5px 8px;
  margin-bottom: 4px;
  border-left: 3px solid var(--border);
  background: var(--card-bg);
  border-radius: 4px;
}
.load-icon { font-weight: 700; }
.issue {
  font-size: 13px;
  line-height: 1.35;
  padding: 5px 8px;
  margin-bottom: 4px;
  border-radius: 4px;
  background: var(--card-bg);
}
.issue-error { border-left: 3px solid var(--bad); }
.issue-warning { border-left: 3px solid #f5c542; }

.event-list {
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: 6px;
}
.event {
  display: flex;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 7px;
  border-radius: 4px;
  color: var(--text-faint);
  cursor: pointer;
}
.event:hover { background: var(--surface-3); }
.event.past { color: var(--text); }
.event-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 46px; }
.event.past.event-cutoff, .event.past.event-loads-off, .event.past.event-overload, .event.past.event-grid-down { color: var(--bad); }
.event.past.event-sunrise, .event.past.event-battery-full { color: var(--text); }
.event.past.event-user-grid-off, .event.past.event-user-grid-on { color: var(--c-grid); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.stat {
  padding: 6px 8px;
  background: var(--card-bg);
  border-radius: 6px;
}
.stat span { display: block; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat strong { display: block; margin-top: 2px; font-size: 16px; font-variant-numeric: tabular-nums; }

/* headline stats: value + one line of meaning */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi {
  padding: 9px 11px 10px;
  background: var(--card-bg);
  border-radius: 7px;
  border-left: 3px solid var(--border);
}
.kpi.wide { grid-column: span 2; }
.kpi .kpi-label { display: block; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi strong { display: block; margin-top: 3px; font-size: 21px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi small { display: block; margin-top: 3px; font-size: 12.5px; color: var(--text-dim); line-height: 1.35; }
.kpi.good { border-left-color: var(--accent2); }
.kpi.good strong { color: var(--ok); }
.kpi.warn { border-left-color: var(--accent); }
.kpi.warn strong { color: var(--warn); }
.kpi.bad { border-left-color: var(--bad); }
.kpi.bad strong { color: var(--bad); }
.kpi.muted small { font-size: 13px; }

/* live "right now" numbers, follow the playback clock */
.live { background: var(--card-bg); border-radius: 7px; padding: 8px; }
.live-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.live-cell { padding: 6px 9px; border-radius: 6px; background: var(--panel-bg); }
.live-cell span { display: block; font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-cell strong { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.live-cell.solar strong { color: var(--accent); }
.live-cell.charge strong { color: var(--ok); }
.live-cell.discharge strong { color: var(--warn); }
.live-cell.grid strong { color: var(--c-grid); }
.live-note { margin: 8px 2px 0; font-size: 13px; color: var(--text-dim); line-height: 1.4; }
.live-note b { color: var(--text); font-weight: 600; }

/* foldable sections */
.section { margin-top: 10px; }
.section > summary {
  cursor: pointer;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 5px;
  user-select: none;
}
.section > summary:hover { color: var(--text); }
.count {
  display: inline-block;
  margin-left: 4px;
  padding: 0 7px;
  font-size: 11px;
  border-radius: 999px;
  background: var(--input-bg);
  color: var(--text-dim);
}
.stat.good strong { color: var(--accent2); }
.stat.bad strong { color: var(--bad); }

.results canvas { display: block; width: 100%; height: 130px; margin-top: 8px; background: var(--card-bg); border-radius: 6px; }
.legend { font-size: 10.5px; color: var(--text-dim); margin: 5px 0 0; }

/* --- smaller screens --- */
@media (max-width: 1200px) {
  body { overflow: auto; }
  /* page scrolls here: let the layout grow past the window instead of squeezing results */
  .layout { flex: none; grid-template-columns: 240px minmax(0, 1fr); grid-template-rows: minmax(560px, calc(100vh - 70px)) auto; }
  .results { grid-column: 1 / -1; overflow: visible; }
}
@media (max-width: 800px) {
  .topbar { flex-direction: column; gap: 2px; }
  .sub { white-space: normal; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; }
  .sidebar { overflow: visible; }
  .canvas-wrap { height: 640px; }
  .props { width: auto; left: 10px; }
  .transport { flex-wrap: wrap; }
}

/* --- "see full results" button in the builder --- */
.full-results-btn {
  display: block;
  margin-top: 10px;
  padding: 8px 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent-line);
  border-radius: 7px;
  background: var(--accent-soft);
}
.full-results-btn:hover { background: var(--accent-soft-2); }

/* ================= full results page (results.html) ================= */
body.page-results { overflow: auto; display: block; }
.page-results .topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); align-items: center; }
.page-results .sub { flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions button, .topbar-actions a {
  height: 30px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  font-size: 12.5px;
  color: var(--text);
  text-decoration: none;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.topbar-actions a:hover, .topbar-actions button:hover { border-color: var(--accent); }

.report {
  /* full width of the window */
  padding: 16px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 13px;
}
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.panel h2.sub-h { margin-top: 16px; }
.panel.empty { text-align: center; padding: 40px; }
.panel.empty .full-results-btn { display: inline-block; padding: 8px 18px; }
.updated-note { margin: 0; font-size: 12px; color: var(--accent2); }

.hero { border-left: 5px solid var(--border); }
.hero-verdict { margin: 4px 0 0; font-size: 20px; font-weight: 700; line-height: 1.35; }

.kpi-grid.wide-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.wide-grid .kpi { padding: 10px 12px; }
.wide-grid .kpi strong { font-size: 24px; }
.wide-grid .kpi small { font-size: 13px; }
.wide-grid .kpi.wide { grid-column: span 2; }

.chart-wrap { position: relative; }
#big-chart { display: block; width: 100%; height: 320px; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  min-width: 150px;
  padding: 6px 9px;
  font-size: 11.5px;
  line-height: 1.45;
  background: rgba(15, 17, 21, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.chart-tip .bad { color: var(--bad); }

/* side-by-side sections: 3 across on wide screens, fewer as it narrows */
.report-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; align-items: start; }
.report-cols .event-list.full { max-height: 460px; overflow-y: auto; }
.report .load-verdict { font-size: 13.5px; }
.report .event-list.full { max-height: none; }
.report .event { font-size: 13.5px; cursor: default; }

table.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.kv th { text-align: left; padding: 6px 0 4px; color: var(--text); font-weight: 700; }
table.kv td { padding: 4px 0; border-top: 1px solid var(--border-soft); }
table.kv td:first-child { color: var(--text-dim); width: 90px; }

.table-scroll { max-height: 520px; overflow: auto; border-radius: 6px; }
table.hourly { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.hourly th {
  position: sticky;
  top: 0;
  background: var(--card-bg);
  text-align: right;
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  padding: 7px 10px;
}
table.hourly td { text-align: right; padding: 5px 10px; border-top: 1px solid var(--border-soft); }
table.hourly th:first-child, table.hourly td:first-child { text-align: left; }
table.hourly tr.cut td { background: rgba(214, 95, 90, 0.08); }
table.hourly tr.cut td:last-child { color: var(--bad); }
.soc-bar { display: inline-block; width: 60px; height: 6px; margin-right: 6px; vertical-align: middle; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.soc-bar i { display: block; height: 100%; background: var(--accent2); }

@media (max-width: 900px) {
  .page-results .topbar { flex-wrap: wrap; }
}


/* --- schedule window --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 7, 11, 0.6);
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(680px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  font-size: 14px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; }
.modal-head h2 { margin: 0; font-size: 17px; color: var(--text); }
.modal-body { padding: 12px 18px 6px; overflow-y: auto; }
.modal-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.modal label { display: block; font-size: 12.5px; color: var(--text-dim); }
.modal input[type="text"], .modal input[type="number"], .modal input[type="time"], .modal select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  color-scheme: dark;
}
.modal input[type="range"] { width: 100%; margin-top: 10px; accent-color: var(--accent-strong); }
.modal .props-actions { padding: 12px 18px 16px; }
.props-actions .primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #ffffff; font-weight: 700; }

.tabs { display: flex; gap: 4px; padding: 3px; margin-bottom: 12px; background: var(--input-bg); border-radius: 8px; }
.tab {
  flex: 1;
  padding: 8px;
  font-size: 14px;
  color: var(--text-dim);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.tab.active { background: var(--accent-strong); color: #ffffff; font-weight: 700; }

.timeline {
  display: grid;
  grid-template-columns: repeat(96, 1fr);
  height: 34px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--border-soft);
  user-select: none;
  touch-action: none;
}
.timeline i { border-left: 1px solid rgba(255, 255, 255, 0.03); }
.timeline i.hour { border-left-color: rgba(255, 255, 255, 0.12); }
.timeline i.on { background: var(--accent-strong); }
.timeline.editable { cursor: pointer; }
.timeline.editable i:hover { background: var(--accent-soft-2); }
.timeline.editable i.on:hover { background: var(--accent-hover); }
.timeline-hours { position: relative; height: 18px; margin: 3px 0 10px; font-size: 11px; color: var(--text-dim); }
.timeline-hours span { position: absolute; transform: translateX(-50%); }
.timeline-hours span:first-child { transform: none; }
.timeline-hours span:last-child { transform: translateX(-100%); }

.windows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.window-row { display: flex; align-items: center; gap: 8px; }
.window-row input { width: 130px !important; margin-top: 0 !important; }
.window-row span { color: var(--text-dim); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); padding: 5px 9px; cursor: pointer; }
.icon-btn:hover { color: var(--bad); border-color: var(--bad); }
.link-btn { align-self: flex-start; background: none; border: none; color: var(--accent-text); font-size: 14px; padding: 4px 0; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.modal-actions-inline { display: flex; gap: 18px; margin-bottom: 6px; }
.sched-summary { margin: 10px 0 4px; font-size: 14px; color: var(--text-dim); }
.sched-summary b { color: var(--text); }

.props-schedule { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; padding: 8px 0 2px; font-size: 12.5px; color: var(--text-dim); }
.props-schedule strong { color: var(--text); font-weight: 600; }
.props-schedule button { flex-basis: 100%; margin-top: 4px; padding: 7px; background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13.5px; cursor: pointer; }
.props-schedule button:hover { border-color: var(--accent-strong); }

@media (max-width: 640px) {
  .modal-row { grid-template-columns: 1fr; }
}

/* --- audit fixes --- */
/* visible keyboard focus everywhere */
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { cursor: default; }
.transport .run-btn:disabled { opacity: 0.7; filter: none; }

/* results that no longer match the circuit */
.results.stale > :not(.stale-note) { opacity: 0.45; }
.stale-note {
  margin: 0 0 10px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid var(--warn-line);
  border-radius: 7px;
}
.stale-note .link-btn { color: var(--accent); font-weight: 700; font-size: 13px; padding: 0; }

/* empty canvas guidance */
.empty-hint {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 40px));
  padding: 16px 18px;
  text-align: center;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-dim);
  background: rgba(15, 17, 21, 0.85);
  border: 1px dashed var(--border);
  border-radius: 10px;
  pointer-events: none;
}
.empty-hint[hidden] { display: none; }
.empty-hint strong { display: block; margin-bottom: 4px; color: var(--text); font-size: 15px; }

.saved-note { margin: 10px 0 0; font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.link-btn.small { font-size: 12px; padding: 0; color: var(--accent); }

/* a little tighter so the left column fits a 768px-tall laptop screen */
.sidebar { gap: 10px; }
.sidebar .card { padding: 12px 14px; }
.dt-time { font-size: 34px; }
.dt-date { margin-top: 6px; }
.dt-meta { margin-top: 6px; }
.palette-item { padding: 8px 6px; }
/* palette tiles: icon beside the label (shorter tiles, left column fits laptops) */
.palette-item { flex-direction: row; justify-content: flex-start; text-align: left; gap: 8px; padding: 8px 10px; min-height: 46px; }
.palette-item .pi-icon { font-size: 20px; flex: none; }
.palette-item:last-child:nth-child(odd) { justify-content: flex-start; }

/* results page on phones: one tile per row, header scrolls away */
@media (max-width: 600px) {
  .kpi-grid.wide-grid { grid-template-columns: 1fr 1fr; }
  .wide-grid .kpi.wide { grid-column: 1 / -1; }
  .wide-grid .kpi strong { font-size: 20px; }
  .page-results .topbar { position: static; gap: 6px; padding: 10px 14px; }
  .report { padding: 12px 12px 32px; }
  .panel { padding: 12px; }
  .hero-verdict { font-size: 17px; }
  #big-chart { height: 240px; }
  .report-cols { grid-template-columns: 1fr; }
}

/* ================= colour refinements ================= */
.logo { display: inline-flex; color: var(--c-solar); }
.logo svg { width: 20px; height: 20px; }

/* primary action: solid accent; everything else neutral */
.transport .run-btn { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.transport .run-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); filter: none; }
.props-actions .primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.props-actions .primary:hover { background: var(--accent-hover); }
.link-btn, .link-btn.small, .stale-note .link-btn { color: var(--accent-text); }
.full-results-btn { color: var(--accent-text); background: var(--card-bg); border-color: var(--border); }
.full-results-btn:hover { background: var(--surface-3); border-color: var(--accent-line); }
.palette-item:hover, .zoom-controls button:hover, .props-schedule button:hover, .topbar-actions a:hover, .topbar-actions button:hover { border-color: var(--accent-line); }
.modal input[type="range"], .transport input[type="range"] { accent-color: var(--accent); }

/* tabs: selected = raised neutral surface with an accent underline */
.tab.active { background: var(--surface-3); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

/* schedule bar: the on-times are load-coloured (it's the load's data) */
.timeline i.on { background: var(--c-load); }
.timeline.editable i:hover { background: var(--accent-soft-2); }
.timeline.editable i.on:hover { background: #6a8cba; }

/* stats: numbers stay neutral; colour marks only what needs attention */
.kpi.good { border-left-color: var(--border); }
.kpi.good strong, .kpi.warn strong { color: var(--text); }
.kpi.warn { border-left-color: var(--warn); }
.kpi.bad { border-left-color: var(--bad); }
.kpi.bad strong { color: var(--bad); }
.stat.good strong { color: var(--text); }
.stat.bad strong { color: var(--bad); }

/* live "right now": small data-colour swatches, neutral numbers */
.live-cell strong, .live-cell.solar strong, .live-cell.charge strong, .live-cell.discharge strong, .live-cell.grid strong { color: var(--text); }
.swatch { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 2px; vertical-align: 0; }
.sw-solar { background: var(--c-solar); }
.sw-battery { background: var(--c-battery); }
.sw-grid { background: var(--c-grid); }
.sw-load { background: var(--c-load); }

/* event feed: only problems are coloured */
.event.past.event-sunrise, .event.past.event-battery-full, .event.past.event-sunset { color: var(--text); }
.event.past.event-user-grid-off, .event.past.event-user-grid-on { color: var(--text); font-weight: 600; }
.event.past.event-cutoff, .event.past.event-loads-off, .event.past.event-overload, .event.past.event-grid-down { color: var(--bad); }

/* date & time card: neutral tags */
.dt-chip.phase { color: var(--text); border-color: var(--border); }

/* stale results note uses the warning tone */
.stale-note { color: var(--text); background: var(--warn-soft); border-color: var(--warn-line); }

/* results page bits */
.soc-bar i { background: var(--c-battery); }
.chart-tip .bad { color: var(--bad); }
.updated-note { color: var(--text-dim); }

/* palette tile icons: one-colour line icons in the data colour */
.palette-item .pi-icon { display: inline-flex; width: 22px; height: 22px; }
.palette-item .pi-icon svg { width: 22px; height: 22px; }
.pi-inverter { color: var(--c-inverter); }
.pi-panel { color: var(--c-solar); }
.pi-battery { color: var(--c-battery); }
.pi-grid { color: var(--c-grid); }
.pi-load { color: var(--c-load); }

/* the legend squares on the results chart */
.legend .swatch { margin-left: 8px; }
.legend .swatch:first-child { margin-left: 0; }

/* version, build and release date (top bar, right) */
.app-version {
  margin-left: auto;
  flex: none;
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.page-results .app-version { margin-left: 0; }
@media (max-width: 800px) { .app-version { margin-left: 0; } }

/* ================= Voratide brand ================= */
/* wordmark: VORA + gold TIDE, as on www.voratide.com */
.brand { color: var(--text); text-decoration: none; }
.wordmark {
  font-family: var(--font-h);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text);
  line-height: 1;
}
.wordmark span { color: var(--gold); }
.brand-rule { width: 1px; height: 18px; margin: 0 4px; background: var(--border); }
.topbar h1 { font-size: 15px; font-weight: 600; letter-spacing: 0.02em; color: var(--text); }
.tag { border-color: var(--accent-line); color: var(--accent-text); }

/* primary actions: cream pill, navy text (www .btn-fill) */
.transport .run-btn,
.props-actions .primary,
.topbar-actions .export-btn {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
  font-weight: 600;
}
.transport .run-btn:hover,
.props-actions .primary:hover,
.topbar-actions .export-btn:hover { background: #ffffff; border-color: #ffffff; color: var(--bg); filter: none; }

/* results headline in the display face */
.hero-verdict { font-family: var(--font-h); font-weight: 500; font-size: 22px; letter-spacing: -0.005em; }
.client-note { border-left: 3px solid var(--gold); }
.client-note p { margin: 0; font-size: 14px; line-height: 1.55; }

/* export form */
.export-modal { width: min(520px, 100%); }
.export-modal label { margin-bottom: 12px; }
.export-modal .optional { color: var(--text-faint); font-size: 11.5px; }
.modal textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  resize: vertical;
}
.modal input:focus, .modal textarea:focus { outline: none; border-color: var(--accent-line); }
.export-tip { margin-top: 2px; }

/* bits that only exist in the PDF */
.print-only { display: none; }

/* ================= client report (PDF / print) =================
   A light A4 document: Voratide cover block, results, hour-by-hour
   appendix on its own page, then assumptions and contact. The page
   footer (brand + page numbers) uses @page margin boxes (Chrome/Edge). */
@page {
  size: A4;
  margin: 16mm 15mm 18mm;
  @bottom-left {
    content: "VORATIDE  ·  Solar Energy Assessment";
    font-family: "Inter", sans-serif;
    font-size: 7pt;
    letter-spacing: 0.08em;
    color: #9c9890;
  }
  @bottom-right {
    content: "Page " counter(page) " of " counter(pages);
    font-family: "Inter", sans-serif;
    font-size: 7pt;
    color: #9c9890;
  }
}

@media print {
  body.page-results {
    /* paper palette: every component picks these up through the tokens */
    --bg: #ffffff;
    --panel-bg: #ffffff;
    --card-bg: #fafaf7;
    --input-bg: #f0ede6;
    --surface-3: #ebe7de;
    --border: #e8e4dc;
    --border-soft: #efebe3;
    --text: #1a1d23;
    --text-dim: #5c5850;
    --text-faint: #9c9890;
    --c-solar: #c4932a;
    --c-battery: #2e857e;
    --c-grid: #7a8496;
    --c-load: #4f74a8;
    --bad: #c0453f;
    background: #fff;
    color: var(--text);
    font-size: 9.5pt;
    overflow: visible;
  }
  body.page-results * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .page-results .topbar,
  .modal-backdrop,
  .chart-tip,
  .updated-note,
  .screen-only { display: none !important; }
  .print-only { display: block; }
  span.print-only { display: inline; }

  .report { padding: 0; gap: 7mm; font-size: 9.5pt; }
  .panel { background: none; border: none; border-radius: 0; padding: 0; }
  .panel h2 {
    margin: 0 0 3mm;
    padding-bottom: 1.6mm;
    font-size: 7.5pt;
    font-weight: 600;
    letter-spacing: 0.16em;
    color: var(--gold-dark);
    border-bottom: 0.6pt solid var(--border);
  }
  .panel h2 .count { display: none; }
  .panel h2.sub-h { margin-top: 5mm; }

  /* cover */
  .print-cover { padding-bottom: 5mm; border-bottom: 1.2pt solid var(--gold); }
  .pc-top { display: flex; justify-content: space-between; align-items: baseline; }
  .print-cover .wordmark { font-size: 15pt; color: var(--navy); }
  .pc-kicker { font-size: 7pt; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-faint); }
  .pc-title { margin: 13mm 0 0; font-family: var(--font-h); font-weight: 400; font-size: 30pt; letter-spacing: -0.01em; line-height: 1.1; color: var(--navy); }
  .pc-sub { margin: 2.5mm 0 0; font-family: var(--font-h); font-style: italic; font-size: 13pt; color: var(--text-dim); }
  .pc-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm 8mm; margin: 9mm 0 0; }
  .pc-meta dt { font-size: 6.5pt; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-faint); }
  .pc-meta dd { margin: 1mm 0 0; font-size: 9pt; color: var(--text); }

  /* verdict + note */
  .hero { padding: 1mm 0 1mm 5mm; border-left-width: 2pt; border-left-style: solid; break-inside: avoid; }
  .hero .kpi-label { font-size: 7pt; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-faint); }
  .hero-verdict { margin-top: 1.5mm; font-size: 16pt; line-height: 1.3; color: var(--navy); }
  .client-note { padding: 3.5mm 5mm; background: var(--card-bg); border-left: 2pt solid var(--gold); break-inside: avoid; }
  .client-note h2 { border: none; padding: 0; margin-bottom: 1.5mm; }
  .client-note p { font-size: 10pt; }

  /* key stats: 3 across, figures in the display face */
  .kpi-grid.wide-grid { grid-template-columns: repeat(3, 1fr); gap: 3mm; }
  .wide-grid .kpi { padding: 3mm 3.5mm; background: var(--card-bg); border-radius: 0; border-left-width: 1.5pt; break-inside: avoid; }
  .wide-grid .kpi.wide { grid-column: span 3; }
  .kpi.muted { display: none; } /* "add a tariff" is advice for us, not the client */
  .kpi .kpi-label { font-size: 6.5pt; letter-spacing: 0.12em; }
  .wide-grid .kpi strong { font-family: var(--font-h); font-weight: 500; font-size: 17pt; color: var(--navy); }
  .wide-grid .kpi.bad strong { color: var(--bad); }
  .wide-grid .kpi small { font-size: 8pt; }

  /* chart: canvas redrawn at 1000x330 for print, scaled to the page */
  .panel:has(#big-chart) { break-inside: avoid; }
  #big-chart { width: 100% !important; height: auto !important; }
  .legend { font-size: 8pt; color: var(--text-dim); }

  /* loads + energy side by side, the event log full width under them */
  .report-cols { grid-template-columns: 1fr 1fr; gap: 7mm 8mm; }
  .report-cols > :nth-child(3) { grid-column: 1 / -1; }
  .report .load-verdict { font-size: 9pt; background: var(--card-bg); break-inside: avoid; }
  .stat { background: var(--card-bg); border-radius: 0; }
  .stat span { font-size: 7pt; color: var(--text-dim); }
  .stat strong { font-size: 10.5pt; }
  table.kv { font-size: 9pt; }
  .report .event-list.full { max-height: none; overflow: visible; columns: 2; column-gap: 8mm; }
  .report .event { font-size: 8.5pt; padding: 1mm 0; break-inside: avoid; }

  /* appendix on its own page */
  .appendix { break-before: page; }
  .table-scroll { max-height: none; overflow: visible; }
  table.hourly { font-size: 8pt; }
  table.hourly th { position: static; background: var(--navy); color: #fff; font-size: 6.5pt; letter-spacing: 0.1em; padding: 2mm 2.5mm; }
  table.hourly td { padding: 1.3mm 2.5mm; }
  table.hourly tbody tr:nth-child(even) td { background: var(--card-bg); }
  table.hourly tr.cut td { background: rgba(192, 69, 63, 0.07); }
  table.hourly tr { break-inside: avoid; }

  /* closing: assumptions + contact */
  .about { break-inside: avoid; margin-top: 4mm; }
  .about p { margin: 0 0 2.5mm; font-size: 8.5pt; line-height: 1.55; color: var(--text-dim); }
  .about-sign { display: flex; align-items: baseline; gap: 5mm; margin-top: 5mm; padding-top: 3.5mm; border-top: 0.6pt solid var(--gold); }
  .about-sign .wordmark { font-size: 11pt; color: var(--navy); }
  .about-contact { font-size: 7.5pt; letter-spacing: 0.04em; color: var(--text-dim); }
}
