:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  --background: #101915;
  --sidebar: #121d17;
  --panel: #18241d;
  --border: #2d3a31;
  --text: #f2f5ec;
  --muted: #a5b3a7;
  --green: #a9e481;
  --teal: #65c6bb;
  --gold: #efc27b;
  --blue: #89b7e3;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--text); min-width: 300px; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible, select:focus-visible, .plot:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 4px;
}
h1, h2, p, dl, dd { margin: 0; }
h1, h2 { font-weight: 600; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 5;
  top: 10px;
  left: 10px;
  padding: 10px 16px;
  background: var(--green);
  color: #152415;
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.sidebar {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  width: 226px;
  background: var(--sidebar);
  border-right: 1px solid #2a362e;
  padding: 27px 16px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 1px 4px 30px; white-space: nowrap; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 41px;
  height: 41px;
  flex: none;
  border-radius: 11px;
  background: #254331;
  color: var(--green);
}
.brand-mark svg { grid-area: 1 / 1; }
.brand strong { display: block; font-size: 1rem; letter-spacing: -.02em; }
.brand small { display: block; color: var(--muted); font-size: .68rem; letter-spacing: .15em; margin-top: 4px; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: .93rem;
  color: var(--muted);
}
.sidebar nav a:hover { background: #203027; color: var(--text); }
.sidebar nav a[aria-current] { background: #23382a; color: #bfeb9f; border-color: #38513c; font-weight: 600; }
.sidebar-foot {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 17px 5px 3px;
  font-size: .85rem;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-top: 6px; flex: none; }
.sidebar-foot small { display: block; color: var(--muted); font-size: .77rem; margin-top: 4px; }

.workspace { margin-left: 226px; }
.topbar {
  min-height: 68px;
  padding: 10px clamp(20px, 3vw, 48px);
  border-bottom: 1px solid #28372e;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
}
.breadcrumb { color: var(--muted); font-size: .88rem; }
.breadcrumb b { color: #718376; margin: 0 8px; font-weight: 400; }
.breadcrumb strong { color: var(--text); font-weight: 600; }
.top-controls, .context-date, .scenario-control { display: flex; align-items: center; gap: 8px; }
.top-controls { gap: 18px; }
.context-date { color: var(--muted); white-space: nowrap; font-size: .82rem; font-variant-numeric: tabular-nums; }
.scenario-control { font-size: .83rem; color: var(--muted); position: relative; }
.scenario-control select {
  appearance: none;
  padding: 8px 28px 8px 12px;
  border: 1px solid #3a4a3f;
  border-radius: 8px;
  background: #1c2a22;
  color: var(--text);
  font-weight: 600;
}
.scenario-control::after {
  content: "";
  position: absolute;
  right: 11px;
  width: 7px;
  height: 7px;
  border: solid var(--muted);
  border-width: 0 1px 1px 0;
  transform: translateY(-2px) rotate(45deg);
  pointer-events: none;
}

main { padding: 23px clamp(20px, 3vw, 48px) 32px; max-width: 1800px; margin: 0 auto; }
main:focus { outline: none; }
.page-title { margin-bottom: 20px; }
.page-title h1 { font-size: clamp(2rem, 4vw, 2.7rem); letter-spacing: -.05em; }
.hero {
  min-height: 206px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: clamp(22px, 3vw, 36px);
  margin-bottom: 16px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #435344;
  border-radius: 13px;
  background: linear-gradient(105deg, #1b2e24 25%, #20392b 100%);
}
.hero-site {
  position: absolute;
  z-index: -1;
  inset: 0 3% 0 30%;
  max-width: 720px;
  margin-left: auto;
  background:
    radial-gradient(ellipse at 65% 58%, #78ab6920 0%, transparent 68%),
    repeating-linear-gradient(0deg, #a5c9a211 0 1px, transparent 1px 23px),
    repeating-linear-gradient(90deg, #a5c9a211 0 1px, transparent 1px 23px);
  mask-image: linear-gradient(90deg, transparent, black 22% 89%, transparent);
}
.hero-site img { position: absolute; width: auto; height: auto; max-height: 84%; }
.hero-site .site-barn { right: 28%; top: 3%; width: min(51%, 320px); }
.hero-site .site-energy { right: 14%; top: 12%; width: min(25%, 180px); }
.hero-site .site-reactor { right: 27%; bottom: -3%; width: min(40%, 250px); }
.hero-location { display: flex; gap: 7px; align-items: center; color: #c1d4c1; font-size: .82rem; }
.hero-location span { background: #a8c6a4; height: 3px; width: 3px; border-radius: 50%; }
.hero h1 { margin: 5px 0 6px; font-size: clamp(2.25rem, 4.45vw, 4.25rem); line-height: 1.04; letter-spacing: -.065em; }
.hero p { color: #d1dfd1; font-size: clamp(.9rem, 1.5vw, 1rem); }
.hero-weather {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 170px;
  padding: 10px 14px;
  border: 1px solid #c8e0c247;
  border-radius: 9px;
  background: #17261ded;
}
.weather-icon { color: var(--gold); display: grid; place-items: center; }
.hero-weather strong { font-weight: 600; font-size: 1.12rem; }
.hero-weather small { display: block; font-size: .78rem; color: #c3d5c6; margin-top: 1px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric, .panel { background: var(--panel); border: 1px solid var(--border); border-radius: 11px; min-width: 0; }
.metric { padding: 14px 16px; --accent: var(--green); }
.tone-gold { --accent: var(--gold); }
.tone-teal { --accent: var(--teal); }
.tone-blue { --accent: var(--blue); }
.metric-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.metric-head h2 { font-size: .89rem; font-weight: 500; color: #dbe6da; }
.metric-head span, .card-icon, .decision-symbol {
  display: grid;
  place-items: center;
  flex: none;
  width: 33px;
  height: 33px;
  border-radius: 8px;
  color: var(--accent, var(--teal));
  background: color-mix(in srgb, var(--accent, var(--teal)) 13%, #18251d);
}
.metric-value, .heat-reading strong, .gas-reading strong {
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  font-size: clamp(1.95rem, 3vw, 2.65rem);
  font-weight: 600;
  letter-spacing: -.06em;
  margin: 6px 0 5px;
  white-space: nowrap;
}
.metric-value small, .heat-reading strong small, .gas-reading strong small {
  font-size: .98rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
}
.metric-meter {
  position: relative;
  height: 8px;
  margin-top: 10px;
  border-radius: 8px;
  background: #2e4035;
}
.metric-meter-fill {
  position: absolute;
  inset-block: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 50%, #31483c), var(--accent));
}
.metric-meter-centered::after {
  content: "";
  position: absolute;
  inset-block: -2px;
  left: 50%;
  width: 1px;
  background: #a5b7a9;
}
.metric-scale {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  margin-top: 4px;
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.metric-scale span { white-space: nowrap; }
.metric-scale span:nth-child(2):not(:last-child) { text-align: center; }
.metric-scale span:last-child { text-align: right; }
.metric-detail { margin-top: 6px; color: var(--muted); font-size: .8rem; line-height: 1.3; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(300px, 1fr); gap: 14px; }
.panel { padding: 17px 18px; }
.panel-heading { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.panel h2 { font-size: 1.12rem; color: var(--text); letter-spacing: -.022em; }
.panel-heading p, .panel-note { color: var(--muted); font-size: .83rem; margin-top: 4px; line-height: 1.4; }
.panel-note { margin-top: 12px; }
.subtle-badge {
  flex: none;
  font-size: .77rem;
  color: #c5d5c6;
  border: 1px solid #3a4b40;
  padding: 4px 8px;
  border-radius: 5px;
}
.chart-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; margin: 0 0 6px; }
.legend-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  padding: 4px 0;
  font-size: .81rem;
  color: #d5e0d2;
}
.legend-toggle i { display: inline-block; width: 13px; height: 3px; border-radius: 4px; background: var(--legend-color); }
.legend-toggle[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.legend-toggle[aria-pressed="false"] i { opacity: .4; }
.plot { position: relative; height: 205px; touch-action: pan-y; }
.plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.plot text { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.grid-line { stroke: #34443a; stroke-width: 1; }
.now-line { stroke: #b2c5af; stroke-opacity: .55; stroke-dasharray: 3 4; }
.chart-cursor line { stroke: #dae6d4; stroke-opacity: .7; }
.chart-cursor circle { stroke: #17251d; stroke-width: 1.5; }
.plot-tooltip {
  position: absolute; top: 5px; z-index: 1; min-width: min(190px, 100%);
  max-width: 100%; pointer-events: none; padding: 8px 10px;
  background: #112019; border: 1px solid #526657; border-radius: 7px;
  box-shadow: 0 5px 16px #0005; font-size: .79rem;
}
.plot-tooltip b { display: block; margin-bottom: 4px; }
.plot-tooltip span { display: flex; align-items: center; gap: 5px; padding: 2px 0; color: var(--muted); }
.plot-tooltip i { width: 6px; height: 6px; border-radius: 50%; }
.plot-tooltip strong { color: var(--text); font-weight: 600; margin-left: auto; padding-left: 5px; }

.decision {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #223527;
  border: 1px solid #374e3b;
  border-radius: 8px;
  margin-bottom: 8px;
}
.decision-symbol { --accent: var(--green); width: 34px; height: 34px; }
.decision strong { color: #c3eea6; font-size: 1.3rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.decision > div:last-child > div { color: #c0d0bf; font-size: .79rem; margin-top: 3px; }
.readings > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.readings dt { color: #cbd7cb; font-size: .84rem; }
.readings dd { font-size: .85rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.economics > div, .compact > div { padding: 4px 0; }
.economics .total { padding-top: 9px; margin-top: 5px; border-top: 1px solid var(--border); }
.total dt, .total dd { color: var(--green); font-weight: 600; }
.prominent > div { padding: 12px 0; border-bottom: 1px solid var(--border); }
.prominent > div:last-child { border: 0; }
.prominent dd { font-size: 1rem; }

.heat-reading, .gas-reading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.heat-reading span, .gas-reading span { color: var(--muted); font-size: .85rem; }
.heat-reading strong, .gas-reading strong { margin-bottom: 10px; }
.gas-reading strong { color: #c6e9bb; }
.gold-icon { --accent: var(--gold); }
.heat-stack, .gas-track { display: flex; height: 9px; border-radius: 7px; overflow: hidden; background: #2e4035; }
.heat-stack { margin-bottom: 9px; }
.gas-track i { border-radius: 7px; background: linear-gradient(90deg, #3c8e77, #b3e771); }
.scale-labels { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: 5px; }
.dot { display: inline-block; width: 7px; height: 7px; margin: 0 6px 1px 1px; border-radius: 50%; }
.teal { background: var(--teal); }
.green { background: var(--green); }
.gold { background: var(--gold); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 8px 14px; padding: 11px 0; border-bottom: 1px solid var(--border); color: #d6e0d5; font-size: .89rem; }
.setting-row:last-child { border-bottom: 0; }
.setting-input { display: flex; align-items: center; gap: 7px; flex: 0 0 172px; }
.setting-input input { width: 75px; padding: 7px; font-variant-numeric: tabular-nums; background: #111e17; border: 1px solid #435648; border-radius: 5px; }
.setting-input span { color: var(--muted); font-size: .8rem; }
.form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 15px; }
.form-actions button { padding: 9px 14px; border-radius: 7px; border: 1px solid #4d6552; font-size: .87rem; font-weight: 600; }
.primary-button { color: #162519; background: var(--green); }
.primary-button:hover { background: #c1eea4; }
.secondary-button { color: var(--text); background: #203027; }
.secondary-button:hover { background: #2d4233; }
#save-message { color: var(--green); font-size: .84rem; }

.chp-control-panel { margin-bottom: 14px; }
.chp-control-row, .chp-power-label { display: flex; align-items: center; gap: 8px; }
.chp-control-row, .chp-power-label { justify-content: space-between; }
.chp-state { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.chp-state strong, .chp-power-label output { font-variant-numeric: tabular-nums; }
.chp-state strong { font-size: 1.35rem; }
.chp-state span, .chp-duration small { color: var(--muted); font-size: .84rem; }
.chp-control-panel button {
  min-height: 44px;
  padding: 8px 13px;
  border: 1px solid #4d6552;
  border-radius: 7px;
  font-size: .89rem;
  font-weight: 600;
}
.chp-mode-switch {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  flex: 0 0 auto;
  width: min(100%, 15rem);
  min-inline-size: 0;
  margin: 0;
  padding: 3px;
  border: 1px solid #4d6552;
  border-radius: 999px;
  background: #111e17;
}
.chp-mode-thumb {
  position: absolute;
  inset: 3px auto 3px 3px;
  z-index: -1;
  width: calc(50% - 3px);
  border-radius: inherit;
  background: var(--green);
  transition: transform 180ms ease;
}
.chp-mode-switch:has(#chp-manual:checked) .chp-mode-thumb { transform: translateX(100%); }
.chp-mode-switch label { position: relative; }
.chp-mode-switch label span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 600;
}
.chp-mode-switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chp-mode-switch input:checked + span { color: #162519; }
.chp-mode-switch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: -3px; }
.chp-mode-switch input:checked:focus-visible + span { outline-color: #162519; }
.chp-mode-status[data-mode="manual"] { color: var(--gold); border-color: #826447; }
@media (prefers-reduced-motion: reduce) {
  .chp-mode-thumb { transition: none; }
}
.chp-manual-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content max-content;
  align-items: center;
  gap: 14px 24px;
  border-top: 1px solid var(--border);
  margin-top: 14px;
  padding-top: 14px;
}
.chp-power-label output { color: var(--green); font-weight: 600; }
.chp-power-field .scale-labels { margin-top: 0; }
.chp-power-input {
  appearance: none;
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0;
  background: transparent;
  accent-color: var(--green);
  touch-action: pan-y;
  cursor: pointer;
}
.chp-power-input::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--green) var(--chp-fill), #384c40 var(--chp-fill));
}
.chp-power-input::-webkit-slider-thumb {
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -9px;
  border: 2px solid #638562;
  border-radius: 50%;
  background: #d3f4ba;
}
.chp-power-input::-moz-range-track { height: 8px; border-radius: 4px; background: #384c40; }
.chp-power-input::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--green); }
.chp-power-input::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 2px solid #638562;
  border-radius: 50%;
  background: #d3f4ba;
}
.chp-duration { display: grid; justify-items: start; gap: 4px; }
.chp-duration input { min-height: 44px; }

@media (max-width: 1190px) {
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1010px) {
  .sidebar { width: 190px; }
  .workspace { margin-left: 190px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1.5fr) minmax(253px, 1fr); }
  .metric { padding-inline: 12px; }
  .metric-head span { width: 28px; height: 28px; }
  .context-date { display: none; }
}
@media (max-width: 880px) {
  .sidebar { position: static; width: auto; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; align-items: center; }
  .brand { padding: 0; }
  .sidebar nav { grid-column: 1 / -1; grid-row: 2; display: flex; gap: 4px; margin-top: 8px; overflow-x: auto; }
  .sidebar nav a { white-space: nowrap; padding: 8px 9px; font-size: .84rem; gap: 6px; }
  .sidebar-foot { border: 0; margin: 0; padding: 3px; }
  .sidebar-foot small { display: none; }
  .workspace { margin: 0; }
  .topbar { min-height: 48px; }
  main { padding-top: 16px; }
}
@media (max-width: 620px) {
  main, .topbar { padding-inline: 13px; }
  .sidebar { padding-inline: 13px; }
  .breadcrumb { display: none; }
  .topbar { justify-content: flex-end; }
  .context-date { display: flex; font-size: .73rem; }
  .top-controls { gap: 8px; width: 100%; justify-content: space-between; }
  .scenario-control > span { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; }
  .hero { padding: 17px; align-items: flex-start; flex-direction: column; gap: 12px; min-height: 0; }
  .hero-site { inset-inline: 31% -2%; opacity: .52; }
  .hero-site .site-barn { top: 9%; right: 23%; width: 58%; }
  .hero-site .site-energy { right: 7%; top: 16%; width: 31%; }
  .hero-site .site-reactor { right: 14%; bottom: 1%; width: 55%; }
  .hero h1 { font-size: clamp(2.05rem, 9vw, 3.1rem); }
  .hero-weather { min-width: 0; padding: 6px 9px; }
  .hero-weather small { font-size: .74rem; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 9px; }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .panel { padding: 13px; }
  .plot { height: 190px; }
  .setting-row { flex-wrap: wrap; }
  .setting-input { flex-basis: auto; }
  .chp-control-panel { margin-bottom: 9px; }
  .chp-control-row { flex-direction: column; align-items: stretch; }
  .chp-mode-switch { width: 100%; }
  .chp-manual-form { grid-template-columns: minmax(0, 1fr); }
  .chp-manual-form > button { justify-self: stretch; }
}
@media (max-width: 390px) {
  .sidebar nav a svg { display: none; }
  .sidebar nav a { padding-inline: 7px; }
  .metric-head h2 { font-size: .82rem; }
}
