/* mangrove-fix.css — drop-in patch for mangroves-carbon-register
   Load AFTER css/style.css:
   <link rel="stylesheet" href="css/mangrove-fix.css">
   Fixes: hidden "Show layers" on mobile, chapter rail intercepting taps,
   duplicated search entry points, unclear satellite loading state. */

/* ---------- 1. Mobile control strip: layers + ask never overlap the rail ---------- */
@media (max-width: 768px) {
  /* One predictable strip directly under the map, above the story. */
  #legend-toggle,
  #ask-toggle {
    position: fixed;
    top: calc(58svh + 8px);
    bottom: auto;
    z-index: 620;              /* above the chapter rail */
    min-height: 44px;
    padding: 10px 14px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
  }
  /* style.css pins the layer toggle with !important and lets the open
     legend drawer (z-index:600) sit on top of it, so on mobile the
     "Hide layers" button is covered and cannot be tapped. Override the
     z-index with !important so the toggle stays reachable, and nudge it
     above the strip so it never hides the first legend row. */
  #legend-toggle {
    left: 12px;
    right: auto;
    top: calc(58svh - 46px) !important;
    top: calc(58dvh - 46px) !important;
    z-index: 620 !important;
  }
  /* When the sheet is open, park the toggle so it does not sit on the
     first legend row: just above the drawer's top edge. */
  #legend-toggle:has(+ #legend:not([hidden])) {
    top: calc(100vh - max(12px, env(safe-area-inset-bottom)) - min(58vh, 500px) - 52px) !important;
    top: calc(100svh - max(12px, env(safe-area-inset-bottom)) - min(58svh, 500px) - 52px) !important;
    top: calc(100dvh - max(12px, env(safe-area-inset-bottom)) - min(58dvh, 500px) - 52px) !important;
    bottom: auto;
  }
  #ask-toggle    { right: 12px; left: auto; }

  /* The ask panel (z-index 920) opens as a bottom sheet that covers the
     control strip, so the "Show layers" button would silently disappear
     behind it. When the ask panel is open, fade the layers toggle out so
     there are never two overlapping controls covering the same corner. */
  #legend-toggle {
    transition: opacity .18s ease;
  }
  #legend-toggle.hidden-on-ask,
  body:has(#ask:not([hidden])) #legend-toggle {
    opacity: 0;
    pointer-events: none;
  }

  /* The chapter rail lives INSIDE the map and must never sit on the strip. */
  #rail {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: calc(42svh + 56px); /* clear of the map edge and the strip */
    z-index: 480;               /* below both toggles */
    max-width: calc(100vw - 16px);
  }
  /* Only the buttons are tappable — the rail background stops stealing taps. */
  #rail { pointer-events: none; }
  #rail .rail-btn { pointer-events: auto; }

  /* Give the story room so the fixed strip never covers the first card. */
  .scrolly-steps { padding-top: 64px; }

  /* Layers sheet opens below the strip — scrollable so no option is ever cut off. */
  /* Layers sheet opens as a bottom drawer anchored to the screen edge,
     so the last row is always reachable. vh/dvh fallback for svh. */
  #legend {
    position: fixed;
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    width: auto;
    max-height: min(58vh, 500px);
    max-height: min(58dvh, 500px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  /* 2. One search entry point on mobile: the selector. */
  #btn-search { display: none !important; }
  .map-search select {
    width: 100%;
    min-height: 46px;
    font-size: 15px;            /* stops iOS zoom-on-focus */
  }
}

/* ---------- 3. Visible state while satellite tiles load ---------- */
#btn-basemap[data-loading="true"] {
  opacity: .85;
  cursor: progress;
}
#basemap-status {
  position: fixed;
  left: 50%;
  top: max(12px, env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 950;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #06201aee;
  color: #eaf7f0;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(4, 24, 20, .35);
  pointer-events: none;
}
#basemap-status[hidden] { display: none; }
#basemap-status::before {
  content: "";
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(234, 247, 240, .35);
  border-top-color: #38d384;
  animation: bm-spin .8s linear infinite;
}
@keyframes bm-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #basemap-status::before { animation: none; }
}

/* ---------- 4. Selected place feedback ---------- */
.map-search select:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- 7. Ask input must stay legible in dark mode ----------
   In dark mode --ink is near-white, but the ask input kept its white
   background, so typed text was invisible (contrast about 1.1:1). Give it
   a dark field like the other dark-mode inputs. */
:root[data-theme="dark"] #ask-input,
:root:not([data-theme="light"]) #ask-input {
  background: #0f2a25;
  color: var(--ink);
  border-color: var(--line);
  caret-color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}
:root[data-theme="dark"] #ask-input::placeholder,
:root:not([data-theme="light"]) #ask-input::placeholder {
  color: var(--muted);
}

/* ---------- 8. Map tools above the story cards ----------
   The map-tools row was trapped inside .scrolly-map-wrap, a sticky
   stacking context, so its z-index could never rise above the story
   cards (.scrolly-steps; z-index:500). The row now lives as the first
   child of section.scrolly, positioned fixed (out of document flow) so
   it stays pinned over the map on every screen without pushing the
   sticky .scrolly-map-wrap (and the map canvas) down below the header.
   It sits above the pins AND the story cards on desktop (z-index:610 >
   steps 500) and above the mobile map wrap (z-index:610 > 110). */
.map-tools {
  position: fixed;
  top: max(14px, calc(env(safe-area-inset-top) + 14px));
  z-index: 610;
}
@media (max-width: 900px) {
  .map-tools {
    left: max(10px, env(safe-area-inset-left));
    width: calc(100% - max(10px, env(safe-area-inset-left)) - max(120px, calc(env(safe-area-inset-right) + 120px)));
  }
  .map-tool-row { flex-wrap: wrap; }
}
@media (min-width: 769px) {
  .scrolly-map-wrap { z-index: auto; }
  #map { z-index: 0; }
  .map-tools {
    top: max(14px, calc(env(safe-area-inset-top) + 14px));
    left: max(14px, env(safe-area-inset-left));
  }
}

/* ---------- 9. Dark theme: white text on --teal fails WCAG AA ----------
   style.css paints three controls as white-on-teal:
     .mpa-chip[aria-pressed=true], .ask-form button / .ask-key button,
     .mpa-back-btn:hover
   That is fine in light theme, where --teal is #0a5450 (8.8:1 with white),
   but dark theme redefines --teal as the bright accent #2dd4bf, which drops
   white text to 1.9:1 — well under the 4.5:1 AA minimum, so the selected
   filter chip and the Ask buttons were hard to read for low-vision readers.

   Fix: keep the bright teal fill (the accent is unchanged) and switch the
   label to --navy #06201a, which measures 9.2:1 on #2dd4bf and is the same
   ink the dark theme already uses for its darkest surfaces.

   Scoped to :root[data-theme="dark"] only. The :not([data-theme="light"])
   variant used in section 7 is deliberately NOT repeated here: with no
   theme attribute the tokens fall back to the light values, where --teal is
   dark and navy-on-dark-teal would be unreadable. main.js always sets
   data-theme explicitly, so the dark selector covers every real case. */
:root[data-theme="dark"] .mpa-chip[aria-pressed="true"],
:root[data-theme="dark"] .ask-form button,
:root[data-theme="dark"] .ask-key button,
:root[data-theme="dark"] .mpa-back-btn:hover {
  color: var(--navy);
}
