/* ChillySOS simulator · "Instrument": true-black flat (taste-skill app style) on Linear's surface ladder.
   One face (Schibsted Grotesk), elevation by lightness only, colour on risk and the one action. */
:root {
  --bg: #0a0a0a; --s1: #121212; --s2: #1a1a1a; --s3: #242424;
  --ink: #efefef; --muted: #a3a3a3; --subtle: #8a8a8a;
  --accent: #e0243a; --accent-ink: #fff;
  --heat: #ff3b40; --cold: #82ceeb; --brand-red: #d61c1f; --brand-navy: #102942; --brand-ice: #82ceeb; --dot-low: #3fbf7f; --line: var(--s3);
  /* names used by auth.js / ask.js styles */
  --panel: var(--s1); --panel-2: var(--s2); --text: var(--ink); --extreme: #eb4d5b; --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --hz: var(--heat);
  --font-ui: "Schibsted Grotesk", system-ui, sans-serif;
  --r: 6px;
}
:root[data-hazard="cold"] { --hz: var(--cold); }
/* The app's theme follows the hazard: warm blacks and crimson for heat, blue-blacks and ice-blue for cold.
   Everything (bar, panel, timebar, inspector, Ask, sign-in) reads these tokens. */
:root[data-hazard="heat"] { --bg: #0d0909; --s1: #170f0f; --s2: #221616; --s3: #2f1f1f; --ink: #f5ecea; --muted: #b8a6a3; --subtle: #998784; --accent: #d61c1f; --accent-ink: #fff; }
:root[data-hazard="cold"] { --bg: #08121d; --s1: #0e1b2a; --s2: #142538; --s3: #1d3249; --ink: #eaf3fa; --muted: #a0b5c8; --subtle: #8499ad; --accent: #82ceeb; --accent-ink: #102942; }
body, .topbar, .panel, .timebar, .inspector, .ask, .seg, select, .bar-row, .shelter-list li { transition: background-color .4s ease, color .4s ease; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* resident filter */
.filter { margin-bottom: 28px; }
.filter-head { display: flex; justify-content: space-between; align-items: baseline; }
.filter h2 { margin: 0 0 12px; }
.filter-selects { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filter-selects select { width: 100%; }
.filter-traits { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.filter-traits button { border: 0; background: var(--s1); color: var(--muted); padding: 6px 10px; border-radius: 99px; cursor: pointer; font-size: 13px; min-height: 32px; }
.filter-traits button:hover { color: var(--ink); background: var(--s2); }
.filter-traits button.on { background: var(--hz); color: var(--bg); }
.filter-summary { margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.filter-summary b { color: var(--ink); font-weight: 600; }
* { box-sizing: border-box; }
html { color-scheme: dark; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.45 var(--font-ui); letter-spacing: -0.005em; }
body { display: flex; flex-direction: column; }
button, select, input { font: inherit; color: inherit; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: 8px; z-index: 20; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: var(--r); }
.skip:focus { left: 8px; }

/* bar: one row, scenario as compact segments */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left)); background: var(--bg); flex: none; z-index: 5; }
.brand { display: flex; align-items: baseline; gap: 8px; color: var(--ink); text-decoration: none; flex: none; }
.logo { width: 30px; height: 31px; align-self: center; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -0.04em; }
.brand-sos { color: var(--brand-red); }
:root[data-hazard="cold"] .brand-sos { color: var(--brand-ice); }
.brand-sub { color: var(--muted); font-size: 14px; }
.controls { display: flex; align-items: center; gap: 18px; flex: 1; min-width: 0; flex-wrap: wrap; }
.control-field { display: flex; align-items: center; gap: 8px; }
.control-label { font-size: 13px; color: var(--subtle); }
.seg { display: flex; background: var(--s1); border-radius: var(--r); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 14px; white-space: nowrap; min-height: 32px; }
.seg button:hover { color: var(--ink); background: var(--s2); }
.seg button.on { background: var(--s3); color: var(--ink); }
#hazard-seg button.on { color: var(--hz); }
select { background: var(--s1); border: 0; border-radius: var(--r); padding: 7px 10px; color: var(--ink); min-height: 34px; }
.top-actions { display: flex; gap: 4px; flex: none; }
.ghost { background: none; border: 0; color: var(--muted); padding: 8px 10px; border-radius: var(--r); cursor: pointer; text-decoration: none; font-size: 14px; }
.ghost:hover { color: var(--ink); background: var(--s1); }

/* map takes the screen; panel is a quiet column */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 360px; }
.map-wrap { position: relative; overflow: hidden; background: var(--bg); }
#map { position: absolute; inset: 0; }
.hud-title { position: absolute; top: 20px; left: 20px; max-width: min(560px, calc(100% - 40px)); z-index: 2; pointer-events: none; }
.hud-title > * { pointer-events: auto; }
.finding { margin: 0; font-weight: 600; font-size: clamp(22px, 2.1vw, 30px); line-height: 1.15; letter-spacing: -0.03em; text-wrap: balance; text-shadow: 0 0 18px #000, 0 0 2px #000; }
.finding b { display: block; font-weight: 800; font-size: clamp(56px, 6vw, 88px); line-height: 0.95; letter-spacing: -0.05em; color: var(--hz); text-shadow: none; }
.finding-sub { margin: 10px 0 0; font-size: 14px; color: var(--muted); max-width: 46ch; text-shadow: 0 0 10px #000; }
.link { background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link:hover { color: var(--hz); }
.map-badge { margin-top: 14px; font-size: 13px; color: var(--muted); max-width: 52ch; }
.map-badge b { display: block; color: var(--ink); font-weight: 600; font-size: 14px; }
.map-badge .muted { display: none; }
.tooltip { position: absolute; pointer-events: none; background: var(--s2); padding: 8px 10px; border-radius: var(--r); font-size: 13px; z-index: 6; max-width: 260px; box-shadow: 0 8px 24px #000a; }

/* timebar floats over the map's foot */
.timebar { position: absolute; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 3;
  display: grid; grid-template-columns: auto auto 1fr auto auto; grid-template-rows: auto auto; align-items: center; gap: 10px 16px;
  padding: 14px 16px; background: var(--s1); border-radius: 10px; }
.play { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); cursor: pointer; position: relative; }
.play:hover { filter: brightness(1.1); }
.play::before { content: ""; position: absolute; left: 17px; top: 14px; border-style: solid; border-width: 8px 0 8px 13px; border-color: transparent transparent transparent var(--accent-ink); }
.play.playing::before { left: 16px; top: 15px; width: 4px; height: 14px; border: 0; background: var(--accent-ink); box-shadow: 8px 0 0 var(--accent-ink); }
.clockbox { min-width: 128px; }
.clock { font-weight: 800; font-size: 26px; letter-spacing: -0.04em; line-height: 1; }
.readout { font-size: 13px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
/* The range thumb's centre runs from --thumb/2 to width − --thumb/2, so the spark and the tick labels are inset by
   the same amount: the playhead line, the thumb and "12 PM" then line up exactly at noon. */
.time-track { --thumb: 16px; position: relative; height: 50px; min-width: 120px; }
.spark { position: absolute; top: 0; left: calc(var(--thumb) / 2); width: calc(100% - var(--thumb)); height: 30px; }
#time { position: absolute; left: 0; right: 0; top: 22px; width: 100%; height: var(--thumb); margin: 0; -webkit-appearance: none; appearance: none; background: none; cursor: pointer; }
#time::-webkit-slider-runnable-track { height: 4px; background: var(--s3); border-radius: 2px; }
#time::-moz-range-track { height: 4px; background: var(--s3); border-radius: 2px; }
#time::-webkit-slider-thumb { -webkit-appearance: none; width: var(--thumb); height: var(--thumb); margin-top: -6px; border-radius: 50%; background: var(--ink); border: 0; }
#time::-moz-range-thumb { width: var(--thumb); height: var(--thumb); border-radius: 50%; background: var(--ink); border: 0; }
.ticks { position: absolute; left: calc(var(--thumb) / 2); right: calc(var(--thumb) / 2); bottom: -6px; height: 14px; font-size: 12px; color: var(--subtle); }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.peak { background: var(--s2); color: var(--ink); white-space: nowrap; }
.speed { background: var(--s2); }
.keyrow { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend { display: flex; gap: 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend b { color: var(--ink); font-weight: 600; min-width: 4ch; }
.ramp { display: flex; align-items: center; gap: 8px; }
.ramp-steps { display: inline-flex; gap: 2px; }
.ramp-steps i { width: 18px; height: 8px; background: var(--hz); border-radius: 1px; }
.ramp-range { color: var(--ink); }

/* panel */
.panel { background: var(--bg); overflow-y: auto; padding: 20px 22px 28px; }
.panel h2 { margin: 0 0 4px; font-size: 20px; font-weight: 600; letter-spacing: -0.03em; }
.panel-head p { margin: 0; font-size: 14px; }
.caution { font-size: 14px; margin: 16px 0 0; padding: 10px 12px; background: var(--s1); border-radius: var(--r); color: var(--ink); }
.bars { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; }
.bar-row { cursor: pointer; padding: 10px 10px 12px; border-radius: var(--r); background: var(--s1); }
.bar-row:hover { background: var(--s2); }
.bar-row.on { background: var(--s3); }
.bar-label { font-size: 14px; margin-bottom: 8px; min-width: 0; }
.bar-label .muted { font-size: 13px; }
.bar-track { position: relative; height: 6px; background: var(--s3); border-radius: 3px; margin-bottom: 4px; }
.bar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; }
.bar-fill.base { background: var(--hz); }
.bar-fill.iv { background: var(--muted); }
.bar-nums { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }
#shelter-panel { margin-top: 24px; }
.shelter-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.shelter-list li { background: var(--s1); border-radius: var(--r); padding: 12px; }
.shelter-site { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; border: 0; background: none; cursor: pointer; padding: 0; }
.shelter-site.selected strong { color: var(--hz); }
.shelter-rank { min-width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--ink); color: var(--bg); }
.shelter-site strong { font-weight: 600; font-size: 14px; }
.site-address { display: block; font-size: 13px; margin-top: 3px; overflow-wrap: anywhere; }
.shelter-site-metrics { margin: 10px 0 0 36px; font-size: 13px; color: var(--muted); line-height: 1.55; }
.credits { margin-top: 28px; font-size: 13px; color: var(--subtle); }

/* inspector */
.inspector { position: absolute; top: 16px; right: 16px; width: 380px; max-height: calc(100% - 170px); overflow-y: auto; z-index: 4;
  background: var(--s1); border-radius: 10px; padding: 20px; overscroll-behavior: contain; box-shadow: 0 16px 48px #000c; }
.close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; border-radius: var(--r); }
.close:hover { background: var(--s2); color: var(--ink); }
.persona-head { display: flex; gap: 12px; align-items: center; padding-right: 36px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--s3); color: var(--ink); flex: none; }
.persona-name { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.03em; }
.persona-sub { font-size: 14px; color: var(--muted); }
.persona-figure { margin: 18px 0 10px; display: flex; align-items: baseline; gap: 10px; }
.persona-figure b { font-size: 40px; font-weight: 800; letter-spacing: -0.05em; line-height: 1; color: var(--hz); }
.persona-figure span { font-size: 14px; color: var(--muted); }
.timeline { display: grid; grid-template-columns: repeat(17, 1fr); gap: 2px; }
.cell { height: 34px; border-radius: 3px; display: grid; place-items: center; font-size: 12px; }
.cell.now { outline: 2px solid var(--ink); outline-offset: 1px; }
.tl-hours { display: grid; grid-template-columns: repeat(17, 1fr); font-size: 12px; color: var(--subtle); margin-top: 4px; }
.tl-hours span { text-align: center; }
.why-box { margin: 16px 0; }
.why-btn { width: 100%; min-height: 44px; border: 0; border-radius: var(--r); background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; padding: 10px 14px; }
.why-btn:hover { filter: brightness(1.1); }
.why-btn:disabled { opacity: .7; cursor: progress; }
.why-text p { margin: 12px 0 6px; font-size: 15px; line-height: 1.55; }
.why-src { font-size: 13px; color: var(--subtle); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chip { font-size: 13px; padding: 4px 8px; border-radius: 4px; background: var(--s2); color: var(--muted); }
.chip.hot { color: var(--ink); background: var(--s3); }
.hint { font-size: 13px; color: var(--subtle); margin: 8px 0 12px; }
details { margin-top: 8px; background: var(--s2); border-radius: var(--r); padding: 10px 12px; font-size: 14px; }
summary { cursor: pointer; color: var(--ink); }
.steps { margin-top: 8px; max-height: 220px; overflow-y: auto; }
.step { display: grid; grid-template-columns: 40px 1fr; gap: 6px; padding: 5px 0; }
.step .h { color: var(--subtle); }
.step .why { color: var(--muted); font-size: 13px; }
.trace ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.trace p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

/* modal */
.modal { width: min(820px, 92vw); max-height: 86vh; border: 0; border-radius: 12px; padding: 28px; background: var(--s1); color: var(--ink); overscroll-behavior: contain; box-shadow: 0 24px 64px #000; }
.modal::backdrop { background: #000c; }
.modal h2 { margin: 0 0 12px; font-size: 24px; letter-spacing: -0.03em; padding-right: 40px; }
.modal p { color: var(--muted); }
.modal table { width: 100%; border-collapse: collapse; font-size: 14px; }
.modal th, .modal td { text-align: left; padding: 8px; border-top: 1px solid var(--s3); }

.maplibregl-ctrl-attrib { background: #0a0a0aaa !important; color: var(--muted) !important; font-size: 12px; }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }

@media (max-width: 1500px) and (min-width: 1101px) {
  .control-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .controls { gap: 10px; flex-wrap: nowrap; }
  .topbar { gap: 16px; }
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(560px, 72svh) auto; }
  .topbar { flex-wrap: wrap; gap: 10px 16px; }
  .controls { order: 3; flex-basis: 100%; }
}
@media (max-width: 600px) {
  body { display: block; height: auto; }
  .topbar { padding: 10px 16px; }
  .brand-sub { display: none; }
  .controls { gap: 8px 12px; }
  .control-field { flex-wrap: wrap; }
  .control-label { width: 100%; font-size: 12px; }
  .seg button { padding: 6px 8px; font-size: 13px; }
  .top-actions .ghost { padding: 8px 6px; font-size: 13px; }
  .layout { grid-template-rows: 640px auto; }
  .hud-title { left: 16px; right: 16px; top: 14px; }
  .finding b { font-size: 52px; }
  .finding { font-size: 20px; }
  .map-badge { display: none; }
  .timebar { left: 8px; right: 8px; bottom: 8px; grid-template-columns: auto 1fr auto auto; padding: 12px; gap: 8px 10px; }
  .time-track { grid-column: 1 / -1; grid-row: 2; }
  .keyrow { grid-row: 3; }
  .ramp { display: none; }
  .inspector { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 78%; }
  .panel { padding: 22px 16px 32px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* tabular figures only where numbers line up (global tabular-nums widens punctuation in this face) */
.legend b { font-variant-numeric: tabular-nums; }

/* sign-in gate (auth.js): the planner page is for government accounts */
.gate {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: var(--bg);
}
.gate-card {
  width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  padding: 28px 24px; display: flex; flex-direction: column; gap: 12px;
}
.gate-card .logo { width: 40px; height: 40px; }
.gate-card h2 { margin: 4px 0 0; font-size: 22px; }
.gate-card p { margin: 0; }
.gate-btn {
  padding: 11px; border-radius: 3px; border: 0; cursor: pointer; font-weight: 600;
  background: var(--accent); color: #062026;
}
.gate-btn:hover { filter: brightness(1.08); }
.gate-msg { color: var(--text); }
.gate-err { color: var(--extreme); }
.who { font-size: 13px; color: var(--muted); align-self: center; margin-right: 4px; white-space: nowrap; }
.top-actions .ghost { white-space: nowrap; }

/* Ask the simulation (ask.js): Gemini text-to-SQL over the resident-hour tables */
.ghost.ask-open { color: var(--accent); }
.ask {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(440px, 100vw);
  display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line);
}
.ask-head { display: flex; justify-content: space-between; gap: 12px; padding: 20px 20px 14px; border-bottom: 1px solid var(--line); }
.ask-head h2 { margin: 0 0 4px; font-size: 17px; font-weight: 600; letter-spacing: -.3px; }
.ask-head p { margin: 0; font-size: 12px; line-height: 1.5; }
.ask-log { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.ask-log:empty { display: none; }
.ask-q { align-self: flex-end; max-width: 85%; background: var(--panel-2); border-radius: 3px; padding: 9px 12px; font-size: 13px; line-height: 1.5; }
.ask-a { font-size: 13px; line-height: 1.6; border-left: 2px solid var(--accent); padding: 2px 0 2px 12px; }
.ask-a p { margin: 0 0 6px; }
.ask-a.pending { color: var(--muted); }
.ask-a.err { border-left-color: var(--extreme); color: var(--muted); }
.ask-meta { font-size: 11px; color: var(--muted); }
.ask-a details { margin-top: 8px; font-size: 12px; }
.ask-a summary { cursor: pointer; color: var(--accent); padding: 4px 0; }
.ask-a pre { white-space: pre-wrap; word-break: break-word; font: 500 11px/1.6 var(--mono); background: var(--bg); padding: 10px; border-radius: 3px; margin: 6px 0; }
.ask-table { overflow-x: auto; }
.ask-table table { border-collapse: collapse; font-size: 11px; width: 100%; }
.ask-table th, .ask-table td { text-align: left; padding: 5px 8px 5px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ask-table th { color: var(--muted); font-weight: 600; }
.ask-presets { padding: 16px 20px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.ask-log:empty + .ask-presets { flex: 1; }
.ask-presets.compact { flex-direction: row; flex-wrap: wrap; padding: 10px 20px 0; max-height: 120px; }
.ask-presets:empty { display: none; }
.ask-label { margin: 0 0 4px; font-size: 11px; font-weight: 600; color: var(--muted); }
.ask-chip {
  text-align: left; padding: 9px 11px; border-radius: 3px; border: 1px solid var(--line); background: none;
  color: var(--text); font: inherit; font-size: 12.5px; line-height: 1.45; cursor: pointer;
}
.ask-chip:hover { background: var(--panel-2); }
.ask-presets.compact .ask-chip { font-size: 11.5px; padding: 6px 9px; }
.ask-form { display: flex; gap: 8px; padding: 14px 20px 18px; }
.ask-form input {
  flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 3px;
  padding: 10px 12px; font: inherit; font-size: 13px;
}
.ask-send { background: var(--accent); color: var(--bg); border: 0; border-radius: 3px; padding: 0 16px; font-weight: 600; cursor: pointer; }
.ask-a p{white-space:pre-line}
.ask-send { color: var(--accent-ink); }

/* sign-in gate shows the full logo (light wordmark for the dark ground) */
.gate-logo { width: 220px; height: auto; margin-bottom: 4px; }
.gate-btn { color: var(--accent-ink); }
