:root{
  --primary:#2563eb;
  --primary-dark:#1d4ed8;
  --primary-light:#eff6ff;
  --danger:#dc2626;
  --green:#16a34a;
  --gray:#6b7280;
  --bg:#f4f6f9;
  --card:#ffffff;
  --border:#e2e8f0;
  --text:#1e293b;
  --radius:10px;
  --shadow:0 1px 2px rgba(15,23,42,.04), 0 1px 8px rgba(15,23,42,.04);
  --shadow-hover:0 4px 16px rgba(15,23,42,.08);
}
*{box-sizing:border-box;}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%;}
body{
  margin:0;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
a{color:var(--primary);text-decoration:none;}
a:hover{text-decoration:underline;}

.navbar{
  background:#111827;
  color:#fff;
  padding:14px 24px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  flex-wrap:wrap;
  position:sticky;
  top:0;
  z-index:100;
  box-shadow:0 2px 10px rgba(0,0,0,.15);
}
.navbar .brand{font-weight:600;font-size:18px;}
.navbar nav a{
  color:#cbd5e1;
  margin-left:16px;
  font-size:14px;
  padding-bottom:3px;
  border-bottom:2px solid transparent;
  transition:color .15s;
}
.navbar nav a:hover, .navbar nav a.active{color:#fff;text-decoration:none;}
.navbar nav a.active{border-bottom-color:var(--primary);}
.navbar .userinfo{font-size:13px;color:#9ca3af;margin-left:16px;}

.container{max-width:1100px;margin:24px auto;padding:0 16px;}

.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:20px;
  margin-bottom:20px;
}
.card h2{margin-top:0;font-size:18px;}


.grid{display:grid;gap:16px;}
/* auto-fit/minmax : le nombre de colonnes s'adapte en continu à la
   largeur disponible, sans dépendre d'un seul point de rupture fixe
   (mieux supporté et plus fluide sur tablette/mobile/desktop). */
.grid-3{grid-template-columns:repeat(auto-fit,minmax(140px,1fr));}
.grid-2{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));}
/* Les cellules de grille ont par défaut min-width:auto : elles refusent
   de rétrécir sous la largeur "native" de leur contenu (ex: un champ
   date). Sans ce reset, la colonne reste large et déborde sur mobile. */
.grid > *{min-width:0;}

.stat{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:10px;
  padding:18px;
  text-align:center;
}
.stat .num{font-size:28px;font-weight:700;color:var(--primary);}
.stat .label{color:var(--gray);font-size:13px;margin-top:4px;}

table{width:100%;border-collapse:collapse;font-size:14px;}
th,td{padding:10px 8px;border-bottom:1px solid var(--border);text-align:left;}
th{background:#f8fafc;color:#475569;font-weight:600;font-size:13px;}
tr:hover td{background:#f9fafb;}

.form-group{margin-bottom:14px;}
.form-group label{display:block;margin-bottom:5px;font-size:14px;font-weight:600;color:#374151;}
input[type=text],input[type=password],input[type=email],input[type=date],select,textarea{
  width:100%;
  max-width:100%;
  padding:9px 10px;
  border:1px solid #cbd5e1;
  border-radius:6px;
  font-size:14px;
}
input:focus,select:focus,textarea:focus{outline:2px solid var(--primary);border-color:var(--primary);}

/* Rendu cohérent des <select> entre navigateurs (Chrome/Edge, Firefox,
   Safari et les navigateurs mobiles appliquent chacun un style natif
   différent) : flèche personnalisée identique partout. */
select{
  -webkit-appearance:none;
  -moz-appearance:none;
  appearance:none;
  background-color:#fff;
  background-image:url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='%236b7280' d='M5.5 7.5l4.5 4.5 4.5-4.5z'/%3e%3c/svg%3e");
  background-repeat:no-repeat;
  background-position:right 10px center;
  background-size:16px;
  padding-right:32px;
  cursor:pointer;
}
select::-ms-expand{display:none;}
select:disabled{cursor:not-allowed;opacity:.7;}

/* Rendu cohérent du champ date entre navigateurs (Chrome/Edge, Firefox,
   Safari affichent tous l'icône et le texte différemment par défaut) */
input[type=date]{
  -webkit-appearance:none;
  appearance:none;
  background-color:#fff;
  color-scheme:light;
  font-family:inherit;
}
input[type=date]::-webkit-calendar-picker-indicator{
  cursor:pointer;
  opacity:.55;
}
input[type=date]::-webkit-datetime-edit{padding:0;}

/* Champ verrouillé (ex: date du jour imposée) : même apparence sur
   tous les navigateurs, sans dépendre du style natif "readonly" */
.input-locked{
  background-color:#f1f5f9 !important;
  color:#475569;
  cursor:not-allowed;
  border-color:#e2e8f0;
}
.input-locked::-webkit-calendar-picker-indicator{
  pointer-events:none;
  opacity:.35;
}

.btn{
  display:inline-block;
  padding:9px 16px;
  border-radius:6px;
  border:none;
  cursor:pointer;
  font-size:14px;
  font-weight:600;
  background:var(--primary);
  color:#fff;
  transition:background .15s, box-shadow .15s, transform .05s;
}
.btn:hover{background:var(--primary-dark);}
.btn:active{transform:translateY(1px);}
.btn:focus-visible{outline:2px solid var(--primary-dark);outline-offset:2px;}
.btn:disabled,.btn[disabled]{opacity:.6;cursor:not-allowed;}
.btn-danger{background:var(--danger);}
.btn-danger:hover{background:#b91c1c;}
.btn-gray{background:#e5e7eb;color:#111827;}
.btn-gray:hover{background:#d1d5db;}
.btn-sm{padding:5px 10px;font-size:12px;}

.alert{padding:12px 14px;border-radius:8px;margin-bottom:16px;font-size:14px;}
.alert-success{background:#dcfce7;color:#166534;border:1px solid #bbf7d0;}
.alert-error{background:#fee2e2;color:#991b1b;border:1px solid #fecaca;}

.badge{padding:3px 9px;border-radius:20px;font-size:12px;font-weight:600;}
.badge-green{background:#dcfce7;color:#166534;}
.badge-red{background:#fee2e2;color:#991b1b;}
.badge-gray{background:#f1f5f9;color:#475569;}
.badge-yellow{background:#fef9c3;color:#854d0e;}

.nav-badge{
  display:inline-block;min-width:16px;height:16px;padding:0 4px;
  background:#dc2626;color:#fff;border-radius:20px;
  font-size:10px;line-height:16px;text-align:center;font-weight:700;
  margin-left:4px;vertical-align:2px;
}

.login-wrap{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  background:linear-gradient(135deg,#1e3a8a,#2563eb);
}
.login-box{
  background:#fff;
  padding:36px;
  border-radius:14px;
  width:100%;
  max-width:380px;
  box-shadow:0 10px 30px rgba(0,0,0,.2);
}
.login-box h1{font-size:20px;margin-bottom:4px;text-align:center;}
.login-box p.sub{text-align:center;color:var(--gray);font-size:13px;margin-bottom:20px;}

.checklist{border:1px solid var(--border);border-radius:8px;overflow:hidden;}
.checklist-row{
  display:flex;
  align-items:center;
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  transition:background .12s;
}
.checklist-row:last-child{border-bottom:none;}
.checklist-row:nth-child(even){background:#fafbfc;}
.checklist-row:hover{background:var(--primary-light);}
.checklist-row.is-checked{background:#fef2f2;}
.checklist-row.is-blocked{background:#fef2f2;box-shadow:inset 3px 0 0 #dc2626;}
.checklist-row.is-hidden{display:none;}
.checklist-row input[type=checkbox]{
  width:22px;height:22px;margin-right:14px;cursor:pointer;flex-shrink:0;
  accent-color:var(--danger);
}
.checklist-row input[type=checkbox]:disabled{cursor:not-allowed;opacity:.55;}
.checklist-row input[type=checkbox]:disabled ~ .name,
.checklist-row input[type=checkbox]:disabled ~ .num{color:var(--gray);opacity:.7;}
.checklist-row .num{color:var(--gray);width:32px;flex-shrink:0;}
.checklist-row .name{flex:1;font-weight:500;}
.checklist-row .tag-absent{
  color:#991b1b;background:#fee2e2;border-radius:20px;padding:2px 10px;
  font-size:12px;font-weight:600;margin-left:8px;white-space:nowrap;
}
.checklist-row .tag-bloque{
  color:#fff;background:#dc2626;border-radius:20px;padding:2px 10px;
  font-size:12px;font-weight:700;margin-left:8px;white-space:nowrap;
}
.checklist-row .tag-billet{
  color:#9a3412;background:#ffedd5;border-radius:20px;padding:2px 10px;
  font-size:12px;font-weight:600;margin-left:8px;white-space:nowrap;
}
.checklist-row .tag-remarque{
  color:#1e40af;background:#dbeafe;border-radius:20px;padding:2px 10px;
  font-size:12px;font-weight:600;margin-left:8px;white-space:nowrap;
  text-decoration:none;
}

.remarque-list{display:flex;flex-direction:column;gap:12px;}
.remarque-item{border:1px solid var(--border);border-radius:8px;padding:12px 14px;background:#fafbfc;}
.remarque-meta{display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:13px;margin-bottom:6px;}
.remarque-contenu{margin:0;white-space:pre-line;}

/* Barre d'actions rapides + compteur (page "Saisie des absences") */
.checklist-toolbar{
  display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:12px 0;
}
.checklist-toolbar input[type=search]{flex:1;min-width:160px;}
.counter-badge{
  display:inline-flex;align-items:center;gap:6px;
  background:var(--primary-light);color:var(--primary-dark);
  border-radius:20px;padding:6px 14px;font-size:13px;font-weight:600;white-space:nowrap;
}
.counter-badge.has-absents{background:#fee2e2;color:#991b1b;}

/* Barre d'enregistrement fixée en bas : toujours accessible sans
   avoir à remonter tout en haut d'une longue liste, surtout mobile */
.sticky-actions{
  position:sticky;bottom:0;
  background:var(--card);
  border-top:1px solid var(--border);
  padding:12px 16px;
  margin:0 -16px;
  box-shadow:0 -4px 12px rgba(15,23,42,.06);
  display:flex;align-items:center;gap:12px;flex-wrap:wrap;
  z-index:10;
}
.sticky-actions .btn{flex:1;min-width:200px;}

.toolbar{display:flex;gap:10px;align-items:end;flex-wrap:wrap;margin-bottom:16px;}
.toolbar .form-group{margin-bottom:0;min-width:160px;}

.empty{color:var(--gray);text-align:center;padding:30px;}

/* ============================================================
   COMPATIBILITÉ SMARTPHONE
   ============================================================ */
@media(max-width:640px){
  .container{padding:0 10px;margin:14px auto;}
  .card{padding:14px;}

  /* Navbar : passe en colonne, liens groupés et espacés proprement */
  .navbar{flex-direction:column;align-items:stretch;gap:10px;padding:12px 14px;}
  .navbar .brand{font-size:16px;}
  .navbar > div{flex-direction:column;align-items:stretch;gap:10px;}
  .navbar nav{display:flex;flex-wrap:wrap;gap:4px 14px;}
  .navbar nav a{margin-left:0;padding:4px 0;}
  .navbar .userinfo{margin-left:0;display:flex;justify-content:space-between;align-items:center;
    border-top:1px solid #374151;padding-top:8px;}

  /* Tableaux : on garde la mise en page mais on autorise le défilement
     horizontal à l'intérieur de la carte plutôt que de tout écraser */
  .card{overflow-x:auto;-webkit-overflow-scrolling:touch;}
  table{min-width:520px;}

  /* Formulaires : évite le zoom automatique iOS (police < 16px) */
  input[type=text],input[type=password],input[type=email],input[type=date],select,textarea{
    font-size:16px;padding:10px;
  }

  /* Barre d'outils (filtres) et grilles : un seul élément par ligne */
  .toolbar{flex-direction:column;align-items:stretch;}
  .toolbar .form-group{min-width:0;}
  .toolbar .btn{width:100%;}

  /* Fiches "checklist" (appel des stagiaires) : plus lisibles en colonne */
  .checklist-row{flex-wrap:wrap;padding:10px 12px;}
  .checklist-row .name{flex-basis:100%;order:1;margin-top:4px;}
  .checklist-row .tag-absent{margin-left:0;order:2;}
  .checklist-row .tag-bloque{margin-left:0;order:2;}
  .checklist-row .tag-billet{margin-left:0;order:3;}
  .checklist-row .tag-remarque{margin-left:0;order:4;}

  .login-box{padding:24px;}

  .stat .num{font-size:24px;}
}

/* ---- Recherche et tri automatiques des tableaux ---- */
.table-search-wrap{
  display:flex;
  align-items:center;
  gap:10px;
  margin-bottom:10px;
}
.table-search{
  max-width:320px;
  padding:8px 10px;
  border:1px solid #cbd5e1;
  border-radius:6px;
  font-size:13px;
}
.table-search-count{
  font-size:12px;
  color:var(--gray);
  white-space:nowrap;
}
table th.sortable-col{
  cursor:pointer;
  user-select:none;
}
table th.sortable-col:hover{background:#e0e7ff;}
table th.sorted-asc::after{content:" \25B2";font-size:10px;color:var(--primary);}
table th.sorted-desc::after{content:" \25BC";font-size:10px;color:var(--primary);}

/* ---- Graphiques statistiques ---- */
.chart-card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:10px;
  padding:20px;
  margin-bottom:20px;
}
.chart-card h2{margin-top:0;font-size:18px;}
.chart-wrap{position:relative;height:320px;}

/* ---- Graphiques en barres (pur CSS, sans dépendance externe) ---- */
.barchart{display:flex;flex-direction:column;gap:10px;}
.barchart-row{display:flex;align-items:center;gap:10px;}
.barchart-label{
  width:150px;
  flex-shrink:0;
  font-size:13px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  color:#374151;
}
.barchart-track{
  flex:1;
  background:#f1f5f9;
  border-radius:6px;
  height:22px;
  overflow:hidden;
}
.barchart-fill{
  background:linear-gradient(90deg,var(--primary),#3b82f6);
  height:100%;
  border-radius:6px;
  transition:width .4s ease;
}
.barchart-fill.fill-red{background:linear-gradient(90deg,var(--danger),#ef4444);}
.barchart-fill.fill-green{background:linear-gradient(90deg,var(--green),#22c55e);}
.barchart-value{
  width:65px;
  flex-shrink:0;
  text-align:right;
  font-size:13px;
  font-weight:600;
  color:#111827;
}
