/* ══════════════════════════════════════════════════════════════
   APL Calabria 2026 — Stili
   Palette: marina profonda · terracotta · pergamena
   ══════════════════════════════════════════════════════════════ */

/* ─── Variabili ──────────────────────────────────────────────── */
:root {
  --navy:         #0d1d38;
  --navy-mid:     #162c52;
  --navy-light:   #1e3a68;
  --terra:        #c8432a;
  --terra-light:  #e05a3a;
  --gold:         #d4a843;
  --gold-dim:     rgba(212, 168, 67, 0.18);
  --cream:        #f4ead7;
  --cream-dim:    rgba(244, 234, 215, 0.85);
  --border:       rgba(244, 234, 215, 0.10);
  --border-mid:   rgba(244, 234, 215, 0.18);
  --txt-on-dark:  rgba(244, 234, 215, 0.97);
  --txt-muted:    rgba(244, 234, 215, 0.72);   /* era 0.58 — contrasto WCAG AA */
  --sidebar-w:    400px;
  /* province */
  --c-cs: #e05a3a;
  --c-cz: #d4a843;
  --c-rc: #4faa88;
  --c-kr: #5b9fd4;
  --c-vv: #b86ab0;
}

/* ─── Accessibilità: utilità ─────────────────────────────────── */

/* Visivamente nascosto ma accessibile agli screen reader (WCAG 1.1.1, 1.3.1) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link: visibile solo al focus da tastiera (WCAG 2.4.1) */
.skip-link {
  position: absolute;
  top: -100%;
  left: 12px;
  z-index: 9999;
  background: var(--navy-mid);
  color: var(--cream);
  border: 2px solid var(--gold);
  border-radius: 4px;
  padding: 8px 18px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: top 0.18s ease;
}
.skip-link:focus { top: 12px; }

/* Focus ring globale — sovrascrive outline:none dove necessario (WCAG 2.4.7) */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* ─── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body { font-family: 'Outfit', system-ui, sans-serif; background: #1a2f54; }

/* ─── Shell ──────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  /* pattern a punti cartografici */
  background-image: radial-gradient(rgba(244,234,215,0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  border-right: 1px solid rgba(0,0,0,0.4);
}

/* ─── Header ─────────────────────────────────────────────────── */
.sidebar-header {
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  animation: fade-in-down 0.5s ease both;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.18em;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid rgba(212,168,67,0.28);
  padding: 3px 9px;
  border-radius: 2px;
  margin-bottom: 11px;
}

/* h2 nella sidebar (h1 appartiene al template dell'Ente Regione) */
.sidebar-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.12;
  color: var(--cream);
  letter-spacing: -0.015em;
}

.header-subtitle {
  margin-top: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: rgba(244, 234, 215, 0.82);
  letter-spacing: 0.04em;
}

/* ─── Statistiche (ora in fondo alla sidebar) ────────────────── */
.stats-panel {
  padding: 14px 26px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  animation: fade-in-down 0.5s 0.24s ease both;
}

.stat-total {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 14px;
}

.stat-total-number {
  font-family: 'Playfair Display', serif;
  font-size: 42px;
  font-weight: 700;
  color: var(--cream);
  line-height: 1;
  letter-spacing: -0.02em;
}

.stat-total-label {
  font-size: 14px;
  color: rgba(244, 234, 215, 0.82);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ul: reset list-style per il nuovo markup semantico */
.stats-provinces {
  display: flex;
  flex-direction: column;
  gap: 7px;
  list-style: none;
  padding: 0;
  margin: 0;
}

/* stat-prov: elemento informativo, non interattivo */
.stat-prov {
  display: grid;
  grid-template-columns: 26px 1fr 30px;
  align-items: center;
  gap: 10px;
}

.prov-code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13.5px;
  letter-spacing: 0.08em;
  color: rgba(244, 234, 215, 0.88);
  font-weight: 500;
}

.prov-bar {
  height: 4px;
  background: rgba(244,234,215,0.10);
  border-radius: 2px;
  overflow: hidden;
}

.prov-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  width: 0%;
  transition: width 1.3s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-prov="CS"] .prov-fill { background: var(--c-cs); }
[data-prov="CZ"] .prov-fill { background: var(--c-cz); }
[data-prov="RC"] .prov-fill { background: var(--c-rc); }
[data-prov="KR"] .prov-fill { background: var(--c-kr); }
[data-prov="VV"] .prov-fill { background: var(--c-vv); }

.prov-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14.5px;
  color: var(--txt-on-dark);
  text-align: right;
  font-weight: 500;
}

/* ─── Filtri ─────────────────────────────────────────────────── */
.filters-panel {
  padding: 12px 26px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fade-in-down 0.5s 0.16s ease both;
}

.filter-row { display: flex; gap: 8px; }

.filter-row--split {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input[type="text"], select {
  width: 100%;
  background: rgba(244,234,215,0.08);
  border: 1px solid rgba(244,234,215,0.22);
  border-radius: 4px;
  padding: 9px 13px;
  font-size: 15px;
  font-family: 'Outfit', sans-serif;
  color: var(--cream-dim);
  transition: border-color 0.2s, background 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input[type="text"]::placeholder { color: rgba(244, 234, 215, 0.50); }

/* Focus visibile su input (WCAG 2.4.7): usa gold + bordo rinforzato */
input[type="text"]:focus-visible, select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
  border-color: rgba(212,168,67,0.65);
  background: rgba(244,234,215,0.09);
}

select {
  min-width: 108px;
  width: auto;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(244%2C234%2C215%2C0.35)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 26px;
}

select option { background: var(--navy-mid); color: var(--cream); }

.filter-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn-reset {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--terra-light);
  background: none;
  border: 1px solid rgba(200,67,42,0.35);
  padding: 7px 13px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.18s;
}

.btn-reset:hover {
  background: rgba(200,67,42,0.12);
  border-color: var(--terra-light);
}

/* toggle */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* toggle-label ora è <label for="showAllToggle"> → clic espande l'area attiva */
.toggle-label {
  font-size: 13px;
  color: rgba(244, 234, 215, 0.82);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 19px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: rgba(244,234,215,0.1);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 13px;
  height: 13px;
  left: 2px;
  top: 2px;
  background: rgba(244,234,215,0.45);
  transition: transform 0.3s, background 0.3s;
}

input:checked + .slider {
  background: rgba(212,168,67,0.22);
  border-color: rgba(212,168,67,0.55);
}

input:checked + .slider::before {
  transform: translateX(17px);
  background: var(--gold);
}

.slider.round { border-radius: 19px; }
.slider.round::before { border-radius: 50%; }

/* ─── Link vista tabellare completa ─────────────────────────── */
.view-switcher {
  padding: 0 26px 12px;
  flex-shrink: 0;
}

.btn-table-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--gold);
  text-decoration: none;
  background: rgba(212,168,67,0.06);
  border: 1px solid rgba(212,168,67,0.28);
  border-radius: 4px;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
}

.btn-table-link:hover {
  background: rgba(212,168,67,0.14);
  border-color: rgba(212,168,67,0.55);
  color: var(--cream);
}

.btn-table-link-ico {
  font-size: 14px;
  line-height: 1;
}

/* ─── Tabella wrapper ────────────────────────────────────────── */
.table-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  animation: fade-in-down 0.5s 0.24s ease both;
}

.table-scroll {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(244,234,215,0.12) transparent;
}

.table-scroll::-webkit-scrollbar { width: 3px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb {
  background: rgba(244,234,215,0.12);
  border-radius: 2px;
}

/* ─── Tabella ────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.col-ente   { width: 55%; }
.col-comune { width: 33%; }
.col-prov   { width: 12%; }

thead th {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--txt-muted);
  font-weight: 500;
  padding: 11px 26px 9px;
  text-align: left;
  background: var(--navy);
  position: sticky;
  top: 0;
  z-index: 2;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  user-select: none;
  transition: color 0.15s;
}

thead th:hover { color: var(--txt-on-dark); }

/* Focus visibile sulle intestazioni ordinabili (WCAG 2.4.7) */
thead th:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
  color: var(--txt-on-dark);
}

.sort-icon { margin-left: 3px; opacity: 0.35; font-style: normal; }
th.asc  .sort-icon::after { content: "↑"; opacity: 1; }
th.desc .sort-icon::after { content: "↓"; opacity: 1; }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

tbody tr:hover { background: rgba(244,234,215,0.04); }

/* Focus da tastiera sulle righe — outline interno per non uscire dalla cella (WCAG 2.4.7) */
tbody tr:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -1px;
  background: rgba(244,234,215,0.06);
}

tbody tr.selected {
  background: rgba(212,168,67,0.09) !important;
  border-left: 2px solid var(--gold);
}

tbody td {
  padding: 11px 26px;
  color: var(--txt-on-dark);
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

tbody td:last-child {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--txt-muted);
  text-align: center;
  padding-left: 0;
  padding-right: 16px;
}

/* badge provincia nella riga selezionata */
tbody tr.selected td:last-child {
  color: var(--gold);
}

/* ─── Paginazione ────────────────────────────────────────────── */
/* <nav> semantico: screen reader annuncia "Navigazione pagine elenco" */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 26px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
  background: rgba(0,0,0,0.12);
}

.pag-info {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: rgba(244, 234, 215, 0.78);
  white-space: nowrap;
  letter-spacing: 0.04em;
}

.pag-buttons {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pag-btn, .page-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  background: none;
  border: 1px solid var(--border-mid);
  color: var(--txt-muted);
  padding: 5px 10px;
  border-radius: 3px;
  cursor: pointer;
  min-width: 30px;
  text-align: center;
  transition: all 0.12s;
  line-height: 1;
}

.pag-btn:hover:not(:disabled),
.page-number:hover {
  color: var(--cream-dim);
  border-color: var(--border-mid);
  background: rgba(244,234,215,0.06);
}

.pag-btn:disabled { opacity: 0.2; cursor: not-allowed; }

.page-number.active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--navy);
  font-weight: 600;
}

.page-numbers { display: flex; gap: 2px; }

/* ══════════════════════════════════════════════════════════════
   TEMA CHIARO — Sidebar
   Rimappa le variabili CSS in scope .sidebar per invertire
   il contrasto: sfondo chiaro (pergamena), testo scuro (navy).
   ══════════════════════════════════════════════════════════════ */
.sidebar {
  --navy:        #f5f1ea;
  --navy-mid:    #ede8de;
  --navy-light:  #e5ddd1;
  --cream:       #1c2e4a;
  --cream-dim:   rgba(28, 46, 74, 0.90);
  --border:      rgba(28, 46, 74, 0.10);
  --border-mid:  rgba(28, 46, 74, 0.20);
  --txt-on-dark: rgba(28, 46, 74, 0.94);
  --txt-muted:   rgba(28, 46, 74, 0.62);
  --gold:        #9a6b0e;
  --gold-dim:    rgba(154,107,14,0.12);
  --terra-light: #c03318;
  background: #f5f1ea;
  background-image: radial-gradient(rgba(28,46,74,0.028) 1px, transparent 1px);
  background-size: 22px 22px;
  border-right: 1px solid rgba(28,46,74,0.14);
  box-shadow: 2px 0 12px rgba(0,0,0,0.06);
}

/* Sovrascritture per valori rgba hardcoded ───────────────────── */
.sidebar .sidebar-title   { color: #1c2e4a; }
.sidebar .header-subtitle { color: rgba(28,46,74,0.65); }
.sidebar .stat-total-label { color: rgba(28,46,74,0.62); }
.sidebar .prov-code        { color: rgba(28,46,74,0.72); }
.sidebar .prov-bar         { background: rgba(28,46,74,0.10); }
.sidebar .toggle-label     { color: rgba(28,46,74,0.65); }

.sidebar input[type="text"],
.sidebar select {
  background:   rgba(28,46,74,0.06);
  border-color: rgba(28,46,74,0.20);
  color:        rgba(28,46,74,0.90);
}
.sidebar input[type="text"]::placeholder { color: rgba(28,46,74,0.38); }
.sidebar input[type="text"]:focus-visible,
.sidebar select:focus-visible {
  background:   rgba(28,46,74,0.08);
  border-color: var(--gold);
  outline-color: var(--gold);
}
.sidebar select option { background: #ede8de; color: #1c2e4a; }

.sidebar .slider          { background: rgba(28,46,74,0.10); border-color: rgba(28,46,74,0.22); }
.sidebar .slider::before  { background: rgba(28,46,74,0.32); }

.sidebar thead th          { background: var(--navy-mid); color: var(--txt-muted); border-bottom-color: var(--border-mid); }
.sidebar thead th:hover    { color: var(--txt-on-dark); }
.sidebar thead th:focus-visible { color: var(--txt-on-dark); }

.sidebar tbody tr:hover         { background: rgba(28,46,74,0.045); }
.sidebar tbody tr:focus-visible { background: rgba(28,46,74,0.07); }
.sidebar tbody tr.selected      { background: rgba(154,107,14,0.10) !important; border-left-color: var(--gold); }
.sidebar tbody tr.selected td:last-child { color: var(--gold); }

.sidebar .pagination-bar { background: rgba(28,46,74,0.05); }
.sidebar .pag-info        { color: rgba(28,46,74,0.60); }
.sidebar .pag-btn:hover:not(:disabled),
.sidebar .page-number:hover {
  background:   rgba(28,46,74,0.07);
  border-color: rgba(28,46,74,0.30);
  color:        rgba(28,46,74,0.90);
}
.sidebar .page-number.active { color: #f5f1ea; }

.sidebar .table-scroll { scrollbar-color: rgba(28,46,74,0.18) transparent; }
.sidebar .table-scroll::-webkit-scrollbar-thumb { background: rgba(28,46,74,0.18); }

.sidebar .btn-table-link {
  background:    #1c2e4a;
  border-color:  #1c2e4a;
  color:         #f5f1ea;
  font-size:     13px;
  padding:       11px 14px;
  border-radius: 5px;
  box-shadow:    0 2px 8px rgba(28,46,74,0.22);
}
.sidebar .btn-table-link:hover {
  background:   #243a5e;
  border-color: #243a5e;
  color:        #f5f1ea;
  box-shadow:   0 3px 12px rgba(28,46,74,0.32);
}

/* ══════════════════════════════════════════════════════════════
   MAPPA
   ══════════════════════════════════════════════════════════════ */
.map-main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ─── Popup Leaflet ──────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--navy) !important;
  border-radius: 5px !important;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4) !important;
  border: 1px solid var(--border-mid) !important;
  padding: 0 !important;
  overflow: hidden !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.4 !important;
  min-width: 220px;
  max-width: 280px;
}

.leaflet-popup-tip-container { margin-top: -1px; }
.leaflet-popup-tip { background: var(--navy) !important; }

.leaflet-popup-close-button {
  color: var(--txt-muted) !important;
  font-size: 17px !important;
  top: 7px !important;
  right: 8px !important;
  transition: color 0.15s !important;
}

.leaflet-popup-close-button:hover { color: var(--cream-dim) !important; }

/* struttura popup custom */
.apl-popup { font-family: 'Outfit', sans-serif; }

.popup-head {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.popup-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--cream);
  line-height: 1.35;
  flex: 1;
  padding-right: 18px;
}

.popup-prov-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  padding: 3px 7px;
  border-radius: 2px;
  flex-shrink: 0;
  margin-top: 1px;
  font-weight: 500;
}

.popup-body {
  padding: 10px 14px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.popup-row {
  font-size: 11px;
  color: rgba(244,234,215,0.62);
  display: flex;
  gap: 7px;
  align-items: flex-start;
  line-height: 1.35;
}

.popup-ico {
  color: var(--gold);
  flex-shrink: 0;
  font-style: normal;
  margin-top: 1px;
  font-size: 11px;
  width: 14px;
  text-align: center;
}

.popup-services {
  padding: 7px 14px 9px;
  border-top: 1px solid var(--border);
  font-size: 9px;
  font-family: 'IBM Plex Mono', monospace;
  color: rgba(244,234,215,0.28);
  line-height: 1.55;
  letter-spacing: 0.02em;
}

/* ─── Marker ─────────────────────────────────────────────────── */
.apl-marker-wrap {
  background: none !important;
  border: none !important;
}

.apl-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.12s;
}

.apl-dot-hl {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 0 5px rgba(255,255,255,0.25), 0 4px 16px rgba(0,0,0,0.5);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ─── Animazioni entrata ─────────────────────────────────────── */
@keyframes fade-in-down {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 820px) {
  :root { --sidebar-w: 100%; }

  .app { flex-direction: column; }

  .sidebar {
    width: 100%;
    max-height: 48vh;
    border-right: none;
    border-bottom: 1px solid rgba(0,0,0,0.4);
  }

  .map-main { flex: 1; min-height: 0; }

  .sidebar-title { font-size: 22px; }
  .stat-total-number { font-size: 30px; }

  .sidebar-header { padding: 14px 18px 12px; }
  .stats-panel    { padding: 10px 18px; }
  .filters-panel  { padding: 8px 18px; }
  thead th, tbody td { padding-left: 18px; padding-right: 18px; }
  .pagination-bar { padding-left: 18px; padding-right: 18px; }
}

@media (max-width: 480px) {
  .sidebar { max-height: 42vh; }
  .stats-provinces { display: none; }
  .stat-total-number { font-size: 26px; }
}
