:root {
  --colw: 32px;
  --fs: 11px;
  --fs-input: 14px;
  --namew: 50px;
  --pad: 2px;
  --vac-bg: #cad9e6;        /* Couleur vacances */
  --highlight-bg: #9aaaf3;  /* Personne connectée */
  --count-bg: #f0f0f0;      /* Ligne CDS + PC */
  --block1-bg: #ffffff;
  --block2-bg: #fdfdfd;
}
@media (max-width: 768px) {
    body { padding: 5px; }
    
    /* On permet le défilement horizontal fluide du tableau */
    #content {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* On réduit la taille du texte pour mobile */
    table { font-size: 11px; }
    
    .namecell {
        position: sticky;
        left: 0; /* On fige le nom à gauche même sur petit écran */
        z-index: 5;
        min-width: 80px !important;
    }
    
    /* On masque les éléments moins importants pour les viewers sur mobile */
    .toolbar button:not(.logout) {
        padding: 5px;
        font-size: 12px;
    }
}
/* ============================
      STRUCTURE DE BASE
============================ */
body {
  font-family: Arial, sans-serif;
  margin: 12px;
  font-size: var(--fs);
}

h1 { text-align: center; margin: 0; font-size: 20px; }
h2 { text-align: center; margin: 0 0 12px; color: #666; font-size: 14px; }

/* ============================
            TABLEAU
============================ */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  border: 1px solid #ccc;
  padding: var(--pad);
  text-align: center;
  vertical-align: middle;
}

th {
  background: #fafafa;
  font-size: 11px;
}

/* Largeur colonnes jours */
thead th:not(:first-child):not(:nth-child(2)),
tbody td:not(:first-child):not(:nth-child(2)) {
  width: var(--colw);
  min-width: var(--colw);
  max-width: var(--colw);
}

/* ============================
   HARMONISATION GRADE & NOM
============================ */
/* Colonne Grade (1ère) */
.gradecell, 
tr.count-row td:first-child, 
tr.admin-row td:first-child {
  width: 45px;
  min-width: 45px;
  max-width: 45px;
  padding: 8px 2px;
  font-size: 13px;
  text-align: center;
  background: #f0f0f0 !important;
  border: 1px solid #ccc;
  white-space: nowrap;
}

/* Colonne Nom (2ème) - Sticky */
.namecell, 
tr.count-row .namecell, 
tr.admin-row .namecell {
  /* On utilise la variable --namew (140px par défaut) */
  width: var(--namew) !important;
  min-width: var(--namew) !important;
  max-width: var(--namew) !important;

  /* --- On empêche le retour à la ligne et on coupe proprement --- */
  white-space: nowrap !important;
  overflow: hidden; /* Cache ce qui dépasse */
  text-overflow: ellipsis; /* Ajoute "..." à la fin si c'est trop long */
  
  text-align: left;
  padding: 8px 5px;
  font-weight: bold;
  background: #fff;
  position: sticky;
  left: 0;
  z-index: 3;
  border: 1px solid #ccc;
}

/* ============================
         INPUT DES CASES
============================ */
.oneinput {
  width: 100%;
  padding: 1px;
  min-width: 0;
  border: 1px solid #999;
  border-radius: 3px;
  font-size: var(--fs-input);
  font-weight: bold;
  color:rgb(0, 0, 0);
  text-align: center;
  font-weight: bold;
}

/* ============================
       ALTERNANCE BLOCS
============================ */
.block1 { background: var(--block1-bg); }
.block2 { background: var(--block2-bg); }
.block-sep {
  border-right: 3px solid #444 !important;
}

/* ============================
   LIGNES ADMIN & COMPTEURS
============================ */
.admin-row {
  background-color: #fff9e6; /* Jaune très clair */
}

.admin-input-cell input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-weight: bold;
  color: #d97706; /* Marron/Orange admin */
}

.highlight-vic {
  background-color: #ecfdf5 !important; /* Vert clair */
  color: #059669;
}

/* Séparateur visuel avant les compteurs */
.separator-top td {
  border-top: 15px solid #f8f9fa !important;
  padding-top: 10px;
}

.count-row td, .countcell {
  background: var(--count-bg) !important;
  font-weight: bold;
}

/* ============================
         SÉPARATEURS
============================ */
.grade-sep td {
  background: #8a0a0a;
  height: 1px !important;
  padding: 0;
}

.header-sep td {
  height: 10px;
  background: transparent;
  border: none;
}

/* ============================
         ONGLETS & TOOLBAR
============================ */
.tabs { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tab { padding: 6px 12px; background: #eee; border-radius: 6px; cursor: pointer; border: 1px solid #bbb; }
.tab.active { background: #f6d365; border-color: #e8b200; font-weight: 700; }

.toolbar { text-align: center; margin-bottom: 10px; }
.toolbar button { padding: 6px 10px; border-radius: 6px; border: 1px solid #888; background: #f5f5f5; cursor: pointer; margin: 0 3px; }
/* Ligne de séparation grise */
.stat-separator td {
    height: 10px;
    background-color: #ddd;
    border: none;
}
/* ============================
        MODAL & ÉTATS
============================ */
.vac-cell, .vac-input { background: var(--vac-bg) !important; }

.selected-cell {
  background-color: #e8f3ff !important;
  outline: 2px solid #470486 !important;
  z-index: 10;
}

.highlight-row td, .highlight-row .namecell {
  background: var(--highlight-bg) !important;
  box-shadow: inset 0 0 6px rgba(19, 2, 250, 0.6);
}

#optsModal {
  position: fixed; left: 0; top: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 10;
}

#optsEditor {
  background: #fff; padding: 20px; width: 450px; border-radius: 8px; max-height: 90%; overflow-y: auto;
}
/* ============================
   MASQUER LA FLÈCHE DATALIST
============================ */
/* Masque la flèche native pour les navigateurs Webkit (Chrome, Safari, Edge) */
input.oneinput::-webkit-calendar-picker-indicator {
    display: none !important;
}

/* On s'assure que le curseur reste normal */
input.oneinput {
    cursor: text;
}
/* Indicateur visuel pour les remarques (petit triangle orange) */
.has-remark {
    /* Un orange plus doux ou un bleu info selon vos goûts */
    background: linear-gradient(225deg, #007bff 6px, transparent 6px) !important;
}
/* =========================================
   MENU CONTEXTUEL CLIC DROIT (Ve)
========================================= */
#ve-context-menu {
    display: none;
    position: absolute;
    z-index: 10000;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
    border-radius: 6px;
    padding: 5px 0;
    font-family: Arial, sans-serif;
    font-size: 14px;
    min-width: 120px;
}

.ve-option {
    padding: 10px 20px;
    cursor: pointer;
    color: #333;
    transition: background 0.2s;
}

.ve-option:hover {
    background-color: #007bff;
    color: white;
}

.ve-clear {
    border-top: 1px solid #eee;
    color: #d9534f; /* Rouge pour l'effacement */
    font-size: 13px;
}

.ve-clear:hover {
    background-color: #f2dede;
    color: #a94442;
}
/* Couleur de la case pour le Superviseur (VE: s) */
.sup-input {
    background-color: #d1ecf1 !important; 
    color: #0c5460 !important;
    font-weight: bold;
}
/* =========================================
   MODAL D'ANALYSE DES HORAIRES
========================================= */
.modal {
  display: none; /* Cache la fenêtre par défaut */
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
}

.modal.open {
  display: block; /* L'affiche quand on clique sur le bouton */
}

.modal-content {
  background-color: #fefefe;
  padding: 0; 
  border: 1px solid #888;
  width: 90%; 
  max-width: 650px; 
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  position: absolute; 
  margin: 0; 
}

.modal-header {
  padding: 10px 15px;
  background-color: #003366;
  color: white;
  border-top-left-radius: 7px;
  border-top-right-radius: 7px;
  cursor: move;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
}

.modal-body {
  padding: 20px;
}
/* Bouton de verrouillage Admin (Discret par défaut pour garder l'ancien style) */
/* Conteneur de la cellule de verrouillage */
.lock-cell {
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    height: 24px;
    position: relative;
    /* On force la cellule à ne pas influencer la largeur */
    width: 0; 
    white-space: nowrap;
}

/* Le bouton "flottant" */
/* --- PROTECTION DES LARGEURS --- */
/* On force toutes les cellules de jours (th et td) à garder la taille définie par --colw */
table th:not(.namecell):not(.gradecell),
table td:not(.namecell):not(.gradecell) {
    width: var(--colw) !important;
    min-width: var(--colw) !important;
    max-width: var(--colw) !important;
    box-sizing: border-box;
    padding: 5px 0 !important; /* Évite que le padding n'élargisse la cellule */
}
/* Mettre le texte des cellules horaires en gras */
table tbody td input.oneinput {
    font-weight: bold !important;
    color:black
}
/* Mettre le texte des cellules horaires en gras ET en noir absolu */
table tbody td input.oneinput {
    font-weight: bold !important;
    color: #000000 !important; /* Noir pur */
}

/* Empêcher le navigateur d'éclaircir le texte quand la case est verrouillée */
table tbody td input.oneinput:disabled {
    color: #000000 !important;
    -webkit-text-fill-color: #000000 !important; /* Obligatoire pour forcer Safari/Chrome */
    opacity: 1 !important; 
}
/* --- STYLE DES VERROUS --- */
.lock-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    margin: 0;
    display: inline-block;
    line-height: 1;
}

/* Quand c'est ouvert : petit badge vert discret */
.lock-toggle-btn.is-open {
    background-color: #10b981;
    color: white;
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 10px;
    font-weight: bold;
}

/* L'aspect "Ouvert" du bloc (UTILISE OUTLINE pour ne pas ajouter de pixels) */
/* --- STYLE DES VERROUS (Corrigé pour les séparateurs) --- */

/* 1. On allège un peu le cadre vert pour qu'il ne masque pas les bordures du tableau */
/* --- STYLE DES VERROUS (FOND UNIQUEMENT) --- */

/* 1. Fond vert très clair pour les cases du tableau ouvertes */
table tbody td.cycle-unlocked {
    background-color: #ecfdf5 !important;
    /* On ne touche absolument pas aux bordures ! */
}

/* 2. En-tête (numéros et lettres des jours) en vert pour bien repérer le bloc */
table thead th.cycle-unlocked {
    background-color: #10b981 !important;
    color: white !important;
}

/* 3. Petit badge/bouton du cadenas */
.lock-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    margin: 0;
    display: inline-block;
    line-height: 1;
}

.lock-toggle-btn.is-open {
    background-color: #10b981;
    color: white;
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 10px;
    font-weight: bold;
}
.table-wrapper {
    overflow-x: auto;
    max-width: 100%;
}
.sticky-name {
    position: sticky;
    left: 0;
    background: white;
    z-index: 2;
    font-weight: bold;
    border-right: 2px solid #ccc;
}
.month-sep {
    background-color: #eee;
    width: 5px !important;
}
/* =========================================
   STYLE ANALYSE NUITS - GRILLE FLEXBOX PURE
========================================= */
#nights-analysis-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 10000;
}

.nights-modal-content {
    background: #fff; width: 95%; max-width: 1400px; height: 90%;
    margin: 3vh auto; border-radius: 6px;
    display: flex; flex-direction: column; box-shadow: 0 0 20px rgba(0,0,0,0.5);
    font-family: Arial, sans-serif;
}

.nights-modal-header {
    padding: 12px 20px; background: #f8f9fa; border-bottom: 2px solid #ddd;
    display: flex; justify-content: space-between; align-items: center; border-radius: 6px 6px 0 0;
}

.nights-modal-header h2 { margin: 0; font-size: 18px; color: #2c3e50; }

.nights-legend { display: flex; align-items: center; gap: 15px; }
.leg-item { font-size: 13px; display: flex; align-items: center; gap: 5px; color:#555;}
.box { width: 15px; height: 15px; border-radius: 3px; border: 1px solid #ccc;}
.box.night-red { background: #e74c3c; border-color: #c0392b; }
.box.night-blue { background: #3498db; border-color: #2980b9; }
.box.night-dark { background: #2c3e50; border-color: #1a252f; }

.nights-scroll-container { 
    flex: 1; overflow: auto; padding: 0; 
    background: #fff; position: relative;
}

/* 🌟 LA GRILLE FLEXBOX */
.n-grid {
    display: flex; flex-direction: column; 
    width: max-content; min-width: 100%;
}

.n-row {
    display: flex; border-bottom: 1px solid #e0e0e0;
}
.n-row:hover { background-color: #f9f9f9; } /* Petit effet sympa au survol */

/* Cellules standards (Données) */
.n-cell {
    flex-shrink: 0; display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    width: 38px; height: 40px; 
    border-right: 1px solid #e0e0e0; 
    background: #fff; box-sizing: border-box; font-size: 13px;
}

/* 🌟 COLONNE 1 FIGÉE : Agent */
.n-name {
    position: sticky; left: 0; z-index: 10;
    width: 180px; align-items: flex-start; justify-content: center;
    padding-left: 15px; border-right: none;
}

/* 🌟 COLONNE 2 FIGÉE : Total */
.n-total {
    position: sticky; left: 180px; z-index: 10;
    width: 60px; border-right: 2px solid #34495e;
    box-shadow: 4px 0 5px -2px rgba(0,0,0,0.1); /* Ombre de séparation */
}

/* 🌟 LIGNE D'EN-TÊTE */
.n-header {
    position: sticky; top: 0; z-index: 20;
}
.n-header .n-cell {
    background: #34495e; color: #fff; height: 46px; border-right: 1px solid #4a6278;
}
.n-header .n-total {
    background: #2c3e50; border-right: 2px solid #1a252f;
}
.n-header .n-name, .n-header .n-total {
    z-index: 30; /* Assure que l'intersection Haut/Gauche reste au-dessus de tout */
}

/* COULEURS DES NUITS */
.is-night-red { background: #e74c3c !important; color: #fff; font-weight: bold; border-color: #c0392b;}
.is-night-blue { background: #3498db !important; color: #fff; font-weight: bold; border-color: #2980b9;}
.is-night-dark { background: #2c3e50 !important; color: #fff; font-weight: bold; border-color: #1a252f;}
.is-empty { background: transparent; }

.nights-close-btn {
    background: #e74c3c; color: #fff; border: none; padding: 6px 15px; 
    border-radius: 4px; cursor: pointer; font-size: 13px; font-weight: bold;
}