:root {
  --sidebar-width: 250px;
  --bs-primary: #0288d1;
  --bs-primary-rgb: 2, 136, 209;
  --brand-blue-dark: #026da8;
  --brand-blue-light: #81c4e8;
  --sidebar-bg: #0f172a;
  --sidebar-fg: #cbd5e1;
  --sidebar-active: #0288d1;
  --content-bg: #f1f5f9;
}

body {
  background: var(--content-bg);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', sans-serif;
}

/* Bootstrap definisce i colori di bottoni/focus con valori fissi per componente
   (non con var(--bs-primary)): li riallineiamo qui al blu del logo. */
.btn-primary {
  --bs-btn-bg: var(--bs-primary);
  --bs-btn-border-color: var(--bs-primary);
  --bs-btn-hover-bg: var(--brand-blue-dark);
  --bs-btn-hover-border-color: var(--brand-blue-dark);
  --bs-btn-active-bg: var(--brand-blue-dark);
  --bs-btn-active-border-color: var(--brand-blue-dark);
  --bs-btn-disabled-bg: var(--bs-primary);
  --bs-btn-disabled-border-color: var(--bs-primary);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

.btn-outline-primary {
  --bs-btn-color: var(--bs-primary);
  --bs-btn-border-color: var(--bs-primary);
  --bs-btn-hover-bg: var(--bs-primary);
  --bs-btn-hover-border-color: var(--bs-primary);
  --bs-btn-active-bg: var(--bs-primary);
  --bs-btn-active-border-color: var(--bs-primary);
  --bs-btn-disabled-color: var(--bs-primary);
  --bs-btn-disabled-border-color: var(--bs-primary);
  --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand-blue-light);
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}

.form-check-input:checked {
  background-color: var(--bs-primary);
  border-color: var(--bs-primary);
}

/* ---------- Layout con sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  overflow-y: auto;
  z-index: 1030;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  padding: 1rem 1.25rem;
  color: #fff;
  font-weight: 600;
  font-size: 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  letter-spacing: 0.3px;
}

.sidebar .brand i {
  margin-right: 0.5rem;
}

.sidebar .brand-logo {
  height: 28px;
  width: auto;
  margin-right: 0.5rem;
  vertical-align: middle;
}

.login-logo {
  height: 64px;
  width: auto;
}

.sidebar a.nav-link {
  color: var(--sidebar-fg);
  border-radius: 0.5rem;
  padding: 0.55rem 0.9rem;
  margin: 0.1rem 0.75rem;
  font-size: 0.95rem;
}

.sidebar a.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar a.nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar .nav-section {
  padding: 0.9rem 1.25rem 0.3rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
}

.sidebar .dropdown-menu {
  background: #1e293b;
  border: none;
  max-height: 60vh;
  overflow-y: auto;
}

.sidebar .dropdown-menu .dropdown-header {
  color: #94a3b8;
  font-size: 0.72rem;
  text-transform: uppercase;
}

.sidebar .dropdown-menu .dropdown-item {
  color: var(--sidebar-fg);
  font-size: 0.88rem;
  padding: 0.4rem 1rem;
}

.sidebar .dropdown-menu .dropdown-item:hover {
  background: #334155;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.85rem;
}

.content {
  margin-left: var(--sidebar-width);
  padding: 1.5rem 2rem;
  min-height: 100vh;
}

/* ---------- Topbar mobile + menu a scomparsa ---------- */
.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 1025;
  background: var(--sidebar-bg);
  color: #fff;
  padding: 0.65rem 1rem;
}

.mobile-topbar .btn-icon {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.15rem 0.4rem;
}

.mobile-topbar-logo {
  height: 26px;
  width: auto;
}

.mobile-topbar-title {
  font-weight: 600;
  letter-spacing: 0.3px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1029;
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .sidebar-backdrop.show {
    display: block;
  }

  .content {
    margin-left: 0;
    padding: 1.25rem 1rem;
  }
}

@media (max-width: 575.98px) {
  .content {
    padding: 1rem 0.75rem;
  }
}

/* ---------- Card ---- */
.card {
  border: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.1);
  border-radius: 0.75rem;
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
  border-radius: 0.75rem 0.75rem 0 0 !important;
}

.card .chart-container {
  position: relative;
  min-height: 320px;
}

.card .chart-container.map-container {
  min-height: 420px;
}

.kpi-card .kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
}

.kpi-card .kpi-label {
  color: #64748b;
  font-size: 0.85rem;
}

.kpi-card .kpi-icon {
  font-size: 1.6rem;
  opacity: 0.85;
}

/* ---------- Statistiche ---------- */
.filtri-card .row > [class*='col-'] {
  margin-bottom: 0.5rem;
}

.table-statistiche {
  font-size: 0.85rem;
}

.table-statistiche thead th {
  vertical-align: middle;
  background: #f8fafc;
  white-space: nowrap;
}

.table-statistiche .gruppo-anno {
  text-align: center;
  color: #334155;
  border-bottom: 2px solid #e2e8f0 !important;
}

.table-statistiche td, .table-statistiche th {
  border-color: #eef2f7;
}

.table-statistiche th[data-sort-key] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.table-statistiche th[data-sort-key]:hover {
  background: #eef2f7;
}

.table-statistiche .sort-icon {
  font-size: 0.7rem;
  margin-left: 0.2rem;
  color: var(--bs-primary);
}

.table-statistiche .sort-icon-idle {
  color: #cbd5e1;
}

.table-statistiche tfoot .riga-totale td {
  font-weight: 700;
  background: #f1f5f9;
  border-top: 2px solid #cbd5e1;
}

.card-anni-table {
  font-size: 0.82rem;
}

.card-anni-table thead th {
  color: #64748b;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.card-anni-table .anno-cell {
  font-weight: 700;
  color: #fff;
  background: var(--bs-primary);
  border-radius: 0.35rem;
  padding: 0.15rem 0.5rem;
  text-align: center;
}

.card-anni-table td {
  white-space: nowrap;
}

.card-mini-chart-wrap {
  height: 130px;
  margin-bottom: 0.75rem;
}

.drill-select {
  max-width: 200px;
}

/* ---------- Drill-down a cascata: breadcrumb ---------- */
#zonaBreadcrumb {
  row-gap: 0.35rem;
}

.breadcrumb-chip {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.breadcrumb-chip:hover {
  background: #eef2f7;
  border-color: var(--bs-primary);
  color: var(--bs-primary);
}

.breadcrumb-chip-corrente {
  border: 1px solid var(--bs-primary);
  background: rgba(var(--bs-primary-rgb), 0.08);
  color: var(--bs-primary);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: default;
}

.breadcrumb-sep {
  color: #94a3b8;
  font-size: 0.7rem;
}

.card-stat-item {
  height: 100%;
}

.card-stat-item .delta {
  font-size: 0.78rem;
}

.btn-group-toggle .btn {
  min-width: 72px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
}