/* ============================================================================
   KaiProva — Public Regional Activation Map
   Panel / choropleth / heat-band / region-card / pledge-form / reveal styles.
   Consumes the existing brand tokens (/brand/tokens.css + landing.html :root
   green-ramp lift). No new colour values invented outside the --kp-* palette.
   Loaded only by landing.html; the .visibility-map section self-gates hidden
   until the API returns 200 (see public/js/visibility-map.js).
   ============================================================================ */

/* The section ships hidden; JS removes [hidden] only on a 200 from the API. */
section.visibility-map[hidden] { display: none; }

section.visibility-map { background: var(--kp-paper-2); }

.vm-head { max-width: 64ch; }

/* ---- In-page NZ/AU toggle — visually matches .audience-tab, but a vanilla-JS
   in-page switch (no navigation). Rendered on the cream section, so the colours
   invert vs the dark topbar tabs. ---- */
.vm-toggle {
  display: inline-flex;
  gap: 0;
  margin: 1.75rem 0 0.5rem;
  border-bottom: 1px solid var(--brand-rule);
}
.vm-tab {
  appearance: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--kp-sans);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--kp-ink-2);
  padding: 0.55rem 1.25rem;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.vm-tab:hover { color: var(--kp-pasture-deep); }
.vm-tab[aria-selected="true"] {
  color: var(--kp-pasture-deep);
  border-bottom-color: var(--kp-gold);
  font-weight: 600;
}
.vm-tab:focus-visible { outline: 2px solid var(--kp-pasture-mid); outline-offset: 2px; }

.vm-context {
  font-family: var(--kp-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--kp-ink-2);
  margin: 0.4rem 0 0;
  min-height: 1.2em;
}

/* ---- Two-column layout: map left, region card right. Stacks on narrow. ---- */
.vm-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 2rem;
  margin-top: 1.75rem;
  align-items: start;
}
@media (max-width: 760px) {
  .vm-stage { grid-template-columns: 1fr; gap: 1.25rem; }
}

/* ---- Choropleth ---- */
.vm-map-wrap {
  background: var(--kp-paper-3);
  border: 1px solid var(--brand-rule);
  border-radius: var(--kp-radius-md);
  padding: 1rem;
  position: relative;
}
.vm-map { display: none; width: 100%; height: auto; }
.vm-map.is-active { display: block; }
.vm-map path {
  stroke: var(--kp-paper-3);
  stroke-width: 0.9;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill 0.18s ease, stroke 0.15s ease, fill-opacity 0.18s ease;
  outline: none;
}
.vm-map path:hover,
.vm-map path:focus-visible {
  stroke: var(--kp-pasture-deep);
  stroke-width: 1.6;
}
.vm-map path.is-selected {
  stroke: var(--kp-pasture-deep);
  stroke-width: 2;
}

/* ---- Heat bands — keyed on band names from the API (latent_band/enrolled_band).
   `none` (and suppressed-and-low) renders as soft grey "enrolling", never blank.
   Ramp runs young-growth → bright → lit → mid → deep, all inside the palette. ---- */
.vm-map path { fill: var(--kp-paper-2); }                       /* default before bind */
.vm-map path[data-band="none"]      { fill: #D8D2C4; fill-opacity: 0.85; }  /* soft grey-cream "enrolling" */
.vm-map path[data-band="low"]       { fill: var(--kp-pasture-bright); fill-opacity: 0.55; }
.vm-map path[data-band="medium"]    { fill: var(--kp-pasture-lit);    fill-opacity: 0.78; }
.vm-map path[data-band="high"]      { fill: var(--kp-pasture-mid);    fill-opacity: 0.92; }
.vm-map path[data-band="very_high"] { fill: var(--kp-pasture-deep);   fill-opacity: 1; }

/* ---- Legend (which metric drives the heat + the band scale) ---- */
.vm-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.1rem;
  margin-top: 0.9rem;
  font-family: var(--kp-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--kp-ink-2);
}
.vm-legend-metric { display: inline-flex; gap: 0.4rem; align-items: center; }
.vm-metric-btn {
  appearance: none; border: 1px solid var(--brand-rule); background: var(--kp-paper-3);
  font-family: var(--kp-mono); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--kp-ink-2); cursor: pointer; padding: 0.25rem 0.6rem; border-radius: var(--kp-radius-sm);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.vm-metric-btn[aria-pressed="true"] {
  border-color: var(--kp-pasture-deep); color: var(--kp-pasture-deep); background: var(--kp-paper);
  font-weight: 500;
}
.vm-legend-scale { display: inline-flex; align-items: center; gap: 0.3rem; }
.vm-swatch { width: 16px; height: 12px; border-radius: 2px; border: 1px solid var(--brand-rule); display: inline-block; }
.vm-swatch[data-band="none"]      { background: #D8D2C4; }
.vm-swatch[data-band="low"]       { background: var(--kp-pasture-bright); }
.vm-swatch[data-band="medium"]    { background: var(--kp-pasture-lit); }
.vm-swatch[data-band="high"]      { background: var(--kp-pasture-mid); }
.vm-swatch[data-band="very_high"] { background: var(--kp-pasture-deep); }

/* ---- Region detail card ---- */
.vm-card {
  background: var(--kp-paper-3);
  border: 1px solid var(--brand-rule);
  border-radius: var(--kp-radius-md);
  padding: 1.5rem 1.4rem;
  position: sticky;
  top: 1rem;
}
.vm-card-hint {
  font-family: var(--kp-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--kp-ink-2);
  line-height: 1.5;
}
.vm-card-body { display: none; }
.vm-card.has-region .vm-card-body { display: block; }
.vm-card.has-region .vm-card-hint { display: none; }

.vm-card-region {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.vm-card-name {
  font-family: var(--kp-serif);
  font-weight: 500;
  font-size: 1.3rem;
  line-height: 1.1;
  color: var(--kp-pasture-deep);
}
.vm-card-rank {
  font-family: var(--kp-mono);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--kp-gold-2);
  white-space: nowrap;
}
.vm-card-momentum {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-family: var(--kp-mono);
  font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase;
  margin-bottom: 1.1rem;
}
.vm-card-momentum[data-momentum="climbing"] { color: var(--kp-pasture-lit); }
.vm-card-momentum[data-momentum="new"]      { color: var(--kp-gold-2); }
.vm-card-momentum[data-momentum="steady"]   { color: var(--kp-ink-2); }
.vm-card-momentum .arrow-up { font-size: 0.9rem; line-height: 1; }

/* Two distinct figures — latent and enrolled NEVER summed/blended.
   Rendered as two separate stacked rows with their own labels. */
.vm-figs { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-top: 1px solid var(--brand-rule); border-left: 1px solid var(--brand-rule); }
.vm-fig {
  padding: 0.9rem 0.9rem;
  border-right: 1px solid var(--brand-rule);
  border-bottom: 1px solid var(--brand-rule);
}
.vm-fig-label {
  font-family: var(--kp-serif);
  font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em;
  color: var(--kp-pasture-deep);
  margin-bottom: 0.3rem;
}
.vm-fig-value {
  font-family: var(--kp-serif);
  font-weight: 500;
  font-size: 1.5rem;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--kp-pasture-deep);
}
/* "Enrolling" / band states are NOT data — render them as a quiet status
   eyebrow (small gold mono), so the Pledged/Enrolled label stays the hero and
   the two figures never read as identical big-green words. A real number keeps
   the prominent .vm-fig-value treatment above. */
.vm-fig-value.is-band {
  font-family: var(--kp-mono);
  font-size: 0.7rem; font-weight: 400; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--kp-gold-2);
}
.vm-fig-sub {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--kp-ink-2);
  margin-top: 0.35rem;
}
.vm-card-note {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--kp-ink-2);
  margin-top: 1rem;
}
.vm-card-note strong { color: var(--kp-ink); font-weight: 600; }

/* ---- Pledge form ---- */
.vm-form-wrap {
  margin-top: 2.5rem;
  padding-top: 2.25rem;
  border-top: 1px solid var(--brand-rule);
}
.vm-form-intro { max-width: 60ch; }
.vm-form {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.25rem;
  max-width: 640px;
}
.vm-field { display: flex; flex-direction: column; gap: 0.4rem; }
.vm-field.vm-field-full { grid-column: 1 / -1; }
.vm-field label {
  font-family: var(--kp-mono);
  font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--kp-ink-2);
}
.vm-field input,
.vm-field select {
  font-family: var(--kp-sans);
  font-size: 0.98rem;
  color: var(--kp-ink);
  background: var(--kp-paper-3);
  border: 1px solid var(--brand-rule);
  border-radius: var(--kp-radius-md);
  padding: 0.7rem 0.85rem;
  width: 100%;
}
.vm-field input:focus,
.vm-field select:focus {
  outline: none;
  border-color: var(--kp-pasture-mid);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--kp-pasture-mid) 22%, transparent);
}
.vm-field input[aria-invalid="true"],
.vm-field select[aria-invalid="true"] { border-color: var(--kp-clay); }
.vm-field-error {
  font-family: var(--kp-sans);
  font-size: 0.78rem;
  color: var(--kp-clay);
  min-height: 0; display: none;
}
.vm-field-error.is-shown { display: block; }

.vm-country-choice { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 0.5rem; }
.vm-country-options { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.vm-country-pill {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--brand-rule);
  border-radius: var(--kp-radius-md);
  background: var(--kp-paper-3);
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-family: var(--kp-sans); font-size: 0.95rem; color: var(--kp-ink-2);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.vm-country-pill input { accent-color: var(--kp-pasture-deep); }
.vm-country-pill:has(input:checked) {
  border-color: var(--kp-pasture-deep);
  color: var(--kp-pasture-deep);
  background: var(--kp-paper);
  font-weight: 500;
}

.vm-form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.vm-form .btn { cursor: pointer; }
.vm-form-fineprint {
  grid-column: 1 / -1;
  font-family: var(--kp-mono);
  font-size: 0.72rem; line-height: 1.5; letter-spacing: 0.02em;
  color: var(--kp-ink-2);
}
@media (max-width: 560px) {
  .vm-form { grid-template-columns: 1fr; }
}

/* ---- States: "registrations open soon" (capture flag off) + reveal ---- */
.vm-form-status,
.vm-reveal { display: none; }
.vm-form-wrap.state-soon .vm-form { display: none; }
.vm-form-wrap.state-soon .vm-form-status { display: block; }
.vm-form-wrap.state-done .vm-form { display: none; }
.vm-form-wrap.state-done .vm-form-status { display: none; }
.vm-form-wrap.state-done .vm-reveal { display: block; }

.vm-form-status {
  margin-top: 1.5rem;
  padding: 1.5rem 1.4rem;
  background: var(--kp-paper-3);
  border: 1px solid var(--brand-rule);
  border-left: 3px solid var(--kp-gold);
  border-radius: var(--kp-radius-md);
  max-width: 60ch;
}
.vm-form-status h4 {
  font-family: var(--kp-serif); font-weight: 500; font-size: 1.15rem;
  color: var(--kp-pasture-deep); margin-bottom: 0.5rem;
}
.vm-form-status p { font-size: 0.95rem; color: var(--kp-ink-2); line-height: 1.55; }

/* ---- Reveal (post-submit) — collective framing ---- */
.vm-reveal {
  margin-top: 1.5rem;
  padding: 1.75rem 1.6rem;
  background: var(--kp-pasture-deep);
  color: var(--kp-paper);
  border-radius: var(--kp-radius-md);
  max-width: 64ch;
}
.vm-reveal-eyebrow {
  font-family: var(--kp-mono);
  font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--kp-gold);
  margin-bottom: 0.75rem;
}
.vm-reveal h4 {
  font-family: var(--kp-serif);
  font-weight: 400;
  font-size: clamp(1.35rem, 2.6vw, 1.7rem);
  line-height: 1.15;
  margin-bottom: 1rem;
}
.vm-reveal-lines { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.25rem; }
.vm-reveal-line {
  font-size: 0.98rem; line-height: 1.5;
  color: color-mix(in srgb, var(--kp-paper) 88%, transparent);
}
.vm-reveal-line strong { color: var(--kp-paper); font-weight: 600; }
.vm-reveal-line .vm-rl-gold { color: var(--kp-gold); font-weight: 600; }
/* The NZ-only ~2M waste line — hidden on the AU tab via JS toggling this class. */
.vm-reveal-waste { font-size: 0.92rem; }

.vm-share { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.vm-share-btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: var(--kp-gold);
  color: var(--kp-pasture-deep);
  border: none;
  font-family: var(--kp-sans); font-weight: 600; font-size: 0.95rem;
  padding: 0.65rem 1.2rem;
  border-radius: var(--kp-radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.vm-share-btn:hover { background: var(--kp-paper); }
.vm-share-alt {
  display: inline-flex; align-items: center;
  color: var(--kp-gold);
  font-size: 0.9rem; text-decoration: none;
  border-bottom: 1px solid transparent;
}
.vm-share-alt:hover { border-bottom-color: var(--kp-gold); }

/* Region-rally share card (rendered into the reveal, optionally screenshot/shared) */
.vm-rally-card {
  margin-top: 1.25rem;
  background: color-mix(in srgb, var(--kp-paper) 8%, var(--kp-pasture-night));
  border: 1px solid color-mix(in srgb, var(--kp-gold) 35%, transparent);
  border-radius: var(--kp-radius-md);
  padding: 1.1rem 1.2rem;
}
.vm-rally-card .vm-rally-region {
  font-family: var(--kp-serif); font-size: 1.1rem; color: var(--kp-paper); font-weight: 500;
}
.vm-rally-card .vm-rally-sub {
  font-family: var(--kp-mono); font-size: 0.72rem; letter-spacing: 0.05em;
  color: var(--kp-gold); margin-top: 0.3rem;
}

@media (prefers-reduced-motion: reduce) {
  .vm-map path { transition: none; }
}
