:root {
  --vert: #009628;
  --vert-hover: #007d20;
  --vert-fonce: #066051;
  --vert-pale: #e6f4ea;
  --encre: #33373d;
  --gris: #6b7280;
  --gris-leger: #9ca3af;
  --bord: #e5e7eb;
  --fond: #f7f8fa;
  --blanc: #ffffff;
  --rouge: #b91c1c;
  --rouge-pale: #fee2e2;
  --ambre: #b45309;
  --ambre-pale: #fef3c7;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  background: var(--fond);
  color: var(--encre);
  font-size: 15px;
  padding-bottom: 76px;
}

/* ---------- en-tête ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--blanc);
  border-bottom: 1px solid var(--bord);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
}
#topbar .brand { display: flex; gap: 10px; align-items: center; text-decoration: none; }

/* wordmark Plannint (logo SVG : les deux lignes ont exactement la même largeur) */
.logo-svg { height: 38px; width: auto; display: block; }
.logo-nom {
  fill: var(--vert); font-size: 42px; font-weight: 800;
  font-family: "Nunito", "Quicksand", "Segoe UI", system-ui, sans-serif;
}
.logo-sous {
  fill: var(--vert); font-size: 12px; font-weight: 700;
  font-family: "Nunito", "Quicksand", "Segoe UI", system-ui, sans-serif;
}
.logo-login { display: block; margin-bottom: 16px; }
.logo-login .logo-svg { height: 64px; }
#userbox { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--gris); }
#userbox button {
  background: none; border: none; color: var(--gris); font-size: 13.5px;
  cursor: pointer; padding: 4px 2px; text-decoration: underline; text-underline-offset: 3px;
}
#userbox button:hover { color: var(--encre); }

/* ---------- navigation ---------- */
#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--blanc); border-top: 1px solid var(--bord);
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
#bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; color: var(--gris);
  font-size: 10.5px; padding: 6px 2px; border-radius: 8px;
}
#bottomnav a svg { width: 19px; height: 19px; }
#bottomnav a.actif { color: var(--vert-fonce); background: var(--vert-pale); font-weight: 600; }

main { max-width: 1240px; margin: 0 auto; padding: 18px 16px; }

/* ---------- composants ---------- */
.carte {
  background: var(--blanc); border: 1px solid var(--bord);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
h1 { font-size: 21px; font-weight: 700; margin: 4px 0 4px; letter-spacing: -.2px; }
h2 { font-size: 15.5px; font-weight: 700; margin: 0 0 12px; }
h3 {
  font-size: 12px; margin: 18px 0 8px; color: var(--gris);
  text-transform: uppercase; letter-spacing: .8px; font-weight: 600;
}
.sous-titre { color: var(--gris); font-size: 13.5px; margin: 0 0 16px; line-height: 1.5; }

button, .btn {
  font-family: inherit; font-size: 14px; cursor: pointer;
  border: 1px solid var(--bord); background: var(--blanc); color: var(--encre);
  border-radius: 8px; padding: 8px 14px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 7px; line-height: 1.3;
}
button:hover, .btn:hover { border-color: var(--gris-leger); background: #fafafa; }
button svg, .btn svg { width: 15px; height: 15px; flex: none; }
.btn-primaire { background: var(--vert); border-color: var(--vert); color: #fff; font-weight: 600; }
.btn-primaire:hover { background: var(--vert-hover); border-color: var(--vert-hover); }
.btn-danger { color: var(--rouge); border-color: #f3caca; }
.btn-danger:hover { background: var(--rouge-pale); }
.btn-petit { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
.btn-icone { padding: 8px; }

input, select, textarea {
  font-family: inherit; font-size: 14.5px; color: var(--encre);
  border: 1px solid var(--bord); border-radius: 8px; padding: 8px 10px;
  background: var(--blanc); max-width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--vert); box-shadow: 0 0 0 3px rgba(0, 150, 40, .12);
}
label.champ { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--gris); font-weight: 500; }
.ligne-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }

.chip {
  display: inline-flex; align-items: center; border-radius: 6px; padding: 2px 8px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.chip-gris   { background: #eef0f2; color: #4b5563; }
.chip-ambre  { background: var(--ambre-pale); color: var(--ambre); }
.chip-vert   { background: #d9efdf; color: var(--vert-fonce); }
.chip-rouge  { background: var(--rouge-pale); color: var(--rouge); }
.chip-bleu   { background: #dbeafe; color: #1d4ed8; }

/* couleurs des types d'absence */
.abs-Cours    { background: #dbeafe; color: #1d4ed8; }
.abs-CIE      { background: #ede9fe; color: #6d28d9; }
.abs-Stage    { background: #ccfbf1; color: #0f766e; }
.abs-Vacances { background: #fef9c3; color: #a16207; }
.abs-Maladie  { background: var(--rouge-pale); color: var(--rouge); }
.abs-Absent   { background: #e5e7eb; color: #4b5563; }
.abs-Autre    { background: #fce7f3; color: #be185d; }
.abs-Ferie    { background: var(--vert-pale); color: var(--vert-fonce); }

/* ---------- tableaux ---------- */
.defiler { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; background: var(--blanc); }
th, td { border-bottom: 1px solid var(--bord); padding: 8px 10px; text-align: left; vertical-align: top; }
th {
  background: #fafbfc; color: var(--gris); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; position: sticky; top: 0; z-index: 2;
}
.grille th, .grille td { border: 1px solid var(--bord); }
tr.groupe td {
  background: #f3f5f7; color: var(--gris); font-weight: 700; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .8px; padding: 6px 10px;
}
td.vide { background: #fafbfc; color: #d1d5db; text-align: center; }
.duree { color: var(--gris-leger); font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* cellule d'occurrence dans la grille semaine */
.cellocc { display: flex; align-items: center; gap: 6px; min-width: 150px; }
.cellocc select { flex: 1; padding: 5px 7px; font-size: 13px; min-width: 92px; border-radius: 7px; }
.cellocc select.non-attribue { color: var(--gris-leger); }
.cellocc.absent select { border-color: var(--rouge); background: #fff7f7; }
.point-statut {
  width: 20px; height: 20px; min-width: 20px; border-radius: 6px; border: none;
  cursor: pointer; padding: 0;
}
.suppr {
  border: none; background: none; color: #d1d5db; font-size: 14px;
  cursor: pointer; padding: 0 2px; line-height: 1;
}
.suppr:hover { color: var(--rouge); }
.grip {
  cursor: grab; color: #c8cdd3; font-size: 13px; user-select: none;
  padding: 2px 1px; line-height: 1;
}
.grip:hover { color: var(--vert-fonce); }
.grip:active { cursor: grabbing; }
td.drop-ok { outline: 2px dashed var(--vert); outline-offset: -3px; background: var(--vert-pale); }

/* ---------- vue apprenti ---------- */
.nav-jour { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.nav-jour .titre-jour { font-weight: 700; font-size: 17px; text-align: center; flex: 1; }
.tache-carte {
  background: var(--blanc); border: 1px solid var(--bord);
  border-left: 4px solid var(--gris-leger);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
}
.tache-carte.st-1 { border-left-color: #f59e0b; }
.tache-carte.st-2 { border-left-color: var(--vert); }
.tache-carte.st-3 { border-left-color: var(--rouge); }
.tache-carte .nom { font-weight: 600; margin-bottom: 8px; line-height: 1.4; }
.tache-carte .meta { display: flex; gap: 10px; align-items: center; }
.tache-carte .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.tache-carte .actions button { flex: 1; min-width: 92px; padding: 11px 8px; font-size: 14px; font-weight: 600; justify-content: center; }
.b-commencer.actif { background: var(--ambre-pale); border-color: #f59e0b; color: var(--ambre); }
.b-fait.actif { background: #d9efdf; border-color: var(--vert); color: var(--vert-fonce); }
.b-pasfait.actif { background: var(--rouge-pale); border-color: var(--rouge); color: var(--rouge); }
.banniere {
  background: var(--vert-pale); border: 1px solid #c6e6cf; color: var(--vert-fonce);
  border-radius: var(--radius); padding: 11px 14px; margin-bottom: 12px; font-weight: 600; font-size: 14px;
}

/* ---------- login ---------- */
.login-wrap { max-width: 460px; margin: 40px auto; }
.grille-profils { display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 8px; margin: 14px 0; }
.grille-profils button { padding: 13px 8px; font-weight: 600; justify-content: center; }
.grille-profils button.choisi { background: var(--vert); color: #fff; border-color: var(--vert); }

/* ---------- stats ---------- */
td.stat-vert { background: #d9efdf; color: var(--vert-fonce); }
td.stat-ambre { background: var(--ambre-pale); color: var(--ambre); }
td.stat-rouge { background: var(--rouge-pale); color: var(--rouge); }

/* ---------- suivi ---------- */
.progress { background: #eef0f2; border-radius: 999px; height: 7px; min-width: 70px; overflow: hidden; }
.progress > div { height: 100%; background: var(--vert); border-radius: 999px; }

/* ---------- calendrier de présence ---------- */
.cal-presence { border-collapse: collapse; font-size: 12px; }
.cal-presence th, .cal-presence td { border: 1px solid var(--bord); padding: 0; text-align: center; }
.cal-presence th { padding: 5px 6px; position: static; }
.cal-presence th.col-jour { min-width: 27px; font-size: 10.5px; padding: 4px 2px; }
.cal-presence td.nom-apprenti, .cal-presence th.nom-apprenti {
  text-align: left; padding: 6px 10px; font-weight: 600; white-space: nowrap;
  position: sticky; left: 0; background: var(--blanc); z-index: 1; font-size: 13px;
}
.cal-cell { width: 27px; height: 30px; font-size: 10px; font-weight: 700; line-height: 30px; }
.cal-cell.weekend { background: #f3f5f7; }
.cal-cell.ferie { background: var(--vert-pale); }
.cal-cell.cliquable { cursor: pointer; }
.cal-cell.cliquable:hover { outline: 2px solid var(--vert); outline-offset: -2px; }
.legende { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- avatars ---------- */
.avatar {
  border-radius: 50%; object-fit: cover; vertical-align: middle;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.avatar-ini {
  background: var(--vert-pale); color: var(--vert-fonce); font-weight: 700;
}
.btn-avatar { background: none; border: none; padding: 0; cursor: pointer; }
.btn-avatar:hover .avatar { outline: 2px solid var(--vert); }

/* ---------- carte dépliable ---------- */
.entete-carte {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.entete-carte:hover .chevron { color: var(--vert-fonce); }
.chevron { color: var(--gris-leger); font-size: 15px; }

/* ---------- tuiles de synthèse ---------- */
.tuiles { display: flex; flex-wrap: wrap; gap: 24px; margin: 12px 0 18px; }
.tuile { display: flex; flex-direction: column; gap: 2px; }
.tuile strong { font-size: 21px; }

/* ---------- ajout d'un apprenti sur une tâche ---------- */
.ajout-apprenti {
  border: 1px dashed var(--bord); background: none; color: var(--gris-leger);
  font-size: 11.5px; padding: 2px 7px; border-radius: 6px; margin-top: 4px; cursor: pointer;
}
.ajout-apprenti:hover { color: var(--vert-fonce); border-color: var(--vert); background: var(--vert-pale); }

/* ---------- pastille d'information (description de tâche) ---------- */
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%;
  background: #e8f0f8; color: #1d4ed8; font-size: 10px; font-weight: 700;
  font-style: italic; cursor: help; vertical-align: 1px; font-family: Georgia, serif;
}
textarea { resize: vertical; min-height: 40px; width: 100%; }

/* ---------- tri et lignes cliquables ---------- */
th.triable { cursor: pointer; white-space: nowrap; }
th.triable:hover { color: var(--vert-fonce); }
tr.ligne-clic { cursor: pointer; }
tr.ligne-clic:hover td { background: #fafcfa; }

/* ---------- frise annuelle des absences ---------- */
.frise-mois {
  display: flex; margin: 6px 66px 4px 190px; color: var(--gris-leger);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px;
}
.frise-mois span { flex: 1; }
.ligne-frise {
  display: grid; grid-template-columns: 180px 1fr 56px; gap: 0 10px;
  align-items: center; padding: 9px 0; border-bottom: 1px solid var(--bord);
}
.nom-frise { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.frise {
  position: relative; height: 20px; background: #f3f5f7; border-radius: 6px; overflow: hidden;
}
.frise .segment {
  position: absolute; top: 0; bottom: 0; border-radius: 3px; cursor: pointer;
}
.frise .segment:hover { filter: brightness(1.35); }
/* dans la frise, on utilise la couleur soutenue de chaque type (les fonds pastel
   sont illisibles sur des segments fins) */
.frise .segment.abs-Cours    { background: #1d4ed8; }
.frise .segment.abs-CIE      { background: #6d28d9; }
.frise .segment.abs-Stage    { background: #0f766e; }
.frise .segment.abs-Vacances { background: #a16207; }
.frise .segment.abs-Maladie  { background: #b91c1c; }
.num-frise { justify-self: end; font-variant-numeric: tabular-nums; }

/* ---------- modale ---------- */
.modal-fond {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(30, 35, 40, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-boite {
  background: var(--blanc); border-radius: 12px; padding: 20px;
  max-width: 560px; width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.filtres { padding: 8px 12px; background: var(--blanc); border: 1px solid var(--bord); border-radius: var(--radius); }
.filtres svg { width: 15px; height: 15px; color: var(--gris-leger); flex: none; }
.filtres select { padding: 6px 8px; font-size: 13px; }
.suppr svg { width: 13px; height: 13px; }

/* ---------- calendrier de sélection de date ---------- */
.champ-date { display: inline-flex; align-items: center; gap: 4px; }
.btn-cal {
  border: 1px solid var(--bord); background: var(--blanc); border-radius: 8px;
  padding: 8px; cursor: pointer; color: var(--gris); display: inline-flex;
}
.btn-cal svg { width: 15px; height: 15px; }
.btn-cal:hover { color: var(--vert-fonce); border-color: var(--vert); }
#cal {
  position: fixed; z-index: 90; display: none;
  background: var(--blanc); border: 1px solid var(--bord); border-radius: 12px;
  padding: 12px; box-shadow: 0 12px 36px rgba(0, 0, 0, .16); width: 252px;
}
.cal-tete { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-tete strong { font-size: 14px; }
.cal-grille { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-ent {
  text-align: center; font-size: 10.5px; color: var(--gris-leger);
  font-weight: 600; padding: 2px 0;
}
.cal-jour {
  border: none; background: none; border-radius: 7px; padding: 0; height: 30px;
  display: flex; align-items: center; justify-content: center; gap: 0;
  font-size: 12.5px; cursor: pointer; color: var(--encre);
}
.cal-jour.we { color: var(--gris-leger); }
.cal-jour:hover { background: var(--vert-pale); }
.cal-jour.auj { outline: 1px solid var(--vert); }
.cal-jour.choisi { background: var(--vert); color: #fff; font-weight: 700; }

/* ---------- infobulles personnalisées ---------- */
#tooltip {
  position: fixed; z-index: 80; max-width: 340px;
  background: var(--encre); color: #fff;
  padding: 7px 11px; border-radius: 8px;
  font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
  opacity: 0; pointer-events: none; transition: opacity .12s;
}
#tooltip.visible { opacity: 1; }

#toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--encre); color: #fff; padding: 10px 18px; border-radius: 9px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 50;
  max-width: 90vw;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.erreur { background: var(--rouge); }

.absences-jour { font-size: 11px; color: var(--rouge); font-weight: 500; display: block; margin-top: 3px; text-transform: none; letter-spacing: 0; }
.charge-jour { font-size: 11px; color: var(--gris-leger); font-weight: 500; display: block; margin-top: 2px; text-transform: none; letter-spacing: 0; }
.outils { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.outils > svg { width: 15px; height: 15px; color: var(--gris-leger); flex: none; }
.outils input[type=search] { flex: 1; min-width: 150px; }
.jours-badges { display: flex; gap: 4px; }
.jours-badges span { background: var(--vert-pale); color: var(--vert-fonce); border-radius: 5px; font-size: 11px; padding: 2px 5px; font-weight: 700; }
.note { font-size: 12.5px; color: var(--gris); line-height: 1.5; }

/* ---------- impression (A4 paysage) ---------- */
.print-seulement { display: none; }
@page { size: A4 landscape; margin: 8mm; }
@media print {
  #topbar, #bottomnav, #toast, #modal, #tooltip, .no-print { display: none !important; }
  body { padding: 0; background: #fff; font-size: 10px; }
  main { max-width: none; padding: 0; }
  .print-seulement {
    display: block; font-size: 15px; font-weight: 700; margin-bottom: 8px;
  }
  .carte { border: none; border-radius: 0; margin: 0; }
  .defiler { overflow: visible; }
  table.grille { font-size: 8.5px; }
  .grille th, .grille td { padding: 3px 4px; }
  .cellocc { min-width: 0; gap: 3px; }
  .cellocc select {
    border: none; background: none; padding: 0; font-size: 8.5px;
    appearance: none; -webkit-appearance: none; min-width: 0;
  }
  .grip, .suppr, .ajout-apprenti, .info { display: none !important; }
  .point-statut { width: 8px; height: 8px; min-width: 8px; border-radius: 2px; pointer-events: none; }
  .absences-jour, .charge-jour { font-size: 7.5px; }
  tr, td, th { break-inside: avoid; }
}

@media (min-width: 760px) {
  body { padding-bottom: 24px; }
  #bottomnav {
    position: sticky; top: 51px; bottom: auto;
    border-top: none; border-bottom: 1px solid var(--bord);
    justify-content: flex-start; gap: 2px; padding: 6px 16px;
  }
  #bottomnav a { flex: none; flex-direction: row; gap: 7px; font-size: 13.5px; padding: 7px 14px; }
  #bottomnav a svg { width: 16px; height: 16px; }
}
