:root {
  --bg: #0b0f1a;
  --surface: #111827;
  --surface-2: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #3b82f6;
  --primary-contrast: #ffffff;
  --accent: #22c55e;
  --danger: #ef4444;
  --app-header-h: 56px;
  --panel-header-h: 56px;
  --main-pad-y: 16px;
  --main-gap: 8px; /* piccolo distacco tra main e footer */
  --aside-gap: clamp(9px, 1.3vh, 15px); /* riduzione proporzionale, lieve, dell’altezza della sidebar (aside) */
  --aside-max-h: clamp(280px, 34vh, 460px); /* limite responsivo per l’altezza della sidebar */
  --map-gap: 14px; /* riduce ulteriormente l’altezza della mappa rispetto al contenitore */
  --tbl-gap: 12px; /* piccolo distacco sotto la tabella per mostrare il bordo */
  --tbl-reduce: clamp(14px, 2.2vh, 22px); /* piccola riduzione percentuale dell’altezza della tabella */
  --tbl-fine-reduce: clamp(4px, 0.6vh, 8px); /* micro-riduzione aggiuntiva e proporzionale della tabella */
  --tbl-scrollbar-w: 6px; /* spessore sottile della scrollbar della tabella */
  --tbl-scrollbar-thumb: #334155; /* colore thumb (discreto) */
  --tbl-scrollbar-thumb-hover: #475569; /* colore thumb al passaggio/attivo */
  --aside-inner-pad-x: 12px; /* spazio orizzontale interno tra aside e tabella */
  --app-footer-h: 28px;
  --legend-max-h: clamp(200px, 28vh, 320px); /* limite responsivo per l’altezza della legenda */
  --detail-img-h: 240px; /* altezza uniforme immagini dettagli */
  --tbl-max-h: clamp(250px, 35vh, 430px); /* diminuisce di poco l’altezza visibile della tabella */
  --legend-gap: 12px; /* piccolo distacco sotto la legenda per mostrare il bordo */
  --legend-reduce: clamp(10px, 1.8vh, 18px); /* piccola riduzione percentuale dell’altezza della legenda */
  --border: #334155; /* colore bordo predefinito in tema scuro (slate-700) */
  --tbl-head-bg: #0f172a; /* sfondo thead tabella (tema scuro) */
  --tbl-hover-bg: #0f172a; /* sfondo hover riga tabella (tema scuro) */
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
/* Light theme overrides */
html.theme-light {
  --bg: #f8fafc; /* slate-50 */
  --surface: #ffffff;
  --surface-2: #f1f5f9; /* slate-100 */
  --text: #0f172a; /* slate-900 */
  --muted: #334155; /* slate-700 */
  --primary: #2563eb; /* blue-600 */
  --primary-contrast: #ffffff;
  --accent: #16a34a; /* green-600 */
  --danger: #dc2626; /* red-600 */
  --border: #cbd5e1; /* colore bordo uniforme in tema chiaro (slate-300) */
  --tbl-head-bg: var(--surface-2); /* sfondo thead tabella (tema chiaro) */
  --tbl-hover-bg: rgba(59,130,246,0.12); /* sfondo hover riga tabella (tema chiaro) */
}
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid #0f172a;
}
.brand-line { display: inline-flex; align-items: center; gap: 8px; }
.brand-text { display: inline-flex; flex-direction: column; }
.brand { display: flex; flex-direction: column; }
.brand-title { font-weight: 700; font-size: 18px; }
.brand-sub { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; }

.btn {
  appearance: none;
  border: 1px solid #334155;
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.btn.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.btn-icon svg { width: 18px; height: 18px; }
/* Reload: ingrandisce l'icona mantenendo proporzioni e stile */
#btnReload.btn.btn-icon svg { width: 24px; height: 24px; }
/* Assicura allineamento ottimale e colore coerente con il bottone */
.btn.btn-icon svg { display: block; stroke: currentColor; fill: none; }
/* Icone tema: mostra solo l'icona del tema corrente */
.btn.btn-icon.btn-theme .icon-sun,
.btn.btn-icon.btn-theme .icon-moon { display: none; }
html:not(.theme-light) .btn.btn-icon.btn-theme .icon-sun { display: block; }
html.theme-light .btn.btn-icon.btn-theme .icon-moon { display: block; }
/* Focus visibile sul pulsante di ricarica per accessibilità */
#btnReload.btn.btn-icon:focus-visible {
  outline: 2px solid rgba(255,255,255,0.35);
  outline-offset: 2px;
}
/* Supporta anche <img> come icona del pulsante */
.btn.btn-icon img.icon { width: 20px; height: 20px; display: block; object-fit: contain; }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}
.btn:hover { filter: brightness(1.1); }

.app-main {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  height: calc(106dvh - var(--app-header-h) - var(--app-footer-h) - (var(--main-pad-y) * 2) - var(--main-gap));
  overflow: hidden;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid #0f172a;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #0f172a;
}
.panel-header h2 { margin: 0; font-size: 16px; }
.panel-header .controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.panel-header label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.panel-header select, .panel-header input[type="date"], .panel-header input[type="text"], .panel-header input[type="range"] {
  margin-top: 4px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 8px;
  height: 32px;
  padding: 0 8px;
}
.panel-header .control-group { display: inline-flex; align-items: center; gap: 12px; }
.panel-header .marker-controls { display: inline-flex; align-items: center; gap: 12px; }
.switch { flex-direction: row; align-items: center; gap: 8px; }
.switch > span { margin-left: 4px; }
.panel-header .marker-controls .switch { flex-direction: row; align-items: center; gap: 8px; min-height: 32px; }
.panel-header .marker-controls .switch > span { margin-left: 0; margin-right: 8px; }
.panel-header .marker-controls label.switch .control-caption { margin: 0; position: relative; top: 6px; }
.panel-header label.range-stack { flex-direction: column; align-items: flex-start; }
.panel-header label.range-stack select { width: 100%; }
.panel-header .control-caption { margin-top: 4px; text-align: left; align-self: start; }
.panel-header label.range-stack .control-caption { margin-top: 2px; margin-bottom: 0; }

.panel-map { grid-column: 1; height: 100%; position: relative; }
.panel-map-content { display: grid; grid-template-columns: var(--sidebar-w, 320px) 6px 1fr 220px; gap: 12px; padding: 12px 16px; align-items: stretch; height: calc(100% - var(--panel-header-h)); }
.map { width: 100%; height: calc(100% - var(--map-gap)); min-height: 0; position: relative; }

.legend { position: static; width: 100%; background: var(--surface-2); border: 1px solid #0f172a; border-radius: 8px; padding: 12px 16px 12px 8px; height: calc(100% - var(--legend-gap) - var(--legend-reduce)); min-height: 0; overflow-y: auto; overflow-x: hidden; }
.legend-title { font-size: 14px; color: var(--text); font-weight: 700; margin: 0; text-align: center; }
.legend-gap { height: 12px; display: block; }
.legend-scale { display: grid; grid-template-rows: repeat(20, 1fr); gap: 4px; min-height: 0; }
.legend-row { display: grid; grid-template-columns: var(--legend-label-w, 86px) var(--legend-swatch-w, 44px) var(--legend-count-w, 56px); align-items: center; column-gap: 16px; overflow: hidden; width: max-content; margin: 0 auto; }
.legend-swatch { width: var(--legend-swatch-w, 44px); height: 12px; border-radius: 2px; border: 1px solid #0f172a; }
.legend-label { font-size: 11px; color: var(--text); text-align: right; padding-right: 1px; }
.legend-count { font-size: 10px; color: var(--muted); text-align: left; }
.legend-sym-count { font-size: 10px; color: var(--muted); margin-left: 6px; text-align: left; }

.legend-symbols { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid #0f172a; }
.legend-symbol { display: inline-flex; align-items: center; gap: 6px; }
.legend-sym-label { font-size: 11px; color: var(--text); }
.legend-symbol .icon-no-data, .legend-symbol .icon-oor { transform: scale(0.85); transform-origin: center; }

/* Overlay immagini sulla mappa */
.map-overlay {
  position: absolute;
  bottom: 20px;
  background: #ffffff; /* always white, regardless of theme */
  border: 0.25px solid #0f172a;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  padding: 8px;
  z-index: 500; /* sopra il contenuto della mappa */
  width: 200px;
  box-sizing: border-box;
}
.map-overlay-left { left: 16px; }
.map-overlay-right { right: 16px; }
.map-overlay img {
  display: block;
  width: 100%;
  height: var(--overlay-img-h, auto);
  object-fit: contain;
}

/* About dialog styles to match provided layout */
.about { font-size: 14px; line-height: 1.6; color: var(--text); }
.about .brand { color: #2563eb; font-weight: 700; }
.about h4 { margin: 16px 0 8px; font-size: 14px; }
.about ul.guide { list-style: disc; margin: 0 0 8px 22px; padding: 0; }
.about ul.guide li { margin: 4px 0; }
.about .enjoy { color: #2563eb; font-weight: 700; font-size: 16px; margin: 10px 0; }
.about .refer { font-size: 12px; color: var(--muted); }
.about .refer a { color: #2563eb; text-decoration: underline; }

/* Sidebar stazioni a sinistra della mappa */
.map-sidebar {
  background: var(--surface-2);
  border: 1px solid #0f172a;
  border-radius: 8px;
  height: calc(100% - var(--aside-gap));
  align-self: stretch;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-resizer { align-self: stretch; background: var(--surface-2); border: 1px solid #0f172a; border-radius: 8px; cursor: col-resize; position: relative; }
.panel-resizer:hover { background-color: #0b1324; }
.panel-resizer:focus { outline: 2px solid var(--primary); }
.panel-resizer::before { content: ''; position: absolute; left: 50%; top: 8px; bottom: 8px; width: 2px; background: #334155; transform: translateX(-50%); border-radius: 1px; }
.sidebar-header { padding: 8px 12px; border-bottom: 1px solid #0f172a; position: relative; z-index: 5; }
.sidebar-header h3 { 
  margin: 0; 
  font-size: 14px; 
  position: relative;
  padding-bottom: 8px;
}
.sidebar-header h3::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: #334155;
  opacity: 0.6;
}
.stations-count { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid #0f172a;
  background: #e5e7eb;
  color: #0f172a;
  text-shadow: 0 0 1px rgba(255,255,255,0.4);
}

/* Variante compatta per la legenda */
.pill-legend {
  height: 16px;
  line-height: 16px;
  font-size: 10px;
  padding: 0 6px;
  border-radius: 999px;
}
.pill:focus-visible { outline: 2px solid #0f172a; outline-offset: 2px; }
.pill[aria-pressed="true"] { border-width: 2px; box-shadow: inset 0 0 0 1px currentColor; border-color: var(--primary) !important; }
/* Puntatore mano e feedback hover sulle pills interattive */
.stations-count .pill { cursor: pointer; }
.stations-count .pill:hover { border-color: var(--primary) !important; }
/* Maggiore evidenza della pill selezionata in tema scuro */
html:not(.theme-light) .pill[aria-pressed="true"] { outline: 2px solid var(--primary); outline-offset: 2px; }
.pill-total { background: #e5e7eb; color: #0f172a; }
.pill-ok { background: #dcfce7; color: #14532d; }

.pill-nd { background: #fee2e2; color: #7f1d1d; }
.pill-out { background: #e2e8f0; color: #0f172a; }
@media (forced-colors: active) { .pill, .pill-total, .pill-ok, .pill-nd, .pill-out { color: CanvasText; background: Canvas; border-color: CanvasText; } }
#stationsCount { font-size: 12px; font-weight: normal; margin-top: 2px; }
.col-panel { margin-top: 6px; }
.col-filter { margin-top: 6px; }
.col-filter input[type="text"] {
  width: 100%;
  height: 32px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0 8px;
}
.btn.btn-compact { font-size: 12px; padding: 4px 8px; }
.col-panel-content {
  width: 100%;
  background: var(--surface);
  border: 1px solid #0f172a;
  border-radius: 8px;
  padding: 8px;
  display: block;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  transition: max-height var(--colpanel-transition, 200ms) ease, opacity var(--colpanel-transition, 200ms) ease, transform var(--colpanel-transition, 200ms) ease;
}
.col-panel.open .col-panel-content {
  max-height: var(--colpanel-max-h, 260px);
  opacity: 1;
  transform: translateY(0);
}
.col-item { display: flex; align-items: center; gap: 8px; padding: 2px 0; font-size: 12px; color: var(--text); }
.col-item input { accent-color: var(--primary); }
.sidebar-table-wrap { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--aside-inner-pad-x) var(--tbl-gap); margin-bottom: calc(var(--tbl-reduce) + var(--tbl-fine-reduce)); scrollbar-width: thin; scrollbar-color: var(--tbl-scrollbar-thumb) transparent; }

/* Scrollbar sottile e discreta (Blink/WebKit) */
.sidebar-table-wrap::-webkit-scrollbar { width: var(--tbl-scrollbar-w); height: var(--tbl-scrollbar-w); }
.sidebar-table-wrap::-webkit-scrollbar-track { background: transparent; }
.sidebar-table-wrap::-webkit-scrollbar-thumb { background-color: var(--tbl-scrollbar-thumb); border-radius: 999px; border: 1px solid transparent; background-clip: padding-box; }
.sidebar-table-wrap:hover::-webkit-scrollbar-thumb,
.sidebar-table-wrap:focus-within::-webkit-scrollbar-thumb { background-color: var(--tbl-scrollbar-thumb-hover); }
.chk-all { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; }

.panel-table { grid-row: 2; }
.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 10px; line-height: 1.3; }
.data-table th, .data-table td { border-bottom: 1px solid #0f172a; padding: 5px; vertical-align: middle; text-align: left; }
.data-table th.col-sigla, .data-table td.col-sigla, .data-table td.col-sigla .link {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
}
.data-table .col-select input[type="checkbox"] { margin: 0; }
.data-table thead { position: sticky; top: 0; z-index: 5; background: var(--tbl-head-bg, #0f172a); }
.data-table thead th { position: static; background: transparent; font-size: 10px; font-weight: 600; }
.data-table tbody tr:hover { background: var(--tbl-hover-bg, #0f172a); }
/* Evidenziazione riga corrispondente alla ricerca */
.data-table tbody tr.row-highlight { background: rgba(59,130,246,0.18); box-shadow: inset 3px 0 0 0 var(--primary); }
.data-table tbody tr.row-highlight:hover { background: rgba(59,130,246,0.24); }
.link { background: none; border: none; color: var(--primary); text-decoration: underline; cursor: pointer; }

/* Nome/codice stazione: grassetto e font leggermente aumentato */
.data-table tbody td.col-sigla .link {
  font-weight: 700;
  font-size: 11px;
  text-decoration: none;
}

/* Visibilità colonne della tabella */
.data-table.hide-col-select th.col-select, .data-table.hide-col-select td.col-select { display: none; }
.data-table.hide-col-ind th.col-ind, .data-table.hide-col-ind td.col-ind { display: none; }
.data-table.hide-col-sigla th.col-sigla, .data-table.hide-col-sigla td.col-sigla { display: none; }
.data-table.hide-col-lat th.col-lat, .data-table.hide-col-lat td.col-lat { display: none; }
.data-table.hide-col-lon th.col-lon, .data-table.hide-col-lon td.col-lon { display: none; }
.data-table.hide-col-stato th.col-stato, .data-table.hide-col-stato td.col-stato { display: none; }
.data-table.hide-col-val th.col-val, .data-table.hide-col-val td.col-val { display: none; }

/* Colonna indicatore */
.data-table th.col-ind, .data-table td.col-ind { width: 48px; text-align: left; }
.tbl-indicator { display: inline-flex; align-items: center; justify-content: flex-start; width: 24px; height: 24px; }
.ind-swatch { width: 16px; height: 16px; border-radius: 3px; border: 1px solid #0f172a; box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.tbl-indicator .icon-no-data, .tbl-indicator .icon-oor { transform: scale(0.8); transform-origin: center; }

/* Colonna status */
.data-table th.col-stato, .data-table td.col-stato { width: 48px; text-align: left; }
.tbl-status { display: inline-flex; align-items: center; justify-content: flex-start; width: 24px; height: 24px; }
.tbl-status { font-size: 18px; font-weight: 700; line-height: 1; }
.tbl-status.ok { color: #22c55e; /* verde */ }
.tbl-status.ko { color: #ef4444; /* rosso */ }
.status-icon { width: 20px; height: 20px; }

/* Indicatori ordinamento tabella */
.data-table th.sortable { cursor: pointer; user-select: none; position: relative; }
.data-table th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.data-table th.sorted-asc::after,
.data-table th.sorted-desc::after {
  content: '';
  display: inline-block;
  margin-left: 6px;
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
}
.data-table th.sorted-asc::after { border-bottom: 7px solid var(--muted); }
.data-table th.sorted-desc::after { border-top: 7px solid var(--muted); }

.panel-images { display: none; }
.images-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 16px; }
.images-grid figure { margin: 0; background: var(--surface-2); border: 1px solid #0f172a; border-radius: 8px; overflow: hidden; }
.images-grid img { display: block; width: 100%; height: auto; }
.images-grid figcaption { padding: 8px; font-size: 12px; color: var(--muted); }

.station-label { pointer-events: none; }
.station-label span {
  position: relative;
  left: 50%;
  transform: translate(-50%, calc(var(--marker-radius, 10px) + 8px));
  display: inline-block;
  color: #fff; /* sempre visibile su qualsiasi basemap */
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0,0,0,0.35); /* contrasto su mappe chiare e satellitari */
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.popup { font-size: 12px; color: var(--text); }
.popup .warn { margin-top: 6px; color: var(--danger); }
.popup-img { width: 100%; height: auto; margin-top: 6px; border-radius: 6px; border: 1px solid #0f172a; cursor: pointer; }
.popup .link { color: var(--primary); text-decoration: underline; }

/* Migliora il contrasto dei popup Leaflet */
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border: 1px solid #0f172a;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}
.leaflet-popup-content { font-size: 12px; line-height: 1.35; }
.leaflet-popup-tip { background: var(--surface); border: 1px solid #0f172a; }
.images-inline { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 6px; }

/* Marker animato per assenza dati */
.no-data-div-icon { background: transparent; border: none; }
.icon-no-data { position: relative; width: 24px; height: 24px; animation: nd-blink 1s ease-in-out infinite; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }
.icon-no-data .triangle {
  position: absolute;
  top: 1px; left: 0;
  width: 0; height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 22px solid #f59e0b; /* amber */
}
.icon-no-data .bang {
  position: absolute;
  top: 8px; left: 50%; transform: translateX(-50%);
  color: #111827; font-weight: 800; font-size: 14px; line-height: 1;
}
@keyframes nd-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Marker animato per valori fuori intervallo */
.oor-div-icon { background: transparent; border: none; }
.icon-oor { position: relative; width: 24px; height: 24px; animation: oor-blink 1s ease-in-out infinite; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }
.icon-oor .circle { position: absolute; top: 0; left: 0; width: 24px; height: 24px; background: #ef4444; border-radius: 50%; border: 1px solid #1f2937; }
.icon-oor .bang { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -58%); color: #ffffff; font-weight: 800; font-size: 14px; line-height: 1; }
@keyframes oor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.loading {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(17,24,39,0.85);
  border: 1px solid #0f172a;
  border-radius: 12px;
  z-index: 1000;
  pointer-events: none;
}
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid var(--primary);
  border-top-color: transparent;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-weight: 600; display: none; }

/* Toast di notifica (coerente con stile app) */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -52%);
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid #0f172a;
  border-radius: 12px;
  padding: 14px 20px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  text-align: left;
  font-weight: 600;
  font-size: 14px;
  max-width: min(95vw, 820px);
}
.toast-text { white-space: nowrap; }
.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}
/* Spinner nel toast rimosso: si utilizza la barra di progressione */

/* Barra di progressione nel toast */
.toast-progress {
  flex: 0 0 clamp(200px, 30vw, 360px);
  height: 8px;
  background: #0f172a;
  border: 1px solid #1f2937;
  border-radius: 999px;
  overflow: hidden;
}
.toast-progress-inner {
  width: 0%;
  height: 100%;
  background: var(--primary);
  transition: width 180ms ease;
}

/* Cursore loader durante caricamento (simile al loader circolare) */
.is-loading, .is-loading * {
  cursor: progress !important;
}

dialog {
  border: 1px solid #0f172a;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  max-width: 960px;
}
/* Dialog About: leggermente più largo */
#dlgAbout {
  width: 85vw;
  max-width: 1200px;
}
/* Dialog specifico per viewer: più ampio e alto */
#dlgImgViewer {
  width: 96vw;
  max-width: 96vw;
  max-height: 90vh;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog-actions { display: flex; justify-content: flex-end; padding-top: 8px; }
.about { max-height: 60vh; overflow: auto; }
/* Scrollbar sottile per il dialog About, coerente con la tabella stazioni */
.about { scrollbar-width: thin; scrollbar-color: var(--tbl-scrollbar-thumb) transparent; }
.about::-webkit-scrollbar { width: var(--tbl-scrollbar-w); height: var(--tbl-scrollbar-w); }
.about::-webkit-scrollbar-track { background: transparent; }
.about::-webkit-scrollbar-thumb { background-color: var(--tbl-scrollbar-thumb); border-radius: 999px; border: 1px solid transparent; background-clip: padding-box; }
.about:hover::-webkit-scrollbar-thumb,
.about:focus-within::-webkit-scrollbar-thumb { background-color: var(--tbl-scrollbar-thumb-hover); }

/* Viewer immagine dettagli */
.viewer-container {
  position: relative;
  width: 100%;
  height: 70vh;
  background: var(--surface-2);
  border: 1px solid #0f172a;
  border-radius: 8px;
  overflow: hidden;
}
.viewer-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(var(--s, 1));
  transform-origin: center;
  cursor: grab;
}
.viewer-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}
.viewer-container.grabbing .viewer-stage { cursor: grabbing; }
.viewer-controls {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 8px;
  background: rgba(17,24,39,0.85);
  border: 1px solid #0f172a;
  border-radius: 8px;
  padding: 6px;
}

.details-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.details-grid figure { margin: 0; background: var(--surface-2); border: 1px solid #0f172a; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.details-grid figure.highlight { outline: 2px solid var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,0.4); }
.details-grid img { display: block; width: 100%; height: var(--detail-img-h); object-fit: contain; object-position: center; background: var(--surface); }
.details-grid img.detail-img { cursor: zoom-in; }
.details-grid figcaption { padding: 8px; font-size: 12px; color: var(--muted); }

.app-footer { position: fixed; bottom: 0; left: 0; right: 0; height: var(--app-footer-h); padding: 6px 16px; color: var(--muted); background: var(--surface); border-top: 1px solid #0f172a; display: flex; align-items: center; gap: 12px; }
.sr-only { position: absolute !important; clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; height: 1px !important; width: 1px !important; overflow: hidden !important; white-space: nowrap !important; }

/* Responsive */
@media (max-width: 1200px) {
  .app-main { grid-template-columns: 1fr; }
  .panel-map { grid-column: 1; }
  .panel-map { min-height: auto; }
  .panel-map-content { grid-template-columns: 1fr; height: auto; }
  .panel-table, .panel-images { grid-row: auto; }
  .images-grid { grid-template-columns: 1fr; }
  .images-inline { grid-template-columns: 1fr; }
  .details-grid { grid-template-columns: 1fr; }
  :root { --detail-img-h: 220px; }
  .map { height: 380px; }
  .legend { height: auto; margin: 0 16px 16px; }
}

@media (max-width: 640px) {
  .panel-header .controls { gap: 8px; }
  .map { height: 320px; }
}
.panel-map .panel-header {
  display: grid;
  grid-template-columns: 320px 1fr auto;
  grid-template-rows: auto auto;
  align-items: start;
  gap: 8px 12px;
}
.panel-map .panel-header h2 { grid-column: 1; grid-row: 1; }
.panel-map .panel-header .controls { grid-column: 2; grid-row: 1 / span 2; align-self: start; }
.panel-map .map-filter { grid-column: 1; grid-row: 2; width: 320px; }
.panel-map .map-filter label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.panel-map .map-filter input[type="text"] {
  margin-top: 4px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 8px;
  height: 32px;
  padding: 0 8px;
  width: 100%;
}
@media (max-width: 1200px) {
  .panel-map .map-filter { width: 100%; }
  .panel-map .panel-header { grid-template-columns: 1fr auto; }
  .panel-map .panel-header .controls { grid-column: 1; grid-row: 2; }
}
.data-table th.col-select, .data-table td.col-select { width: 28px; text-align: center; }

/* Mini Toggle (accessibile, responsivo) */
input[type="checkbox"].toggle-mini {
  --tw: 20px; /* track width */
  --th: 12px; /* track height */
  --knob: 10px; /* knob size */
  --pad: 2px; /* inner padding */
  -webkit-appearance: none;
  appearance: none;
  width: var(--tw);
  height: var(--th);
  background: #334155;
  border: 1px solid #0f172a;
  border-radius: calc(var(--th) / 2);
  position: relative;
  cursor: pointer;
  outline: none;
  display: inline-block;
  vertical-align: middle;
}
input[type="checkbox"].toggle-mini::before {
  content: "";
  position: absolute;
  top: 50%;
  left: var(--pad);
  width: var(--knob);
  height: var(--knob);
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
  transform: translateY(-50%);
  transition: transform 0.2s ease;
}
input[type="checkbox"].toggle-mini:checked {
  background: var(--primary);
  border-color: var(--primary);
}
input[type="checkbox"].toggle-mini:checked::before {
  transform: translate(calc(var(--tw) - var(--knob) - (var(--pad) * 2)), -50%);
}
input[type="checkbox"].toggle-mini:focus-visible {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}
input[type="checkbox"].toggle-mini:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Toggle "Labels" ingrandito (solo nel header) */
.panel-header .marker-controls input#chkLabels.toggle-mini {
  --tw: 36px; /* track più largo */
  --th: 20px; /* track più alto */
  --knob: 16px; /* knob più grande */
  --pad: 2px; /* padding interno */
}
.panel-header .marker-controls input#chkLabels.toggle-mini:focus-visible {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.7);
}
.panel-header .marker-controls select { width: 100%; }
html.theme-light *,
html.theme-light *::before,
html.theme-light *::after {
  border-color: var(--border) !important;
}
/* Eccezioni: icone basate su border non devono ereditare il colore del bordo tematico */
html.theme-light .icon-no-data .triangle {
  border-left-color: transparent !important;
  border-right-color: transparent !important;
  border-bottom-color: #f59e0b !important; /* amber */
}
html.theme-light .icon-oor .circle {
  border-color: #1f2937 !important; /* bordo scuro per miglior contrasto sul rosso */
}
.panel-header .controls .btn { height: 32px; padding: 0 12px; display: inline-flex; align-items: center; }
.panel-header .controls input[type="range"].range-compact {
  height: 32px; /* uniforma l’altezza agli altri controlli */
  padding: 0 4px;
  width: 100px; /* larghezza significativamente ridotta */
  min-width: 100px; /* mantiene usabilità senza espandersi troppo */
  flex: 0 0 100px; /* blocca la dimensione nel layout flex */
  align-self: flex-end; /* garantisce l’allineamento al bordo inferiore */
  position: relative; top: 6px; /* abbassa visivamente la traccia per allinearla ai selettori */
}
/* WebKit/Blink */
.panel-header .controls input[type="range"].range-compact::-webkit-slider-runnable-track {
  height: 4px;
  background: #334155;
  border-radius: 999px;
}
.panel-header .controls input[type="range"].range-compact::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
  margin-top: -3px; /* centra il thumb sulla traccia da 4px */
  cursor: pointer;
}
/* Firefox */
.panel-header .controls input[type="range"].range-compact::-moz-range-track {
  height: 4px;
  background: #334155;
  border-radius: 999px;
}
.panel-header .controls input[type="range"].range-compact::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
  cursor: pointer;
}
/* Focus accessibile */
.panel-header .controls input[type="range"].range-compact:focus-visible {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}
.panel-header .marker-controls select { width: 100%; }