/*
 * App shell: page layout, masthead + search, tabs, panel / mobile bottom sheet, footer, map chrome.
 * Components rendered by MK.ui live in components.css; dialogs in dialogs.css; tokens in tokens.css.
 *
 * Desktop (>= 900 px): 420 px sheet column on the left (masthead above the panel), map fills the rest.
 * Mobile: full-screen map, floating search card on top, bottom sheet with peek / half / full snap points
 * keyed on #panel[data-sheet-state] (set by MK.ui.sheet or the app.js fallback; --sheet-drag while dragging).
 *
 * The page itself never scrolls: #panel-body is the only scroller and the containing block of everything
 * absolutely positioned inside it (visually hidden captions, radio inputs), and .app clips to the viewport.
 * Without that, those elements escaped the scroller, grew the document, and focus()/scrollIntoView()
 * scrolled the viewport (masthead pushed off-screen) although body has overflow: hidden.
 */

/* ---- base ------------------------------------------------------------------------------------------ */

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

html,
body {
  height: 100%;
  overflow: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: var(--focus-w) solid var(--c-focus);
  outline-offset: 2px;
}

.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.skip-link {
  position: fixed;
  top: var(--sp-2);
  left: var(--sp-2);
  z-index: var(--z-toast);
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-ink);
  color: var(--c-surface);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

.noscript {
  padding: var(--sp-4);
  background: var(--c-warn-soft);
  border-bottom: 1px solid var(--c-warn);
}

/* Line icons inherit the text colour; `.fill` parts are solid. */
.search-icon,
.search-submit svg,
.map-fab svg,
.btn svg,
.icon-btn svg {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

svg .fill {
  fill: currentColor;
  stroke: none;
}

/* ---- buttons (shell) ----------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--c-ink);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}

.btn:hover {
  background: var(--c-surface-2);
}

.btn--primary {
  border-color: var(--c-accent);
  background: var(--c-accent);
  color: var(--c-accent-ink);
}

.btn--primary:hover {
  border-color: var(--c-accent-hover);
  background: var(--c-accent-hover);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
}

.btn--small {
  min-height: 28px;
  padding: 3px 10px;
  font-size: var(--fs-xs);
}

.btn--on-ink {
  border-color: currentColor;
  background: transparent;
  color: inherit;
}

.btn--on-ink:hover {
  background: rgba(255, 255, 255, .12);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--c-line);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-ink);
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--c-ink);
}

.icon-btn[aria-pressed="true"] {
  background: var(--c-ink);
  color: var(--c-surface);
  border-color: var(--c-ink);
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--c-ink);
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* ---- layout: desktop ------------------------------------------------------------------------------ */

.app {
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "head map"
    "panel map";
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overflow: clip; /* hidden stays a (programmatically) scrollable box; clip does not */
}

.masthead {
  grid-area: head;
  position: relative;
  z-index: var(--z-masthead);
  background: var(--c-surface);
  border-right: 1px solid var(--c-line);
  border-bottom: 1px solid var(--c-ink);
}

.panel {
  grid-area: panel;
  position: relative;
  z-index: var(--z-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--c-bg);
  border-right: 1px solid var(--c-line);
}

.panel:focus {
  outline: none;
}

.map-region {
  grid-area: map;
  position: relative;
  z-index: 0;
  isolation: isolate;
  min-width: 0;
  min-height: 0;
}

.map {
  position: absolute;
  inset: 0;
  background: var(--c-surface-2);
}

/* ---- masthead ------------------------------------------------------------------------------------- */

.masthead-inner {
  display: grid;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
}

/* Colour key of the VMD mežaudžu plāns along the top edge of the sheet. */
.species-strip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  height: 4px;
}

.species-strip i {
  flex: 1;
}

/* Header strip in the Līvu Koks logo colours (gold crest, teal and blue waves). */
.ss-priede { background: var(--brand-gold); }
.ss-egle { background: var(--brand-teal); }
.ss-berzs { background: var(--brand-blue); }
.ss-melnalksnis { background: var(--brand-gold); }
.ss-apse { background: var(--brand-teal); }
.ss-baltalksnis { background: var(--brand-blue); }

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
}

.brand-mark svg {
  width: 40px;
  height: 40px;
}

.brand-logo {
  display: block;
  max-width: 40px;
  max-height: 40px;
  object-fit: contain;
}

.bm-paper { fill: var(--c-surface); }
.bm-p { fill: var(--brand-gold); }
.bm-e { fill: var(--brand-teal); }
.bm-a { fill: var(--c-accent-soft); }
.bm-b { fill: var(--brand-blue); }

.bm-line {
  fill: none;
  stroke: var(--map-ink);
  stroke-width: 1.2;
  stroke-linejoin: round;
}

.bm-frame {
  fill: none;
  stroke: var(--c-ink);
  stroke-width: 2;
}

.brand-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -.005em;
  line-height: var(--lh-tight);
}

.brand-tagline {
  font-size: var(--fs-xs);
  color: var(--c-ink-2);
  line-height: 1.35;
}

/* ---- search --------------------------------------------------------------------------------------- */

.search {
  display: grid;
  gap: var(--sp-2);
  min-width: 0;
}

.search-field {
  display: flex;
  align-items: stretch;
  min-width: 0;
  border: 1px solid var(--c-ink);
  border-radius: var(--r-sm);
  background: var(--c-surface);
}

.search-field:focus-within {
  outline: var(--focus-w) solid var(--c-focus);
  outline-offset: 2px;
}

.search-icon {
  align-self: center;
  margin-left: 10px;
  color: var(--c-ink-2);
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  font-size: 1rem; /* >= 16 px: no zoom-on-focus in iOS Safari */
  text-overflow: ellipsis;
}

.search-input:focus,
.search-input:focus-visible {
  outline: none;
}

.search-input::placeholder {
  color: var(--c-ink-2);
  opacity: 1;
}

.search-input::-webkit-search-cancel-button {
  cursor: pointer;
}

.search-submit {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--c-ink);
  background: var(--c-ink);
  color: var(--c-surface);
  cursor: pointer;
}

.search-submit:hover {
  background: var(--c-accent);
  color: var(--c-accent-ink);
}

.search-submit:focus-visible {
  outline-offset: -4px;
  outline-color: var(--c-surface);
}

.search-help {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--c-ink-2);
}

.kbd {
  flex: none;
  min-width: 18px;
  padding: 0 5px;
  border: 1px solid var(--c-line);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  font: 500 var(--fs-xs)/1.4 var(--font-mono);
  text-align: center;
  color: var(--c-ink-2);
}

.search-results {
  max-height: 40vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ---- tabs ----------------------------------------------------------------------------------------- */

.tabs {
  display: flex;
  flex: none;
  padding: 0 var(--sp-3);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-line);
}

.tab {
  display: flex;
  flex: 1;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  margin-bottom: -1px;
  padding: 12px 6px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--c-ink-2);
  font-size: var(--fs-sm);
  font-weight: 650;
  font-stretch: var(--wdth-cond);
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover {
  color: var(--c-ink);
}

.tab[aria-selected="true"] {
  color: var(--c-ink);
  border-bottom-color: var(--c-ink);
}

.tab:focus-visible {
  outline-offset: -3px;
}

.tab-no {
  font: 500 var(--fs-xs)/1 var(--font-mono);
  letter-spacing: 0;
  color: var(--c-ink-3);
}

.tab[aria-selected="true"] .tab-no {
  color: var(--c-accent-text);
}

/* ---- panel body: ruled paper with a faint kvartāls grid -------------------------------------------- */

.panel-body {
  position: relative; /* containing block for absolutely positioned content: it scrolls with the panel */
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--c-bg);
  background-image:
    linear-gradient(var(--c-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--c-grid) 1px, transparent 1px),
    linear-gradient(var(--c-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--c-grid) 1px, transparent 1px);
  background-size:
    var(--grid-major) var(--grid-major),
    var(--grid-major) var(--grid-major),
    var(--grid-cell) var(--grid-cell),
    var(--grid-cell) var(--grid-cell);
  background-attachment: local;
}

.messages {
  padding: var(--sp-4) var(--sp-5) 0;
}

.messages:empty {
  display: none;
}

.tabpanel {
  padding: var(--sp-5);
}

.tabpanel:focus-visible {
  outline-offset: -3px;
}

.view {
  display: grid;
  gap: var(--sp-4);
  min-width: 0;
}

/* ---- empty states --------------------------------------------------------------------------------- */

.empty {
  display: grid;
  gap: var(--sp-4);
  padding: var(--sp-5);
  border: 1px solid var(--c-line);
  border-top: 2px solid var(--c-ink);
  background: var(--c-surface);
}

.empty-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  font-stretch: var(--wdth-cond);
  letter-spacing: .07em;
  text-transform: uppercase;
}

.empty-note {
  font-size: var(--fs-sm);
  color: var(--c-ink-2);
}

.steps {
  display: grid;
  gap: var(--sp-3);
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  counter-increment: step;
}

.steps li::before {
  content: counter(step, decimal-leading-zero);
  align-self: start;
  padding-top: 2px;
  border-top: 2px solid var(--c-ink);
  font: 600 var(--fs-xs)/1.4 var(--font-mono);
  color: var(--c-accent-text);
}

.example .btn {
  gap: var(--sp-3);
}

.example-code {
  font-weight: 500;
  color: var(--c-ink-2);
}

.legend-key {
  margin: 0;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--c-line);
}

.legend-key-title {
  margin-bottom: var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 650;
  font-stretch: var(--wdth-cond);
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--c-ink-2);
}

.legend-key-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(4, 32px);
  gap: 3px 4px;
  align-items: center;
}

.lk-head {
  font-size: var(--fs-xs);
  text-align: center;
  color: var(--c-ink-2);
}

.lk-name {
  font-size: var(--fs-sm);
}

.sw {
  display: block;
  height: 14px;
  border: 1px solid rgba(23, 32, 26, .28);
}

.sw-priede-1 { background: var(--sp-priede-1); }
.sw-priede-2 { background: var(--sp-priede-2); }
.sw-priede-3 { background: var(--sp-priede-3); }
.sw-priede-4 { background: var(--sp-priede-4); }
.sw-egle-1 { background: var(--sp-egle-1); }
.sw-egle-2 { background: var(--sp-egle-2); }
.sw-egle-3 { background: var(--sp-egle-3); }
.sw-egle-4 { background: var(--sp-egle-4); }
.sw-berzs-1 { background: var(--sp-berzs-1); }
.sw-berzs-2 { background: var(--sp-berzs-2); }
.sw-berzs-3 { background: var(--sp-berzs-3); }
.sw-berzs-4 { background: var(--sp-berzs-4); }
.sw-melnalksnis-1 { background: var(--sp-melnalksnis-1); }
.sw-melnalksnis-2 { background: var(--sp-melnalksnis-2); }
.sw-melnalksnis-3 { background: var(--sp-melnalksnis-3); }
.sw-melnalksnis-4 { background: var(--sp-melnalksnis-4); }
.sw-apse-1 { background: var(--sp-apse-1); }
.sw-apse-2 { background: var(--sp-apse-2); }
.sw-apse-3 { background: var(--sp-apse-3); }
.sw-apse-4 { background: var(--sp-apse-4); }
.sw-baltalksnis-1 { background: var(--sp-baltalksnis-1); }
.sw-baltalksnis-2 { background: var(--sp-baltalksnis-2); }
.sw-baltalksnis-3 { background: var(--sp-baltalksnis-3); }
.sw-baltalksnis-4 { background: var(--sp-baltalksnis-4); }

.legend-key-note {
  margin-top: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--c-ink-2);
}

/* ---- footer --------------------------------------------------------------------------------------- */

.panel-foot {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: var(--sp-2);
  margin-top: auto;
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
  border-top: 1px solid var(--c-line);
  background: var(--c-surface);
}

.foot-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.foot-actions .icon-btn {
  margin-left: auto;
}

.disclaimer {
  font-size: var(--fs-xs);
  line-height: 1.4;
  color: var(--c-ink-2);
}

.disclaimer .link-btn {
  margin-left: var(--sp-1);
  color: var(--c-ink-2);
}

.contacts {
  display: flex;
  flex-wrap: wrap;
  gap: 2px var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--c-ink-2);
}

.contacts a {
  color: var(--c-ink);
  text-underline-offset: 2px;
}

/* ---- sheet handle (mobile only; look in components.css) --------------------------------------------- */

.sheet-handle {
  display: none;
}

/* ---- shell fallback renderers (used only without MK.ui) --------------------------------------------- */

.msg {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--c-line);
  border-left: 3px solid var(--c-info);
  background: var(--c-surface);
  font-size: var(--fs-sm);
}

.msg + .msg {
  margin-top: var(--sp-2);
}

.msg--error {
  border-left-color: var(--c-danger);
  background: var(--c-danger-soft);
}

.msg--loading {
  border-left-color: var(--c-ink-2);
}

.msg-text {
  flex: 1 1 12rem;
}

.result-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--c-line);
  background: var(--c-surface);
}

.result-item {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-bottom: 1px solid var(--c-line);
  background: none;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}

.result-item:hover {
  background: var(--c-surface-2);
}

.fallback-title {
  font-size: var(--fs-lg);
}

.fallback-layers fieldset {
  display: grid;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-4);
  padding: var(--sp-3);
  border: 1px solid var(--c-line);
  background: var(--c-surface);
}

.fallback-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 28px;
}

.fallback-note {
  color: var(--c-ink-2);
  font-size: var(--fs-xs);
}

/* ---- map chrome ------------------------------------------------------------------------------------ */

.busy {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  height: 3px;
  overflow: hidden;
  pointer-events: none;
}

.busy::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -30%;
  width: 30%;
  background: var(--c-accent);
  animation: mk-busy 1.1s var(--ease-out) infinite;
}

@keyframes mk-busy {
  to { left: 100%; }
}

.map-hint {
  position: absolute;
  top: var(--sp-3);
  left: 50%;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: calc(100% - 128px);
  padding: 6px 6px 6px 12px;
  border-radius: var(--r-sm);
  background: var(--map-ink);
  color: #fdfaf2;
  font-size: var(--fs-sm);
  line-height: 1.3;
  box-shadow: var(--shadow-2);
  transform: translateX(-50%);
}

.map-hint-text {
  min-width: 0;
}

.map-hint .btn:focus-visible {
  outline-color: #fdfaf2;
}

.map-fab {
  position: absolute;
  right: 10px;
  z-index: 1000;
  display: none;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--c-ink);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-ink);
  box-shadow: var(--shadow-1);
  cursor: pointer;
}

/* ---- Leaflet overrides ------------------------------------------------------------------------------ */

.leaflet-container {
  background: var(--c-surface-2);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
}

.leaflet-container:focus-visible {
  outline: var(--focus-w) solid var(--c-focus);
  outline-offset: -3px;
}

.leaflet-bar,
.leaflet-touch .leaflet-bar {
  border: 1px solid var(--c-ink);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-1);
  background-clip: border-box;
}

.leaflet-bar a,
.leaflet-touch .leaflet-bar a {
  width: 36px;
  height: 36px;
  border-bottom: 1px solid var(--c-line);
  background: var(--c-surface);
  color: var(--c-ink);
  font: 500 18px/35px var(--font-mono);
}

.leaflet-bar a:hover,
.leaflet-bar a:focus {
  background: var(--c-surface-2);
  color: var(--c-ink);
}

.leaflet-bar a:first-child,
.leaflet-touch .leaflet-bar a:first-child {
  border-top-left-radius: 1px;
  border-top-right-radius: 1px;
}

.leaflet-bar a:last-child,
.leaflet-touch .leaflet-bar a:last-child {
  border-bottom: 0;
  border-bottom-left-radius: 1px;
  border-bottom-right-radius: 1px;
}

.leaflet-bar a.leaflet-disabled {
  background: var(--c-surface);
  color: var(--c-ink-3);
}

.leaflet-control a:focus-visible,
.leaflet-bar a:focus-visible {
  outline: var(--focus-w) solid var(--c-focus);
  outline-offset: 1px;
}

/* Scale bar, readout and credits are "printed" on the map: light in both themes. */
.leaflet-control-scale-line {
  padding: 1px 6px;
  border: 1.5px solid var(--map-ink);
  border-top: 0;
  background: var(--map-chrome);
  color: var(--map-ink);
  font: 500 11px/1.5 var(--font-mono);
}

/* Rises above the attribution when the two would overlap (map.js sets --mk-attr-clear). */
.leaflet-bottom.leaflet-left {
  margin-bottom: var(--mk-attr-clear, 0px);
}

.mk-readout {
  padding: 2px 6px;
  border: 1px solid rgba(23, 32, 26, .35);
  background: var(--map-chrome);
  color: var(--map-ink);
  font: 500 11px/1.4 var(--font-mono);
  letter-spacing: .02em;
}

.leaflet-control-attribution,
.leaflet-container .leaflet-control-attribution {
  padding: 1px 6px;
  background: var(--map-chrome);
  color: #45413a;
  font-size: 10.5px;
  line-height: 1.5;
}

.leaflet-control-attribution a {
  color: var(--map-ink);
}

.leaflet-tooltip.mk-tip {
  padding: 4px 7px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--map-ink);
  color: #fdfaf2;
  font: 500 12px/1.3 var(--font-mono);
  box-shadow: var(--shadow-1);
}

.leaflet-tooltip-top.mk-tip::before {
  border-top-color: var(--map-ink);
}

.leaflet-tooltip-bottom.mk-tip::before {
  border-bottom-color: var(--map-ink);
}

/* Dim the street map a little under a dark UI; data overlays keep their colours. */
[data-theme="dark"] .mk-base--osm {
  filter: brightness(.84) contrast(1.05) saturate(.85);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mk-base--osm {
    filter: brightness(.84) contrast(1.05) saturate(.85);
  }
}

/* ---- mobile: floating search card + bottom sheet ------------------------------------------------ */

@media (max-width: 899.98px) {
  .app {
    display: block;
  }

  .map-region {
    position: fixed;
    inset: 0;
  }

  .masthead {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 0;
    border: 0;
    background: transparent;
    pointer-events: none;
  }

  .masthead-inner {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--c-ink);
    border-radius: var(--r-md);
    background: var(--c-surface);
    box-shadow: var(--shadow-2);
    pointer-events: auto;
  }

  .species-strip {
    display: none;
  }

  /* Brand name and search help stay available to screen readers only. */
  .brand-text,
  .search-help {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .brand-mark,
  .brand-mark svg {
    width: 44px;
    height: 44px;
  }

  .search-input {
    height: 42px;
  }

  /* The input keeps 16 px (no iOS zoom); only the hint text is smaller so it fits the phone field. */
  .search-input::placeholder {
    font-size: .875rem;
  }

  .search-results:not([hidden]) {
    max-height: 45vh;
    margin-top: 4px;
  }

  .panel {
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--sheet-h, var(--sheet-peek)) + var(--safe-bottom));
    max-height: 100vh;
    max-height: 100dvh;
    padding-bottom: var(--safe-bottom);
    border: 0;
    border-top: 1px solid var(--c-ink);
    border-radius: var(--r-md) var(--r-md) 0 0;
    background: var(--c-surface);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, .18);
    transition: height var(--dur-2) var(--ease-out);
  }

  .panel[data-sheet-state="peek"] { --sheet-h: var(--sheet-peek); }
  .panel[data-sheet-state="half"] { --sheet-h: var(--sheet-half); }
  .panel[data-sheet-state="full"] { --sheet-h: var(--sheet-full); }

  .panel.is-dragging {
    height: calc(clamp(var(--sheet-peek), calc(var(--sheet-h, var(--sheet-peek)) - var(--sheet-drag, 0px)), var(--sheet-full)) + var(--safe-bottom));
    transition: none;
  }

  .sheet-handle {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 28px;
    border: 0;
    background: transparent;
    touch-action: none;
  }

  .tabs {
    padding: 0 var(--sp-2);
  }

  .messages {
    padding: var(--sp-3) var(--sp-4) 0;
  }

  .tabpanel {
    padding: var(--sp-4);
  }

  .panel-foot {
    position: static;
    padding: var(--sp-3) var(--sp-4) var(--sp-4);
  }

  .leaflet-top {
    top: var(--masthead-h, 66px);
  }

  .leaflet-bottom {
    bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom, 0px));
  }

  .leaflet-control-attribution,
  .leaflet-container .leaflet-control-attribution {
    max-width: calc(100vw - 20px);
    white-space: normal;
  }

  .map-hint {
    top: calc(var(--masthead-h, 66px) + 8px);
    max-width: calc(100% - 112px);
  }

  .map-fab {
    display: grid;
    top: calc(var(--masthead-h, 66px) + 96px);
  }
}

/* ---- motion ----------------------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }

  .busy::before {
    left: 0;
    width: 100%;
    opacity: .6;
    animation: none;
  }
}
