/* ==========================
   VARIABILI GLOBALI :root
   ==========================
   Definizione di variabili personalizzate per un tema coerente e facile da mantenere.
   Questo approccio rende semplice cambiare i colori, le ombre e le spaziatura
   dell'intera applicazione modificando solo questi valori. */
:root {
  --header-footer-bg: #2c3e50; /* Colore sfondo intestazione e piè di pagina, un grigio scuro-bluastro. */
  --main-accent-color: #3498db; /* Colore principale (accento), un blu acceso. */
  --secondary-text-color: #7f8c8d; /* Colore testo secondario, un grigio chiaro. */
  --table-header-bg: #34495e; /* Sfondo intestazione tabella, un grigio scuro. */
  --table-stripe-color: rgba(52, 152, 219, 0.05); /* Colore righe alternate tabella, un blu molto trasparente. */
  --light-bg: #f4f7f6; /* Sfondo chiaro generico, un grigio molto chiaro. */
  --white-color: #ffffff; /* Colore bianco. */
  --shadow-light: 0 2px 10px rgba(0,0,0,0.05); /* Ombra leggera per dare profondità. */
  --shadow-medium: 0 8px 25px rgba(0,0,0,0.1); /* Ombra media, più pronunciata. */
  --card-bg: #ffffff; /* Sfondo card, bianco. */
  --border-color: #e0e6eb; /* Colore bordi, un grigio-azzurro molto chiaro. */
  --success-data-color: #209450; /* Verde per dati validi/di successo. */
  --incomplete-data-color: #e67e22; /* Arancione per dati incompleti/attenzione. */
  --today-data-color: #3498db; /* Azzurro per dati di oggi (uguale al colore principale). */
}

/* ==========================
   STILE TABELLA HOME MODERNA
   ==========================
   Stile generale per le tabelle.
   `border-collapse: separate` e `border-spacing: 0` permettono di usare `border-radius`
   sulla tabella stessa, creando angoli arrotondati.
   `overflow: hidden` nasconde i bordi che eccedono l'angolo arrotondato. */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  background-color: var(--white-color);
  font-family: 'Poppins', sans-serif;
}

/* ==========================
   INTESTAZIONE TABELLA
   ==========================
   Stili specifici per l'intestazione (header) della tabella. */
.table thead th {
  background-color: var(--table-header-bg) !important;
  color: var(--white-color) !important;
  border-color: var(--table-header-bg) !important;
  padding: 1rem 1.2rem;
  font-weight: 600; /* Testo in grassetto. */
  text-transform: uppercase; /* Testo tutto in maiuscolo. */
  letter-spacing: 0.05em; /* Spaziatura tra le lettere. */
  font-size: 0.9rem;
  vertical-align: middle;
  text-align: center;
}

/* ==========================
   CORPO TABELLA
   ==========================
   Stili per le celle del corpo della tabella. */
.table tbody td {
  padding: 0.9rem 1.2rem;
  font-size: 0.95rem; /* leggermente più grande */
  vertical-align: middle;
  text-align: center;
  color: #2c3e50; /* Colore testo scuro. */
  font-weight: 500;
  font-variant-numeric: tabular-nums; /* Allinea i numeri in colonna anche se hanno larghezza diversa. */
}

/* ==========================
   RIGHE ALTERNATE
   ==========================
   Utilizza lo pseudo-selettore `:nth-child(odd)` per dare un colore di sfondo
   diverso alle righe dispari, migliorando la leggibilità. */
.table tbody tr:nth-child(odd) {
 background-color: var(--table-stripe-color);
}

/* ==========================
   EFFETTO HOVER
   ==========================
   Cambia il colore di sfondo della riga quando il mouse ci passa sopra,
   fornendo un feedback visivo all'utente. */
.table tbody tr:hover {
 background-color: rgba(31, 58, 147, 0.12);
 transition: background-color 0.2s ease-in-out;
}

/* ==========================
   COLORI PER COLONNE SPECIFICHE
   ==========================
   Stili specifici per singole colonne della tabella, usando `:nth-child()`. */
.table td:nth-child(3) { /* Obiettivo */
  color: #000000 !important; /* Nero */ 
  font-weight: 700;
}

.table td:nth-child(4) { /* Validi */
  color: var(--success-data-color) !important;
  font-weight: 700;
}

.table td:nth-child(5) { /* Incompleti */
  color: var(--incomplete-data-color) !important;
  font-weight: 700;
}

.table td:nth-child(6) { /* Oggi */
  color: var(--today-data-color) !important;
  font-weight: 700;
}
/* ==========================
   STILE GENERALE BODY
   ==========================
   Stili applicati a tutto il corpo del documento.
   `display: flex` e `flex-direction: column` insieme a `min-height: 100vh`
   assicurano che il footer rimanga sempre in fondo alla pagina. */
body {
  font-family: 'Poppins', sans-serif;
  background-color: var(--light-bg);
  color: #34495e;
  display: flex;
  flex-direction: column;
  min-height: 100vh; /* Assicura altezza piena */
}

/* ==========================
   NAVBAR PERSONALIZZATA
   ==========================
   Stili per la barra di navigazione. `position: sticky` la mantiene visibile
   in cima anche durante lo scroll. */
.navbar-custom {
  background-color: var(--header-footer-bg);
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow-medium);
  position: sticky;
  top: 0; /* Fissa in alto */
  z-index: 1000; /* Sopra altri elementi */
}

.navbar-brand {
  font-weight: 500;
  font-size: 1.85rem;
  color: var(--white-color) !important;
  display: flex;
  align-items: center;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.navbar-brand img {
  height: 65px;
  margin-right: 12px;
}

.navbar-title {
  color: var(--white-color);
  font-size: 1.5rem;
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* ==========================
   STRUTTURA PRINCIPALE
   ==========================
   Stili per il contenitore principale della pagina.
   `flex: 1` fa sì che il `main` si espanda per occupare tutto lo spazio disponibile,
   spingendo il footer in basso. */
main {
  flex: 1;
  padding: 40px 0;
}

.main-container {
  width: 100%;
  padding: 0 20px;
}

/* Layout contenuti dashboard */
.dashboard-content-layout {
  display: flex;
  flex-direction: column;
  gap: 30px; /* Spazio tra gli elementi figli. */
  background-color: var(--card-bg);
  padding: 40px 50px;
  border-radius: 12px;
  box-shadow: var(--shadow-medium);
  border: 1px solid rgba(0,0,0,0.05);
  margin-top: 20px;
}

/* ==========================
   SEZIONI TITOLI
   ==========================
   Stili per i titoli delle sezioni principali (KPI e visualizzazioni). */
.kpi-section h2,
.data-visualization-section h2 {
  color: var(--main-accent-color);
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid rgba(52,152,219,0.3);
  padding-bottom: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ==========================
   TITOLI TABELLE COLLASSABILI
   ==========================
   Stili per i titoli che fungono da trigger per i pannelli collassabili.
   Il `cursor: pointer` e l'effetto `hover` indicano che sono interattivi. */
.table-title {
  font-size: 1.5rem;
  color: var(--header-footer-bg);
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: color 0.2s ease-in-out;
}

.table-title:hover {
  color: var(--main-accent-color);
}

.table-title .bi {
 transition: transform 0.3s ease-in-out;
}

.table-title[aria-expanded="true"] .bi-chevron-down {
 transform: rotate(-180deg); /* Ruota l'icona quando il pannello è aperto. */
}

.table-title[aria-expanded="false"] .bi-chevron-down {
 transform: rotate(0deg); /* L'icona torna nella sua posizione originale. */
}

/* ==========================
   KPI CARDS
   ==========================
   Stili per le card che mostrano i Key Performance Indicator. */
.kpi-grid {
 display: grid;
 grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); /* Layout reattivo a griglia. */
 gap: 15px;
}

.kpi-card {
  background-color: var(--light-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  box-shadow: var(--shadow-light);
  transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.kpi-card:hover {
  transform: translateY(-3px); /* Effetto "alza" la card al passaggio del mouse. */
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.kpi-card .icon {
  font-size: 1.5rem;
  margin-bottom: 5px;
  color: var(--main-accent-color);
}

.kpi-card .value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--header-footer-bg);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* Punti di sospensione per testo lungo. */
}

.kpi-card .label {
  font-size: 0.7rem;
  color: var(--secondary-text-color);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================
   TABELLA PANDAS STILIZZATA
   ==========================
   Stili per le tabelle generate da librerie come Pandas in Python.
   L'uso di `!important` qui è utile per sovrascrivere gli stili predefiniti. */
.table-container {
 margin-top: 20px;
 margin-bottom: 30px;
}

table.dataframe {
  width: 100% !important;
  border-collapse: separate !important;
  border-spacing: 0 !important;
  margin-top: 10px !important;
  font-size: 0.7rem !important;
  box-shadow: var(--shadow-medium) !important;
  border-radius: 12px !important;
  overflow: hidden !important;
  background-color: var(--card-bg) !important;
  border: 1px solid var(--border-color) !important;
}

table.dataframe th,
table.dataframe td {
  padding: 6px 10px !important;
  border-bottom: 1px solid var(--border-color) !important;
  border-right: 1px solid var(--border-color) !important;
  text-align: left !important;
  vertical-align: middle !important;
}

table.dataframe th:last-child,
table.dataframe td:last-child {
  border-right: none !important;
}

table.dataframe th:first-child,
table.dataframe td:first-child {
  font-weight: 500 !important;
  color: var(--header-footer-bg) !important;
  background-color: rgba(52,152,219,0.03) !important;
}

table.dataframe th {
  background-color: var(--table-header-bg) !important;
  color: var(--white-color) !important;
  font-weight: 600 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
  position: sticky !important;
  top: 0 !important; /* Fissa l'intestazione in cima al contenitore. */
  z-index: 1 !important;
}

table.dataframe tbody tr:nth-child(odd) {
  background-color: var(--table-stripe-color) !important;
}

table.dataframe tbody tr:hover {
  background-color: rgba(52,152,219,0.15) !important;
  transition: background-color 0.2s ease-in-out !important;
}

/* ==========================
   GRAFICI
   ==========================
   Stili per i contenitori dei grafici. */
.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
  margin-bottom: 20px;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 15px;
  box-shadow: var(--shadow-light);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chart-container canvas {
  flex-grow: 1; /* Permette al canvas di occupare lo spazio disponibile. */
  width: 100% !important;
  height: auto !important;
}

.chart-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

/* ==========================
   FOOTER
   ==========================
   Stili per il piè di pagina. `margin-top: auto` lo spinge in basso
   grazie al `flexbox` sul `body`. */
.footer {
  background-color: var(--header-footer-bg);
  color: var(--white-color);
  padding: 1.5rem 0;
  text-align: center;
  margin-top: auto;
  box-shadow: 0 -5px 15px rgba(0,0,0,0.1);
  border-top: 1px solid rgba(255,255,255,0.1);
}

.footer p {
  margin: 0;
  font-size: 0.8rem;
  color: #bdc3c7;
}

/* ==========================
   TIMESTAMP
   ==========================
   Stili per il timestamp di aggiornamento. */
.timestamp {
 font-size: 0.9rem;
 color: var(--secondary-text-color);
 text-align: left;
 margin-top: -15px;
 margin-bottom: 15px;
 padding-left: 20px;
}

/* ==========================
   RESPONSIVE DESIGN
   ==========================
   Media queries per adattare il layout a diverse dimensioni dello schermo. */

/* Desktop grandi */
@media (min-width:1200px) {
  .navbar-title { font-size: 1.8rem; }
}

/* Tablet / schermi medi */
@media (max-width:992px) {
  .dashboard-content-layout { padding: 25px 20px; }
  .kpi-section h2, .data-visualization-section h2 { font-size: 1.5rem; }
  .kpi-card .value { font-size: 1.4rem; }
  table.dataframe th, table.dataframe td {
   padding: 5px 8px !important;
   font-size: 0.65rem !important;
  }
  .chart-container { height: 250px; }
  .timestamp { font-size: 0.8rem; padding-left: 0; }
  .navbar-title { display: none; } /* Nasconde il titolo della navbar. */
  .table-title { font-size: 1.3rem; }
  .navbar-brand img { height: 50px; }
}

/* Smartphone */
@media (max-width:768px) {
 .navbar-brand { font-size: 1.3rem; }
 .navbar-brand img { height: 40px; }
 h1 { font-size: 2rem; margin-bottom: 2rem; }
 .kpi-card { padding: 10px; }
 .kpi-card .icon { font-size: 1.5rem; }
 .kpi-card .value { font-size: 1.1rem; }
 .kpi-card .label { font-size: 0.65rem; }
 .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }
 table.dataframe th, table.dataframe td {
  padding: 4px 6px !important;
  font-size: 0.6rem !important;
 }
}

/* ==========================
   LOGIN
   ==========================
   Stili specifici per la pagina di login. */

.login-container {
 flex: 1;
 display: flex;
 align-items: center;
 justify-content: center;
 padding: 60px 20px;
}
.login-box {
  background-color: var(--white-color);
  padding: 40px 35px;
  border-radius: 12px;
  box-shadow: var(--shadow-medium);
  width: 100%;
  max-width: 420px;
}
.login-box h2 {
  font-weight: 600;
  margin-bottom: 30px;
  color: var(--header-footer-bg);
  text-align: center;
}
.btn-primary {
  background-color: var(--main-accent-color);
  border: none;
  font-weight: 500;
}
.btn-primary:hover {
  background-color: #2980b9;
}
.form-control {
  font-size: 0.95rem;
}
.form-label {
  font-weight: 500;
}
.text-danger {
  font-size: 0.9rem;
}
.toggle-password {
  border: none;
  background: transparent;
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: #6c757d;
}
.position-relative {
  position: relative;
}
.loading-spinner {
 display: flex;
 justify-content: center;
 align-items: center;
 height: 100px;
}
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================
   ACCESSIBILITÀ
   ==========================
   Miglioramenti per l'accessibilità e la navigazione da tastiera. */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Focus visibile per navigazione da tastiera */
.kpi-card:focus,
[data-bs-toggle="collapse"]:focus,
.btn:focus,
.navbar-brand:focus {
  outline: 2px solid #007bff; /* Evidenzia l'elemento con un bordo blu. */
  outline-offset: 2px;
}

/* Miglior contrasto per i tooltip */
.tooltip {
  font-size: 14px;
}

/* Indicatore di caricamento accessibile */
.loading-spinner[role="status"] {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100px;
}

/* Migliore spaziatura per i pulsanti dei grafici */
.chart-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  justify-content: center;
} 

/* Stile per le tabelle collassabili */
.table-title[role="button"] {
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.table-title[role="button"]:hover,
.table-title[role="button"]:focus {
  background-color: rgba(0,123,255,0.1);
}

/* ==========================
   NAVBAR RESPONSIVE
   ==========================
   Stili specifici per la responsività del logo e del titolo della navbar. */

.navbar-brand img {
  height: auto;
  width: auto;
  max-height: 60px; /* Desktop */
}
@media (max-width: 992px) { /* Tablet */
 .navbar-brand img {
 max-height: 50px;
  }
}
@media (max-width: 576px) { /* Mobile */
  .navbar-brand img {
  max-height: 40px;
 }
}
/* Titolo */
.navbar-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50%;
}
/* Timestamp */
.navbar-timestamp {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  text-align: right;
}
.navbar-timestamp i {
  margin-right: 0.25rem;
}
/* Navbar doppia riga */
.navbar-row {
  width: 100%;
}






.login-container {
    min-height: calc(100vh - 200px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 0;
}
        
.login-box {
    max-width: 400px;
    width: 100%;
    padding: 2.5rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(0, 0, 0, 0.05);
}
        
.form-control:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.15);
}
        
.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s ease;
    z-index: 10;
}
        
.toggle-password:hover,
.toggle-password:focus {
    color: #0d6efd;
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}
        
.alert {
    border-radius: 8px;
    margin-bottom: 1.5rem;
}
        
.btn-primary {
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s ease;
}
        
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
}
        
.form-label {
    font-weight: 500;
    color: #495057;
    margin-bottom: 0.75rem;
}
        
        
@media (max-width: 576px) {
    .login-box {
        margin: 1rem;
        padding: 2rem;
    }
}
        
/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 1000;
}
        
.skip-link:focus {
    top: 6px;
}




.kpi-section {
    padding: 1rem;
    background-color: #ffffff;
    border-radius: 8px;
}

.kpi-section-separator {
    border: 2px solid #e0e0e0; /* Bordo attorno alla sezione */
    margin-bottom: 2rem;       /* Spazio tra le sezioni */
    box-shadow: 0px 3px 8px rgba(0,0,0,0.05);
}

.kpi-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 1rem;
    border-bottom: 2px solid #ddd; /* Riga di separazione sotto il titolo */
    padding-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.kpi-grid {
    display: grid;
    gap: 1rem;
}


.footer a {
    color: #ffffff; /* Scegli un colore chiaro per rendere il link visibile */
    text-decoration: none; /* Rimuove la sottolineatura */
}

/* Aggiungi uno stile al passaggio del mouse per una migliore esperienza utente */
.footer a:hover {
    color: #cccccc; /* Cambia colore quando il cursore passa sopra */
    text-decoration: underline; /* Opzionale: rimetti la sottolineatura solo al passaggio del mouse */
}


@keyframes gauge-fill {
  from {
    stroke-dasharray: 0 100;
  }
  to {
    /* Il 'to' verrà sovrascritto inline */
  }
}




.gauge-fill-animated path {
    animation: gauge-fill 1s ease-out forwards;
    /* La transizione è facoltativa, ma offre un fallback/transizione aggiuntiva */
    transition: stroke-dasharray 1s ease-out;
}

@keyframes gauge-fill {
    from {
        stroke-dasharray: 0 100;
    }
    to {
        /* Questo verrà impostato dinamicamente */
        stroke-dasharray: var(--gauge-value) 100;
    }
}




.kpi-card-alert {
  border: 2px solid #dc3545; /* Rosso per l'alert */
  animation: pulse-border 1.5s infinite;
}

@keyframes pulse-border {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
  }
}


.kpi-card-success {
  border: 2px solid #28a745; /* Verde per il successo */
  animation: pulse-border-success 1.5s infinite;
}

@keyframes pulse-border-success {
  0% {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
  }
}

