:root {
  --verde: #1f7a3a; --rosso: #c62828; --arancio: #e08a00; --grigio: #5c6b63; --blu: #1565c0;
  --scuro: #1f3d2b; --carta: #ffffff; --testo: #15201a; --bordo: #d8ddd9;
  --ombra: 0 2px 10px rgba(0,0,0,.25);
  --sa-top: env(safe-area-inset-top, 0px); --sa-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--testo); background: #e9ece9; overflow: hidden;
  display: flex; flex-direction: column;
}

/* semaforo in alto */
.stato {
  padding: calc(8px + var(--sa-top)) 14px 8px; color: #fff; z-index: 20; box-shadow: var(--ombra);
  transition: background .25s;
}
.stato-verde { background: var(--verde); }
.stato-rosso { background: var(--rosso); }
.stato-arancio { background: var(--arancio); }
.stato-grigio { background: var(--grigio); }
.stato-riga1 { display: flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 700; line-height: 1.15; }
.stato-riga2 { font-size: 12.5px; opacity: .95; margin-top: 2px; }
.pallino {
  width: 18px; height: 18px; border-radius: 50%; background: #fff; flex: none;
  box-shadow: 0 0 0 3px rgba(255,255,255,.35);
}
.stato-rosso .pallino { animation: lampeggia 1s infinite; }
@keyframes lampeggia { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .stato-rosso .pallino { animation: none; } }

#mappa { flex: 1; min-height: 0; }

/* ricerca */
.barra-alto { position: absolute; left: 10px; right: 10px; top: calc(58px + var(--sa-top)); z-index: 15; }
.cerca { display: flex; background: var(--carta); border-radius: 10px; box-shadow: var(--ombra); overflow: hidden; }
.cerca input { flex: 1; border: 0; padding: 10px 12px; font-size: 16px; min-width: 0; background: transparent; }
.cerca button { border: 0; background: transparent; padding: 0 14px; font-size: 18px; cursor: pointer; }
.risultati { background: var(--carta); border-radius: 10px; margin-top: 6px; box-shadow: var(--ombra); max-height: 40vh; overflow: auto; }
.risultati button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--bordo); background: transparent; padding: 10px 12px; font-size: 15px; cursor: pointer; }
.risultati button:last-child { border-bottom: 0; }

/* comandi in basso */
.barra-basso {
  display: flex; justify-content: space-around; background: var(--carta); border-top: 1px solid var(--bordo);
  padding: 6px 4px calc(6px + var(--sa-bot)); z-index: 20;
}
.cmd {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: transparent;
  font-size: 12px; color: var(--testo); padding: 4px 0; cursor: pointer; border-radius: 8px;
}
.cmd .ico { font-size: 22px; line-height: 1; }
.cmd.attivo { background: #e3efe6; color: var(--verde); font-weight: 600; }
.cmd:focus-visible { outline: 2px solid var(--blu); }

/* pannelli */
.pannello {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--carta);
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.3);
  padding: 14px 16px calc(14px + var(--sa-bot)); max-height: 78vh; overflow: auto;
}
.pannello h2 { font-size: 17px; margin: 6px 0 8px; }
.pannello h2 + h2 { margin-top: 14px; }
.nota { font-size: 13px; color: #4a5750; margin: 4px 0 10px; }
.chiudi { margin-top: 12px; width: 100%; padding: 11px; border: 1px solid var(--bordo); background: #f3f5f3; border-radius: 10px; font-size: 16px; cursor: pointer; }
.primario { background: var(--verde); color: #fff; border: 0; border-radius: 10px; padding: 11px 16px; font-size: 16px; cursor: pointer; }
.riga-opz { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 15px; }
.riga-opz input { width: 20px; height: 20px; }
.legenda { list-style: none; padding: 0; margin: 0 0 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.legenda li { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.legenda .quadr { width: 18px; height: 14px; border-radius: 3px; flex: none; border: 2px solid; }
@media (max-width: 380px) { .legenda { grid-template-columns: 1fr; } }

.riga-salva { display: flex; gap: 8px; }
.riga-salva input { flex: 1; min-width: 0; padding: 10px; font-size: 16px; border: 1px solid var(--bordo); border-radius: 10px; }
.lista-posti { list-style: none; padding: 0; margin: 0; }
.lista-posti li { border-top: 1px solid var(--bordo); padding: 10px 0; }
.lista-posti .nome { font-weight: 600; font-size: 16px; }
.lista-posti .quando { font-size: 12px; color: #4a5750; }
.lista-posti .azioni { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.lista-posti .azioni a, .lista-posti .azioni button {
  border: 1px solid var(--bordo); background: #f3f5f3; color: var(--testo); border-radius: 8px; padding: 7px 10px;
  font-size: 14px; text-decoration: none; cursor: pointer;
}
.lista-posti .azioni .elimina { color: var(--rosso); }
.lista-atc label { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 16px; }
.lista-atc input { width: 22px; height: 22px; }

/* scheda zona (tocco sulla mappa) */
.pannello-basso { max-height: 45vh; }
.scheda-zona .tipo { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.scheda-zona .nome { font-size: 20px; font-weight: 700; margin: 2px 0 6px; }
.scheda-zona .verdetto { display: inline-block; padding: 4px 10px; border-radius: 999px; color: #fff; font-weight: 600; font-size: 14px; }
.scheda-zona .verdetto.vietato { background: var(--rosso); }
.scheda-zona .verdetto.regolamentato { background: var(--arancio); }
.scheda-zona .verdetto.info { background: var(--blu); }
.scheda-zona .verdetto.ok { background: var(--verde); }

/* avviso iniziale */
.avviso { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.avviso-box { background: var(--carta); border-radius: 16px; padding: 18px 20px; max-width: 440px; }
.avviso-box h2 { margin: 0 0 8px; }
.avviso-box p { font-size: 15px; margin: 0 0 10px; }
.avviso-box .primario { width: 100%; margin-top: 6px; }

/* mappa: pallino posizione e marcatori */
.maplibregl-ctrl-top-right { top: calc(60px + var(--sa-top)); }
.marcatore-posto { font-size: 26px; line-height: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); cursor: pointer; }
.maplibregl-popup-content { font-size: 14px; border-radius: 10px; }

/* messaggio breve (posto salvato) */
.toast {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--sa-bot)); z-index: 40;
  background: rgba(20, 30, 24, .92); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 15px;
  max-width: 92vw; text-align: center; box-shadow: var(--ombra);
}
.lista-posti .rinomina { font-size: 16px; padding: 6px 8px; border: 1px solid var(--bordo); border-radius: 8px; width: 70%; }
.cmd { font-size: 11px; }

.secondario { width: 100%; margin-top: 8px; padding: 10px; border: 1px solid var(--bordo); background: #f3f5f3; border-radius: 10px; font-size: 15px; cursor: pointer; }
