:root {
  --ctsa-navy: #0a2540;
  --ctsa-blue: #1f5fa8;
  --ctsa-blue-light: #eaf2fb;
  --ctsa-ink: #1c2733;
  --ctsa-muted: #64748b;
  --ctsa-border: #e2e8f0;
  --ctsa-bg: #f4f6f9;
  --ctsa-radius: 0.75rem;
  --ctsa-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 8px rgba(16, 24, 40, 0.06);
}

html, body {
  height: 100%;
  background: var(--ctsa-bg);
  color: var(--ctsa-ink);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ---- header brand: immagine reale (header.png) + barra avviso ---- */
#top-header {
  position: relative;
  z-index: 1200;
}

.brand-row {
  position: relative;
  /* posizione verticale dell'immagine spostata verso l'alto: nella foto
   * aerea la Calabria ha nord (Cosenza/Sila) in alto, punta di Reggio in
   * basso — vogliamo l'area di Cosenza nella fascia visibile dell'header */
  background:
    linear-gradient(90deg, rgba(6, 16, 30, 0.92) 0%, rgba(6, 16, 30, 0.55) 32%, rgba(6, 16, 30, 0.2) 55%, rgba(6, 16, 30, 0.65) 100%),
    url('../img/header.png') center 18%/cover no-repeat;
  color: #fff;
  padding: 0 20px;
  height: 116px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.spatiqon-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  object-fit: contain;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.7));
  z-index: 5;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
}

.brand-side {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.brand-side-end {
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  text-align: right;
  gap: 8px;
}

.share-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
}

.share-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.share-btn.copied {
  background: #1f9d55;
  border-color: #1f9d55;
}

.share-sep {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.3);
  margin: 0 2px;
}

.brand-row img:not(.spatiqon-center) {
  height: 50px;
  width: auto;
  background: #fff;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.brand-side-end img {
  height: 34px !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  opacity: 0.9;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.25;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}

.brand-sub {
  font-size: 12px;
  opacity: 0.95;
  font-weight: 500;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.95);
  max-width: 480px;
  line-height: 1.35;
}

.brand-guide-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  white-space: nowrap;
  backdrop-filter: blur(2px);
}

.brand-guide-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.brand-guide-btn.full {
  width: 100%;
  justify-content: center;
  background: var(--ctsa-navy);
  border-color: var(--ctsa-navy);
}

.brand-warning-bar {
  background: #12314f;
  color: #ffd27a;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.3;
}

/* ---------- Layout generale: mappa a tutta larghezza, sidebar filtri galleggiante ---------- */
.app-layout {
  display: flex;
  flex-direction: column;
}

.map-pane {
  position: relative;
  height: 68vh;
  min-height: 420px;
}

#map {
  height: 100%;
  width: 100%;
  background: #dde3ea;
}

.sidebar {
  position: absolute;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: 310px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 2px 4px 16px rgba(0, 0, 0, 0.18);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  transform: translateX(-340px);
}

/* ---- schede (Territorio / Servizi / Analisi / Info) ---- */
.sidebar-tabs {
  display: flex;
  flex-shrink: 0;
  background: var(--ctsa-bg);
  border-bottom: 1px solid var(--ctsa-border);
}

.stab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  border: none;
  background: transparent;
  color: var(--ctsa-muted);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
}

.stab i {
  font-size: 15px;
}

.stab:hover {
  color: var(--ctsa-blue);
}

.stab.active {
  color: var(--ctsa-blue);
  border-bottom-color: var(--ctsa-blue);
  background: #fff;
}

.stab-panel {
  animation: stab-fade 0.15s ease;
}

@keyframes stab-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.panel-intro {
  font-size: 11.5px;
  color: var(--ctsa-muted);
  line-height: 1.45;
  margin: 0 0 0.6rem;
}

/* ---- scorciatoie di navigazione rapida, scheda Info ---- */
.info-jump-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.info-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ctsa-blue-light);
  border: 1px solid #cfe0f5;
  color: var(--ctsa-blue);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.info-jump:hover, .info-jump:focus-visible {
  background: var(--ctsa-blue);
  color: #fff;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem !important;
}

.sidebar-section {
  margin-bottom: 1.1rem;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ctsa-muted);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 7px;
}

.sidebar h6 {
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--ctsa-muted);
  font-weight: 700;
  margin: 1.25rem 0 0.6rem;
}

.sidebar h6:first-of-type {
  margin-top: 0;
}

.form-check {
  padding: 0.2rem 0 0.2rem 1.8em;
}

.form-check-label {
  font-size: 0.88rem;
}

.sidebar-toggle {
  position: absolute;
  top: 12px;
  left: 312px;
  width: 34px;
  height: 34px;
  background: #fff;
  border: none;
  border-radius: 8px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ctsa-navy);
  transition: left 0.3s ease, background 0.2s ease, color 0.2s ease;
}

.sidebar.collapsed ~ .sidebar-toggle {
  left: 12px;
}

.sidebar-toggle:hover {
  background: var(--ctsa-blue);
  color: #fff;
}

/* ---- ricerca comune ---- */
.search-wrap {
  position: relative;
  padding: 10px;
  background: var(--ctsa-bg);
  border-radius: 8px;
}

.search-wrap i {
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ctsa-muted);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 8px 34px 8px 10px;
  border: 2px solid var(--ctsa-border);
  border-radius: 8px;
  font-size: 13px;
}

.search-results {
  display: none;
  position: absolute;
  left: 10px;
  right: 10px;
  top: 42px;
  background: #fff;
  border: 1px solid var(--ctsa-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  z-index: 1400;
  max-height: 240px;
  overflow-y: auto;
}

.search-result-item {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f1f3f5;
}

.search-result-item:hover {
  background: var(--ctsa-bg);
}

/* ---- Province / Servizi: layer-item con toggle a pillola ---- */
.layer-item {
  background: var(--ctsa-bg);
  border: 1px solid var(--ctsa-border);
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s;
  cursor: pointer;
}

.layer-item:hover {
  background: #e9ecef;
  border-color: var(--ctsa-blue);
}

.layer-item.active {
  background: var(--ctsa-blue-light);
  border-color: var(--ctsa-blue);
}

.layer-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.layer-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  color: #fff;
  font-weight: 700;
  overflow: hidden;
}

.layer-icon img.stemma-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.layer-icon svg {
  width: 18px;
  height: 18px;
}

.layer-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ctsa-ink);
}

.layer-type {
  font-size: 10.5px;
  color: var(--ctsa-muted);
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  background: #ced4da;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.3s;
  flex-shrink: 0;
}

.toggle-switch.active {
  background: var(--ctsa-blue);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active::after {
  transform: translateX(18px);
}

/* ---- Comuni meno serviti (classifica) ---- */
.underserved-list .u-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 4px;
  background: #fff5f5;
  border: 1px solid #ffd6d6;
  cursor: pointer;
}

.underserved-list .u-item:hover {
  background: #ffe8e8;
}

.underserved-list .u-name {
  font-weight: 600;
  color: var(--ctsa-ink);
}

.underserved-list .u-badge {
  font-size: 10.5px;
  font-weight: 700;
  color: #c0392b;
  white-space: nowrap;
}

/* ---- Paternità dei dati (sostituisce il logo AGID del riferimento) ---- */
.footer-source-box {
  background: var(--ctsa-bg);
  border: 1px solid var(--ctsa-border);
  border-radius: 8px;
  padding: 10px 12px;
}

/* ---- tabella fonti dati (scheda Info) ---- */
.source-table {
  background: var(--ctsa-bg);
  border: 1px solid var(--ctsa-border);
  border-radius: 8px;
  padding: 4px 12px;
}

.source-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--ctsa-border);
  font-size: 11.5px;
}

.source-row:last-child {
  border-bottom: none;
}

.source-row .k {
  color: var(--ctsa-ink);
}

.source-row .v {
  color: var(--ctsa-muted);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.footer-source-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--ctsa-navy);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-source-box .footer-caption {
  font-size: 10.5px;
  color: var(--ctsa-muted);
  line-height: 1.5;
}

.footer-source-box code {
  font-size: 10px;
  background: #e9ecef;
  padding: 1px 4px;
  border-radius: 3px;
}

.stats-pane {
  padding: 1.25rem 1.5rem 2.5rem;
  background: var(--ctsa-bg);
}

.stats-pane-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ctsa-navy);
  margin-bottom: 0.9rem;
}

/* ---- avviso di completezza dati, pannello chiudibile sopra la mappa ---- */
.data-disclaimer {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 1100;
  max-width: min(640px, calc(100% - 380px));
  background: #fff8e8;
  border: 1px solid #f0c675;
  color: #6b4a12;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  padding: 10px 34px 10px 14px;
  font-size: 11.5px;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.data-disclaimer i.fa-triangle-exclamation {
  color: #c07a1f;
  margin-top: 1px;
  flex-shrink: 0;
}

.data-disclaimer a {
  color: #8a5a10;
  font-weight: 700;
}

.data-disclaimer.hidden {
  display: none;
}

.data-disclaimer-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: transparent;
  color: #8a5a10;
  cursor: pointer;
  font-size: 12px;
  padding: 4px;
}

@media (max-width: 900px) {
  .data-disclaimer {
    max-width: calc(100% - 32px);
    left: 16px;
    right: 16px;
    transform: none;
  }
}

.kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0 0 1.25rem;
}

.kpi-card {
  background: #fff;
  border: 1px solid var(--ctsa-border);
  border-left: 3px solid var(--ctsa-blue);
  border-radius: var(--ctsa-radius);
  box-shadow: var(--ctsa-shadow);
  padding: 0.85rem 1.1rem;
  flex: 1 1 160px;
  min-width: 150px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.1);
}

.kpi-card .value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ctsa-navy);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.kpi-card .label {
  font-size: 0.7rem;
  color: var(--ctsa-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 0.15rem;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.card {
  border: 1px solid var(--ctsa-border);
  border-radius: var(--ctsa-radius);
  box-shadow: var(--ctsa-shadow);
}

.card-body {
  padding: 1.1rem 1.2rem;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ctsa-navy);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card-title::before {
  content: "";
  width: 3px;
  height: 0.9rem;
  background: var(--ctsa-blue);
  border-radius: 2px;
  display: inline-block;
}

.legend {
  background: #fff;
  border: 1px solid var(--ctsa-border);
  border-radius: var(--ctsa-radius);
  padding: 0.7rem 0.8rem;
}

.legend-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ctsa-muted);
  margin-bottom: 0.4rem;
  font-weight: 700;
}

.legend div.row-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.76rem;
  color: var(--ctsa-ink);
  padding: 4px 2px;
  margin-bottom: 3px;
  border-bottom: 1px solid #f1f3f5;
}

.legend div.row-item:last-child {
  margin-bottom: 0;
  border-bottom: none;
}

.legend .swatch {
  width: 12px;
  height: 12px;
  margin-right: 0;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.legend .swatch.square {
  border-radius: 3px;
}

.chart-note {
  font-size: 0.72rem;
  color: var(--ctsa-muted);
  margin: 0.5rem 0 0;
}

/* ---------- Etichette comuni sulla mappa (Leaflet tooltip permanenti) ---------- */
.municipality-label {
  background: rgba(255, 255, 255, 0.85);
  border: none;
  box-shadow: none;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--ctsa-navy);
  padding: 0 3px;
  white-space: nowrap;
}

.municipality-label::before {
  display: none;
}

/* ---------- Popup Leaflet, coerenti con la palette ---------- */
.leaflet-popup-content-wrapper {
  border-radius: 8px;
  box-shadow: var(--ctsa-shadow);
}

.popup-title {
  font-weight: 700;
  color: var(--ctsa-navy);
  margin-bottom: 0.3rem;
  font-size: 0.92rem;
}

.popup-row {
  font-size: 0.8rem;
  color: var(--ctsa-ink);
  margin: 0.15rem 0;
}

.popup-row .k {
  color: var(--ctsa-muted);
  margin-right: 0.3rem;
}

.popup-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.05rem 0.4rem;
  border-radius: 3px;
  background: var(--ctsa-blue-light);
  color: var(--ctsa-blue);
  margin-top: 0.3rem;
}

.popup-warn {
  display: inline-block;
  font-size: 0.7rem;
  color: #9a5b12;
  background: rgba(154, 91, 18, 0.1);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  margin-top: 0.3rem;
}

/* ---------- Popup comune: solo simbolo + nome + situazione servizi ---------- */
.popup-comune {
  min-width: 190px;
}

.popup-comune-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.4rem;
}

.popup-comune-symbol {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ctsa-navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.popup-comune-symbol img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.popup-comune-name {
  font-weight: 700;
  color: var(--ctsa-navy);
  font-size: 0.95rem;
}

.popup-service-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ctsa-ink);
  margin: 0.15rem 0;
}

.popup-service-row .count {
  margin-left: auto;
  font-weight: 700;
  color: var(--ctsa-navy);
}

.popup-service-row.zero {
  color: var(--ctsa-muted);
}

/* ---------- Fabbisogno territoriale ---------- */
.fabbisogno-result {
  background: #fff;
  border: 1px solid var(--ctsa-border);
  border-left: 3px solid var(--ctsa-blue);
  border-radius: var(--ctsa-radius);
  padding: 0.7rem 0.8rem;
  font-size: 0.8rem;
  display: none;
}

.fabbisogno-result.visible { display: block; }

.fabbisogno-result .big {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ctsa-navy);
  font-variant-numeric: tabular-nums;
}

.fabbisogno-result .note {
  color: var(--ctsa-muted);
  font-size: 0.72rem;
  margin-top: 0.3rem;
  line-height: 1.4;
}

/* ---------- Icone pin dei servizi (marker SVG per categoria) ---------- */
.service-pin {
  filter: drop-shadow(0 1px 2px rgba(16, 24, 40, 0.35));
}

.candidate-pin {
  filter: drop-shadow(0 1px 2px rgba(16, 24, 40, 0.35));
}

.legend .swatch.pin {
  width: 16px;
  height: 20px;
  border-radius: 0;
  border: none;
  background: none;
}

/* ---------- Badge stato/completezza dato, riusati nei popup ---------- */
.popup-badge.partial {
  background: rgba(154, 91, 18, 0.12);
  color: #9a5b12;
}

.popup-badge.programmed {
  background: var(--ctsa-blue-light);
  color: var(--ctsa-blue);
}

@media (max-width: 900px) {
  .brand-warning {
    display: none;
  }
  .spatiqon-center {
    display: none;
  }
  .map-pane {
    height: 78vh;
  }
  .sidebar {
    width: calc(100% - 24px);
    max-width: 340px;
  }
}
