/* ==========================================================================
   StileWeb — mappa (MapLibre GL): controlli, segnalini, gruppi, legenda
   Richiede tema.css. Libreria: Progetti/_Comune/StileWeb
   ========================================================================== */

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
}
.maplibregl-map { font-family: var(--font); }
.maplibregl-canvas:focus-visible { outline: none; }

/* Controlli della mappa (zoom, bussola, 3D) */
.maplibregl-ctrl-bottom-right { margin: 0 var(--gap) var(--gap) 0; }
/* Con lo spazio pubblicitario in basso, legenda e suggerimento si spostano per non finire sotto */
body.has-ad-footer .legend { bottom: calc(28px + var(--ad-footer-h) + 8px); }
body.has-ad-header .map-hint { top: calc(var(--gap) * 2 + var(--top-h) + env(safe-area-inset-top, 0px)); }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl { margin: 8px 0 0 0; }
.maplibregl-ctrl-group {
  background: var(--surface-strong) !important;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}
.maplibregl-ctrl-group button {
  width: 42px !important;
  height: 42px !important;
  background: transparent;
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--border) !important; }
.maplibregl-ctrl-group button:not(:disabled):hover { background: var(--hover) !important; }
:root[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) brightness(1.6); }
.ctrl-3d { font-family: var(--font); font-weight: 800; font-size: 14px; color: var(--text); letter-spacing: .02em; }
.maplibregl-ctrl-group .ctrl-3d.is-on,
.maplibregl-ctrl-group .ctrl-3d.is-on:not(:disabled):hover { background: var(--grad-sun) !important; color: var(--on-sun); }
/* Bussola (mappa.js, BussolaControl): solo con la mappa girata o inclinata; la punta rossa indica il nord */
.ctrl-bussola-box { opacity: 0; transform: scale(.6); pointer-events: none; transition: opacity .25s, transform .25s; }
.ctrl-bussola-box.is-visibile { opacity: 1; transform: none; pointer-events: auto; }
.ctrl-bussola { width: 50px; height: 50px; margin-left: -4px; border-radius: 50%; padding: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--surface-strong); border: 2px solid var(--sun); box-shadow: var(--shadow); }
.ctrl-bussola:hover { background: var(--hover); }
.ctrl-bussola svg { width: 44px; height: 44px; }
.ctrl-bussola .b-nord { fill: #ef4444; } .ctrl-bussola .b-sud { fill: var(--muted); } .ctrl-bussola .b-centro { fill: var(--surface-strong); }
.ctrl-bussola text { fill: var(--text); font: 800 10px var(--font); }

.maplibregl-ctrl-attrib.maplibregl-compact {
  background: var(--surface-strong);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 11px;
}
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
:root[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }

/* ---------- Segnalino a goccia: .pin-wrap > .pin (--st) > .pin-body + svg.pin-ico [+ i.pin-badge] ---------- */
.pin-wrap { width: 34px; height: 42px; cursor: pointer; }
.pin-wrap:focus-visible { outline: none; }
.pin-wrap:focus-visible .pin-body { border-color: var(--sun); }
.pin {
  position: relative;
  width: 34px; height: 42px;
  transform-origin: 50% 98%;
  transition: transform .2s cubic-bezier(.3, 1.6, .5, 1);
}
.pin-body {
  position: absolute; left: 0; top: 0;
  width: 34px; height: 34px;
  border-radius: 50% 50% 50% 5px;
  transform: rotate(-45deg);
  background: var(--grad);
  border: 3px solid var(--st);
  box-shadow: 0 8px 16px -4px rgba(0, 10, 40, .6);
}
.pin-ico {
  position: absolute; left: 9px; top: 9px;
  width: 16px; height: 16px;
  fill: var(--sun);
}
.pin-badge {
  position: absolute; right: -4px; top: -4px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--sun);
  border: 2px solid #06122E;
}
/* Etichetta accanto al segnalino (fuori da .pin, così non si ingrandisce): span.pin-label > b + span.pin-sub */
.pin-label {
  position: absolute; left: 30px; top: 5px;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px 3px 7px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  box-shadow: 0 4px 10px -3px rgba(0, 10, 40, .5);
  font-size: 11px; line-height: 1.2; white-space: nowrap;
  color: var(--text);
  pointer-events: none;
}
.pin-label b { font-weight: 800; font-variant-numeric: tabular-nums; }
.pin-label .pin-sub { padding-left: 5px; border-left: 1px solid var(--border-strong); color: var(--sun); font-weight: 700; font-variant-numeric: tabular-nums; }
:root[data-theme="light"] .pin-label .pin-sub { color: #9A6B00; }
.pin-wrap:hover .pin-label, .pin-wrap:has(.is-selected) .pin-label { border-color: var(--sun); }

/* Segno a sinistra del segnalino (es. ★ preferito): i.pin-mark */
.pin-mark {
  position: absolute; left: -6px; top: -6px;
  width: 17px; height: 17px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--sun); color: var(--on-sun);
  border: 2px solid #06122E;
  font-style: normal; font-size: 10px; font-weight: 900; line-height: 1;
}
/* Avviso a sinistra in basso (es. segnalata dagli utenti): i.pin-warn */
.pin-warn {
  position: absolute; left: -7px; top: 14px;
  width: 17px; height: 17px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bad); color: #fff;
  border: 2px solid #06122E;
  font-style: normal; font-size: 11px; font-weight: 900; line-height: 1;
}
.pin.pulse::before {
  content: '';
  position: absolute; left: 0; top: 0;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--st);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { from { transform: scale(.9); opacity: .9; } to { transform: scale(1.9); opacity: 0; } }
.pin.is-dim { opacity: .62; }
.pin-wrap:hover .pin { transform: scale(1.12); opacity: 1; }
.pin.is-selected { transform: scale(1.3); }
.pin.is-selected .pin-body {
  border-color: var(--sun);
  box-shadow: 0 0 0 5px rgba(255, 200, 61, .35), 0 10px 20px -4px rgba(0, 10, 40, .7);
}

/* ---------- Gruppo di segnalini: .cluster-wrap > .cluster [.is-ok] > span ---------- */
.cluster-wrap { cursor: pointer; }
.cluster {
  width: 100%; height: 100%;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--grad);
  color: #fff;
  font-weight: 800;
  border: 2px solid rgba(255, 243, 176, .9);
  box-shadow: 0 0 0 6px rgba(79, 195, 247, .22), 0 0 0 12px rgba(79, 195, 247, .08), 0 10px 22px -6px rgba(0, 10, 40, .7);
  transition: transform .2s;
}
.cluster:hover { transform: scale(1.08); }
.cluster.is-ok { border-color: #4ADE80; box-shadow: 0 0 0 6px rgba(34, 197, 94, .2), 0 0 0 12px rgba(34, 197, 94, .07), 0 10px 22px -6px rgba(0, 10, 40, .7); }
.cluster span { font-size: 14px; text-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.cluster.c-l span { font-size: 15px; }

/* Punto d'interesse: div.poi-dot con un'icona (emoji); .is-hot = evidenziato */
.poi-dot {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-strong);
  border: 2px solid var(--sky);
  box-shadow: 0 4px 10px -2px rgba(0, 10, 40, .55);
  font-size: 14px; line-height: 1;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.poi-dot:hover, .poi-dot.is-hot { transform: scale(1.3); border-color: var(--sun); }

/* Tappa numerata di un percorso: div.map-step (.is-end per partenza/arrivo). Marker con anchor 'bottom', offset [0, -6] */
.map-step {
  min-width: 30px; height: 30px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--sun); color: var(--on-sun);
  border: 2px solid #fff;
  box-shadow: 0 4px 14px rgba(3, 10, 30, .45);
  font-weight: 800; font-size: 14px;
  cursor: pointer;
}
.map-step::after {   /* punta verso il punto */
  content: ''; position: absolute; left: 50%; bottom: -8px;
  border: 6px solid transparent; border-top-color: #fff; border-bottom: 0;
  transform: translateX(-50%);
}
.map-step.is-end { background: var(--grad); color: #fff; }

/* Posizione dell'utente */
.me-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--sky);
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(79, 195, 247, .3), 0 0 18px rgba(79, 195, 247, .9);
}
/* Pulsante della posizione mentre la mappa segue l'utente (Mappa.posizione, stato "segue"): anello azzurro che pulsa */
.icon-btn.is-follow { box-shadow: 0 0 0 3px var(--sky); animation: segui 2s ease-in-out infinite; }
@keyframes segui { 50% { box-shadow: 0 0 0 6px rgba(79, 195, 247, .35); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.is-follow { animation: none; } }

/* ---------- Suggerimento sopra la mappa, legenda ---------- */
.map-hint {
  position: fixed;
  z-index: 800;
  top: calc(var(--gap) * 2 + var(--top-h) + env(safe-area-inset-top, 0px));
  left: calc(var(--panel-w) + var(--gap) * 2);
  right: var(--gap);
  margin: 0 auto;
  max-width: 460px;
  padding: 16px 18px;
  border-radius: 18px;
  text-align: center;
}
.map-hint p { margin: 0 0 12px; color: var(--muted); }
.map-hint p b { color: var(--text); }
.hint-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.hint-chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-size: 13px; font-weight: 600;
  transition: background .2s, color .2s, border-color .2s;
}
.hint-chip:hover { background: var(--grad-sun); color: var(--on-sun); border-color: transparent; }
/* Con la scheda laterale aperta (Tema.cassetto) suggerimento e legenda restano nella parte di mappa libera */
@media (min-width: 761px) {
  html.drawer-aperto .map-hint { right: calc(var(--drawer-w) + var(--gap) * 2); }
  html.drawer-aperto .legend { right: calc(var(--drawer-w) + var(--gap) * 2); }
  .map-hint, .legend { transition: right .28s cubic-bezier(.2, .8, .2, 1); }
}

/* Legenda: span (--st) > i (icona) + testo; i.dim-sample = esempio semitrasparente */
.legend {
  position: fixed;
  z-index: 800;
  right: calc(var(--gap) + 58px);
  bottom: 28px;
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  max-width: 520px;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 12px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.legend i {
  width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--st); color: #06122E;
  font-style: normal; font-size: 9px; font-weight: 900;
}
.legend .dim-sample { background: var(--grad); border: 2px solid var(--ok); opacity: .62; }
/* Legenda richiudibile (Mappa.legenda): pulsante in testa, contenuto in .legend-body */
.legend:has(.legend-toggle) { align-items: center; }
.legend-body { display: contents; }
.legend-toggle {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 2px 8px 2px 4px; border: 1px solid var(--border); border-radius: 8px;
  background: none; color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
}
.legend-toggle:hover { border-color: var(--sun); }
.legend-toggle svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.legend.is-ridotta { padding: 6px; }
.legend.is-ridotta .legend-body { display: none; }
.legend.is-ridotta .legend-toggle { border-color: transparent; }

/* ---------- Telefono ---------- */
@media (max-width: 760px) {
  .map-hint { left: var(--gap); right: var(--gap); top: calc(var(--gap) * 2 + var(--top-h) + env(safe-area-inset-top, 0px) + var(--ad-header-h)); }
  body.has-ad-header .map-hint { top: calc(var(--gap) * 2 + var(--top-h) + env(safe-area-inset-top, 0px) + var(--ad-header-h) + 8px); }
  .legend { display: none; }
  .maplibregl-ctrl-bottom-right { bottom: calc(var(--sheet-h) + var(--ad-footer-h)); transition: bottom .3s; }
  .maplibregl-ctrl-group:has(.maplibregl-ctrl-zoom-in) { display: none; }
}
