/* ==============================================================
   MAP — styles
   Real Leaflet map underneath; everything here restyles Leaflet's
   default chrome to match the app, plus our own floating UI
   (search, layer chips, zoom control, empty state). Self-contained
   design tokens — doesn't depend on styles.css.
   ============================================================== */

/* ---------- 1. VARIABLES ---------- */

:root {
  --forest: #0F3D2E;
  --forest-soft: #E7F0EA;
  --amber: #E8A33D;
  --amber-soft: #FBEBD2;

  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-sunken: #F4F3EF;
  --border: #E7E4DC;
  --border-strong: #D8D4C8;

  --ink: #1B221E;
  --ink-soft: #5B655F;
  --ink-faint: #8A928C;
  --on-forest: #F4F8F5;

  --shadow: 0 1px 2px rgba(15, 61, 46, 0.04), 0 8px 24px rgba(15, 61, 46, 0.06);
  --shadow-lift: 0 4px 10px rgba(15, 61, 46, 0.07), 0 16px 32px rgba(15, 61, 46, 0.09);

  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --fs-h1: clamp(22px, 5.6vw, 34px);
  --fs-subtitle: clamp(12.5px, 3.2vw, 14px);

  --gutter: clamp(12px, 4vw, 24px);
  --r-pill: 100px;
  --nav-size: 72px;
}

[data-theme="dark"] {
  --bg: #0D1712;
  --surface: #142019;
  --surface-sunken: #0F1913;
  --border: #223229;
  --border-strong: #2C3F33;

  --ink: #EDF3EE;
  --ink-soft: #A9B6AE;
  --ink-faint: #718077;
  --on-forest: #F4F8F5;

  --forest-soft: #16261F;
  --amber-soft: #2C2318;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lift: 0 4px 10px rgba(0, 0, 0, 0.22), 0 20px 40px rgba(0, 0, 0, 0.32);
}

/* ---------- 2. RESET ---------- */

*, *::before, *::after { box-sizing: border-box; min-width: 0; }
html, body { width: 100%; height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  overflow: hidden; /* the page itself never scrolls — only the map pans */
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; max-width: 100%; }
img, svg { display: block; max-width: 100%; height: auto; }

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- 3. LAYOUT CONTAINER ---------- */

.app-shell {
  width: 100%;
  height: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--nav-size);
}

/* ---------- 4. PRIMARY NAVIGATION (same as Explore) ---------- */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 900;
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 2px;
  width: 100%;
  max-width: 100vw;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px min(6px, 2vw) calc(6px + env(safe-area-inset-bottom, 0));
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; flex: 1 1 0; min-width: 0; max-width: 110px; min-height: 52px;
  padding: 6px min(10px, 2.5vw); border-radius: 14px; color: var(--ink-faint);
  text-decoration: none; transition: background 0.15s ease, color 0.15s ease;
}
.nav-item svg { width: 21px; height: 21px; flex-shrink: 0; }
.nav-item span { font-size: clamp(10px, 2.6vw, 10.5px); font-weight: 600; white-space: nowrap; }
.nav-item:hover { color: var(--ink-soft); }
.nav-item.is-active { color: var(--forest); background: var(--forest-soft); }
[data-theme="dark"] .nav-item.is-active { color: var(--amber); background: var(--amber-soft); }

@media (min-width: 860px) {
  .nav {
    top: 0; right: auto; bottom: 0; width: var(--nav-size); max-width: var(--nav-size);
    flex-direction: column; justify-content: flex-start; padding: 22px 10px; gap: 8px;
    border-top: none; border-right: 1px solid var(--border);
  }
  .nav-item { width: 100%; max-width: 100%; min-height: 56px; }
  .app-shell { padding-bottom: 0; padding-left: var(--nav-size); }
}

/* ---------- 5. TOP BAR ---------- */

.topbar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0);
  position: relative;
  z-index: 300;
}
.topbar-inner { width: 100%; padding: clamp(12px, 3.5vw, 18px) var(--gutter) clamp(10px, 3vw, 14px); }
.topbar-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.heading-text { min-width: 0; flex: 1 1 auto; }
.heading-text h1 { font-size: var(--fs-h1); font-weight: 800; letter-spacing: -0.02em; color: var(--forest); line-height: 1.1; }
[data-theme="dark"] .heading-text h1 { color: var(--on-forest); }
.heading-text p {
  margin-top: 2px; font-size: var(--fs-subtitle); color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.theme-toggle {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-sunken); border: 1px solid var(--border); color: var(--forest);
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; color: var(--amber); }

/* ---------- 6. MAP STAGE ---------- */

.map-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  background: var(--surface-sunken);
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: var(--surface-sunken);
}

.leaflet-container {
  font-family: var(--font-body);
  background: var(--surface-sunken);
}
.leaflet-fade-anim .leaflet-popup { transition: opacity 0.2s linear, transform 0.2s cubic-bezier(0.34, 1.4, 0.64, 1); }

/* dark mode recolors the same keyless OSM tiles with a filter —
   no second tile provider or API key needed */
[data-theme="dark"] .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.92) saturate(0.85);
}

/* attribution + scale, restyled to blend but stay legible/functional
   (required by the tile provider's terms — kept intact, just styled) */
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  color: var(--ink-faint);
  font-size: 10.5px;
  border-radius: 8px 0 0 0;
  padding: 2px 8px;
}
.leaflet-control-attribution a { color: var(--ink-soft); }
.leaflet-control-scale-line {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border-color: var(--border-strong) !important;
  color: var(--ink-soft);
  font-size: 11px;
  border-radius: 4px;
  padding: 1px 6px;
}

.tile-banner {
  position: absolute;
  left: 50%;
  bottom: clamp(16px, 4vw, 24px);
  transform: translateX(-50%);
  z-index: 550;
  max-width: min(90vw, 360px);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-lift);
  animation: tileBannerIn 0.25s ease both;
}
@keyframes tileBannerIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ---------- 7. CUSTOM MARKER (Leaflet divIcon content) ---------- */

.pin-icon { transition: opacity 0.2s ease; }

.pin-inner {
  position: relative;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.pin-icon.is-entering .pin-inner {
  animation: pinDrop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes pinDrop {
  0% { opacity: 0; transform: translateY(-16px) scale(0.4); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.pin-icon.is-filtered { opacity: 0; pointer-events: none; }

.pin-ring {
  position: absolute;
  bottom: 2px;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--pin-color);
  opacity: 0.28;
  animation: pinPulse 2.2s ease-out infinite;
}
@keyframes pinPulse {
  0% { transform: scale(0.5); opacity: 0.35; }
  70% { transform: scale(1.9); opacity: 0; }
  100% { transform: scale(1.9); opacity: 0; }
}

.pin-dot {
  position: relative;
  z-index: 2;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(45deg);
  background: var(--pin-color);
  border: 2.5px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  display: grid;
  place-items: center;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;
}
.pin-dot svg { width: 40%; height: 40%; color: var(--on-forest); transform: rotate(-45deg); }

.pin-icon:hover .pin-dot { animation: pinWiggle 0.6s ease-in-out infinite; }
@keyframes pinWiggle {
  0%, 100% { transform: rotate(45deg) scale(1.2); }
  25% { transform: rotate(30deg) scale(1.28); }
  75% { transform: rotate(60deg) scale(1.28); }
}
.pin-icon:hover .pin-ring { animation-duration: 1.1s; opacity: 0.4; }

.pin-icon.is-selected .pin-dot {
  transform: rotate(45deg) scale(1.22);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--pin-color) 32%, transparent), 0 2px 6px rgba(0,0,0,0.25);
}
.pin-dot.pin-jump { animation: pinJump 0.55s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pinJump {
  0%   { transform: rotate(45deg) translateY(0) scale(1); }
  30%  { transform: rotate(45deg) translateY(-18px) scale(1.16); }
  55%  { transform: rotate(45deg) translateY(0) scale(0.9); }
  78%  { transform: rotate(45deg) translateY(-7px) scale(1.08); }
  100% { transform: rotate(45deg) translateY(0) scale(1); }
}

/* ---------- 8. LEAFLET TOOLTIP (hover preview) ---------- */

.pin-tooltip-wrap.leaflet-tooltip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lift);
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-width: 200px;
  white-space: normal;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.pin-tooltip-wrap.leaflet-tooltip.leaflet-tooltip-top:before { display: none; }
@media (hover: hover) {
  .leaflet-interactive:hover + .leaflet-tooltip-pane .pin-tooltip-wrap { opacity: 1; }
}
/* Leaflet toggles visibility itself on marker hover — this just
   gives the reveal a bit of motion instead of a hard cut */
.leaflet-tooltip.pin-tooltip-wrap { animation: tooltipIn 0.15s ease both; }
@keyframes tooltipIn { from { opacity: 0; transform: translateY(6px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
.pin-tooltip-wrap strong { font-size: 12.5px; font-weight: 700; display: block; overflow-wrap: anywhere; }
.pin-tooltip-wrap span { font-size: 11px; color: var(--ink-faint); }

/* ---------- 9. LEAFLET POPUP — the floating "post card" ---------- */

.leaflet-popup.pin-popup { margin-bottom: 12px; }
.pin-popup .leaflet-popup-content-wrapper {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lift);
  padding: 0;
  overflow: hidden;
}
.pin-popup .leaflet-popup-content { margin: 0; }
.pin-popup .leaflet-popup-tip-container { display: none; } /* cleaner without the little pointer */
.pin-popup .leaflet-popup-close-button {
  width: 26px; height: 26px;
  top: 10px !important; right: 10px !important;
  border-radius: 50%;
  background: var(--surface-sunken);
  color: var(--ink-soft) !important;
  display: grid; place-items: center;
  font-size: 0;
}
.pin-popup .leaflet-popup-close-button::before {
  content: "";
  width: 11px; height: 11px;
  background:
    linear-gradient(45deg, transparent 45%, currentColor 45%, currentColor 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, currentColor 45%, currentColor 55%, transparent 55%);
}

.pin-card {
  width: 100%;
  max-width: 100%;
  padding: 16px;
  opacity: 0;
}
.pin-card.pin-card-enter {
  animation: pinCardIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes pinCardIn {
  0% { opacity: 0; transform: translateY(10px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.pin-card-cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 10px;
  padding-right: 24px; /* keep clear of the close button */
}
.layer-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); flex-shrink: 0; }

.pin-card-thumb {
  width: 100%;
  aspect-ratio: 16/10;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-sunken);
  margin-bottom: 12px;
}
.pin-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pin-card-thumb--empty {
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  font-size: 12px;
  font-weight: 700;
}

.pin-card-title {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}
.pin-card-summary {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}

.pin-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-bottom: 10px;
  font-size: 11.5px;
  color: var(--ink-faint);
}
.pin-card-loc { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.pin-card-loc svg { width: 13px; height: 13px; flex-shrink: 0; }
.pin-card-stat { margin-left: auto; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }

.pin-card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
.pin-card-tags span {
  font-size: 11px; font-weight: 600; color: var(--forest);
  background: var(--forest-soft); padding: 4px 9px; border-radius: var(--r-pill);
}
[data-theme="dark"] .pin-card-tags span { color: var(--amber); background: var(--amber-soft); }

.pin-card-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  border-radius: var(--r-pill);
  background: var(--forest);
  color: var(--on-forest);
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
}
.pin-card-link svg { width: 15px; height: 15px; }

/* ---------- 10. FLOATING SEARCH ---------- */

.map-search {
  position: absolute;
  top: clamp(12px, 3vw, 18px);
  left: clamp(12px, 3vw, 18px);
  right: clamp(12px, 3vw, 18px);
  z-index: 500;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 10px 14px;
  box-shadow: var(--shadow-lift);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.map-search:focus-within {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--forest) 18%, transparent), var(--shadow-lift);
  transform: translateY(-1px);
}
.search-icon { width: 18px; height: 18px; color: var(--ink-faint); flex-shrink: 0; }
.map-search input {
  flex: 1 1 auto; min-width: 0; border: none; background: none; font: inherit;
  font-size: clamp(13.5px, 3.4vw, 14.5px); color: var(--ink); outline: none;
}
.map-search input::placeholder { color: var(--ink-faint); }
.search-clear {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink-faint); background: var(--surface-sunken);
}
.search-clear svg { width: 13px; height: 13px; }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lift);
  overflow: hidden;
  max-height: 60vh;
  overflow-y: auto;
}
.search-result {
  display: flex; align-items: center; gap: 10px; width: 100%; max-width: 100%;
  padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--surface-sunken); }
.search-result-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.search-result-text strong { font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.search-result-text span { font-size: 11.5px; color: var(--ink-faint); }
.search-empty { padding: 14px; font-size: 13px; color: var(--ink-faint); text-align: center; }

/* ---------- 11. FLOATING LAYER CHIPS ---------- */

.map-layers {
  position: absolute;
  top: clamp(66px, 15vw, 78px);
  left: clamp(12px, 3vw, 18px);
  right: clamp(12px, 3vw, 18px);
  z-index: 480;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 10px), transparent 100%);
          mask-image: linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 10px), transparent 100%);
}
.map-layers::-webkit-scrollbar { display: none; }

.layer-chip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 13px; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--ink-soft); font-size: clamp(12px, 3vw, 13px); font-weight: 600;
  white-space: nowrap; box-shadow: var(--shadow); opacity: 0.55;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
.layer-chip.is-active { opacity: 1; border-color: var(--dot); }
.layer-chip.chip-pop { animation: chipPop 0.35s ease; }
@keyframes chipPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.86); }
  70%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ---------- 12. CUSTOM ZOOM / VIEW CONTROLS ---------- */

.map-controls {
  position: absolute;
  right: clamp(12px, 3vw, 18px);
  bottom: clamp(16px, 4vw, 24px);
  z-index: 480;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lift);
  padding: 4px;
  overflow: hidden;
}
.map-controls button {
  position: relative;
  overflow: hidden;
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; color: var(--forest);
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
[data-theme="dark"] .map-controls button { color: var(--amber); }
.map-controls button svg { width: 18px; height: 18px; }
.map-controls button:hover:not(:disabled) { background: var(--surface-sunken); }
.map-controls button:active:not(:disabled) { transform: scale(0.88); }
.map-controls button:disabled { opacity: 0.32; cursor: not-allowed; }
.map-controls button + button { border-top: 1px solid var(--border); }
.btn-ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.28;
  transform: scale(0);
  animation: rippleAnim 0.5s ease-out forwards;
  pointer-events: none;
}
@keyframes rippleAnim { to { transform: scale(1); opacity: 0; } }

/* ---------- 13. EMPTY STATE ---------- */

.map-empty {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 470;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lift);
  padding: 22px 26px;
  max-width: min(88vw, 300px);
}
.map-empty p { font-size: 14.5px; font-weight: 700; color: var(--ink-soft); margin-bottom: 12px; }
.map-empty button {
  padding: 9px 18px; border-radius: var(--r-pill);
  background: var(--forest); color: var(--on-forest);
  font-size: 13.5px; font-weight: 700;
}

/* ---------- 14. TABLET ---------- */

@media (min-width: 768px) {
  .map-layers { top: clamp(70px, 9vw, 80px); }
}

/* ---------- 15. DESKTOP ---------- */

@media (min-width: 1024px) {
  .map-controls { bottom: clamp(20px, 3vw, 28px); }
  .pin-popup .leaflet-popup-content-wrapper { max-width: 300px; }
}

/* ---------- 16. SAFETY NET ---------- */

html, body { max-width: 100%; overflow-x: hidden; }
.app-shell, .topbar, .map-stage { max-width: 100%; }
