/* Map page: floating glass UI, pins, info card / bottom sheet, Leaflet chrome */
:root {
  --cat-villa: #b7791f; --cat-camping_spot: #2f7d4f; --cat-viewpoint: #6a4fb3; --cat-onsite_activity: #0b7a8a;
  --cat-attraction: #c2571a; --cat-nearby_activity: #b0306a; --cat-food: #a33a2a; --cat-transport: #4a5a68;
}

body.full-screen { overflow: hidden; }
body.full-screen main { height: calc(100vh - var(--header-h)); height: calc(100dvh - var(--header-h)); animation: none; }
.map-layout { position: relative; height: 100%; }
#map { position: absolute; inset: 0; z-index: 1; background: var(--bg-alt); }

.glass { background: var(--glass-bg); border: 1px solid var(--line); backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%); box-shadow: var(--shadow-2); }

/* Floating toolbar */
.map-ui { position: absolute; z-index: 1000; top: 12px; left: 12px; right: 12px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.map-ui > * { pointer-events: auto; }
.map-bar { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: var(--r-sm); max-width: 660px; }
.map-bar .icon-btn { border-radius: var(--r-sm); }
.map-bar .icon-btn, .map-bar .segmented { flex: none; }
.segmented { display: inline-flex; padding: 2px; border-radius: var(--r-sm); background: transparent; border: 1px solid var(--line-strong); }
.segmented .filter.mode {
  display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 16px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text);
  font: 500 0.7rem/1 var(--font-ui); letter-spacing: 0.13em; text-transform: uppercase; transition: background 0.35s var(--ease-out), color 0.35s;
}
.segmented .filter.mode .icon { color: var(--accent-text); transition: color 0.35s; }
.segmented .filter.mode:not(.is-on):hover { background: var(--brand-soft); }
.segmented .filter.mode.is-on { background: var(--brand); color: var(--brand-contrast); }
.segmented .filter.mode.is-on .icon { color: var(--brass-300); }
.map-search { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--text-muted); }
.map-search input { flex: 1; min-width: 0; height: 40px; border: 0; background: transparent; color: var(--text); font-size: 0.95rem; outline: none; }
.map-search input::placeholder { color: var(--text-muted); }
.map-search:focus-within { background: var(--surface); border-radius: var(--r-sm); box-shadow: 0 0 0 2px var(--ring); }
#map-search-results { position: absolute; top: calc(100% + 10px); left: -4px; right: -4px; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-3); max-height: 320px; overflow: auto; z-index: 1100; }
#map-search-results[hidden] { display: none; }
#map-search-results li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer; color: var(--text); }
#map-search-results li[aria-selected="true"], #map-search-results li:hover { background: var(--brand-soft); }
#map-search-results .result-icon { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--c, var(--brand)); color: #fff; }
#map-search-results small { display: block; color: var(--text-muted); }
#map-search-results .no-results { color: var(--text-muted); cursor: default; }
.map-layout[data-map-mode="routes"] .map-search { display: none; }
.map-layout[data-map-mode="routes"] .map-bar { width: max-content; }

.map-chips { display: flex; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; margin: 0 -2px; }
.map-chips::-webkit-scrollbar { display: none; }
.filters-places, .filters-routes { display: flex; gap: 8px; align-items: center; }
.filters-places[hidden], .filters-routes[hidden] { display: none; }
.chip-btn {
  --c: var(--brand);
  display: inline-flex; align-items: center; gap: 8px; flex: none; min-height: 38px; padding: 0 14px; border-radius: var(--r-sm);
  background: var(--glass-bg); color: var(--text); border: 1px solid var(--line-strong); box-shadow: none;
  font: 500 0.68rem/1 var(--font-ui); letter-spacing: 0.12em; text-transform: uppercase;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: background 0.35s var(--ease-out), color 0.35s, border-color 0.35s, box-shadow 0.35s, opacity 0.3s;
}
.chip-btn .icon { color: var(--accent-text); transition: color 0.35s; }
.chip-btn:hover { border-color: var(--text-muted); }
.chip-btn:not(.is-on) { background: transparent; opacity: 0.62; }
.chip-btn:not(.is-on):hover { opacity: 1; }
.chip-btn.is-on { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }
.chip-btn.is-on .icon { color: var(--brass-300); }
/* Category chips keep their map colour, but as a thin accent instead of a solid fill */
.chip-btn.cat .icon { color: var(--c); }
.chip-btn.cat.is-on { background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: var(--text); border-color: var(--c); box-shadow: inset 0 -2px 0 var(--c); }
.chip-btn.cat.is-on .icon { color: var(--c); }
.chip-btn[hidden] { display: none; }
.map-chips .sep { width: 1px; height: 22px; background: var(--line-strong); flex: none; margin: 0 2px; }

/* Pins */
.pin-wrap { background: none; border: 0; }
.pin {
  --c: var(--brand); position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--c); color: #fff;
  border: 3px solid #fff; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35); transition: transform 0.2s var(--ease);
}
.pin:hover { transform: translateY(-3px) scale(1.06); }
.pin-villa { --c: var(--cat-villa); width: 50px; height: 50px; }
.pin-camping_spot { --c: var(--cat-camping_spot); } .pin-viewpoint { --c: var(--cat-viewpoint); } .pin-onsite_activity { --c: var(--cat-onsite_activity); }
.pin-attraction { --c: var(--cat-attraction); } .pin-nearby_activity { --c: var(--cat-nearby_activity); } .pin-food { --c: var(--cat-food); } .pin-transport { --c: var(--cat-transport); }
.pin.is-selected { transform: scale(1.22); z-index: 5; animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 55%, transparent), 0 4px 12px rgba(0, 0, 0, 0.35); } 100% { box-shadow: 0 0 0 18px transparent, 0 4px 12px rgba(0, 0, 0, 0.35); } }
@media (prefers-reduced-motion: reduce) { .pin.is-selected { animation: none; outline: 3px solid var(--ring); } }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: color-mix(in srgb, var(--brand) 35%, transparent) !important; }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div { background: var(--brand) !important; color: #fff; font: 700 13px var(--font-ui); border: 2px solid #fff; }

/* Info card (desktop) / bottom sheet (phones) */
.info-panel {
  position: absolute; z-index: 1050; top: 12px; right: 12px; bottom: 12px; width: min(420px, calc(100% - 24px)); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-3); overflow: hidden;
  animation: card-in 0.35s var(--ease);
}
.info-panel[hidden] { display: none; }
@keyframes card-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
#panel-content { flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.panel-close { position: absolute; z-index: 5; top: 12px; right: 12px; display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.92); color: #14301f; box-shadow: var(--shadow-2); }
.panel-close:hover { background: #fff; }
.sheet-handle { display: none; }
.panel-article { display: flex; flex-direction: column; min-height: 100%; }
.panel-body { padding: 18px 22px 12px; flex: 1; }
.panel-body h2 { font-size: 1.5rem; padding-right: 44px; margin-bottom: 10px; }
.panel-body h2.mini-h { font-size: 0.7rem; padding-right: 0; margin: 30px 0 14px; }   /* section labels, not titles */
.panel-cover { width: 100%; height: 200px; object-fit: cover; }
.panel-actions { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 22px 14px; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.05); z-index: 4; }
.route-info { margin: 12px 0; padding: 12px 14px; border-radius: var(--r-sm); background: var(--brand-soft); font-size: 0.92rem; }
.route-info .start-select { width: 100%; margin: 8px 0; min-height: 42px; border-radius: var(--r-sm); border: 1.5px solid var(--line-strong); background: var(--surface); padding: 0 10px; }
.loading { padding: 32px; text-align: center; color: var(--text-muted); }

/* Route cards inside the panel list */
.route-card-btn {
  display: block; width: 100%; text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-left: 6px solid var(--c, var(--brand));
  border-radius: var(--r-md); padding: 14px 16px; margin: 0 0 12px; transition: transform 0.2s var(--ease), box-shadow 0.2s;
}
.route-card-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.route-card-btn strong { display: block; font-size: 1.05rem; }
.route-card-btn .small { display: block; margin: 2px 0 8px; }
.route-card-btn .route-swatch { display: none; }
.route-card-btn .chips { margin: 0; }

/* Leaflet chrome */
.leaflet-container { font-family: var(--font-ui); background: var(--bg-alt); }
.leaflet-touch .leaflet-bar, .leaflet-bar { border: 0; border-radius: var(--r-sm); overflow: hidden; box-shadow: var(--shadow-2); }
.leaflet-bar a, .leaflet-bar a:hover { width: 42px; height: 42px; line-height: 42px; background: var(--glass-bg); color: var(--text); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.leaflet-bar a:hover { background: var(--brand-soft); }
.leaflet-bar a:last-child { border-bottom: 0; }
.leaflet-touch .leaflet-control-layers { border: 0; border-radius: var(--r-sm); box-shadow: var(--shadow-2); background: var(--glass-bg); backdrop-filter: blur(10px); }
.leaflet-control-layers-expanded { padding: 8px 12px; color: var(--text); }
.leaflet-control-attribution { background: var(--glass-bg) !important; color: var(--text-muted) !important; border-radius: var(--r-sm) 0 0 0; font-size: 11px; }
.leaflet-control-attribution a { color: var(--link) !important; }
.leaflet-tooltip { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-2); font: 500 0.78rem var(--font-ui); padding: 6px 10px; }
.leaflet-tooltip-top::before { border-top-color: var(--surface); }
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--text); border-radius: var(--r-md); box-shadow: var(--shadow-3); }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 14px 16px; font-family: var(--font-ui); line-height: 1.45; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }
.leaflet-bottom.leaflet-right { bottom: 8px; }

/* Dark map: darken the street tiles (satellite is left alone) */
:root[data-theme="dark"] .tiles-street { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.92) saturate(0.7); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tiles-street { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.92) saturate(0.7); } }

/* Desktop: keep map controls clear of the open card */
@media (min-width: 801px) {
  body.panel-open .leaflet-bottom.leaflet-right { right: 444px; }
}

/* Small screens: compact toolbar */
@media (max-width: 800px) {
  .map-ui { top: 8px; left: 8px; right: 8px; }
  .map-bar { max-width: none; }
  .segmented .filter.mode { padding: 0 12px; letter-spacing: 0.1em; }
}
@media (max-width: 520px) {
  .map-bar { flex-wrap: wrap; border-radius: var(--r-sm); row-gap: 2px; }
  .segmented { flex: 1; }
  .segmented .filter.mode { flex: 1; justify-content: center; }
  .map-search { order: 3; flex: 1 1 100%; padding: 0 10px; border-top: 1px solid var(--line); }
  .map-search input { height: 44px; }
}

/* Phones held upright (and small tablets): the panel is a bottom sheet */
@media (max-width: 800px) and (min-height: 481px) {
  .info-panel {
    --sheet: 60%; top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: var(--sheet); border-radius: 10px 10px 0 0; border-width: 1px 0 0;
    animation: sheet-in 0.35s var(--ease); transition: height 0.3s var(--ease);
  }
  .info-panel[data-snap="peek"] { --sheet: 24%; }
  .info-panel[data-snap="half"] { --sheet: 60%; }
  .info-panel[data-snap="full"] { --sheet: 92%; }
  .info-panel.is-dragging { transition: none; }
  @keyframes sheet-in { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
  .sheet-handle { display: block; flex: none; width: 100%; height: 44px; border: 0; background: transparent; cursor: grab; touch-action: none; }
  .sheet-handle span { display: block; width: 44px; height: 5px; margin: 18px auto 0; border-radius: 3px; background: var(--line-strong); }
  .panel-close { top: 6px; right: 8px; }
  .panel-body h2 { padding-right: 48px; }
  body.panel-open .leaflet-bottom { display: none; }
  .carousel-slide { aspect-ratio: 2 / 1; }
}

/* Phones on their side: a one-row toolbar and the card on the right (no room for a bottom sheet) */
@media (max-height: 480px) and (orientation: landscape) {
  .map-ui { flex-direction: row; align-items: flex-start; gap: 8px; }
  .map-bar { flex: none; max-width: 56%; flex-wrap: nowrap; border-radius: var(--r-sm); }
  .map-search { order: 0; flex: 1 1 auto; border-top: 0; min-width: 120px; }
  .map-search input { height: 40px; }
  .map-chips { flex: 1; min-width: 0; padding-bottom: 0; }
  .info-panel { top: 8px; right: 8px; bottom: 8px; left: auto; width: min(380px, 50vw); height: auto; border-radius: var(--r-lg); }
  .sheet-handle { display: none; }
  .panel-body { padding: 14px 16px 8px; }
  .panel-body h2 { font-size: 1.25rem; }
  .carousel-slide { aspect-ratio: 3 / 1; }
  .panel-actions { padding: 10px 16px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .panel-actions .btn { flex: none; }
  body.panel-open .leaflet-bottom.leaflet-right { right: min(396px, 54vw); }
  body.panel-open .map-ui { right: calc(min(380px, 50vw) + 16px); }
  body.panel-open .map-chips { display: none; }
  body.panel-open .map-bar { max-width: none; }
}

/* Touch screens: bigger controls on the map */
@media (pointer: coarse), (max-width: 700px) {
  .chip-btn, .segmented .filter.mode { min-height: 44px; }
  .panel-close { width: 44px; height: 44px; }
  .map-search input { min-height: 44px; }
  .link-back { padding-top: 4px; }
  .leaflet-bar a, .leaflet-bar a:hover { width: 44px; height: 44px; line-height: 44px; }
}

@media (max-width: 520px) {
  .panel-actions { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 10px 14px 12px; gap: 8px; }
  .panel-actions::-webkit-scrollbar { display: none; }
  .panel-actions .btn { flex: none; }
}

@media (max-width: 800px) and (min-height: 481px) and (max-height: 680px) {
  .carousel-slide { aspect-ratio: 5 / 2; }
  .panel-body { padding-top: 12px; }
}

@media (min-width: 521px) and (max-width: 800px) and (min-height: 481px) {
  .info-panel .carousel-slide { aspect-ratio: auto; height: min(34vh, 300px); }
}
