/* Whetstone Geo web map style
   Overlay controls that sit on a Leaflet or MapLibre map.
   Wrap the map library container in .wg-map and place these
   components as siblings over the map pane.

   Default sequential ramp (--ramp-seq-1 to --ramp-seq-7) is light
   to dark blue. Also provided: a warm ochre sequential ramp, a
   blue to ochre diverging ramp, and an 8 color categorical set.
   The ramps can be used as MapLibre interpolate or step expressions.
   See map-style-spec.md for markup and paint snippets. */

:root,
.wg-map {
  /* Brand, aligned to the live site styles.css */
  --forest-950: #0b1913;
  --forest-900: #10241c;
  --forest-800: #173328;
  --forest-700: #204435;
  --forest-600: #2c5a46;
  --slate-700: #3a4542;
  --slate-600: #4e5b57;
  --slate-500: #626f6a;
  --stone-300: #d8d1c4;
  --stone-200: #e8e2d6;
  --stone-100: #f3efe6;
  --stone-50: #f8f5ef;
  --paper: #fcfaf6;
  --ochre-600: #8a6615;
  --ochre-500: #c4962a;
  --ochre-400: #d4a94a;
  --ochre-200: #ead49a;
  --ochre-100: #f3e4b8;
  --ink: #141c18;
  --ink-soft: #3d4a44;
  --radius: 0.4rem;
  --shadow: 0 1px 2px rgba(16, 36, 28, 0.06), 0 8px 24px rgba(16, 36, 28, 0.06);
  --font: "IBM Plex Sans", "Source Sans 3", "Source Sans Pro", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --focus: var(--ochre-500);

  /* Sequential ramp, default, light to dark blue */
  --ramp-seq-1: #b7d6ec;
  --ramp-seq-2: #8cbeda;
  --ramp-seq-3: #5ba3c9;
  --ramp-seq-4: #3386b5;
  --ramp-seq-5: #1a6a96;
  --ramp-seq-6: #134e73;
  --ramp-seq-7: #0b3556;

  /* Alternate sequential ramp, brand ochre */
  --ramp-warm-1: #e8d392;
  --ramp-warm-2: #d4b04a;
  --ramp-warm-3: #c4962a;
  --ramp-warm-4: #a67b1c;
  --ramp-warm-5: #8a6615;
  --ramp-warm-6: #6a4e10;
  --ramp-warm-7: #46340c;

  /* Diverging ramp, blue through stone to ochre */
  --ramp-div-1: #0b3556;
  --ramp-div-2: #1a6a96;
  --ramp-div-3: #8cbeda;
  --ramp-div-4: #f3efe6;
  --ramp-div-5: #e8d392;
  --ramp-div-6: #c4962a;
  --ramp-div-7: #6a4e10;

  /* Categorical palette, 8 colors, colorblind safe, brand aligned */
  --cat-1: #0072b2;
  --cat-2: #c4962a;
  --cat-3: #009e73;
  --cat-4: #56b4e9;
  --cat-5: #d55e00;
  --cat-6: #cc79a7;
  --cat-7: #f0e442;
  --cat-8: #141c18;

  --wg-pad: 0.85rem 1rem;
  --wg-title-max: 18.5rem;
  --wg-legend-max: 16.5rem;
  --wg-overlay-inset: 0.85rem;
}

/* ----- Map shell ----- */
.wg-map {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: var(--stone-100);
  -webkit-font-smoothing: antialiased;
}

.wg-map-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.wg-map-title,
.wg-map-legend,
.wg-map-footer {
  position: absolute;
  z-index: 2;
  pointer-events: auto;
  box-sizing: border-box;
}

.wg-map *,
.wg-map *::before,
.wg-map *::after {
  box-sizing: border-box;
}

/* ----- Title block, top left ----- */
.wg-map-title {
  top: var(--wg-overlay-inset);
  left: var(--wg-overlay-inset);
  max-width: min(var(--wg-title-max), calc(100% - 2 * var(--wg-overlay-inset)));
  padding: var(--wg-pad);
  background: var(--paper);
  border: 1px solid var(--stone-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.wg-map-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.55rem;
}

.wg-map-mark {
  width: 1.7rem;
  height: 1.7rem;
  flex-shrink: 0;
  color: var(--ochre-500);
  display: block;
  overflow: visible;
}

.wg-map-wordmark {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--forest-900);
}

.wg-map-title-text {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--forest-900);
}

.wg-map-subtitle {
  margin: 0.28rem 0 0;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink-soft);
}

/* ----- Legend card ----- */
.wg-map-legend {
  top: var(--wg-overlay-inset);
  right: var(--wg-overlay-inset);
  width: min(var(--wg-legend-max), calc(100% - 2 * var(--wg-overlay-inset)));
  background: var(--paper);
  border: 1px solid var(--stone-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--wg-pad);
}

.wg-map-legend + .wg-map-legend {
  top: auto;
  /* Stack a second card (for example a categorical legend) below the first.
     The first card is estimated to land here; tighten in the host page if needed. */
  margin-top: 0;
}

.wg-map-legends {
  position: absolute;
  top: var(--wg-overlay-inset);
  right: var(--wg-overlay-inset);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: min(var(--wg-legend-max), calc(100% - 2 * var(--wg-overlay-inset)));
  pointer-events: none;
}

.wg-map-legends .wg-map-legend {
  position: relative;
  top: auto;
  right: auto;
  width: 100%;
  pointer-events: auto;
}

.wg-map-legend-heading {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--forest-800);
}

.wg-map-legend-collapse {
  display: none;
}

/* Continuous: a single gradient bar */
.wg-map-ramp {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.wg-map-ramp-bar {
  display: block;
  height: 0.7rem;
  border-radius: 2px;
  border: 1px solid rgba(16, 36, 28, 0.12);
  background: linear-gradient(
    to right,
    var(--ramp-seq-1),
    var(--ramp-seq-2),
    var(--ramp-seq-3),
    var(--ramp-seq-4),
    var(--ramp-seq-5),
    var(--ramp-seq-6),
    var(--ramp-seq-7)
  );
}

.wg-map-ramp--warm .wg-map-ramp-bar {
  background: linear-gradient(
    to right,
    var(--ramp-warm-1),
    var(--ramp-warm-2),
    var(--ramp-warm-3),
    var(--ramp-warm-4),
    var(--ramp-warm-5),
    var(--ramp-warm-6),
    var(--ramp-warm-7)
  );
}

.wg-map-ramp--div .wg-map-ramp-bar {
  background: linear-gradient(
    to right,
    var(--ramp-div-1),
    var(--ramp-div-2),
    var(--ramp-div-3),
    var(--ramp-div-4),
    var(--ramp-div-5),
    var(--ramp-div-6),
    var(--ramp-div-7)
  );
}

.wg-map-ramp-labels {
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.68rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink-soft);
}

/* Stepped: one swatch per class */
.wg-map-steps {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.wg-map-steps-bar {
  display: flex;
  height: 0.7rem;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid rgba(16, 36, 28, 0.12);
}

.wg-map-steps-bar span {
  flex: 1;
  display: block;
  min-width: 0;
}

.wg-map-steps-bar span:nth-child(1) { background: var(--ramp-seq-1); }
.wg-map-steps-bar span:nth-child(2) { background: var(--ramp-seq-2); }
.wg-map-steps-bar span:nth-child(3) { background: var(--ramp-seq-3); }
.wg-map-steps-bar span:nth-child(4) { background: var(--ramp-seq-4); }
.wg-map-steps-bar span:nth-child(5) { background: var(--ramp-seq-5); }
.wg-map-steps-bar span:nth-child(6) { background: var(--ramp-seq-6); }
.wg-map-steps-bar span:nth-child(7) { background: var(--ramp-seq-7); }

.wg-map-steps--warm .wg-map-steps-bar span:nth-child(1) { background: var(--ramp-warm-1); }
.wg-map-steps--warm .wg-map-steps-bar span:nth-child(2) { background: var(--ramp-warm-2); }
.wg-map-steps--warm .wg-map-steps-bar span:nth-child(3) { background: var(--ramp-warm-3); }
.wg-map-steps--warm .wg-map-steps-bar span:nth-child(4) { background: var(--ramp-warm-4); }
.wg-map-steps--warm .wg-map-steps-bar span:nth-child(5) { background: var(--ramp-warm-5); }
.wg-map-steps--warm .wg-map-steps-bar span:nth-child(6) { background: var(--ramp-warm-6); }
.wg-map-steps--warm .wg-map-steps-bar span:nth-child(7) { background: var(--ramp-warm-7); }

.wg-map-steps-labels {
  display: flex;
  justify-content: space-between;
  gap: 0.15rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.62rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink-soft);
}

.wg-map-steps-labels li {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.wg-map-steps-labels li:first-child { text-align: left; }
.wg-map-steps-labels li:last-child { text-align: right; }

/* Categorical: stacked labeled swatches */
.wg-map-swatches {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.wg-map-swatch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--ink);
}

.wg-map-swatch-color {
  width: 0.85rem;
  height: 0.85rem;
  flex-shrink: 0;
  border-radius: 2px;
  border: 1px solid rgba(16, 36, 28, 0.16);
  background: var(--cat-1);
}

.wg-map-swatch:nth-child(1) .wg-map-swatch-color { background: var(--cat-1); }
.wg-map-swatch:nth-child(2) .wg-map-swatch-color { background: var(--cat-2); }
.wg-map-swatch:nth-child(3) .wg-map-swatch-color { background: var(--cat-3); }
.wg-map-swatch:nth-child(4) .wg-map-swatch-color { background: var(--cat-4); }
.wg-map-swatch:nth-child(5) .wg-map-swatch-color { background: var(--cat-5); }
.wg-map-swatch:nth-child(6) .wg-map-swatch-color { background: var(--cat-6); }
.wg-map-swatch:nth-child(7) .wg-map-swatch-color { background: var(--cat-7); }
.wg-map-swatch:nth-child(8) .wg-map-swatch-color { background: var(--cat-8); }

/* ----- Layer toggle (on/off switch) ----- */
.wg-map-switch {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.75rem 0 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--stone-200);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--forest-900);
}

.wg-map-switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.wg-map-switch-ui {
  position: relative;
  flex-shrink: 0;
  width: 2.1rem;
  height: 1.2rem;
  border-radius: 999px;
  background: var(--stone-300);
  border: 1px solid var(--slate-500);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.wg-map-switch-ui::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: calc(1.2rem - 4px);
  height: calc(1.2rem - 4px);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(16, 36, 28, 0.25);
  transition: transform 0.16s ease;
}

.wg-map-switch-input:checked + .wg-map-switch-ui {
  background: var(--forest-700);
  border-color: var(--forest-700);
}

.wg-map-switch-input:checked + .wg-map-switch-ui::after {
  transform: translateX(0.9rem);
}

.wg-map-switch-input:focus-visible + .wg-map-switch-ui {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.wg-map-switch-label {
  line-height: 1.3;
}

/* Hide a sequential theme layer when its switch is off.
   Pair the input id with aria-controls or wrap both in .wg-map. */
.wg-map:not(:has(.wg-map-switch-input[data-layer="theme"]:checked)) .wg-map-theme {
  display: none;
}

.wg-map:not(:has(.wg-map-switch-input[data-layer="theme"]:checked)) .wg-map-theme-off {
  display: block;
}

.wg-map-theme-off {
  display: none;
}

/* ----- Footer / attribution strip ----- */
.wg-map-footer {
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.35rem 0.85rem;
  background: rgba(252, 250, 246, 0.94);
  border-top: 1px solid var(--stone-200);
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.35;
}

.wg-map-footer p {
  margin: 0;
}

/* ----- Mobile ----- */
@media (max-width: 640px) {
  :root,
  .wg-map {
    --wg-overlay-inset: 0.6rem;
    --wg-pad: 0.6rem 0.7rem;
    --wg-title-max: 14.5rem;
  }

  .wg-map-brand {
    margin-bottom: 0.3rem;
    gap: 0.4rem;
  }

  .wg-map-mark {
    width: 1.15rem;
    height: 1.15rem;
  }

  .wg-map-wordmark {
    font-size: 0.7rem;
  }

  .wg-map-title-text {
    font-size: 0.95rem;
  }

  .wg-map-subtitle {
    font-size: 0.7rem;
  }

  .wg-map-legends,
  .wg-map-legend {
    width: min(15.5rem, calc(100% - 2 * var(--wg-overlay-inset)));
  }

  /* Collapsed legend: only the heading row shows until opened */
  .wg-map-legend-collapse {
    display: block;
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }

  .wg-map-legend-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0;
    cursor: pointer;
  }

  .wg-map-legend-heading::after {
    content: "Show";
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ochre-600);
  }

  .wg-map-legend-body {
    display: none;
    margin-top: 0.65rem;
  }

  .wg-map-legend:has(.wg-map-legend-collapse:checked) .wg-map-legend-body {
    display: block;
  }

  .wg-map-legend:has(.wg-map-legend-collapse:checked) .wg-map-legend-heading::after {
    content: "Hide";
  }

  .wg-map-footer {
    padding: 0.3rem 0.6rem;
    font-size: 0.62rem;
  }
}
