:root {
  --fond: #12161b;
  --surface: #1a2027;
  --surface-2: #222b34;
  --trait: #2e3841;
  --texte: #e9edf1;
  --muted: #8795a3;
  --present: #4cc38a;
  --absent: #ef6461;
  --rd: #f2a65a;
  --lien: #7aa7e9;
  --r: 12px;
  --haut-onglets: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--haut-onglets) + env(safe-area-inset-bottom)); }

h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 .3rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 1.6rem 0 .6rem; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.erreur { color: var(--absent); }
.aide { color: var(--muted); font-size: .88rem; margin: 0 0 .8rem; }

/* ---------- Connexion ---------- */
.ecran { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.connexion { width: 100%; max-width: 320px; text-align: center; }
.pin {
  width: 100%; margin: 1.2rem 0 .8rem; padding: .9rem;
  font-size: 1.8rem; text-align: center; letter-spacing: .5em; text-indent: .5em;
  background: var(--surface); border: 1px solid var(--trait); border-radius: var(--r); color: var(--texte);
}

/* ---------- Boutons ---------- */
button { font: inherit; color: inherit; cursor: pointer; }
.bouton-plein {
  width: 100%; padding: .85rem; border: 0; border-radius: var(--r);
  background: var(--lien); color: #0d1116; font-weight: 600;
}
.bouton-fin {
  padding: .6rem .9rem; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--trait); color: var(--texte); font-size: .92rem;
}
.bouton-fin.discret { background: transparent; color: var(--muted); }
.fleche {
  width: 44px; height: 44px; border-radius: 50%; font-size: 1.5rem; line-height: 1;
  background: var(--surface-2); border: 1px solid var(--trait);
}
:focus-visible { outline: 2px solid var(--lien); outline-offset: 2px; }

/* ---------- Entête ---------- */
.entete {
  position: sticky; top: 0; z-index: 10;
  background: rgba(18, 22, 27, .93);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--trait);
  padding: calc(env(safe-area-inset-top) + .5rem) .9rem .7rem;
}
.ligne-date { display: flex; align-items: center; gap: .5rem; }
.date-btn {
  flex: 1; background: none; border: 0; font-size: 1.05rem; font-weight: 600;
  padding: .4rem; text-align: center;
}
.date-cachee { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }

.segments { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 11px; margin-top: .55rem; }
.segment {
  flex: 1; padding: .55rem 0; border: 0; border-radius: 8px; background: none;
  color: var(--muted); font-size: .95rem; font-weight: 550;
}
.segment.actif { background: var(--surface-2); color: var(--texte); box-shadow: inset 0 0 0 1px var(--trait); }

.compteur { margin-top: .7rem; }
.chiffre { display: flex; align-items: baseline; gap: .45rem; }
.chiffre b { font-size: 2rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.chiffre small { color: var(--muted); font-size: .88rem; }
.pastilles { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: .15rem; }
.pastille b { font-variant-numeric: tabular-nums; }
.pastille.absent b { color: var(--absent); }
.pastille.rd b { color: var(--rd); }
.jauge { height: 3px; background: var(--trait); border-radius: 2px; margin-top: .55rem; overflow: hidden; }
.jauge i { display: block; height: 100%; background: var(--present); transition: width .25s ease; }

/* ---------- Vues ---------- */
main { padding: .9rem; max-width: 640px; margin: 0 auto; }
.barre-actions { display: flex; gap: .5rem; margin-bottom: .9rem; }
.barre-actions button { flex: 1; }

/* ---------- Liste d'appel ---------- */
.chambre { margin-top: 1.1rem; }
.chambre:first-child { margin-top: 0; }
.chambre-titre {
  display: flex; align-items: center; gap: .6rem;
  color: var(--muted); font-size: .82rem; margin-bottom: .35rem; padding-left: .1rem;
}
.chambre-titre::after { content: ""; flex: 1; height: 1px; background: var(--trait); }

.eleves { border: 1px solid var(--trait); border-radius: var(--r); overflow: hidden; }
.eleve {
  display: flex; align-items: center; gap: .7rem;
  min-height: 58px; padding: .5rem .7rem .5rem .85rem;
  background: var(--surface); border-bottom: 1px solid var(--trait);
  user-select: none;
}
.eleve:last-child { border-bottom: 0; }
.eleve .nom { flex: 1; font-weight: 500; }
.eleve .nom em { font-style: normal; color: var(--muted); font-weight: 400; }
.eleve .prevu { display: block; font-size: .76rem; color: var(--rd); }
.eleve .prevu.abs { color: var(--absent); }

.eleve[data-statut="present"] { background: color-mix(in srgb, var(--present) 13%, var(--surface)); }
.eleve[data-statut="rd"] { background: color-mix(in srgb, var(--rd) 13%, var(--surface)); }
.eleve[data-statut="absent"] { background: color-mix(in srgb, var(--absent) 13%, var(--surface)); }

.marque {
  width: 46px; height: 46px; flex: none; border-radius: 11px;
  border: 1px solid var(--trait); background: var(--surface-2);
  display: grid; place-items: center; font-size: .82rem; font-weight: 650;
}
.marque.present { background: var(--present); border-color: var(--present); color: #0d1116; }
.marque.rd { background: var(--rd); border-color: var(--rd); color: #0d1116; }
.marque.absent { background: var(--absent); border-color: var(--absent); color: #0d1116; }

/* ---------- Observations ---------- */
.bloc-obs { margin-top: 1.8rem; }
.liste-obs { display: grid; gap: .5rem; margin-bottom: .7rem; }
.obs {
  background: var(--surface); border: 1px solid var(--trait); border-left: 3px solid var(--rd);
  border-radius: 10px; padding: .6rem .75rem; font-size: .93rem;
}
.obs .meta { color: var(--muted); font-size: .76rem; margin-top: .25rem; display: flex; justify-content: space-between; gap: .5rem; }
.obs .supprimer { background: none; border: 0; color: var(--muted); padding: 0; text-decoration: underline; font-size: .76rem; }
textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--trait);
  border-radius: var(--r); color: var(--texte); padding: .7rem; font: inherit; resize: vertical; margin-bottom: .6rem;
}

/* ---------- Semaine ---------- */
.barre-semaine { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .8rem; }
#libelle-semaine { font-weight: 600; }
.sem-eleve { border: 1px solid var(--trait); border-radius: var(--r); background: var(--surface); padding: .6rem .7rem; margin-bottom: .6rem; }
.sem-nom { font-weight: 550; margin-bottom: .45rem; font-size: .95rem; }
.sem-jours { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.sem-jour { text-align: center; }
.sem-jour .lettre { font-size: .7rem; color: var(--muted); display: block; margin-bottom: 3px; }
.sem-case {
  width: 100%; height: 38px; border-radius: 9px; border: 1px solid var(--trait);
  background: var(--surface-2); font-size: .72rem; font-weight: 650; color: var(--muted); padding: 0;
}
.sem-case[data-etat="rd"] { background: var(--rd); border-color: var(--rd); color: #0d1116; }
.sem-case[data-etat="absence"] { background: var(--absent); border-color: var(--absent); color: #0d1116; }

/* ---------- Historique ---------- */
.champs-dates { display: flex; gap: .7rem; margin-bottom: .8rem; }
.champs-dates label { flex: 1; font-size: .82rem; color: var(--muted); }
.champs-dates input {
  display: block; width: 100%; margin-top: .25rem; padding: .55rem;
  background: var(--surface); border: 1px solid var(--trait); border-radius: 10px; color: var(--texte); font: inherit;
}
.jour-hist { border: 1px solid var(--trait); border-radius: var(--r); background: var(--surface); padding: .7rem .8rem; margin-top: .7rem; }
.jour-hist h3 { margin: 0 0 .45rem; font-size: .95rem; font-weight: 600; }
.jour-hist .l { display: flex; justify-content: space-between; font-size: .88rem; padding: .18rem 0; color: var(--muted); }
.jour-hist .l b { color: var(--texte); font-variant-numeric: tabular-nums; font-weight: 550; }

/* ---------- Réglages ---------- */
.rang {
  display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem;
  background: var(--surface); border: 1px solid var(--trait); border-radius: 10px; margin-bottom: .4rem; font-size: .93rem;
}
.rang span { flex: 1; }
.rang.inactif { opacity: .5; }
.ajout { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; }
.ajout input {
  flex: 1 1 90px; padding: .6rem; background: var(--surface);
  border: 1px solid var(--trait); border-radius: 10px; color: var(--texte); font: inherit;
}

/* ---------- Onglets ---------- */
.onglets {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: rgba(18, 22, 27, .95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--trait); padding-bottom: env(safe-area-inset-bottom);
}
.onglet {
  flex: 1; padding: .9rem 0; border: 0; background: none; color: var(--muted); font-size: .8rem;
}
.onglet.actif { color: var(--texte); box-shadow: inset 0 2px 0 var(--lien); }

/* ---------- Feuille d'actions ---------- */
.voile { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 40; display: flex; align-items: flex-end; }
.feuille {
  width: 100%; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: .9rem .9rem calc(.9rem + env(safe-area-inset-bottom));
  display: grid; gap: .45rem; animation: monte .18s ease;
}
@keyframes monte { from { transform: translateY(12px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .feuille { animation: none; } .jauge i { transition: none; } }
.feuille-titre { margin: .2rem 0 .5rem; text-align: center; color: var(--muted); font-size: .85rem; }
.choix { padding: .85rem; border-radius: 11px; border: 1px solid var(--trait); background: var(--surface-2); font-weight: 550; }
.choix.present { border-color: var(--present); color: var(--present); }
.choix.rd { border-color: var(--rd); color: var(--rd); }
.choix.absent { border-color: var(--absent); color: var(--absent); }
.choix.annuler { background: none; border: 0; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--haut-onglets) + 14px + env(safe-area-inset-bottom));
  background: var(--surface-2); border: 1px solid var(--trait); color: var(--texte);
  padding: .55rem .9rem; border-radius: 20px; font-size: .85rem; z-index: 50; max-width: 90vw; text-align: center;
}

/* ---------- Hors ligne et horodatage ---------- */
.horodatage { margin: .35rem 0 0; font-size: .78rem; color: var(--muted); min-height: 1em; }
.bandeau {
  margin: .6rem -0.9rem -0.7rem; padding: .5rem .9rem;
  background: color-mix(in srgb, var(--rd) 22%, var(--fond));
  border-top: 1px solid color-mix(in srgb, var(--rd) 45%, var(--trait));
  font-size: .82rem; text-align: center;
}
.bandeau.envoi { background: color-mix(in srgb, var(--present) 20%, var(--fond)); }
.eleve.en-attente .marque { box-shadow: 0 0 0 2px var(--rd); }

/* ---------- Contacts ---------- */
.recherche {
  width: 100%; padding: .7rem .85rem; margin-bottom: .9rem;
  background: var(--surface); border: 1px solid var(--trait); border-radius: var(--r);
  color: var(--texte); font: inherit;
}
.fiche { border: 1px solid var(--trait); border-radius: var(--r); background: var(--surface); margin-bottom: .5rem; overflow: hidden; }
.fiche-tete {
  display: flex; align-items: center; gap: .7rem; padding: .75rem .85rem; width: 100%;
  background: none; border: 0; text-align: left;
}
.fiche-tete .id { flex: 1; }
.fiche-tete .id b { font-weight: 550; }
.fiche-tete .id span { display: block; font-size: .78rem; color: var(--muted); }
.fiche-tete .chevron { color: var(--muted); font-size: 1.2rem; }
.fiche-corps { padding: 0 .85rem .85rem; display: grid; gap: .5rem; }
.contact-ligne { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.contact-ligne .etiq { color: var(--muted); font-size: .78rem; min-width: 92px; }
.contact-ligne a { color: var(--lien); text-decoration: none; }
.contact-ligne .vide { color: var(--muted); font-style: italic; }
.actions-contact { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .2rem; }
.actions-contact a, .actions-contact button {
  flex: 1 1 auto; text-align: center; text-decoration: none;
  padding: .55rem .8rem; border-radius: 10px; border: 1px solid var(--trait);
  background: var(--surface-2); color: var(--texte); font-size: .88rem;
}
.form-contact { display: grid; gap: .4rem; }
.form-contact input {
  padding: .55rem .7rem; background: var(--surface-2); border: 1px solid var(--trait);
  border-radius: 9px; color: var(--texte); font: inherit; font-size: .9rem;
}

/* ---------- Portraits ---------- */
.portrait {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  object-fit: cover; background: var(--surface-2); border: 1px solid var(--trait);
}
.vide-portrait { display: grid; place-items: center; color: var(--muted); font-weight: 600; }
.portrait-grand {
  width: 100%; max-width: 220px; aspect-ratio: 1; object-fit: cover;
  border-radius: var(--r); border: 1px solid var(--trait); margin: 0 auto .3rem; display: block;
}

[hidden] { display: none !important; }
