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

/* Status palette — every error, warning, and success surface in the app
   (status line, credentials modal, GPS button, invalid inputs) reads from
   these tokens. Keeps the three ad-hoc reds that used to ship (#b0321d,
   #c1432c, #8c2413) from drifting apart. Contrast on the paired bg meets
   WCAG AA for body text at 12 px+. */
:root {
  --err-text:   #a1361f;
  --err-bg:     #fff1ee;
  --err-border: #f0c4bb;
  --warn-text:   #8a5a00;
  --warn-bg:     #fff8e1;
  --warn-border: #ebd39a;
  --ok-text:   #0f4d2a;
  --ok-bg:     #e9f5ee;
  --ok-border: #bdd9c4;
}

html, body { height: 100%; margin: 0; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #152514;
  background: #f5f7f3;
  -webkit-font-smoothing: antialiased;
}

.shell {
  display: flex;
  flex-direction: column;
  /* 100vh is iOS Safari's "largest" viewport (address bar hidden). When the
     real visible area shrinks — soft keyboard open, address bar expanded,
     gesture chrome visible — content measured against 100vh becomes taller
     than what the user can see, and any flex item that can shrink gets
     squeezed. 100dvh tracks the *current* visible area on iOS 16+ / Android
     Chrome 108+ and is the right anchor for mobile. 100vh stays as a
     fallback for older browsers. */
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  /* Safe-area insets so iOS PWA standalone (black-translucent status bar)
     and Android cutouts don't overlap the brand/actions row. */
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           14px max(20px, env(safe-area-inset-left));
  background: #0f4d2a;
  color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,0.12);
  /* Sit above the bottom sheet AND every Leaflet control so a full-snap
     sheet on short viewports can never cover the brand row. Positioned
     ancestor is required for z-index to take effect on a static element. */
  position: relative;
  z-index: 1500;
  /* Pin the bar so a keyboard-resized viewport can't flex-shrink it down
     to a thin green sliver (user-reported on both iOS + Android). Without
     this, the default flex-shrink:1 lets the parent compress the topbar
     when .shell's min-height briefly exceeds the visible area. min-height
     guarantees the brand row stays readable even if padding/content shift. */
  flex-shrink: 0;
  min-height: 54px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  flex-shrink: 0;
  display: block;
  border-radius: 8px;
}

.brand-text { min-width: 0; }

.brand-name {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.brand-caption {
  font-size: 12px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.back-link {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #d9f0e1;
  text-decoration: none;
  border-radius: 8px;
  transition: background-color 0.14s ease, color 0.14s ease;
  -webkit-tap-highlight-color: transparent;
}

.back-link:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.back-link:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.back-link svg { display: block; }

.lang-switch {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,0.12);
  padding: 3px;
  border-radius: 8px;
}

.lang-btn {
  color: #fff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  letter-spacing: 0.4px;
}

.lang-btn.is-active {
  background: #fff;
  color: #0f4d2a;
}

.layout {
  flex: 1;
  position: relative;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 0;
  min-height: 0;
  transition: grid-template-columns 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

.layout.is-panel-collapsed {
  grid-template-columns: 0 1fr;
}

.panel { min-width: 0; }

.panel--controls {
  padding: 18px 18px 24px;
  background: #fff;
  border-right: 1px solid #dde4d8;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 56px);
  transition: padding 280ms cubic-bezier(0.4, 0, 0.2, 1),
              border-right-color 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

.layout.is-panel-collapsed .panel--controls {
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  pointer-events: none;
}

/* Panel toggle — half hugs the panel right edge when open; fully visible at the
   left of the map area when collapsed. 38px circle exceeds Apple/Material touch
   target minimums so it stays comfortable on phones too. */
.panel-toggle {
  position: absolute;
  top: 14px;
  left: 341px;             /* 360px panel - 19px (half of 38px) -> centered on edge */
  z-index: 600;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1.5px solid #fff;
  border-radius: 50%;
  background: #0f4d2a;
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
  transition: left 280ms cubic-bezier(0.4, 0, 0.2, 1),
              background-color 0.16s ease,
              box-shadow 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.panel-toggle:hover {
  background: #15683a;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}
.panel-toggle:active { background: #0a3a1f; }
.panel-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(15, 77, 42, 0.45);
}

.panel-toggle svg {
  display: block;
  width: 16px;
  height: 16px;
  transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* When collapsed: button sits flush against viewport left edge, fully visible */
.layout.is-panel-collapsed .panel-toggle { left: 0; }
.layout.is-panel-collapsed .panel-toggle svg { transform: rotate(180deg); }

/* Leaflet zoom + draw controls — top-right vertical column, brand-tuned.
   Visual blocks are the LEAF toolbars (zoom, rectangle/polygon, edit/delete)
   — NOT the .leaflet-draw wrapper, which holds two sub-toolbars and would
   otherwise glue them together. Wrapper is reset to a transparent shell so
   every visible group gets its own pill with identical 8px spacing. */
.leaflet-top.leaflet-right { padding-top: 12px; padding-right: 12px; }

.leaflet-top.leaflet-right .leaflet-control,
.leaflet-top.leaflet-right .leaflet-draw,
.leaflet-top.leaflet-right .leaflet-draw-section {
  margin: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  padding: 0 !important;
}

.leaflet-top.leaflet-right .leaflet-control-zoom,
.leaflet-top.leaflet-right .leaflet-draw-toolbar {
  width: 34px;
  margin-top: 0 !important;       /* override Leaflet's 12px on the second draw toolbar */
  margin-bottom: 8px !important;  /* uniform 8px gap below every group */
  border: 1px solid #c4d0bf !important;  /* consistent frame on zoom + draw + edit */
  border-radius: 10px !important;
  overflow: hidden;
  background-color: #fff !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15) !important;
}

/* Last group has no trailing gap */
.leaflet-top.leaflet-right .leaflet-draw-section:last-child .leaflet-draw-toolbar {
  margin-bottom: 0 !important;
}

/* Action subtoolbar (Apply / Cancel that opens after clicking edit / delete)
   — slide it far enough LEFT that it never overlaps the icon column. Default
   Leaflet offset is right:26px which clips the right edge of our 34px buttons. */
.leaflet-right .leaflet-draw-actions,
.leaflet-top.leaflet-right .leaflet-draw-actions {
  right: 44px !important;   /* 34px button + 1px border + ~9px breathing */
  left: auto !important;
}

.leaflet-control-zoom a,
.leaflet-draw-toolbar a {
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  background-color: #fff !important;
  color: #2f4431 !important;
  border-bottom: 1px solid #eef2ea !important;
  font-size: 18px !important;
  font-weight: 500 !important;
  transition: background-color 0.14s ease, color 0.14s ease;
  -webkit-tap-highlight-color: transparent;
}

/* Lock the Leaflet.Draw icon spritesheet to its logical 300×30 cell grid.
   Without this, some mobile browsers (Safari iOS, older Chromium) render
   the 2x retina sprite (spritesheet-2x.png is 600×60) at its natural size
   when .leaflet-retina is active, which bleeds two adjacent icons into
   each 34px button — a user-reported "double icon" on rectangle, polygon,
   edit and delete. Explicitly pinning background-size + background-repeat
   makes both 1x and 2x sprites render identically. */
.leaflet-draw-toolbar a,
.leaflet-retina .leaflet-draw-toolbar a {
  background-size: 300px 30px !important;
  background-repeat: no-repeat !important;
}

.leaflet-control-zoom a:last-child,
.leaflet-draw-toolbar a:last-child { border-bottom: none !important; }

.leaflet-control-zoom a:hover,
.leaflet-draw-toolbar a:hover {
  background-color: #f0f6ed !important;
  color: #0f4d2a !important;
}

.leaflet-control-zoom a.leaflet-disabled,
.leaflet-draw-toolbar a.leaflet-disabled {
  background-color: #f5f7f3 !important;
  color: #b7c5b4 !important;
  cursor: not-allowed;
}

/* Action subtoolbar (Apply / Cancel after edit/delete) */
.leaflet-draw-actions a {
  background-color: #fff !important;
  color: #2f4431 !important;
  font-weight: 600 !important;
  border-color: #c4d0bf !important;
}
.leaflet-draw-actions a:hover {
  background-color: #f0f6ed !important;
  color: #0f4d2a !important;
}

/* ---- OSM attribution ---------------------------------------------------
   Legally required per ODbL + OSMF Attribution Guidelines. Must stay
   readable — never use opacity < ~0.7 or colour below #888 on #fff, and
   never shrink below ~10px. Hover reveals the full strength for anyone
   actually trying to read or click through. */
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.72) !important;
  padding: 1px 7px !important;
  border-radius: 4px 0 0 0 !important;
  font-size: 10px !important;
  line-height: 1.5 !important;
  color: #6b7363 !important;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.leaflet-control-attribution a {
  color: #4a5a49 !important;
  text-decoration: none;
}

.leaflet-control-attribution:hover {
  background: rgba(255, 255, 255, 0.95) !important;
  color: #2f4431 !important;
}

.leaflet-control-attribution:hover a {
  color: #0f4d2a !important;
  text-decoration: underline;
}

/* Hide every Leaflet / Leaflet.Draw tooltip surface.
   - `.leaflet-draw-tooltip`: the floating hint that follows the cursor
     while a drawing tool is active ("Click to start drawing shape",
     "Click to continue…", etc.) — noise, not guidance.
   - `.leaflet-tooltip`: the generic Leaflet tooltip used by layers.
   Native browser `title` tooltips are stripped in JS (see
   repurposeControlTooltips), so no other hover hint sneaks back in. */
.leaflet-draw-tooltip,
.leaflet-draw-tooltip-single,
.leaflet-tooltip {
  display: none !important;
}

.panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #4a6048;
  margin: 18px 0 8px;
}

.panel-title:first-of-type { margin-top: 0; }

/* Hints are a whisper under the heading — dimmer and smaller than the
   title so the heading dominates the vertical rhythm. Default top margin
   leaves breathing room when the hint follows a form row (e.g. the date
   inputs); the `.panel-title + .hint` rule below pulls it closer only in
   the heading→hint→inputs case so the heading and its hint read as one unit. */
.hint {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.35;
  color: #7a877a;
  margin: 8px 0 10px;
}

.panel-title + .hint {
  margin-top: -2px;
}

.search-box {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.search-box input {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid #c4d0bf;
  border-radius: 8px;
  background: #fafcf8;
}

.search-box input:focus {
  outline: 2px solid #2d8a4f;
  outline-offset: -2px;
  border-color: transparent;
}

/* Scoped to the search submit only. Previously this selector ALSO styled
   the GPS icon button next to it — with dark-green fill, text-align inherit,
   and horizontal padding that squeezed the SVG to one edge of its square.
   :not(.gps-btn) keeps the GPS button on its own dedicated rules below. */
.search-box button:not(.gps-btn) {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: #0f4d2a;
  color: #fff;
  cursor: pointer;
}

.search-box button:not(.gps-btn):hover { background: #15683a; }

.geocode-results {
  border: 1px solid #dde4d8;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 10px;
  max-height: 180px;
  overflow-y: auto;
}

.geocode-result {
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid #eef2ea;
}

.geocode-result:last-child { border-bottom: none; }
.geocode-result:hover { background: #f0f6ed; }

.bbox-readout {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  padding: 8px 10px;
  background: #f5f7f3;
  border-radius: 8px;
  margin-bottom: 6px;
  color: #2f4431;
}

.bbox-label { color: #4a6048; font-weight: 600; }
.bbox-value { font-variant-numeric: tabular-nums; }

.clear-btn {
  margin-left: auto;
  font: inherit;
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid #c4d0bf;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  color: #4a6048;
}

.clear-btn:hover { background: #f0f6ed; }

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.date-row label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: #4a6048;
}

.date-row input {
  font: inherit;
  font-size: 13px;
  padding: 7px 8px;
  border: 1px solid #c4d0bf;
  border-radius: 8px;
  background: #fafcf8;
}

.layer-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.layer-chip {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 8px;
  text-align: left;
  border: 1px solid #c4d0bf;
  border-radius: 8px;
  background: #fafcf8;
  color: #2f4431;
  cursor: pointer;
  transition: all 0.12s;
}

.layer-chip:hover { background: #f0f6ed; }

.layer-chip.is-active {
  background: #0f4d2a;
  color: #fff;
  border-color: #0f4d2a;
}

.resolution-hint {
  font-size: 11px;
  color: #6a7e68;
  margin: 4px 0 12px;
  min-height: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.resolution-hint strong {
  color: #2f4431;
  font-weight: 600;
}

.resolution-hint-note {
  color: #7a8d77;
  font-size: 10.5px;
  margin-top: 2px;
}

.primary-btn {
  width: 100%;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #0f4d2a;
  color: #fff;
  cursor: pointer;
  letter-spacing: 0.3px;
  margin-top: 6px;
}

.primary-btn:hover:not(:disabled) { background: #15683a; }

.primary-btn:disabled {
  background: #b7c5b4;
  cursor: not-allowed;
}

.secondary-btn {
  width: 100%;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 12px;
  border: 1px solid #c4d0bf;
  border-radius: 8px;
  background: #fafcf8;
  color: #2f4431;
  cursor: pointer;
  margin-top: 10px;
  letter-spacing: 0.2px;
}

.secondary-btn:hover { background: #f0f6ed; border-color: #a8b8a3; }
.secondary-btn:active { background: #e2ecdc; }

.status-line {
  font-size: 12px;
  color: #4a6048;
  min-height: 16px;
  margin: 10px 0 0;
}

.status-line.is-error   { color: var(--err-text); }
.status-line.is-warning { color: var(--warn-text); }
.status-line.is-success { color: var(--ok-text); }

.scene-info {
  margin-top: 14px;
  padding: 12px 14px;
  background: #f5f7f3;
  border: 1px solid #e3e9de;
  border-radius: 10px;
  font-size: 12px;
  color: #2f4431;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scene-info-title {
  display: block;
  color: #0f4d2a;
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  font-weight: 700;
}

.scene-info-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.scene-info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
}

.scene-info-row > span:first-child {
  color: #5e6e5c;
}

.scene-info-row > span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: #1f2f22;
}

.scene-info-note {
  margin: 0;
  padding: 6px 10px;
  background: #ffffff;
  border-left: 2px solid #0f4d2a;
  border-radius: 4px;
  font-size: 11.5px;
  line-height: 1.4;
  color: #4a5a49;
}

.scene-info-list {
  margin: 0;
  border-top: 1px dashed #c8d2c0;
  padding-top: 8px;
}

.scene-info-list > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  font-size: 11.5px;
  user-select: none;
  outline: none;
  border-radius: 4px;
}

.scene-info-list > summary::-webkit-details-marker {
  display: none;
}

.scene-info-list > summary:hover .scene-info-list-toggle,
.scene-info-list > summary:focus-visible .scene-info-list-toggle {
  color: #0a3a1f;
  text-decoration: underline;
}

.scene-info-list-count {
  color: #5e6e5c;
}

.scene-info-list-toggle {
  color: #0f4d2a;
  font-weight: 600;
  font-size: 11px;
}

.scene-info-list[open] .scene-info-list-items {
  margin-top: 6px;
}

.scene-info-list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 176px;
  overflow-y: auto;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid #e3e9de;
}

.scene-info-list-items::-webkit-scrollbar {
  width: 6px;
}

.scene-info-list-items::-webkit-scrollbar-thumb {
  background: #c8d2c0;
  border-radius: 3px;
}

.scene-info-list-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  font-size: 11.5px;
  border-bottom: 1px solid #eef2eb;
}

.scene-info-list-item:last-child {
  border-bottom: none;
}

.scene-info-list-item.is-chosen {
  background: #e6f0df;
}

.scene-info-list-item.is-skipped .scene-info-list-date,
.scene-info-list-item.is-skipped .scene-info-list-meta {
  color: #8b978a;
}

.scene-info-list-date {
  font-weight: 500;
  color: #1f2f22;
  font-variant-numeric: tabular-nums;
}

.scene-info-list-meta {
  color: #5e6e5c;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  min-width: 3ch;
  text-align: right;
}

.scene-info-list-tag {
  font-size: 10px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.scene-info-list-tag.is-chosen {
  background: #0f4d2a;
  color: #ffffff;
}

.scene-info-list-tag.is-used {
  background: #dbe7d0;
  color: #0f4d2a;
}

.scene-info-list-tag.is-skipped {
  background: #edf0e9;
  color: #8b978a;
}

/* Clickable rows — the whole row behaves like a button so the larger touch
   target helps on mobile. Keyboard users get a crisp focus ring. */
.scene-info-list-item.is-clickable {
  cursor: pointer;
  transition: background-color 0.12s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.scene-info-list-item.is-clickable:hover {
  background: #f0f6ed;
}

.scene-info-list-item.is-clickable.is-chosen:hover {
  /* Chosen row hover is a no-op action (re-renders the same scene), so we
     don't lift the background — it would hint at an action that isn't there. */
  background: #e6f0df;
}

.scene-info-list-item.is-clickable:active {
  transform: translateY(0.5px);
}

.scene-info-list-item.is-clickable:focus-visible {
  outline: 2px solid #0f4d2a;
  outline-offset: -2px;
  background: #f0f6ed;
}

.scene-info-list-hint {
  margin: 6px 2px 0;
  font-size: 10.5px;
  color: #8b978a;
  line-height: 1.4;
}

/* Manual-pick strategy note gets a subtle amber accent + inline reset link */
.scene-info-note.is-manual {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border-left-color: #c48a17;
  background: #fdf6e3;
  color: #5a4711;
}

.scene-info-reset {
  appearance: none;
  background: none;
  border: none;
  padding: 2px 4px;
  margin: 0;
  color: #0f4d2a;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.scene-info-reset:hover {
  color: #0a3a1f;
  background: #e6f0df;
}

.scene-info-reset:focus-visible {
  outline: 2px solid #0f4d2a;
  outline-offset: 1px;
}

.panel--map {
  position: relative;
  min-height: 400px;
}

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

.legend {
  position: absolute;
  bottom: 18px;
  left: 18px;
  z-index: 400;
  background: rgba(255,255,255,0.96);
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  font-size: 11px;
  min-width: 180px;
}

.legend-title {
  font-weight: 700;
  color: #0f4d2a;
  margin-bottom: 6px;
}

.legend-gradient {
  height: 10px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.legend-ticks {
  display: flex;
  justify-content: space-between;
  color: #4a6048;
  font-variant-numeric: tabular-nums;
}

/* ---- Sheet handle (drag grip) — mobile only -------------------------- */
/* Desktop: hidden. On mobile the bottom-sheet uses this pill as its primary
   drag target. Sticky so it stays reachable after the user has scrolled the
   sheet's contents. */
.sheet-handle { display: none; }

/* ---- Inline GPS button inside the search-box ------------------------- */
/* Visible on all breakpoints, invaluable on mobile where drawing a precise
   rectangle with a finger is painful. One tap → center + auto-select a
   500m × 500m square at the user's location. */
.gps-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #c4d0bf;
  border-radius: 8px;
  background: #fafcf8;
  color: #2f4431;
  cursor: pointer;
  /* inline-flex + align/justify is robust across Safari/Chrome/Firefox
     and immune to inherited text-align from parents. grid+place-items has
     an older-Safari quirk on buttons where the SVG anchors to one edge. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.gps-btn svg {
  display: block;
  flex: none;
}

.gps-btn:hover { background: #f0f6ed; border-color: #0f4d2a; color: #0f4d2a; }
.gps-btn:active { background: #e2ecdc; }
.gps-btn:focus-visible { outline: 2px solid #0f4d2a; outline-offset: 2px; }
/* Busy: the whole SVG spins around its concentric center dot — reads as
   "locating…" better than fading the glyph and works at any size. */
.gps-btn[data-state="busy"] { cursor: progress; color: #0f4d2a; }
.gps-btn[data-state="busy"] svg { animation: gps-spin 1s linear infinite; transform-origin: 50% 50%; }
.gps-btn[data-state="error"] {
  border-color: var(--err-border);
  color: var(--err-text);
  background: var(--err-bg);
}

@keyframes gps-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}


/* ---- Mobile layout: bottom sheet ------------------------------------- */
/*
   Activates on narrow OR short viewports — so landscape phones (iPhone 14
   is 844×390-ish in landscape) get the sheet instead of a cramped 360px
   sidebar eating half the horizontal space. Desktops with ≥500px height
   stay on the desktop layout unless they're also narrow.

   Three snap heights driven by JS (`data-snap` = peek | half | full).
   Transition disabled mid-drag so the finger follows the sheet 1:1.

   Why a sheet, not a left drawer: better one-hand thumb reach, no conflict
   with iOS's edge-swipe back gesture, and when the on-screen keyboard
   appears the sheet promotes itself to "full" so the focused input never
   ends up hidden.
*/
@media (max-width: 760px), (max-height: 500px) {
  /* flex column (not grid/block) because .panel--map needs a resolvable
     height, not `height: 100%` against an auto parent. `.shell` is
     flex-column with `.layout` set to flex:1, which gives layout an
     explicit pixel height; flex:1 on .panel--map then gives IT an explicit
     height too, so #map (position:absolute inset:0 inside) finally has
     something to anchor against. Without this, mapOffsetH = 0. */
  .layout,
  .layout.is-panel-collapsed {
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: none;
  }

  .panel--map {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }

  /* The desktop chevron has no place on mobile — the bottom-sheet handle
     replaces it. */
  .panel-toggle { display: none; }

  /* The side-panel becomes a fixed bottom sheet whose height is driven by
     a CSS variable set from JS. `overscroll-behavior: contain` stops the
     over-fling at the top from pulling the page behind. */
  /* z-index 1200 sits the sheet ABOVE every Leaflet control (zoom,
     draw, edit/delete, attribution — all ~1000). Topbar still wins at
     1500 so short viewports never lose the brand row. */
  .panel--controls,
  .layout.is-panel-collapsed .panel--controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    height: var(--sheet-h, 56px);
    /* --topbar-h comes from JS (measureTopbar). CSS + JS share the cap
       so the snap math and the visual max-height agree to the pixel.
       100dvh tracks the *visible* viewport (keyboard open, address bar
       expanded) so the sheet never over-shoots and covers the topbar. */
    max-height: calc(100vh - var(--topbar-h, 54px) - 8px);
    max-height: calc(100dvh - var(--topbar-h, 54px) - 8px);
    border: none;
    border-top: 1px solid #dde4d8;
    border-radius: 18px 18px 0 0;
    background: #fff;
    box-shadow: 0 -6px 24px rgba(10, 30, 20, 0.14),
                0 -1px 0 rgba(255, 255, 255, 0.9) inset;
    z-index: 1200;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 18px max(18px, env(safe-area-inset-bottom));
    pointer-events: auto;
    transition: height 340ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* While the user is mid-drag we want instantaneous feedback, not easing. */
  .panel--controls[data-dragging="true"] {
    transition: none;
  }

  /* Sticky handle at the top of the sheet. Binary open/closed model:
     the chevron rotates 180° between states (points up when closed —
     "open me"; points down when open — "collapse me"). 44px tall hit
     area. `touch-action: none` is REQUIRED — otherwise iOS steals
     vertical pan and drag-to-toggle dies. */
  .sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 0;
    left: -18px;
    right: -18px;
    width: calc(100% + 36px);
    margin: 0 -18px 4px;
    padding: 10px 0 8px;
    border: none;
    background: #fff;
    color: #4a6048;
    cursor: pointer;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    z-index: 3;
    border-radius: 18px 18px 0 0;
    transition: color 0.15s ease;
  }
  .sheet-handle:hover,
  .sheet-handle:focus-visible { color: #0f4d2a; outline: none; }
  .sheet-handle:active { cursor: grabbing; }

  .sheet-handle-chevron {
    display: block;
    transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
  }
  /* Closed state → chevron up ("tap to open"). Open state → chevron
     down ("tap to close"). Direction tells user where the card will go. */
  .panel--controls[data-snap="open"] .sheet-handle-chevron {
    transform: rotate(180deg);
  }

  /* When closed, hide every form element so nothing peeks above the
     handle row. visibility:hidden preserves the scroll container's
     sizing without rendering anything. Handle stays visible via explicit
     exclusion. Result: closed state = ONLY the chevron-bearing strip. */
  .panel--controls[data-snap="closed"] > *:not(.sheet-handle) {
    visibility: hidden;
  }

  /* Run lives in the normal document flow at the END of the form (after
     layer chips). User scrolls to reach it — same as desktop. Two
     earlier attempts failed here:
       1. sticky bottom:0 never engages because Run's natural position at
          half-snap is below the viewport, so sticky doesn't pull it up.
       2. position:absolute bottom:14 pinned Run to the sheet bottom —
          but then it floated OVER the layer chips below "NDVI", making
          the last four chips (NDMI/NDRE/LST/SAR) untappable on mobile.
     Flow positioning avoids both traps: content is always reachable by
     scrolling, and at peek the sheet is only 56px tall so Run is
     naturally offscreen without any opacity tricks. */
  .panel--controls #run-btn {
    margin-top: 16px;
  }

  /* Leaflet controls inherit the desktop default (34×34 pills, 300×30
     sprite) as-is. Every previous attempt to enlarge them on mobile
     introduced either sprite bleed, missing icons, or size mismatches
     between zoom and draw/edit pills. The desktop layout is already
     battle-tested and looks right; keeping it unchanged on mobile is
     the simplest correct answer. Only the viewport safe-area padding
     is kept, since that fixes a real iPhone notch overlap. */
  .leaflet-top.leaflet-right {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  /* Legend tracks the sheet's height so it never hides under the sheet. */
  .legend {
    left: max(12px, env(safe-area-inset-left));
    right: auto;
    bottom: calc(var(--sheet-h, 140px) + 12px);
    max-width: calc(100vw - 24px);
    transition: bottom 340ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* Slight mobile squeeze on the layer chip grid so all six layer labels
     (NDVI / NDMI / NDRE / True-color / LST / SAR) fit without awkward
     wrapping. */
  .layer-chips { gap: 8px; }
  .layer-chip { padding: 12px 8px; }

  /* Tap targets inside the sheet go up to a finger-friendly size. */
  .date-row input { padding: 10px; font-size: 14px; }
  .search-box input { padding: 11px 12px; font-size: 14px; }
  .gps-btn { width: 42px; height: 42px; }
}


/* ---- Topbar credentials button ---------------------------------------- */

.creds-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  color: #d9f0e1;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease;
  -webkit-tap-highlight-color: transparent;
}

.creds-btn:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.creds-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.creds-btn svg { display: block; }

/* Amber dot in the top-right corner signals that custom user credentials
   are saved. Ringed with topbar green so it pops against the white SVG. */
.creds-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffc933;
  box-shadow: 0 0 0 2px #0f4d2a;
  pointer-events: none;
}


/* ---- Modal ------------------------------------------------------------- */

.sm-modal {
  position: fixed;
  inset: 0;
  /* Leaflet's zoom/draw toolbars sit at z-index ~1000; modal must clear them
     completely, including the draw-subtoolbar (Apply/Cancel) which is layered
     on top of the main toolbar. 3000 is comfortably above anything map-side. */
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 18px;
  animation: sm-modal-fade 180ms ease-out;
}

.sm-modal[hidden] { display: none; }

@keyframes sm-modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.sm-modal-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  margin: 0;
  padding: 0;
  background: rgba(15, 30, 20, 0.48);
  backdrop-filter: blur(8px) saturate(1.08);
  -webkit-backdrop-filter: blur(8px) saturate(1.08);
  cursor: pointer;
}

.sm-modal-card {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100vw - 28px));
  background: #ffffff;
  border: 1px solid #e2ecdc;
  border-radius: 16px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.8),
    0 18px 48px rgba(10, 30, 20, 0.28);
  padding: 22px 22px 18px;
  display: grid;
  gap: 14px;
  animation: sm-modal-rise 200ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

@keyframes sm-modal-rise {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.sm-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid #e2ecdc;
  background: #fafcf8;
  color: #4a6048;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.sm-modal-close:hover { background: #f0f6ed; border-color: #c4d0bf; }

.sm-modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #0f4d2a;
  letter-spacing: 0.1px;
  padding-right: 32px;
}

.sm-modal-desc {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: #5a6d58;
}

.sm-modal-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  color: #0f4d2a;
  font-weight: 600;
  text-decoration: none;
  background: #e9f5ee;
  border: 1px solid #bdd9c4;
  padding: 3px 9px;
  border-radius: 999px;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
  white-space: nowrap;
}

.sm-modal-link:hover {
  background: #d6ead9;
  border-color: #8eb89a;
  color: #0a3a1f;
}

.sm-modal-link:focus-visible {
  outline: 2px solid #0f4d2a;
  outline-offset: 2px;
}

.sm-modal-link svg {
  transition: transform 0.14s ease;
}

.sm-modal-link:hover svg {
  transform: translate(1px, -1px);
}

.sm-modal-steps-lead {
  display: inline;
  color: #5a6d58;
  font-size: 12.5px;
}

.sm-modal-steps {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: #4a6048;
  counter-reset: sm-step;
}

.sm-modal-steps li {
  position: relative;
  padding: 6px 10px 6px 30px;
  background: #f5f7f3;
  border: 1px solid #e2ecdc;
  border-radius: 8px;
  line-height: 1.4;
  counter-increment: sm-step;
}

.sm-modal-steps li::before {
  content: counter(sm-step);
  position: absolute;
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #0f4d2a;
  color: #fff;
  font-weight: 700;
  font-size: 10.5px;
  display: grid;
  place-items: center;
  line-height: 1;
}

.sm-modal-body {
  display: grid;
  gap: 12px;
  margin-top: 2px;
}

.sm-field { display: grid; gap: 6px; }

.sm-field-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #4a6048;
}

.sm-field-input {
  font: inherit;
  font-size: 13px;
  padding: 10px 12px;
  border: 1px solid #c4d0bf;
  border-radius: 9px;
  background: #fafcf8;
  color: #152514;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.14s ease, background 0.14s ease;
  width: 100%;
}

.sm-field-input:focus {
  outline: none;
  border-color: #15683a;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(21, 104, 58, 0.14);
}

.sm-field-input[aria-invalid="true"] {
  border-color: var(--err-border);
  background: var(--err-bg);
}

.sm-field-wrap {
  position: relative;
  display: flex;
}

.sm-field-reveal {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: #7a8d77;
  cursor: pointer;
  display: grid;
  place-items: center;
  border-radius: 6px;
}

.sm-field-reveal:hover { color: #0f4d2a; background: #f0f6ed; }

.sm-status {
  font-size: 12px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid transparent;
  line-height: 1.4;
}

.sm-status.is-error {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err-text);
}

.sm-status.is-warning {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.sm-status.is-success {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.sm-saved {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 11px;
  border-radius: 9px;
  background: #f5f7f3;
  border: 1px solid #e2ecdc;
  font-size: 12px;
  color: #2f4431;
}

.sm-saved strong { font-weight: 700; color: #0f4d2a; }

.sm-saved code {
  font-family: "Menlo", "Consolas", monospace;
  font-size: 11.5px;
  background: #fff;
  border: 1px solid #dde4d8;
  border-radius: 5px;
  padding: 1px 6px;
  margin-left: 4px;
}

.sm-saved-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2d8a4f;
  box-shadow: 0 0 0 3px rgba(45, 138, 79, 0.18);
}

.sm-saved-clear {
  margin-left: auto;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
  border: 1px solid #c4d0bf;
  border-radius: 6px;
  background: #fff;
  color: #8c2413;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.sm-saved-clear:hover { background: #fff5f3; border-color: #e6b0a5; }

.sm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.sm-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 9px;
  cursor: pointer;
  letter-spacing: 0.2px;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
}

.sm-btn:active { transform: translateY(1px); }

.sm-btn:disabled {
  opacity: 0.5;
  cursor: wait;
  transform: none;
}

.sm-btn-ghost {
  background: #ffffff;
  color: #4a6048;
  border: 1px solid #c4d0bf;
}

.sm-btn-ghost:hover:not(:disabled) {
  background: #f0f6ed;
  border-color: #0f4d2a;
  color: #0f4d2a;
}

.sm-btn-primary {
  background: #0f4d2a;
  color: #ffffff;
  border: 1px solid #0f4d2a;
  box-shadow: 0 2px 6px rgba(15, 77, 42, 0.22);
}

.sm-btn-primary:hover:not(:disabled) {
  background: #15683a;
  border-color: #15683a;
}

body.sm-modal-open { overflow: hidden; }

/* ---- Service worker update banner ----------------------------------------
   Shown when a newer SW has finished installing while the user's current
   tab is still running the previous build in memory. A tap on "Yenile"
   forces a full reload so the stale JS in memory is replaced. Fixed at
   the bottom so it never obscures the topbar or main controls; z-index
   above the bottom sheet (1200) but below the modal (3000). */
.update-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 1800;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 16px;
  background: #0f4d2a;
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  font-size: 13px;
  font-weight: 500;
  max-width: calc(100vw - 24px);
  animation: update-banner-in 0.22s ease-out;
}

@keyframes update-banner-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.update-banner-btn {
  appearance: none;
  border: none;
  background: #fff;
  color: #0f4d2a;
  font: inherit;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.14s ease;
}

.update-banner-btn:hover { background: #e9f5ee; }
.update-banner-btn:active { background: #dbe9d4; }
.update-banner-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
