:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #7c3aed;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

header { padding: 16px 24px 4px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.about-btn { flex: none; }
header h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 4px 0 0; color: var(--muted); }

/* Scenario bar */
.scenario-bar {
  /* flex-start (not center): an expanding Quick guide grows the bar downward
     only — the summary's top edge never moves. */
  display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap;
  padding: 10px 24px; position: relative;
  /* border-bottom: 1px solid var(--border); */
  background: var(--panel);
  /* width: 400px; */
  margin-top: 20px;
}

.settings-panel {
  width: 400px;
}

.scenario-bar select, .scenario-bar input[type="text"] { min-width: 170px; }

/* Preset select + ⓘ bubble stay glued as one no-wrap unit even when the
   400px settings panel wraps; the select caps its width so the unit fits. */
.select-with-info { display: inline-flex; align-items: center; gap: 6px; flex-wrap: nowrap; max-width: 100%; }
.select-with-info select { min-width: 0; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }

/* Scenario notes live in an ⓘ bubble right of the preset select: popover on
   hover/focus; JS adds .flash briefly when a message arrives (link copied,
   preset loaded) so transient feedback is seen without hovering. */
.info-bubble { position: relative; cursor: help; color: var(--muted); font-size: 14px; align-self: center; user-select: none; }
.info-pop {
  position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
  width: 340px; max-height: 220px; overflow-y: auto; z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; line-height: 1.45; color: #111827;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
  opacity: 0; visibility: hidden; transition: opacity 0.15s;
}
.info-bubble:hover .info-pop, .info-bubble:focus .info-pop, .info-bubble.flash .info-pop { opacity: 1; visibility: visible; }

/* Quick guide: in-flow right after the settings panel. details is a flex row,
   so the text opens to the RIGHT of the summary — the summary never moves and
   the bar height stays one line (text just wraps on mobile). State remembered. */
.quick-help {
  /* block layout: summary on its own line, body flows below — with the bar
     top-aligned (flex-start), the summary's position is constant */
  flex: 1; min-width: 0; margin-top: 0;
  font-size: 12px; color: var(--muted); line-height: 1.5;
  margin-left: 10%;
}
.quick-help summary { flex: none; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; margin-bottom: 0; }

/* First-visit intro modal: closed by default (invisible, no pointer events);
   .open fades the dim backdrop in and settles the card. */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}
.modal-backdrop.open { opacity: 1; visibility: visible; }
.modal {
  position: relative; background: var(--panel); border-radius: 12px;
  max-width: 720px; padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
  transform: translateY(8px); transition: transform 0.18s ease;
}
/* Two columns: info left, email signup right; stacks to one block on narrow */
.modal-cols { display: grid; grid-template-columns: 1.25fr 1fr; gap: 22px; }
.modal-signup { border-left: 1px solid var(--border); padding-left: 22px; }
.modal-signup h3 { margin: 0 0 6px; font-size: 14px; }
.modal-signup p { font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.modal-signup form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.modal-signup form .modal-go { align-self: flex-start; }
@media (max-width: 640px) {
  .modal-cols { grid-template-columns: 1fr; }
  .modal-signup { border-left: none; padding-left: 0; border-top: 1px solid var(--border); padding-top: 14px; }
}
.modal-backdrop.open .modal { transform: none; }
.modal h2 { margin: 0 0 8px; font-size: 17px; }
.modal p, .modal li { font-size: 13px; line-height: 1.55; color: #334155; }
.modal ul { margin: 8px 0 12px; padding-left: 18px; }
.modal-go { background: var(--accent); color: #fff; border: none; padding: 8px 18px; }
/* Beat the generic button:hover (light gray) — white text needs the accent to stay */
.modal-go:hover { background: #6d28d9; color: #fff; }
/* Secondary action: outlined accent, visually distinct from the solid primary */
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); padding: 8px 18px; }
.btn-outline:hover { background: #ede9fe; color: var(--accent); }
.modal .qr-close { top: 8px; right: 10px; }

/* Audience picker (About modal): radios styled as toggle pills, one selected */
.audience { border: none; padding: 0; margin: 0; min-width: 0; }
.aud-btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.aud-btn input { position: absolute; opacity: 0; pointer-events: none; }
.aud-btn span {
  display: inline-block; padding: 5px 11px; border: 1px solid var(--border);
  border-radius: 999px; font-size: 12px; cursor: pointer; color: var(--muted);
  user-select: none; transition: background 0.12s ease, border-color 0.12s ease;
}
.aud-btn span:hover { border-color: var(--accent); color: var(--accent); }
.aud-btn input:checked + span { border-color: var(--accent); color: var(--accent); background: #ede9fe; font-weight: 600; }
.aud-btn input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.audience-text { font-size: 13px; line-height: 1.55; color: #334155; min-height: 2.6em; margin: 4px 0 8px; }

/* QR share popover: drops from the scenario bar under the share/QR buttons */
.qr-pop {
  position: absolute; top: calc(100% + 8px); right: 24px; z-index: 40;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.qr-pop svg { width: 180px; height: 180px; display: block; }
.qr-url { max-width: 220px; word-break: break-all; font-size: 11px; text-align: center; }
.qr-close { position: absolute; top: 4px; right: 8px; border: none; background: none; cursor: pointer; font-size: 15px; color: var(--muted); }

/* Structured preset notes inside the popover */
.info-pop h5 { margin: 9px 0 3px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.info-pop h5:first-child { margin-top: 0; }
.info-pop p { margin: 0 0 6px; font-weight: 400; }
.info-pop p:last-child { margin-bottom: 0; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  padding: 16px 24px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.panel h3 { margin: 16px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* .panel.revenue {
  max-height: 500px;
  overflow-y: scroll;
} */

/* Inputs */
label { display: block; margin-bottom: 10px; font-weight: 500; }
input[type="number"], input[type="text"], input[type="email"], select {
  width: 100%; margin-top: 3px; padding: 5px 7px;
  border: 1px solid var(--border); border-radius: 6px; font: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type="email"]:focus { border-color: var(--accent); }
input[type="range"] { width: calc(100% - 98px); vertical-align: middle; }
input.mini { width: 75px; display: inline-block; margin-left: 6px; }

.growth-inline + label input[type="range"] {
  width: 70px !important;
}

.capacity-source {
  margin-bottom: 20px !important;
}

/* Left panel: text label sits tight above its input row; larger gap between
   label+input groupings. Text-only labels vs input-row labels split via :has().
   (Supersedes the old nth-of-type spacing experiment.) */

   .panel.inputs {
    max-height: 540px;
  overflow-y: scroll;
   }


.inputs label { display: block; margin: 0 0 0px; font-weight: 500; }
.inputs label:has(input, select) {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 0 0 20px; font-weight: 400;
}
.inputs label input[type="range"] { flex: 1 1 60px; min-width: 60px; width: auto; }
.inputs label input.mini { flex: 0 0 60px; width: 60px; margin: 0; }
.inputs label select { flex: 1 1 100%; }
.inputs .derived { margin: -6px 0 14px; }
.inputs h3 { margin: 18px 0 10px; }

/* In-table slider + numeric pairs */
td { white-space: nowrap; }
input.cellrange { width: 64px; vertical-align: middle; }
input.cellnum { width: 78px; display: inline-block; margin-left: 4px; padding: 3px 6px; }
.tierlabel { font-size: 11px; color: var(--muted); white-space: normal; margin: 2px 0; }

/* Task cards */
.taskcard { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.taskcard-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.taskcard-body { display: flex; gap: 18px; flex-wrap: wrap; }
.taskcard .advanced { margin-top: 6px; }
.taskcard .advanced label { font-weight: 400; font-size: 12px; margin-bottom: 6px; display: block; }

/* Standard controls on one line: bipolar slider + growth side by side */
.tc-top { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
/* .bipolar-wrap { flex: 1 1 220px; } */
.cloud-local { display: block; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.growth-inline { flex: 0 1 220px; margin: 0; }
.growth-inline input[type="range"] { width: 50px; }
.growth-inline .mini { width: 56px; }

/* Token spectrum slider with icon ticks */
.tokslider-wrap { margin: 0px 0 48px; width: 400px; }
.tokslider-inner { position: relative; }
input[type="range"].tokslider { width: 100%; }
.tokslider-wrap > .hint { margin-bottom: 2px; }
.tok-ticks { position: absolute; left: 0; right: 0; top: 20px; height: 38px; }
.tok-tick { position: absolute; transform: translateX(-50%); border: none; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.tok-tick::before { content: ''; display: block; width: 1px; height: 5px; background: var(--muted); margin-bottom: 2px; }
.tok-tick .sw-ico { width: 16px; height: 16px; }
.tok-tick .sw-letter { line-height: 16px; font-size: 11px; }
.tok-name { font-size: 9px; color: var(--muted); margin-top: 1px; max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Bipolar Cloud <-> Local slider */
.bipolar { display: flex; align-items: center; gap: 8px; font-weight: 500; }
/* .bipolar input[type="range"] { flex: 1; width: auto; } */
.bipolar-marks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin: 0 2px; }

.bipolar input[type="range"] {
  width: 100px;
}

/* Software / model mix column */
.software-col { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }
.software-rows { display: flex; flex-direction: column; gap: 3px; }
.sw-row { display: grid; grid-template-columns: 16px minmax(90px, 1fr) 80px 56px 20px; align-items: center; gap: 6px; font-size: 13px; }
.sw-ico { position: relative; width: 14px; height: 14px; display: inline-block; }
.sw-ico img { position: absolute; inset: 0; width: 100%; height: 100%; background: var(--panel); }
.sw-letter { position: absolute; inset: 0; font-size: 10px; font-weight: 700; color: var(--muted); text-align: center; line-height: 14px; }
.sw-name { white-space: normal; }
.sw-local { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #b45309; background: #fef3c7; border-radius: 3px; padding: 0 4px; margin-left: 4px; vertical-align: middle; }
.sw-local.hybrid { color: #0369a1; background: #e0f2fe; }
.cloudcap { margin: 4px 0 2px; display: none; }
/* .tok-local { opacity: 0.45; } */
/* .tok-local .tok-name { text-decoration: line-through; } */
.sw-row input[type="range"] { width: 80px; }
.sw-row input.cellnum { width: 56px; margin: 0; padding: 2px 4px; }
.sw-remove { border: none; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 14px; line-height: 1; }
.sw-remove:hover { color: #dc2626; }
.sw-catalog { margin-top: 6px; font-size: 12px; }

/* Advanced settings wrapper for the model mix / capacity / horizon block */
.advanced-panel { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.advanced-panel summary { font-weight: 600; }

.derived { color: var(--muted); font-size: 13px; margin: 8px 0; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }

details { margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; color: var(--muted); margin-bottom: 8px; }

/* Center column */
.center { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; min-width: 120px;
}
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .v { font-size: 17px; font-weight: 650; }
.stat.good .v { color: #16a34a; }
.stat.bad .v { color: #dc2626; }

.chart-wrap {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; overflow: hidden;
}

/* Chart header: electricity-curve toggle sits top-right above the plot */
.chart-head { display: flex; justify-content: flex-end; gap: 16px; align-items: center; margin-bottom: 4px; }
.toggle-elec { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 400; color: var(--muted); margin: 0; cursor: pointer; }
.toggle-elec input { width: auto; margin: 0; }

/* Horizontal pan strip: appears (JS) when the full-horizon y spread is wide
   enough that t=0 values render glued to the axis; scrolling pans the time
   window and the y-axis re-fits to the visible slice. */
.chart-scroll { overflow-x: auto; overflow-y: hidden; height: 14px; margin-top: 4px; cursor: default; }
.chart-scroll > div { height: 1px; }

/* Mini chart: fixed to the top-left corner; revealed by JS
   (IntersectionObserver) once the main chart scrolls out of view. */
#miniChartWrap {
  position: fixed; top: 8px; left: 24px; width: 300px; z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}
#miniChartWrap .hint { margin-bottom: 4px; }
@media (max-width: 900px) {
  #miniChartWrap { display: none; }
}

/* Mix tables */
table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 4px 6px; }
td { padding: 2px 6px; }
td input { padding: 3px 6px; margin: 0; }

.rev-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 4px 16px;
  margin-top: 8px;
}

button {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font: inherit; cursor: pointer;
}
button:hover { background: #f1f5f9; }
button:disabled { opacity: 0.65; cursor: wait; }

footer { padding: 8px 24px 24px; color: var(--muted); font-size: 12px; }
code { background: #eef2ff; padding: 1px 5px; border-radius: 4px; }

/* uPlot legend tweaks */
.u-legend { font-size: 12px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  /* Graph first on mobile: center column (stats + chart + usage) above the
     inputs panel; compact stat chips so the chart is one glance away. */
  .center { order: -1; }
  .stats { gap: 6px; }
  .stat { padding: 5px 8px; min-width: 0; }
  .stat .k { font-size: 9.5px; }
  .stat .v { font-size: 14px; }
  /* Quick guide takes its own row under the settings panel on small screens */
  .quick-help { flex-basis: 100%; margin-left: 0px; }
}
