:root {
  --accent: #2e8b57;
  --accent-dark: #236b43;
  --muted: #666;
  --bg: #f7f8fa;
  --text: #111;
  --hover: #e6f2ea;
  --border: #ddd;
  --danger: #d32f2f;
  --warning: #f57c00;
  --success: #388e3c;
  /* NOUVELLES COULEURS DE FOND POUR L'ALERTE */
  --cell-warn-bg: #fff3e0; /* Orange très clair pour > 9mm */
  --cell-error-bg: #fcc; /* Rouge clair et plus intense pour > 19mm (anciennement #ffebee) */
  --cell-text-dark: #000;
  /* Couleur pour la correction */
  --correction-color: #008080; /* Teal/Bleu vert */
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  padding-bottom: 40px; /* Espace pour le scroll */
}

/* --- Header & Nav --- */
header {
  background: #fff;
  padding: 8px 16px;
  display: flex; flex-direction: column; gap: 8px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.header-top {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

header h1 { margin: 0; font-size: 1.1rem; color: var(--accent); white-space: nowrap; }

#voile-info {
    font-size: 0.85rem;
    background: #e3f2fd;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid #bbdefb;
    display: flex;
    gap: 8px;
}

.tabs { 
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px;
}

.tab {
  flex: 1; white-space: nowrap;
  padding: 10px; border-radius: 8px;
  background: #f0f0f0; border: none; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  font-size: 0.9rem;
}
.tab.active { background: var(--accent); color: #fff; }

.mobile-only { display: none; }

/* OPTIMISATION MOBILE : Menu déroulant en haut à droite */
@media (max-width: 700px) {
    .mobile-only { display: block; }
    
    header {
        padding: 10px 16px;
    }
    
    #menu-toggle {
        background: var(--accent);
        color: white;
        font-size: 1.5rem;
        padding: 5px 12px;
        border-radius: 6px;
        border: none;
        cursor: pointer;
    }

    .tabs {
        display: none; /* Caché par défaut sur mobile */
        flex-direction: column;
        position: absolute;
        top: 100%;
        right: 16px;
        width: 200px;
        background: #fff;
        border: 1px solid var(--border);
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        border-radius: 12px;
        padding: 8px;
        z-index: 1000;
        gap: 5px;
    }
    
    .tabs.open {
        display: flex; /* Affiché quand ouvert */
    }
    
    .tab {
        width: 100%;
        text-align: left;
        padding: 12px;
        background: transparent;
        color: var(--text);
        border-radius: 8px;
    }
    
    .tab.active {
        background: var(--hover);
        color: var(--accent);
    }
    
    body {
        padding-bottom: 20px;
    }
}

/* --- Layout --- */
main { padding: 16px; width: 100%; }
section { display: none; animation: fadeIn 0.3s ease; }
section:not(.hidden) { display: block; }
.hidden { display: none !important; }

.card {
  background: #fff; border: 1px solid var(--border);
  padding: 16px; border-radius: 12px; margin-bottom: 16px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

/* --- Typography & Elements --- */
.top-meta span { margin-right: 10px; display: inline-block; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 6px; border-bottom: 1px solid #eee; text-align: center; }
th { background: #f9f9f9; font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* Sticky header for Admin table */
#admin-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f9f9f9;
}

input, select {
  padding: 10px; border-radius: 6px; border: 1px solid #ccc;
  width: 100%; font-size: 1rem;
  text-align: center;
  text-align-last: center; /* Pour centrer la valeur sélectionnée */
}

button {
  padding: 10px 16px; border-radius: 8px; border: none;
  background: #e0e0e0; cursor: pointer; font-weight: 600;
  transition: background 0.2s;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); color: white; }
button.primary:hover { background: var(--accent-dark); }
button.danger { background: #ffebee; color: var(--danger); }

/* --- Page Saisie --- */
.saisie-controls { display: flex; gap: 10px; margin-bottom: 15px; }
.btn-side { flex: 1; padding: 12px; opacity: 0.6; border: 2px solid transparent; }
.btn-side.active { opacity: 1; border-color: var(--accent); background: #e8f5e9; color: var(--accent-dark); }



/* Style pour les sélecteurs de ligne/colonne */
.select-group {
    display: flex;
    gap: 8px;
    margin-bottom: 15px; /* Espace après les sélecteurs */
}

.select-group select {
    font-size: 1.8rem;
    font-weight: 800;
    color: #333;
    padding: 8px;
    text-align: center;
    background: #fafafa;
}



.input-controls-group {
    display: flex; 
    flex-direction: column;
    gap: 10px;
}

.input-group { display: flex; gap: 10px; }
.input-group input { font-size: 1.5rem; text-align: center; font-weight: bold; }

/* Zone des infos attendues dans la colonne de droite */
.info-attendu-box {
    background: #f0f0f0;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 15px;
}

/* --- Page Analyse --- */
.analyse-grid {
    border-collapse: separate; /* Permet d'appliquer une bordure aux cellules */
    border-spacing: 0; /* Supprime l'espace entre les cellules pour un cadre continu */
}
/* Style de cellule uniforme pour les deux tableaux d'analyse */
.analyse-grid th, .analyse-grid td { 
  padding: 6px; 
  font-size: 0.85rem; 
  border: 1px solid rgba(0,0,0,0.1); /* Bordure fine par défaut */
  background: #fff; /* Fond blanc par défaut */
  box-sizing: border-box; /* Inclusion de la bordure dans la taille */
}

/* Classes de bordure épaisse pour délimiter les groupes */
.group-top { border-top: 2px solid var(--text) !important; }
.group-bottom { border-bottom: 2px solid var(--text) !important; }
.group-left { border-left: 2px solid var(--text) !important; }
.group-right { border-right: 2px solid var(--text) !important; }

/* Classes d'alerte restent pour le tableau Admin */
.cell-warn { background-color: var(--warning); color: #000; }
.cell-error { background-color: var(--danger); color: white; }

/* NOUVELLES CLASSES POUR LE FOND DES CELLULES DANS ANALYSE */
.bg-warn { background-color: var(--cell-warn-bg) !important; color: var(--cell-text-dark); }
.bg-error { background-color: var(--cell-error-bg) !important; color: var(--cell-text-dark); font-weight: bold; }

/* Cadre rouge interne pour les écarts G/D > 10mm */
.diff-alert {
    box-shadow: inset 0 0 0 3px var(--danger) !important;
}

/* --- Utils --- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Toast Notification */
#toast-container {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #333; color: #fff; padding: 12px 24px; border-radius: 25px;
  font-size: 0.9rem; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Helper classes */
.flex-wrap { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.w-50 { width: 48%; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.mt-2 { margin-top: 1rem; }

/* Styles pour la nouvelle section Admin */
.checkbox-group {
    display: flex; gap: 10px; align-items: center;
    flex: 1 1 100px; /* Permet un petit wrapp autour de l'axe */
}
.checkbox-group input[type="checkbox"] {
    width: auto; height: 1.2rem; margin-right: 5px;
}
.admin-delete-controls {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}

/* Styles spécifiques à la correction */
.correction-table {
    margin-top: 15px;
    background: #f0f8ff; /* Bleu très clair */
    border: 1px solid #b0e0e6;
}
.correction-table th {
    background: #e0f2f7;
}
.correction-applied {
    font-weight: bold;
    color: var(--correction-color);
    background: #e6fafa;
}
/* Nouveau style pour le tableau de corrections pour ressembler au tableau de moyennes */
.correction-grid-table {
    border-collapse: collapse; 
    text-align: center;
    width: 100%;
}
.correction-grid-table th {
    background: #f9f9f9;
    font-weight: 600;
    border-bottom: 1px solid #eee;
}
.correction-grid-table td {
    padding: 3px 2px;
    border: 1px solid rgba(0,0,0,0.1); /* Bordure fine */
    background: #fff;
    font-size: 0.8rem;
}
/* MODIFICATION DE STYLE: On applique le style BG-GRP uniquement à la cellule de correction, pas à la cellule de groupe/ligne */
.correction-grid-table .bg-grp {
    background: #e6fafa; /* Similaire au fond correction-applied */
    font-weight: bold;
    color: var(--correction-color);
    /* Retiré: border: 1px solid #b0e0e6; pour unifier le style avec les moyennes simulées */
}
.correction-grid-table .grp-cell {
    background:#eee; 
    border: 1px solid rgba(0,0,0,0.1); /* Bordure fine */
}

/* --- Merged Layout --- */
.merged-container {
    display: flex;
    gap: 16px;
    align-items: start;
    width: 100%;
}

.column-left {
    flex: 0 0 320px; /* Largeur fixe pour la saisie */
    position: sticky;
    top: 80px; /* Garde la saisie visible si l'analyse est longue */
}

.column-right {
    flex: 1;
    min-width: 0; /* Évite les débordements des tableaux */
}

/* Adaptabilité mobile */
@media (max-width: 900px) {
    .merged-container {
        flex-direction: column;
    }
    .column-left {
        flex: none;
        width: 100%;
        position: static;
    }
}

/* --- Saisie Form Rows --- */
.saisie-form-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.saisie-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f9f9f9;
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.row-label {
    font-weight: 500;
    color: var(--muted);
    font-size: 0.9rem;
}

.row-value {
    font-size: 1.8rem;
    font-weight: 800;
    text-align: right;
    max-width: 60%;
    border: none;
    background: transparent;
    color: var(--text);
}

input.row-value {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 8px;
    width: 120px;
}

/* --- Layout Correction 2 Colonnes --- */
.correction-section {
    display: flex;
    gap: 20px;
    margin-bottom: 5px;
    align-items: start;
}

.correction-info {
    flex: 0 0 300px;
}

.correction-info h3 {
    margin-top: 0;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 10px;
}

.correction-info p {
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.4;
}

.correction-data {
    flex: 1;
    min-width: 0;
}

@media (max-width: 900px) {
    .correction-section {
        flex-direction: column;
        gap: 15px;
    }
    .correction-info {
        flex: none;
        width: 100%;
    }
}
