/*========================*/
/* 1. VARIABILI E BASE    */
/*========================*/

:root {
  --green-700: #166534;
  --green-500: #22c55e;
  --yellow-400: #facc15;
  --sky-500: #0ea5e9;
  --red-500: #ef4444;
  --text: #1f2937;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e5e7eb;
  --muted: #6b7280;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, Segoe UI, Roboto, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ===============================
   Header + Nav
================================*/
.page-header {
  background: linear-gradient(135deg, var(--green-700), var(--green-500));
  color: #fff;
  padding: 32px 16px 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .15);
}

.page-title {
  font-size: clamp(1.8rem, 2.4vw, 2.6rem);
  font-weight: 800;
  text-align: center;
  letter-spacing: .5px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  margin: 0 0 12px;
}

/* Regole per la navigazione principale e il sottomenu */
.main-nav {
  background: rgba(0, 0, 0, .12);
  backdrop-filter: blur(2px);
}

.main-menu {
  list-style: none;
  margin: 0;
  padding: 10px 16px;
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  position: relative; /* Importante per posizionare correttamente il sottomenu */
}

.main-menu li {
    position: relative;
}

/* Stile per le voci di primo livello non cliccabili (<span>) */
.main-menu .has-submenu > span {
  color: #fff;
  font-weight: 700;
  padding: .4rem .75rem;
  border-radius: 8px;
  cursor: default;
  pointer-events: none; /* Disabilita completamente il click */
  transition: transform .15s ease, background .25s ease, color .25s ease;
  display: block; /* Rende lo span un blocco per il padding */
}

/* Stile per i link di secondo livello nel sottomenu */
.main-menu .submenu {
    display: none; /* Nasconde il sottomenu di default */
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    min-width: 160px;
    background-color: var(--card);
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 10px;
}

.main-menu .has-submenu:hover .submenu {
    display: block; /* Mostra il sottomenu al passaggio del mouse */
}

.main-menu .submenu a {
    color: var(--text);
    text-decoration: none;
    display: block;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.main-menu .submenu a:hover {
    background-color: var(--line);
    color: var(--sky-500);
}

/* Stile per i link standard del menu principale */
.main-menu > li > a {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    padding: .4rem .75rem;
    border-radius: 8px;
    transition: transform .15s ease, background .25s ease, color .25s ease;
    display: inline-block;
}

.main-menu > li > a:hover {
  background: rgba(255, 255, 255, .12);
  color: #fff;
  transform: translateY(-1px);
}

/* Fine nuove regole per il menu */

/* ===============================
   Menu a tendina (sotto header)
================================*/
.menu-dropdown select {
  display: block;
  margin: 18px auto 10px;
  width: min(100%, 420px);
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid #d1d5db;
  background: #fff;
  font-size: 1rem;
  transition: border .25s, box-shadow .25s;
}

.menu-dropdown select:focus {
  border-color: var(--sky-500);
  box-shadow: 0 0 0 6px rgba(14, 165, 233, .15);
  outline: 0;
}
/* ===============================
   FIX MENU MOBILE + SUBMENU
================================*/

@media (max-width: 768px) {
  .hamburger-menu {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    padding: 10px;
  }

  .hamburger-menu .bar {
    height: 3px;
    width: 28px;
    background-color: #fff;
    margin: 4px 0;
    border-radius: 2px;
  }

  .main-menu {
    display: none;
    flex-direction: column;
    background: rgba(22, 101, 52, 0.95); /* verde scuro semitrasparente */
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    padding: 0;
    margin: 0;
    z-index: 999;
  }

  .main-menu.active {
    display: flex;
  }

  .main-menu li {
    text-align: left;
    width: 100%;
  }

  .main-menu > li > a,
  .main-menu .has-submenu > span {
    display: block;
    padding: 14px 20px;
    width: 100%;
    color: #fff;
    cursor: pointer;
  }

  /* submenu */
  .submenu {
    display: none;
    flex-direction: column;
    background: rgba(250, 204, 21, 0.9); /* giallo chiaro semitrasparente */
    padding: 0;
    position: static;
    box-shadow: none;
    border-radius: 0;
    width: 100%;
  }

  .main-menu li.open > .submenu {
    display: flex;
  }

  .submenu a {
    color: #1f2937; /* testo scuro per leggibilità */
    padding: 12px 20px;
    display: block;
    border-top: 1px solid rgba(0,0,0,0.1);
  }

  .submenu a:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #000;
  }
}


/*========================*/
/* 5. FORM A SCOMPARSA    */
/*========================*/

.collapsible {
  margin-top: 5px;
  margin-bottom: 5px;
  width: 100%;
  background: var(--green-700);
  color: #fff;
  border: 0;
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, .12);
  transition: filter .2s, transform .1s;
}

.collapsible:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.chevron {
  transition: transform 0.3s ease-in-out;
}

.chevron.rot {
  transform: rotate(180deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.form-inner-content {
  margin-top: 20px;
  background: #fff;
  border-left: 4px solid var(--green-500);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
}

.collapsible-content form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-field label {
  font-weight: 700;
  color: var(--text);
  display: block;
  margin-bottom: 8px;
}

.form-field input, .form-field select {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  transition: border .2s, box-shadow .2s;
}

.form-field input:focus, .form-field select:focus {
  outline: 0;
  border-color: var(--sky-500);
  box-shadow: 0 0 0 6px rgba(14, 165, 233, .12);
}

.form-field textarea {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    transition: border .2s, box-shadow .2s;
}

.form-field textarea:focus {
    outline: 0;
    border-color: var(--sky-500);
    box-shadow: 0 0 0 6px rgba(14, 165, 233, .12);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

@media (max-width: 599px) {
  .collapsible-content form {
    grid-template-columns: 1fr;
  }
}

/*========================*/
/* 6. PULSANTI E LINK     */
/*========================*/

.btn-primary {
  background: var(--sky-500);
  color: #fff;
  border: 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .1s, filter .2s;
  box-shadow: 0 10px 20px rgba(14, 165, 233, .25);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.btn-action {
  background: #f3f4f6;
  border: 0;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: transform .1s, background .2s;
  text-decoration: none;
}

.btn-action:hover {
  transform: scale(1.08);
  background: #e5e7eb;
}

.btn-action.edit {
  color: var(--green-500);
}

.btn-action.copy {
  color: var(--sky-500);
}

.btn-action.info {
  color: var(--yellow-400);
}

.btn-action.open {
  color: #0284c7;
}

.btn-action.close {
  color: #475569;
}

.btn-action.delete {
  color: var(--red-500);
}

.legend {
  margin: 10px 0 24px;
  color: var(--muted);
  font-weight: 700;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.legend .green {
  color: var(--green-500);
}

.legend .yellow {
  color: var(--yellow-400);
}

.legend .celeste {
  color: var(--sky-500);
}

.legend .red {
  color: var(--red-500);
}

/*========================*/
/* 7. TABELLE (versione fluida) */
/*========================*/

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* scroll fluido su iOS */
  box-shadow: 0 10px 24px rgba(0, 0, 0, .06);
  border-radius: 12px;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
  border-radius: 12px;
  min-width: 600px; /* evita che si stringa troppo */
}

.data-table thead th {
  background: var(--green-700);
  color: #fff;
  text-transform: uppercase;
  font-weight: 800;
  font-size: clamp(0.8rem, 1.5vw, 1rem);
  padding: clamp(8px, 1.2vw, 14px);
  text-align: left;
  white-space: nowrap;
}

.data-table tbody td {
  padding: clamp(6px, 1vw, 12px) clamp(8px, 1.5vw, 16px);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: clamp(0.8rem, 1.2vw, 0.95rem);
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 220px; /* controlla la larghezza massima del contenuto */
  white-space: nowrap;
}

.data-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.data-table tbody tr:hover {
  background: #f1f5f9;
}

/* Colonna Azioni */
td.actions .actions-wrap {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

td.actions .btn-action {
  flex: 0 0 auto;
}

/* Breakpoints adattivi */
@media (max-width: 1024px) {
  .data-table {
    min-width: 500px;
  }
}

@media (max-width: 768px) {
  .data-table {
    min-width: 400px;
  }
  .data-table td,
  .data-table th {
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .data-table {
    min-width: 320px;
  }
  .data-table td,
  .data-table th {
    font-size: 0.75rem;
    padding: 6px 8px;
  }
}

/*========================*/
/* 8. DASHBOARD CARDS     */
/*========================*/

.dashboard {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 40px auto;
  flex-wrap: wrap;
  max-width: 1000px;
}

.card {
  flex: 1 1 250px;
  background: #f9f9f9;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 16px 36px rgba(0, 0, 0, .14);
}

.card.green h3,
.card.green p {
    color: #28a745;
}

.card.yellow h3,
.card.yellow p {
    color: #ffc107;
}

.card.red h3,
.card.red p {
    color: #dc3545;
}

/*========================*/
/* 9. FOOTER              */
/*========================*/

.footer {
  padding: 24px 16px;
  text-align: center;
  background: #e6f7ff;
}

.footer-menu {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-bottom: 6px;
}

.footer-menu a {
  margin: 0 12px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
}

.footer-menu a:hover {
  color: var(--sky-500);
}

/* NUOVE REGOLE AGGIUNTE */
.details-card {
  margin: 20px 0;
}

/*========================*/
/* 10. REGOLE PER MODAL   */
/*========================*/
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.6);
  backdrop-filter: blur(5px);
  padding-top: 60px;
}

/*========================*/
/* 11. REGOLE DI ALLINEAMENTO */
/*========================*/
.legend,
.email-form {
    max-width: 600px;
    margin: 20px auto;
    text-align: center;
}

.modal-content {
  background-color: var(--card);
  margin: 5% auto;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 10px 20px rgba(0,0,0,0.25);
  width: min(90%, 600px);
  animation: fadeIn 0.3s ease-out;
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-content h3 {
  margin: 0 0 16px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 8px;
  color: var(--green-700);
}

.close-button {
  color: var(--muted);
  float: right;
  font-size: 2rem;
  font-weight: bold;
  position: absolute;
  top: 10px;
  right: 20px;
  cursor: pointer;
  transition: color 0.2s;
}

.close-button:hover,
.close-button:focus {
  color: var(--red-500);
  text-decoration: none;
  cursor: pointer;
}

.pesate-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--line);
  padding: 10px;
  margin-bottom: 20px;
  background: #fcfcfc;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pesate-list label {
  display: block;
  padding: 8px;
  border-radius: 6px;
  background: #f9f9f9;
  cursor: pointer;
  transition: background 0.2s;
}

.pesate-list label:hover {
  background: #f1f5f9;
}

.pesate-list input[type="checkbox"] {
  margin-right: 10px;
}

/* Stile unificato per le notifiche (successo e errore) */
.notification-container {
    margin-top: 5px;
    margin-bottom: 5px;
}

.notification {
    padding: 15px;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease-in-out;
}

.notification.success {
    background-color: #e6f7ec;
    color: #28a745;
    border: 1px solid #c3e6cb;
}

.notification.error {
    background-color: #fcebeb;
    color: #dc3545;
    border: 1px solid #f5c6cb;
}

.navigation-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.week-info {
    font-weight: bold;
    color: var(--green-700);
}

.navigation-buttons .btn-primary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
}

/*
 * ==========================================================
 * CORREZIONE ESSENZIALE PER I BADGE DELLO STATO (PUNTO 12)
 * Rende le icone e il testo NERI per contrasto su sfondo colorato.
 * ==========================================================
 */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 50px;
    font-size: 0.85em;
    font-weight: 700;
    white-space: nowrap;
}

.status-paid {
    background-color: var(--green-500);
    /* Correzione: usare il colore del testo scuro per visibilità */
    color: var(--text); 
}

.status-rejected {
    background-color: var(--red-500);
    /* Correzione: usare il colore del testo scuro per visibilità */
    color: var(--text);
}

.status-pending {
    background-color: var(--yellow-400);
    color: var(--text); /* Già corretto */
}

/* ==============================
   CORREZIONI PER TABELLE + AZIONI
=================================*/
@media (max-width: 767px) {
  .data-table, 
  .data-table tbody, 
  .data-table tr, 
  .data-table td, 
  .data-table thead {
    display: table !important;
    width: auto !important;
  }

  .data-table thead {
    display: table-header-group !important;
  }

  .data-table tbody {
    display: table-row-group !important;
  }

  .data-table tr {
    display: table-row !important;
  }

  .data-table td {
    display: table-cell !important;
    white-space: nowrap;
  }

  .data-table td::before {
    content: none !important;
  }

  /* Azioni sempre sulla stessa riga */
  td.actions .actions-wrap {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 6px;
    overflow-x: auto;
  }

  td.actions .btn-action {
    flex: 0 0 auto;
  }
}

/*======================================================*/
/* 14. STILE LINK ID SCHEDA */
/*======================================================*/

/* Rende l'ID della scheda un link chiaro e distinto */
.scheda-id-link {
    font-weight: 700;
    color: var(--green-700) !important; /* Usa il verde scuro del tema */
    text-decoration: none;
    transition: color 0.2s;
    cursor: pointer;
}

.scheda-id-link:hover {
    color: var(--green-500) !important; /* Diventa verde brillante al passaggio del mouse */
    text-decoration: underline;
}

/*======================================================*/
/* 15. RICONCILIAZIONE LARGHZZA COLONNE (Forza layout fisso) */
/*======================================================*/

/* * Larghezze Colonne Ottimizzate (Totale 100%)
 * 1: Checkbox (3%) | 2: ID (5%) | 3: Data (8%) | 4: Squadra (13%) | 5: Luogo (13%) | 
 * 6: Acquirente (13%) | 7: DDT (8%) | 8: Quintali (9%) | 9: Azioni (28%) 
 */

.data-table thead th:nth-child(1), .data-table tbody td:nth-child(1) { width: 3%; } 
.data-table thead th:nth-child(2), .data-table tbody td:nth-child(2) { width: 5%; }
.data-table thead th:nth-child(3), .data-table tbody td:nth-child(3) { width: 8%; }
.data-table thead th:nth-child(4), .data-table tbody td:nth-child(4) { width: 13%; }
.data-table thead th:nth-child(5), .data-table tbody td:nth-child(5) { width: 13%; }
.data-table thead th:nth-child(6), .data-table tbody td:nth-child(6) { width: 13%; }
.data-table thead th:nth-child(7), .data-table tbody td:nth-child(7) { width: 8%; }
.data-table thead th:nth-child(8), .data-table tbody td:nth-child(8) { width: 9%; }
.data-table thead th:nth-child(9), .data-table tbody td:nth-child(9) { width: 28%; } 

/* Centra i bottoni Azioni anche per la testa della tabella (per coerenza) */
.data-table thead th:nth-child(9) {
    text-align: center;
}

/* =================================================================
   16. SEPARATORE MENU (menu-divider)
   ================================================================= */

/* Regole di base per il separatore all'interno di un sottomenu */
.submenu .menu-divider {
    /* Rimuove ogni spaziatura ereditata */
    padding: 0;
    
    /* Aggiunge spazio sopra e sotto la riga per separare le voci */
    margin: 5px 0; 
    
    /* Altezza e aspetto della riga */
    height: 1px;  
    background-color: var(--line); /* Usa la variabile CSS per il colore del bordo */
    
    /* Assicura che non sia un elemento cliccabile e non abbia pallini di lista */
    list-style: none; 
    pointer-events: none; 
    width: 100%;
}

/* Regola specifica per il menu in modalità mobile.
   Assumendo che in mobile il background del sottomenu sia più scuro,
   definiamo un separatore più scuro per un miglior contrasto. */
@media (max-width: 768px) {
  /* Dato che il sottomenu è su uno sfondo potenzialmente colorato o scuro */
  .main-menu li.open > .submenu .menu-divider {
    background-color: var(--muted); /* Usa un grigio più scuro per maggiore visibilità */
  }
}