/* situation-map-canada
 *
 * The chrome follows the viewer's browser preference. Light is defined on bare
 * :root and dark overrides only the tokens that change, so every rule below is
 * written against roles rather than raw colour.
 *
 * Data colours (the fire ramp, air-quality ramp, layer colours) are NOT themed:
 * they are drawn over satellite imagery and carry meaning, so they have to stay
 * identical in both modes or the legend stops matching the map.
 */
:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --surface-2: #eeede9;
  --page: #f9f9f7;

  --panel-bg: rgba(252, 252, 251, 0.94);
  --chip-bg: rgba(252, 252, 251, 0.82);

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #78766f;

  --border: rgba(11, 11, 11, 0.14);
  --border-strong: rgba(11, 11, 11, 0.26);

  --accent: #2a78d6;
  --accent-ink: #ffffff;

  /* Fire radiative power — blackbody, dim ember to near-white. Lightness rises
     with power so magnitude reads against dark imagery. */
  --frp-1: #b3311f;
  --frp-2: #e2521d;
  --frp-3: #f5871f;
  --frp-4: #fab219;
  --frp-5: #ffe9a3;

  /* Air quality keeps to a cool/violet ramp so it never reads as fire. */
  --aqhi-1: #2a78d6;
  --aqhi-4: #6d8fe0;
  --aqhi-7: #9085e9;
  --aqhi-10: #b56fd8;
  --aqhi-max: #d55181;

  /* Operational layers */
  --perimeter: #e34948;
  --m3: #9085e9;
  --order: #d03b3b;     /* status: critical */
  --alert: #fab219;     /* status: warning */
  --restrict: #199e70;
  --wind: #e8e6df;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --surface-1: #1a1a19;
    --surface-2: #232322;
    --page: #0d0d0d;

    --panel-bg: rgba(26, 26, 25, 0.93);
    --chip-bg: rgba(18, 18, 17, 0.72);

    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;

    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.20);

    --accent: #3987e5;
    --accent-ink: #ffffff;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  overflow: hidden;
}

#map { position: absolute; inset: 0; }

/* ------------------------------------------------------------------ panel */

#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 316px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  z-index: 4;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

#panel.hidden { display: none; }

/* The reopen affordance: only present while the panel is collapsed, on any size. */
#panel-toggle {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 13px;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#panel-toggle.shown { display: flex; }

.pt-label { font-size: 12.5px; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

#panel-close {
  flex: none;
  width: 26px;
  height: 26px;
  margin: -3px -3px 0 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

#panel-close:hover { color: var(--text-primary); background: var(--surface-2); }

/* Dim the map behind the layer sheet on small screens. */
#scrim {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: rgba(0, 0, 0, 0.5);
  border: 0;
}

#scrim[hidden] { display: none; }

/* ----------------------------------------------------------------- transport
 * One element, two homes: docked inside the panel on desktop, floating in a bar
 * above the fold on phones. JS moves the node; these classes carry the styling.
 */

#transport {
  display: flex;
  align-items: center;
  gap: 11px;
}

/* Docked in the sidebar: no chrome of its own, the panel already provides it. */
#transport.docked {
  margin-top: 12px;
}

/* The sidebar is too narrow for the time and the count side by side, so the
   readout stacks there and only runs inline in the full-width mobile bar. */
#transport.docked .transport-head {
  display: block;
  margin-bottom: 4px;
}

#transport.docked #cursor-meta { display: block; }
#transport.docked #play { width: 38px; height: 38px; }

/* Floating above the fold on phones. */
#transport.floating {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 4;
  padding: 9px 11px;
  padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px));
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.transport-main { flex: 1; min-width: 0; }

.transport-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 5px;
}

#cursor-time {
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#cursor-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0 0 4px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.45;
}

.section {
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

.label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 7px;
}

/* ----------------------------------------------------------- segmented set */

.segmented {
  display: flex;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px;
}

.segmented button {
  flex: 1;
  padding: 5px 0;
  font: inherit;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.segmented button:hover { background: var(--surface-1); }

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* --------------------------------------------------------------- chips */

.chips { display: flex; gap: 5px; }

.chips button {
  flex: 1;
  padding: 5px 4px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.25;
}

.chips button em {
  display: block;
  font-style: normal;
  font-weight: 400;
  font-size: 9.5px;
  opacity: 0.75;
}

.chips button[aria-pressed="true"] {
  color: var(--text-primary);
  border-color: var(--frp-3);
  background: rgba(245, 135, 31, 0.18);
}

/* -------------------------------------------------------------- transport */

#play {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

#play:hover { filter: brightness(1.12); }

input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  /* Comfortable drag target on touch without inflating the bar. */
  height: 22px;
}

/* Tick marks under the scrubber — one per satellite acquisition in the window. */
#overpass-track { position: relative; height: 12px; margin-top: 2px; }

#overpass-track i {
  position: absolute;
  top: 0;
  width: 2px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 1px;
  transform: translateX(-1px);
}

/* ----------------------------------------------------------------- pills */

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* One on/off language, used by every control on the page and identical in both
   themes: ON is filled with the accent, OFF is a ghost of the surface. Relying
   on a light-vs-dark chip would invert its meaning between the two modes, and
   relying on tone alone disappeared against satellite imagery. The swatch adds
   a second channel — saturated when on, desaturated when off — so state never
   rests on one signal. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px 7px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 18px;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;

  /* off */
  color: var(--text-muted);
  background: var(--chip-bg);
  border: 1px solid var(--border);
}

.pill .swatch {
  opacity: 0.3;
  filter: grayscale(1);
  transition: opacity 120ms ease, filter 120ms ease;
}

.pill:hover {
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

.pill[aria-pressed="true"] {
  color: var(--accent-ink);
  font-weight: 600;
  background: var(--accent);
  border-color: var(--accent);
}

.pill[aria-pressed="true"]:hover { filter: brightness(1.08); }

.pill[aria-pressed="true"] .swatch {
  opacity: 1;
  filter: none;
  border-color: rgba(255, 255, 255, 0.55);
}

/* The layer row sits on the map, not in the panel: one line, scrolled sideways
   rather than wrapped, so it never steals vertical space from the map. */
#quick-pills.quick {
  position: absolute;
  top: 12px;
  left: 344px;          /* clear of the panel */
  right: 12px;
  z-index: 4;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 2px;
  display: flex;
  mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent);
}

/* With the panel collapsed the row only has to clear the Layers pill. */
body.panel-collapsed #quick-pills.quick { left: 168px; }

#quick-pills.quick::-webkit-scrollbar { display: none; }

#quick-pills.quick .pill {
  flex: none;
  backdrop-filter: blur(12px);
  padding: 9px 14px 9px 11px;
}

/* --------------------------------------------------------------- toggles */

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3.5px 0;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle input { accent-color: var(--accent); margin: 0; cursor: pointer; flex: none; }

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.sw-hot     { background: var(--frp-3); border-color: rgba(255, 233, 163, 0.6); }
.sw-heat    { background: linear-gradient(135deg, var(--frp-1), var(--frp-4)); }
.sw-perim   { background: rgba(227, 73, 72, 0.35); border: 1.5px solid var(--perimeter); }
.sw-m3      { background: rgba(144, 133, 233, 0.3); border: 1.5px solid var(--m3); }
.sw-incident{ background: transparent; border: 1.5px solid #fff; }
.sw-order   { background: rgba(208, 59, 59, 0.4); border: 1.5px solid var(--order); border-radius: 2px; }
.sw-restrict{ background: rgba(25, 158, 112, 0.3); border: 1.5px solid var(--restrict); border-radius: 2px; }
.sw-aqhi    { background: linear-gradient(135deg, var(--aqhi-1), var(--aqhi-max)); }

.sw-wind {
  background: transparent;
  border: 0;
  color: var(--wind);
  font-size: 11px;
  line-height: 11px;
  text-align: center;
}

/* ---------------------------------------------------------------- legend */

.ramp {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--frp-1), var(--frp-2), var(--frp-3), var(--frp-4), var(--frp-5));
  border: 1px solid var(--border);
}

.ramp-aqhi {
  background: linear-gradient(90deg, var(--aqhi-1), var(--aqhi-4), var(--aqhi-7), var(--aqhi-10), var(--aqhi-max));
}

.ramp-scale {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}

.legend-note {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 9px 0 0;
}

/* ----------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 8px;
}

.stat-value { font-size: 17px; font-weight: 600; line-height: 1.15; }

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#quota {
  margin-top: 11px;
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

#error {
  display: none;
  margin-top: 10px;
  padding: 8px 9px;
  font-size: 11px;
  line-height: 1.45;
  border-radius: 6px;
  background: rgba(208, 59, 59, 0.14);
  border: 1px solid rgba(208, 59, 59, 0.4);
  color: #f5b5b5;
}

/* ---------------------------------------------------------------- popup */

.mapboxgl-popup-content {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.mapboxgl-popup-close-button { color: var(--text-muted); font-size: 16px; }
.mapboxgl-popup-tip { border-top-color: var(--surface-1) !important; border-bottom-color: var(--surface-1) !important; }

.pop-title { font-weight: 600; margin-bottom: 6px; font-size: 12.5px; }

.pop-kind {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 6px;
  background: var(--surface-2);
  color: var(--text-secondary);
}

.pop-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 1.5px 0;
  color: var(--text-secondary);
}

.pop-row b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

.pop-link { display: inline-block; margin-top: 7px; color: var(--accent); font-size: 11.5px; }

/* ---------------------------------------------------------------- mobile */

@media (max-width: 720px) {
  /* The panel becomes a sheet; the transport is relocated out of it so the
     timeline stays one thumb-drag away even while the sheet is closed. */
  #panel {
    left: 8px;
    right: 8px;
    top: 60px;
    width: auto;
    max-height: calc(100% - 190px);
    padding: 13px;
  }

  /* Layers sit just above the transport, both in easy thumb reach. */
  #quick-pills.quick,
  body.panel-collapsed #quick-pills.quick {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: calc(112px + env(safe-area-inset-bottom, 0px));
  }

  /* Without the transport the bar collapses, so the pills drop with it. */
  body.no-transport #quick-pills.quick {
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  #play { width: 46px; height: 46px; }

  input[type="range"] { height: 30px; }

  .transport-head { gap: 8px; }
  #cursor-time { font-size: 13px; }
  #cursor-meta { font-size: 10.5px; }

  /* The bottom belongs to the pills and the transport. Basemap attribution is a
     licence condition and cannot simply be deleted, but it can be a collapsed
     (i) — moved out of the thumb zone to under the zoom controls, with the full
     credits also listed in the panel. */
  .maplibregl-ctrl-bottom-right {
    top: 112px;
    bottom: auto;
    right: 8px;
  }

  /* Scale bar sits above the pills rather than beside them. */
  .maplibregl-ctrl-bottom-left {
    bottom: calc(158px + env(safe-area-inset-bottom, 0px));
  }

  body.no-transport .maplibregl-ctrl-bottom-left {
    bottom: calc(54px + env(safe-area-inset-bottom, 0px));
  }
}

/* Very short screens (landscape phones): drop the readout's second line. */
@media (max-height: 460px) {
  #panel { max-height: calc(100% - 150px); }
  #cursor-meta { display: none; }
}
