/*
 * Field-Atlas map page styles. Ported 1:1 from the Python prototype
 * (johannisberg-scan/scripts/map_template.html). Custom CSS by design —
 * Tailwind utilities cannot express the typographic detail this layout needs.
 *
 * Loaded for the maps#index action only via the layout's `:head` slot in
 * combination with `application.css` (which also includes Tailwind).
 */

:root {
  --paper: #faf6ee;
  --paper-card: #fffef9;
  --ink: #2a1f14;
  --ink-soft: #4d3f30;
  --ink-mute: #8a7a64;
  --rule: #d9cfbb;
  --forest: #1f3a2e;
  --sage: #6b7c3e;
  --sage-soft: #9bab6e;
  --sand: #d4b896;
  --terracotta: #c66b3d;
  --crimson: #8b2e2e;
  --shadow: 0 1px 0 rgba(42, 31, 20, 0.04), 0 6px 24px -12px rgba(42, 31, 20, 0.16);
  --shadow-deep: 0 12px 40px -16px rgba(42, 31, 20, 0.32);
}

/* The map page takes over the whole viewport. The body otherwise stays
 * untouched so login / detail pages keep their Tailwind layout. */
body.map-page {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Public Sans", system-ui, sans-serif;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.map-page html, body.map-page { height: 100%; }

/* Grain overlay sits above the map but lets clicks through. */
body.map-page::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.035;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
}

.map-page-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ── header ──────────────────────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 16px;
  padding: 18px 24px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  position: relative;
  z-index: 1000;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 0;
  height: 1px;
  background: var(--rule);
}

.brand h1 {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 600;
  font-style: italic;
  font-variation-settings: "opsz" 36;
  font-size: clamp(22px, 4vw, 32px);
  line-height: 1;
  letter-spacing: -0.015em;
  margin: 0;
  color: var(--forest);
}

.brand .subtitle {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-mute);
  margin-top: 6px;
}

.meta {
  text-align: right;
  line-height: 1;
}

.meta .count {
  font-family: "Newsreader", Georgia, serif;
  font-variation-settings: "opsz" 60;
  font-weight: 400;
  font-size: clamp(28px, 5vw, 42px);
  letter-spacing: -0.02em;
  color: var(--ink);
  display: block;
}

.meta .meta-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink-mute);
  margin-top: 4px;
  display: block;
}

/* Status counter strip — sits inside the topbar grid spanning both columns,
 * separated from the brand+meta row by a dashed rule. Counts are kept in
 * sync from the Stimulus controller. Export/Import buttons trail at the end. */
.status-strip {
  grid-column: 1 / -1;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--rule);
}

.status-strip__item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.status-strip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-strip__count {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.status-strip__action {
  background: none;
  border: 1px solid var(--rule);
  color: var(--ink-mute);
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.12s ease;
}

.status-strip__action:first-of-type { margin-left: auto; }

.status-strip__action:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* Map-local .toast styles removed — the global toast UI lives in
 * application.css (.toast-container / .toast-item). All map notifications
 * now flow through lib/toast.js. */

/* Logout link sits inside the topbar grid as a quiet secondary action. */
.topbar__actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.topbar__logout {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.topbar__logout:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ── filter bar ──────────────────────────────────────────── */
.filter-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  scrollbar-width: none;
  position: relative;
  z-index: 1000;
}

.filter-bar::-webkit-scrollbar { display: none; }

.filter-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 14px 8px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  color: var(--ink-soft);
  font-family: "Public Sans", sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.filter-pill .swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transform: translateY(-1px);
}

.filter-pill .pill-count {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mute);
  letter-spacing: 0;
}

.filter-pill:hover {
  background: var(--paper-card);
  border-color: var(--ink-mute);
}

.filter-pill.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.filter-pill.active .pill-count { color: var(--sand); }

.filter-divider {
  width: 1px;
  align-self: stretch;
  background: var(--rule);
  margin: 0 4px;
}

/* ── map ─────────────────────────────────────────────────── */
.map-shell {
  flex: 1 1 auto;
  width: 100%;
  position: relative;
  background: var(--paper);
}

.map-shell #map {
  width: 100%;
  height: 100%;
}

.leaflet-container {
  background: #efe6d4;
  font-family: "Public Sans", sans-serif;
  cursor: crosshair;
}

.leaflet-control-zoom {
  border: 1px solid var(--rule) !important;
  box-shadow: var(--shadow) !important;
  border-radius: 2px !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--paper-card) !important;
  color: var(--ink) !important;
  font-family: "Newsreader", Georgia, serif !important;
  font-weight: 400 !important;
  font-size: 18px !important;
  border: none !important;
  border-bottom: 1px solid var(--rule) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
}

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

.leaflet-control-zoom a:hover {
  background: var(--ink) !important;
  color: var(--paper) !important;
}

.leaflet-control-attribution {
  background: rgba(250, 246, 238, 0.85) !important;
  backdrop-filter: blur(4px);
  font-family: "JetBrains Mono", monospace !important;
  font-size: 9px !important;
  font-weight: 500;
  color: var(--ink-mute) !important;
  padding: 2px 8px !important;
}

.leaflet-control-attribution a {
  color: var(--terracotta) !important;
  text-decoration: none !important;
}

/* ── geolocate button ────────────────────────────────────── */
.locate-btn {
  position: absolute;
  bottom: 24px;
  right: 16px;
  width: 52px;
  height: 52px;
  border: 1px solid var(--rule);
  background: var(--paper-card);
  border-radius: 50%;
  box-shadow: var(--shadow-deep);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  z-index: 1000;
  color: var(--terracotta);
}

.locate-btn:hover {
  transform: translateY(-2px);
  background: var(--ink);
  color: var(--sand);
}

.locate-btn:active { transform: translateY(0); }

.locate-btn.tracking,
.locate-btn.is-active {
  background: var(--terracotta);
  color: var(--paper-card);
  border-color: var(--terracotta);
  position: relative;
}

/* Pulse outline ring around the FAB while tracking is active. The ring grows
 * outward and fades — animation runs forever, only present while is-active. */
.locate-btn.is-active::before {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--terracotta);
  border-radius: 50%;
  opacity: 0;
  animation: locate-pulse 2s ease-out infinite;
  pointer-events: none;
}

@keyframes locate-pulse {
  0%   { opacity: 0.6; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.6); }
}

/* Live-position marker pulse — subtle, just keeps the eye on it. */
.live-location-marker {
  animation: marker-pulse 2s ease-in-out infinite;
}

@keyframes marker-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

.locate-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
}

.layer-toggle {
  position: absolute;
  bottom: 24px;
  right: 80px;
  padding: 0 14px;
  height: 36px;
  border: 1px solid var(--rule);
  background: var(--paper-card);
  border-radius: 2px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-transform: uppercase;
  z-index: 1000;
  transition: all 0.15s ease;
}

.layer-toggle:hover {
  background: var(--ink);
  color: var(--sand);
  border-color: var(--ink);
}

/* ── popup ───────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--paper-card) !important;
  color: var(--ink) !important;
  border: 1px solid var(--ink) !important;
  border-radius: 2px !important;
  box-shadow: var(--shadow-deep) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  width: 280px !important;
  line-height: 1.45;
}

.leaflet-popup-tip { background: var(--ink) !important; }

.leaflet-popup-close-button {
  color: var(--ink-mute) !important;
  font-family: "JetBrains Mono", monospace !important;
  font-size: 16px !important;
  font-weight: 500 !important;
  padding: 8px !important;
  top: 4px !important;
  right: 4px !important;
}

.leaflet-popup-close-button:hover { color: var(--crimson) !important; }

.pcard { padding: 16px 20px 14px; }

.pcard__head {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.pcard__id {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 4px;
}

.pcard__title {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  font-style: italic;
  font-variation-settings: "opsz" 36;
  font-size: 26px;
  line-height: 1.05;
  color: var(--forest);
  letter-spacing: -0.015em;
  margin: 0;
}

.pcard__measure {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 400;
  font-size: 15px;
  color: var(--ink);
  margin-top: 6px;
}

.pcard__measure b {
  font-weight: 600;
  color: var(--terracotta);
  font-variant-numeric: tabular-nums;
}

.pcard__bucket {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 3px 8px;
  border: 1px solid currentColor;
  border-radius: 2px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.pcard__bucket--fga       { color: #5c8a3e; }
.pcard__bucket--wohn      { color: var(--terracotta); }
.pcard__bucket--natur     { color: #a87e54; }
.pcard__bucket--misch     { color: var(--sage); }
.pcard__bucket--unbekannt { color: var(--ink-mute); }

.pcard__pin-banner {
  margin: 12px -20px -2px;
  padding: 10px 20px;
  color: var(--paper);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.pcard__pin-banner.color-crimson { background: var(--crimson); }
.pcard__pin-banner.color-violet  { background: #5e3a7a; }
.pcard__pin-banner.color-amber   { background: #a06a14; }

.pcard__pin-banner::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--paper);
  flex: 0 0 auto;
  margin-top: 5px;
}

.pcard__pin-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.pcard__pin-note {
  font-family: "Public Sans", sans-serif;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  color: rgba(255, 254, 249, 0.92);
  line-height: 1.4;
}

/* Pinned parcels: permanent label rendered as Leaflet DivIcon. */
.pin-label {
  background: var(--crimson);
  color: var(--paper);
  border: none;
  padding: 4px 10px 5px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: var(--shadow);
  border-radius: 2px;
  white-space: nowrap;
  /* Counter-translate to center the icon (Leaflet anchors at top-left). */
  transform: translate(-50%, -50%);
  position: relative;
}

.pin-label--violet { background: #5e3a7a; }
.pin-label--amber  { background: #a06a14; }

/* The DivIcon wrapper Leaflet draws around our html should be invisible. */
.pin-label-wrapper {
  background: transparent !important;
  border: none !important;
}

.pcard__rows {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 20px;
  font-size: 13px;
}

.pcard__rows dt {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  align-self: center;
}

.pcard__rows dd {
  margin: 0;
  font-family: "Public Sans", sans-serif;
  font-size: 13px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.pcard__foot {
  border-top: 1px solid var(--rule);
  margin-top: 14px;
  padding-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.pcard__coord {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-mute);
  letter-spacing: 0.05em;
}

.pcard__links { display: flex; gap: 14px; }

.pcard__links a {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--terracotta);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}

.pcard__links a:hover { border-color: var(--terracotta); }

/* Prominent detail-page CTA inside the desktop popup. Full-width block,
   terracotta border, hover swap to a filled state. The popup-card already
   exposes Maps/Streetview links for spatial context — this one points at
   the editing surface (photo/voice/notes/listings). */
.pcard__detail-link {
  display: block;
  margin-top: 14px;
  padding: 10px 12px;
  font-family: "Newsreader", "Times New Roman", serif;
  font-style: italic;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  color: var(--terracotta);
  background: var(--paper);
  border: 1.5px solid var(--terracotta);
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}

.pcard__detail-link:hover,
.pcard__detail-link:focus {
  background: var(--terracotta);
  color: var(--paper);
  outline: none;
}

.pcard__detail-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-mute);
  text-align: center;
  font-style: italic;
}

/* ── tooltip on hover ────────────────────────────────────── */
.leaflet-tooltip {
  background: var(--ink) !important;
  color: var(--paper) !important;
  border: none !important;
  box-shadow: var(--shadow) !important;
  border-radius: 2px !important;
  padding: 4px 10px !important;
  font-family: "JetBrains Mono", monospace !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  letter-spacing: 0.04em;
}

.leaflet-tooltip-top:before { border-top-color: var(--ink) !important; }

/* Edge length labels on the map (DivIcon-based). */
.edge-label {
  background: var(--paper-card);
  color: var(--terracotta);
  border: 1px solid var(--terracotta);
  box-shadow: 0 2px 6px -2px rgba(42, 31, 20, 0.4);
  border-radius: 2px;
  padding: 2px 6px 3px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  position: relative;
}

.edge-label-wrapper {
  background: transparent !important;
  border: none !important;
}

/* ── status row ──────────────────────────────────────────── */
.pcard__status {
  border-top: 1px solid var(--rule);
  margin-top: 12px;
  padding-top: 12px;
}

.pcard__status-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 8px;
}

.pcard__status-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.status-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font-family: "Public Sans", sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.12s ease;
}

.status-btn:hover { background: var(--paper); border-color: var(--ink-soft); }

.status-btn[data-active="1"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.status-btn::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.status-btn[data-status="verwildert"]::before     { background: #d97a3c; }
.status-btn[data-status="bewirtschaftet"]::before { background: #5a7da8; }
.status-btn[data-status="ungeklaert"]::before     { background: #b8a064; }
.status-btn[data-status="kontaktiert"]::before    { background: var(--crimson); }
.status-btn[data-status="reset"]::before          { background: var(--rule); }

/* ── research side panel ─────────────────────────────────── */
/* Toggle button anchored top-right of the map shell. Slides the panel into
 * view, leaving the map underneath dimmed via the panel's drop shadow. */
.research-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 8px 14px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  border-radius: 2px;
  box-shadow: var(--shadow-deep);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  z-index: 1100;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.research-toggle::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(198, 107, 61, 0.25);
}

.research-toggle:hover { background: var(--terracotta); border-color: var(--terracotta); }

.research-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(440px, 100vw);
  height: 100vh;
  background: var(--paper);
  border-left: 1px solid var(--rule);
  box-shadow: -16px 0 48px -16px rgba(42, 31, 20, 0.32);
  z-index: 1200;
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.2, 0.7, 0.2, 1);
  overflow-y: auto;
}

.research-panel.open { transform: translateX(0); }

.research-panel__head {
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 2;
}

.research-panel__close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.research-panel__close:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.research-panel__kicker {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 8px;
}

.research-panel__title {
  font-family: "Newsreader", Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-variation-settings: "opsz" 32;
  font-size: 26px;
  letter-spacing: -0.015em;
  line-height: 1.1;
  color: var(--forest);
  margin: 0 0 10px;
}

.research-panel__summary {
  font-family: "Public Sans", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0;
}

.research-panel__body {
  padding: 8px 24px 32px;
}

.research-section-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--rule);
}

.lead-card {
  border: 1px solid var(--rule);
  background: var(--paper-card);
  padding: 14px 16px 16px;
  margin-bottom: 12px;
  border-radius: 2px;
}

.lead-card__kind {
  display: inline-block;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 2px 8px;
  border: 1px solid currentColor;
  border-radius: 2px;
  margin-bottom: 8px;
}

.lead-card__kind--lead { color: var(--terracotta); }
.lead-card__kind--context { color: var(--sage); }

.lead-card__title {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  font-size: 18px;
  line-height: 1.2;
  color: var(--ink);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.lead-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.lead-card__meta b {
  color: var(--terracotta);
  font-weight: 600;
}

.lead-card__body {
  font-family: "Public Sans", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.lead-card__action {
  font-family: "Public Sans", sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink);
  padding: 8px 10px;
  background: var(--paper);
  border-left: 2px solid var(--terracotta);
  margin-bottom: 10px;
}

.lead-card__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--terracotta);
  text-decoration: none;
  border-bottom: 1px solid var(--terracotta);
  padding-bottom: 1px;
}

.lead-card__link:hover { color: var(--crimson); border-color: var(--crimson); }

.source-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--rule);
  font-size: 12px;
  line-height: 1.4;
}

.source-row:last-child { border-bottom: none; }

.source-row__name {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}

.source-row__link {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--terracotta);
  text-decoration: none;
  align-self: start;
}

.source-row__result {
  grid-column: 1 / -1;
  color: var(--ink-soft);
  font-family: "Public Sans", sans-serif;
}

.pacht-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.pacht-table th, .pacht-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}

.pacht-table th {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.pacht-table td {
  font-family: "Public Sans", sans-serif;
  color: var(--ink);
}

.pacht-table td.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--terracotta);
  font-weight: 600;
}

.pacht-table tr.row-clickable { cursor: pointer; }
.pacht-table tr.row-clickable:hover { background: var(--paper-card); }

/* ── responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .topbar { padding: 14px 16px 10px; }
  .filter-bar { padding: 10px 16px; }
  .layer-toggle { right: auto; left: 16px; bottom: 24px; }
  .leaflet-popup-content { width: 260px !important; }
  .pcard { padding: 14px 16px 12px; }
  .pcard__title { font-size: 22px; }
  .status-strip { font-size: 9px; gap: 10px; }
  .research-toggle { top: 12px; right: 12px; padding: 6px 10px; font-size: 9px; }
}

/* ── safe-area insets (notch / home-indicator on iOS) ──────
 * Modern iOS devices need viewport-fit=cover (set in the layout) plus
 * env(safe-area-inset-*) padding to keep the UI clear of the notch and
 * home-indicator. Wrapped in @supports so older browsers ignore it
 * cleanly. The mobile-layer rules below already use env() inline; this
 * block exists so the floating buttons + sheets respect the insets even
 * outside the strict 768px breakpoint. */
@supports (padding: env(safe-area-inset-top)) {
  .bottom-sheet,
  .modal {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal {
    padding-top: env(safe-area-inset-top);
  }
}

/* ── mobile / desktop visibility ────────────────────────────
 * Mobile-first switches use a 768px breakpoint. By default we only hide
 * .mobile-only nodes — .desktop-only keeps its original display so flex/
 * grid layouts (status-strip, filter-bar) stay intact. The media query
 * flips both at the same breakpoint. */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
  .mobile-only { display: flex !important; }
  .desktop-only { display: none !important; }

  .topbar {
    padding: max(10px, env(safe-area-inset-top)) 16px 10px 16px;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
  }

  .topbar::after { display: none; }

  .brand h1 { font-size: 22px; }

  .topbar-icons {
    display: flex;
    gap: 10px;
    align-items: center;
  }

  .topbar-icon {
    background: var(--paper-card);
    border: 1px solid var(--rule);
    color: var(--ink);
    width: 40px;
    height: 40px;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .topbar-icon:active {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
  }

  /* Map fills almost the entire viewport below the slim topbar. */
  .map-shell { height: calc(100vh - 60px); }

  /* FAB-row sits above the home-indicator on iOS. */
  .locate-btn,
  .layer-toggle {
    bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ── bottom-sheet ────────────────────────────────────────── */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--paper-card);
  border-top: 1px solid var(--rule);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-deep);
  z-index: 2000;
  transform: translateY(100%);
  transition: transform 220ms ease-out;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-sheet.is-open { transform: translateY(0); }

.bottom-sheet__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 31, 20, 0.4);
  z-index: 1999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

/* Backdrop is a sibling of the sheet — pair them via the `is-open` flag set
 * on the sheet so we don't need a second controller for the overlay. */
.bottom-sheet.is-open ~ .bottom-sheet__backdrop {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet__handle {
  width: 40px;
  height: 4px;
  background: var(--rule);
  border-radius: 2px;
  margin: 12px auto 8px;
  flex-shrink: 0;
  cursor: grab;
}

.bottom-sheet__head {
  padding: 4px 20px 12px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.bottom-sheet__title {
  font-family: "Newsreader", Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 22px;
  margin: 0;
  color: var(--forest);
}

.bottom-sheet__close {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  width: 32px;
  height: 32px;
  border-radius: 2px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.bottom-sheet__body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Stacked filter pills inside the mobile sheet — overrides the row layout
 * from the desktop .filter-bar without duplicating selectors. */
.filter-bar--stacked {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  border: none;
  overflow: visible;
  background: transparent;
}

.filter-bar--stacked .filter-pill {
  width: 100%;
  justify-content: flex-start;
  padding: 12px 14px;
  font-size: 14px;
  min-height: 48px;
  align-items: center;
}

.filter-bar--stacked .filter-divider {
  width: 100%;
  height: 1px;
  background: var(--rule);
  margin: 4px 0;
  align-self: auto;
}

.filter-bar__status {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

.filter-bar__status-title {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-mute);
  margin: 0 0 10px 0;
}

.status-strip--stacked {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: none;
}

/* ── modal (full-screen) ─────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: var(--paper-card);
  z-index: 2100;
  transform: translateY(100%);
  transition: transform 250ms ease-out;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

.modal.is-open { transform: translateY(0); }

.modal__head {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--rule);
  position: relative;
  flex-shrink: 0;
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  color: var(--ink);
  width: 36px;
  height: 36px;
  border-radius: 2px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal__kicker {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-mute);
}

.modal__title {
  font-family: "Newsreader", Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 26px;
  letter-spacing: -0.015em;
  margin: 8px 0 4px;
  color: var(--forest);
}

.modal__summary {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.5;
}

.modal__body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}
