:root {
  --fond: #f3f4f6;
  --carte: #ffffff;
  --texte: #1f2933;
  --doux: #5f6b7a;
  --ligne: #d9dee5;
  --accent: #1f3a5f;
  --accent-clair: #e6edf6;
  --accent-texte: #ffffff;
  --ok: #1d7a46;
  --ok-fond: #e5f4ea;
  --erreur: #b42318;
  --erreur-fond: #fdecea;
  --attente: #8a5a00;
  --attente-fond: #fff4d6;
  --rayon: 12px;
  --ombre: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #111418;
    --carte: #1b2027;
    --texte: #e8ebef;
    --doux: #9aa5b1;
    --ligne: #2e3640;
    --accent: #7fa7d9;
    --accent-clair: #1e2a3a;
    --accent-texte: #0d1520;
    --ok: #6fcf97;
    --ok-fond: #15291e;
    --erreur: #f2867c;
    --erreur-fond: #331a18;
    --attente: #f0c060;
    --attente-fond: #33290f;
    --ombre: none;
  }
}
:root[data-theme="dark"] {
  --fond: #111418; --carte: #1b2027; --texte: #e8ebef; --doux: #9aa5b1; --ligne: #2e3640;
  --accent: #7fa7d9; --accent-clair: #1e2a3a; --accent-texte: #0d1520; --ok: #6fcf97; --ok-fond: #15291e;
  --erreur: #f2867c; --erreur-fond: #331a18; --attente: #f0c060; --attente-fond: #33290f; --ombre: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  background: var(--fond);
  color: var(--texte);
}
a { color: var(--accent); }
h1, h2 { line-height: 1.2; }

/* ---------- Barre du haut ---------- */
.barre {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--accent); color: var(--accent-texte);
}
.barre-titre { font-weight: 700; }
.barre-qui { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.barre .lien-discret { color: inherit; opacity: .85; }
.barre-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.barre-nav a { color: inherit; text-decoration: none; opacity: .85; padding: 4px 0; }
.barre-nav a.actif { opacity: 1; font-weight: 700; border-bottom: 2px solid currentColor; }

.page { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
body.bureau .page { max-width: 1100px; }
.titre { font-size: 1.5rem; margin: 8px 0 16px; }
.sous-titre { font-size: 1.15rem; margin: 0 0 12px; }
.carte { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 16px; margin: 0 0 16px; border: 1px solid var(--ligne); }
.vide { color: var(--doux); text-align: center; padding: 16px 0; }
.aide { color: var(--doux); font-size: .9rem; margin: 6px 0 0; }
.lien-discret { font-size: .95rem; text-decoration: none; }
.retour { display: inline-block; margin: 4px 0 8px; text-decoration: none; }

/* ---------- Messages ---------- */
.message { padding: 12px 14px; border-radius: var(--rayon); margin: 0 0 14px; font-weight: 500; }
.message.ok { background: var(--ok-fond); color: var(--ok); }
.message.erreur { background: var(--erreur-fond); color: var(--erreur); }
.message.info { background: var(--accent-clair); color: var(--texte); font-weight: 400; }
.erreur-texte { color: var(--erreur); font-weight: 600; margin: 8px 0 0; }
.alerte-texte { color: var(--erreur); margin-top: -8px; margin-bottom: 12px; }

/* ---------- Boutons et champs ---------- */
.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--ligne); background: var(--carte); color: var(--texte);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.bouton.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.bouton.danger { color: var(--erreur); border-color: var(--erreur); }
.bouton.petit { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.bouton.large { width: 100%; min-height: 54px; font-size: 1.1rem; }
.bouton:focus-visible, .champ:focus-visible, .puce:focus-visible, .choix:focus-within, .bouton-nom:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.champ {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--ligne); border-radius: 10px;
  background: var(--carte); color: var(--texte); font: inherit;
}
select.champ { appearance: auto; }
.champ-heures { font-size: 1.4rem; font-weight: 700; text-align: center; }
label { font-weight: 600; }
.groupe { border: 0; padding: 0; margin: 0 0 18px; }
.groupe legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
details.groupe summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
details.groupe .champ { margin-top: 8px; }

/* ---------- Choix du nom / PIN ---------- */
.grille-noms { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.bouton-nom {
  display: flex; align-items: center; justify-content: center; min-height: 72px; padding: 12px;
  background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); box-shadow: var(--ombre);
  color: var(--texte); font-size: 1.15rem; font-weight: 700; text-decoration: none; text-align: center;
}
.form-pin { display: grid; gap: 10px; max-width: 360px; }
.champ-pin {
  width: 100%; height: 72px; font-size: 2.4rem; letter-spacing: .6em; text-align: center;
  border: 2px solid var(--ligne); border-radius: var(--rayon); background: var(--carte); color: var(--texte);
}

/* ---------- Jour ---------- */
.nav-jour { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 14px; }
.fleche {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--carte); border: 1px solid var(--ligne); box-shadow: var(--ombre);
  font-size: 2rem; line-height: 1; text-decoration: none; color: var(--accent);
}
.fleche.inactive { opacity: .3; }
.nav-jour-date { text-align: center; }
.nav-jour-libelle { font-size: 1.3rem; font-weight: 700; }
.nav-jour-sous { color: var(--doux); }
.total-jour { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.total-jour.alerte { border-color: var(--erreur); }
.total-libelle { color: var(--doux); font-size: .95rem; }
.total-valeur { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.lignes { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.ligne {
  display: flex; align-items: center; gap: 10px;
  background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 10px 10px 10px 14px;
}
.ligne-texte { flex: 1; min-width: 0; }
.ligne-titre { font-weight: 600; overflow-wrap: anywhere; }
.ligne-note { color: var(--doux); font-size: .9rem; }
.ligne-heures { font-weight: 800; font-size: 1.15rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bouton-icone {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--ligne);
  background: transparent; color: var(--erreur); font-size: 1.1rem; cursor: pointer;
}

/* ---------- Liste de chantiers ---------- */
.liste-choix {
  max-height: 46vh; overflow-y: auto; margin-top: 8px;
  border: 1px solid var(--ligne); border-radius: 10px; background: var(--fond);
}
.groupe-titre {
  position: sticky; top: 0; z-index: 1;
  padding: 6px 12px; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--doux); background: var(--fond); border-bottom: 1px solid var(--ligne);
}
.choix {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px; cursor: pointer;
  border-bottom: 1px solid var(--ligne); background: var(--carte); font-weight: 400;
}
.choix input { margin-top: 4px; width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.choix:has(input:checked) { background: var(--accent-clair); }
.choix-corps { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-width: 0; }
.choix-libelle { overflow-wrap: anywhere; }
.code { font-weight: 700; font-variant-numeric: tabular-nums; }
.choix-nouveau { margin-top: 8px; border: 1px dashed var(--ligne); border-radius: 10px; }
.nouveau-chantier { margin-top: 10px; display: grid; gap: 6px; }
.pastille {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700;
  background: var(--accent-clair); color: var(--accent);
}
.pastille.attente { background: var(--attente-fond); color: var(--attente); }
.pastille.clos { background: var(--fond); color: var(--doux); border: 1px solid var(--ligne); }

.segments {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin-bottom: 10px;
  background: var(--fond); border: 1px solid var(--ligne); border-radius: 12px;
}
.segment { position: relative; margin: 0; }
.segment input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segment span {
  display: flex; align-items: center; justify-content: center; min-height: 46px; border-radius: 9px;
  font-weight: 700; font-size: 1.05rem; color: var(--doux);
}
.segment input:checked + span { background: var(--accent); color: var(--accent-texte); box-shadow: var(--ombre); }
.segment input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.puces { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.puce {
  min-height: 44px; min-width: 56px; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--ligne); background: var(--carte); color: var(--texte); font: inherit; font-weight: 600; cursor: pointer;
}

/* ---------- Semaine ---------- */
.semaine { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.jour-semaine {
  display: block; padding: 12px 14px; background: var(--carte); border: 1px solid var(--ligne);
  border-radius: var(--rayon); color: var(--texte); text-decoration: none;
}
.jour-semaine-etat { font-size: .88rem; font-weight: 600; }
.jour-semaine.etat-manque { border-left: 5px solid var(--erreur); }
.jour-semaine.etat-manque .jour-semaine-etat { color: var(--erreur); }
.jour-semaine.etat-ok { border-left: 5px solid var(--ok); }
.jour-semaine.etat-ok .jour-semaine-etat { color: var(--ok); }
.jour-semaine.etat-libre { opacity: .75; }

/* ---------- Contrôle des heures ---------- */
.etat-texte { font-size: .95rem; margin-top: 2px; }
.total-jour.etat-manque { border-left: 6px solid var(--erreur); }
.total-jour.etat-manque .etat-texte { color: var(--erreur); }
.total-jour.etat-ok { border-left: 6px solid var(--ok); }
.total-jour.etat-ok .etat-texte { color: var(--ok); font-weight: 600; }
.liste-rappels { margin: 6px 0 0; padding-left: 20px; font-weight: 400; }
.liste-rappels a { color: inherit; font-weight: 600; }
td.cel-ok { background: var(--ok-fond); color: var(--ok); font-weight: 700; }
td.cel-manque { background: var(--erreur-fond); color: var(--erreur); font-weight: 700; }
td.cel-libre, td.cel-non_controle { color: var(--doux); }
.legende { display: flex; flex-wrap: wrap; gap: 12px; font-size: .88rem; color: var(--doux); margin: -4px 0 12px; }
.legende span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legende .l-ok::before { background: var(--ok-fond); border: 1px solid var(--ok); }
.legende .l-manque::before { background: var(--erreur-fond); border: 1px solid var(--erreur); }
.jour-semaine.futur { opacity: .5; }
.jour-semaine-tete { display: flex; justify-content: space-between; font-weight: 600; }
.jour-semaine-ligne { display: flex; justify-content: space-between; gap: 12px; color: var(--doux); font-size: .92rem; }
.jour-semaine-ligne span:last-child { white-space: nowrap; }

/* ---------- Bureau ---------- */
.tableau-conteneur { overflow-x: auto; border: 1px solid var(--ligne); border-radius: var(--rayon); background: var(--carte); margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--ligne); text-align: left; vertical-align: top; }
th { background: var(--fond); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
td.nombre, th.nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 800; background: var(--fond); }
.filtres { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filtres > div { display: grid; gap: 4px; min-width: 150px; flex: 1; }
.filtres label { font-size: .85rem; }
.filtres .champ { min-height: 42px; }
.form-grille { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.form-grille > div { display: grid; gap: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.onglets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.onglets a { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--ligne); text-decoration: none; color: var(--texte); background: var(--carte); }
.onglets a.actif { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 700; }
.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.chiffre { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 14px; }
.chiffre-valeur { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.chiffre-libelle { color: var(--doux); font-size: .9rem; }
.jeton { font-family: ui-monospace, Consolas, monospace; word-break: break-all; padding: 12px; background: var(--fond); border-radius: 8px; border: 1px solid var(--ligne); }
.inline { display: inline; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .total-valeur { font-size: 1.7rem; }
}
