/* SpecEnvoy Heat Tracker — styles. Builds on /style.css design tokens.
 * Choropleth ramp: "fire & ice" diverging scale validated for the dark navy
 * surface (#0e1730) with the dataviz palette validator — extremes get brighter
 * (blazing amber / pale ice), near-normal recedes into dark slate. Both arms
 * pass monotone-lightness, step-gap, and light-end contrast checks. */

.heat-wide { max-width: 1100px; }

.heat {
  /* cold arm c4 (extreme) … c0 (leaning cool) | neutral | a0 (leaning warm) … a4 (extreme).
   * c0/a0 distinguish by hue/chroma, not lightness — deliberate: near-normal must stay
   * quiet but read as a color, never as disabled. CVD ΔE vs neutral ≥ 13 (validated). */
  --hc4: #a5d8f0; --hc3: #64b0e0; --hc2: #3f86c4; --hc1: #2b5f9e; --hc0: #38598f;
  --hn:  #444d6e;
  --ha0: #84462a; --ha1: #9c3218; --ha2: #c94a1b; --ha3: #ea6a24; --ha4: #ff9433;
  --hnodata: #1c2338;
  --hrec: #ffffff;          /* record-breaker stroke */
  --hsel: #ffffff;          /* selection stroke */
  margin-top: 8px;
}

/* ---------------------------------------------------------------- header */
.heat-head { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: baseline;
  margin: 0 0 12px; }
.heat-window { font-size: 14px; color: var(--ink); font-weight: 600; }
.heat-updated { font-size: 12.5px; color: var(--muted); }
.heat-counts { font-size: 13.5px; color: var(--muted); }
.heat-counts strong { color: #ff9433; font-variant-numeric: tabular-nums; }
.heat-counts strong.rec { color: #fff; }
.heat-stale { background: rgba(255, 148, 51, .14); border: 1px solid rgba(255,148,51,.5);
  color: var(--ink); border-radius: 10px; padding: 9px 13px; font-size: 13.5px; margin: 0 0 12px; }
body.heat-kiosk .heat-stale { display: none; }

/* ---------------------------------------------------------------- controls */
.heat-controls {
  display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 14px;
}
.ctr-group { display: flex; flex-direction: column; gap: 6px; }
.ctr-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ctr-search { flex: 1 1 220px; position: relative; }

.heat-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn { background: transparent; color: var(--muted); border: 0; padding: 9px 14px;
  font: inherit; font-size: 14px; cursor: pointer; min-height: 40px; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.on { background: var(--accent); color: #fff; }
.seg-btn:not(.on):hover { color: var(--ink); background: var(--accent-soft); }

.heat-search { width: 100%; box-sizing: border-box; padding: 10px 14px; min-height: 42px;
  background: rgba(255,255,255,.05); border: 1px solid var(--border); border-radius: 10px;
  color: var(--ink); font: inherit; font-size: 15px; }
.heat-search:focus { outline: none; border-color: var(--accent); }
.heat-results { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin-top: 6px;
  background: #0f1830; border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,.4); max-height: 320px; overflow-y: auto; }
.res-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; border-bottom: 1px solid var(--border); color: var(--ink);
  padding: 11px 14px; font: inherit; font-size: 15px; cursor: pointer; text-align: left; }
.res-row:last-child { border-bottom: 0; }
.res-row:hover { background: var(--accent-soft); }
.res-tag { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }
.res-val { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }

.heat-play { background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 16px; min-height: 40px; font: inherit; font-size: 14px; cursor: pointer; }
.heat-play.on { background: var(--heart); }

/* ------------------------------------------------------------ stage layout */
.heat-stage { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 860px) { .heat-stage { grid-template-columns: 1.35fr 1fr; align-items: start; } }

.heat-mapbox { position: relative; background: #0c1426; border: 1px solid var(--border);
  border-radius: 16px; overflow: hidden; height: clamp(300px, 54vh, 560px); touch-action: none; }
.heat-mapbox:fullscreen { border-radius: 0; height: 100%; }
.heat-map, .heat-svg.main { width: 100%; height: 100%; display: block; }
.heat-svg.main { cursor: grab; }
.heat-svg.main.grabbing { cursor: grabbing; }

/* choropleth buckets — classes assigned by heat.js bucket(); CSS owns the colors */
.heat-svg .nodata { fill: var(--hnodata); stroke: #0c1426; stroke-width: .3; }
.heat-svg .hit { stroke: #0c1426; stroke-width: .3; cursor: pointer; transition: fill .2s; }
.heat-svg .h-c4 { fill: var(--hc4); } .heat-svg .h-c3 { fill: var(--hc3); }
.heat-svg .h-c2 { fill: var(--hc2); } .heat-svg .h-c1 { fill: var(--hc1); }
.heat-svg .h-c0 { fill: var(--hc0); }
.heat-svg .h-n  { fill: var(--hn); }
.heat-svg .h-a0 { fill: var(--ha0); }
.heat-svg .h-a1 { fill: var(--ha1); } .heat-svg .h-a2 { fill: var(--ha2); }
.heat-svg .h-a3 { fill: var(--ha3); } .heat-svg .h-a4 { fill: var(--ha4); }
.heat-svg .hit:hover { filter: brightness(1.3); }
.heat-svg .h-rec { stroke: var(--hrec); stroke-width: .9; }
.heat-svg .sel { stroke: var(--hsel); stroke-width: 1.3; filter: brightness(1.15); }
.heat-marker circle { stroke: #fff; stroke-width: 1.2; cursor: pointer; fill: var(--hn); }
.heat-marker.h-rec circle { stroke-width: 2; }
.heat-marker text { fill: var(--ink); paint-order: stroke; stroke: #0c1426; stroke-linejoin: round;
  font-weight: 600; text-anchor: middle; pointer-events: none;
  font-family: system-ui, sans-serif; }

.heat-zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.heat-zoom button { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
  background: rgba(10,16,32,.85); color: var(--ink); font-size: 20px; line-height: 1; cursor: pointer; }
.heat-zoom button:hover { border-color: var(--accent); }
.heat-zoom .heat-fsbtn { font-size: 15px; }
.heat-playtag { position: absolute; left: 10px; top: 10px; background: rgba(255,93,143,.92);
  color: #fff; font-size: 12px; padding: 5px 10px; border-radius: 8px; max-width: 70%; z-index: 5; }

/* legend — swatches reuse the same custom props as the map buckets */
.heat-legend { position: absolute; left: 10px; bottom: 10px; z-index: 4;
  background: rgba(10,16,32,.88); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 11px; max-width: calc(100% - 70px); }
.heat-legend .lg-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-bottom: 5px; }
.lg-row { display: flex; align-items: flex-end; gap: 0; }
.lg-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.lg-swatch { width: 26px; height: 10px; }
.lg-cell:first-child .lg-swatch { border-radius: 3px 0 0 3px; }
.lg-cell:nth-last-child(2) .lg-swatch { border-radius: 0 3px 3px 0; }
.lg-lab { font-size: 9.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lg-extra { display: flex; align-items: center; gap: 5px; margin-left: 12px; }
.lg-extra .lg-swatch { width: 14px; border-radius: 3px; }
.lg-extra.lg-record .lg-swatch { background: var(--ha4); box-shadow: 0 0 0 1.5px #fff; height: 8px; }
.lg-extra .lg-lab { font-size: 10px; }

/* --------------------------------------------------------------- panel */
.heat-panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.heat-hint { color: var(--muted); font-size: 15px; background: var(--card);
  border: 1px dashed var(--border); border-radius: 14px; padding: 22px; text-align: center; }

.heat-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; }
.heat-card.subject { border-color: var(--accent); background: var(--accent-soft); }
.card-head { margin-bottom: 8px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-kind { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.card-title { margin: 2px 0 0; font-size: 19px; font-weight: 650; line-height: 1.25; }

.heat-big { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 4px 0 2px; }
.heat-big .val { font-size: 40px; font-weight: 750; line-height: 1; letter-spacing: -.01em; }
.heat-big .when { font-size: 13px; color: var(--muted); }
.heat-chip { display: inline-block; font-size: 13px; font-weight: 700; border-radius: 8px;
  padding: 4px 9px; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.heat-chip.hot { background: rgba(234,106,36,.18); color: #ff9433; border: 1px solid rgba(255,148,51,.45); }
.heat-chip.cold { background: rgba(100,176,224,.15); color: #a5d8f0; border: 1px solid rgba(165,216,240,.4); }
.heat-chip.flat { background: rgba(255,255,255,.06); color: var(--muted); border: 1px solid var(--border); }
.heat-chip.record { background: rgba(255,255,255,.92); color: #9c3218; border: 0; }

.heat-metrics { width: 100%; border-collapse: collapse; margin: 8px 0 2px; }
.heat-metrics th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px;
  padding: 6px 0; white-space: nowrap; vertical-align: baseline; }
.heat-metrics td { text-align: right; font-variant-numeric: tabular-nums; font-size: 15px;
  font-weight: 600; padding: 6px 0; }
.heat-metrics .sub { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }

.heat-breakdown { display: block; width: 100%; margin-top: 12px; background: var(--accent);
  color: #fff; border: 0; border-radius: 10px; padding: 10px 14px; font: inherit;
  font-size: 14px; cursor: pointer; text-align: center; }
.heat-breakdown:hover { filter: brightness(1.12); }

.heat-event { border-left: 3px solid #ff9433; }
.heat-event h4 { margin: 0 0 6px; font-size: 15px; }
.heat-event p { margin: 0 0 8px; font-size: 13.5px; line-height: 1.55; color: var(--ink); }
.heat-event .ev-links { font-size: 12.5px; }
.heat-event .ev-links a { color: var(--accent); margin-right: 10px; }

.heat-footnote { font-size: 11.5px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

/* --------------------------------------------------------------- footer */
.heat-foot { color: var(--muted); font-size: 13px; margin-top: 16px; }
.heat-foot a { color: var(--accent); }

/* --------------------------------------------------------------- modal */
.heat-modal { position: fixed; inset: 0; z-index: 100; background: rgba(4,8,18,.7);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.heat-modal-box { background: #0f1830; border: 1px solid var(--border); border-radius: 16px;
  padding: 22px 24px; max-width: 500px; width: 100%; max-height: 80vh; overflow-y: auto; }
.heat-modal-box h3 { margin: 0 0 10px; }
.heat-modal-box ul { margin: 6px 0 14px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.heat-modal-box .muted { font-size: 13px; color: var(--muted); }
.heat-modal-close { background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 9px 18px; font: inherit; cursor: pointer; margin-top: 6px; }

/* ------------------------------------------- recording: kiosk + tour mode
 * Same contract as GDP Atlas (?kiosk=1 / ?tour=…, see heat.js + specenvoy-video). */
body.heat-kiosk { background: #0a0f1f; }
body.heat-kiosk .topbar,
body.heat-kiosk .crumbs,
body.heat-kiosk .hero-title,
body.heat-kiosk .tagline,
body.heat-kiosk .note,
body.heat-kiosk .heat-feels,
body.heat-kiosk .heat-foot,
body.heat-kiosk footer { display: none !important; }
body.heat-kiosk .wrap.heat-wide { max-width: none; margin: 0; padding: 20px; }
body.heat-kiosk .heat { margin-top: 0; }
body.heat-kiosk .heat-mapbox { height: clamp(360px, 88vh, 1400px); }
body.heat-tour .heat-controls,
body.heat-tour .heat-playtag { display: none !important; }

/* -------------------------------------------------- overflow safeguards */
.heat, .heat-stage > *, .heat-panel, .heat-mapbox, .heat-card { min-width: 0; }
.heat-metrics td { overflow-wrap: anywhere; }

/* -------------------------------------------------------- mobile layout */
@media (max-width: 600px) {
  .heat-controls { flex-direction: column; align-items: stretch; gap: 12px; }
  .ctr-group { width: 100%; }
  .heat-seg { width: 100%; }
  .seg-btn { flex: 1; }
  .heat-play { width: 100%; }
  .ctr-search { flex-basis: auto; }
  .heat-big .val { font-size: 34px; }
  .lg-swatch { width: 20px; }
  .lg-cell:nth-child(even) .lg-lab { visibility: hidden; } /* declutter tick labels */
}
