:root {
  --blu: #1d4ed8;
  --rossa: #dc2626;
  --nera: #111827;
  --chiusa: #9ca3af;
  --mancante: #c4b5fd;
  --impianto: #f59e0b;
  --sfondo-pannello: rgba(255, 255, 255, 0.96);
  --testo: #111827;
  --testo-tenue: #4b5563;
  --avviso-sfondo: #fef3c7;
  --avviso-testo: #78350f;
  --info-sfondo: #e0e7ff;
  --info-testo: #1e3a8a;
  --errore-sfondo: #fee2e2;
  --errore-testo: #7f1d1d;
  --bordo: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sfondo-pannello: rgba(17, 24, 39, 0.95);
    --testo: #f9fafb;
    --testo-tenue: #d1d5db;
    --bordo: #374151;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--testo);
  background: #e5e7eb;
}

#mappa { position: absolute; inset: 0; }

#pannello, .legenda {
  position: absolute;
  left: 12px;
  right: 12px;
  background: var(--sfondo-pannello);
  border: 1px solid var(--bordo);
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
  padding: 12px 14px;
  max-width: 420px;
}

#pannello { top: calc(12px + env(safe-area-inset-top)); }
.legenda { top: auto; bottom: calc(40px + env(safe-area-inset-bottom)); }

.riga-titolo { display: flex; gap: 8px; align-items: center; }

select {
  flex: 1;
  min-width: 0;
  font-size: 1.15rem;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--testo);
  padding: 4px 0;
}

button {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--bordo);
  background: transparent;
  color: var(--testo);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

p { margin: 6px 0 0; }
.aggiornato { color: var(--testo-tenue); font-size: 0.9rem; }
.conteggi { font-size: 1rem; font-weight: 600; }
.nota { color: var(--testo-tenue); font-size: 0.85rem; }

.avviso { border-radius: 10px; padding: 8px 10px; font-size: 0.92rem; font-weight: 600; }
.avviso.info { background: var(--info-sfondo); color: var(--info-testo); }
.avviso.attenzione { background: var(--avviso-sfondo); color: var(--avviso-testo); }
.avviso.errore { background: var(--errore-sfondo); color: var(--errore-testo); }

.legenda h2 { font-size: 1rem; margin: 0 0 6px; }
.legenda ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 0.9rem; }
.tratto { display: inline-block; width: 28px; height: 5px; border-radius: 3px; vertical-align: middle; margin-right: 8px; }
.tratto.blu { background: var(--blu); }
.tratto.rossa { background: var(--rossa); }
.tratto.nera { background: var(--nera); }
.tratto.chiusa { background: var(--chiusa); }
.tratto.impianto { background: var(--impianto); height: 3px; }
.tratto.impianto-chiuso { background: repeating-linear-gradient(90deg, var(--chiusa) 0 5px, transparent 5px 8px); height: 3px; }
.tratto.mancante { background: repeating-linear-gradient(90deg, var(--mancante) 0 6px, transparent 6px 10px); }

.nascosto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.maplibregl-popup-content { font: 0.95rem system-ui, sans-serif; color: #111827; }

/* Attribuzione obbligatoria (licenza ODbL): sempre leggibile, anche col tema scuro. */
.maplibregl-ctrl-attrib.maplibregl-ctrl { background: rgba(255, 255, 255, 0.85); color: #1f2937; font-size: 11px; }
.maplibregl-ctrl-attrib a { color: #1f2937; }

/* I pulsanti della mappa restano scuri su bianco anche col tema scuro. */
.maplibregl-ctrl-group button { color: #111827; border-radius: 0; padding: 0; font-size: 0.8rem; }
