/* App chantier MSF — mise en forme MOBILE D'ABORD.
 *
 * Contraintes qui viennent du terrain, pas du goût :
 *   - cibles tactiles d'au moins 44 px : on saisit avec des gants ;
 *   - aucun défilement horizontal du corps de page ;
 *   - `env(safe-area-inset-*)` : la barre du bas ne passe pas sous l'encoche ;
 *   - contrastes de la charte, lisibles au soleil.
 *
 * ⚠️ Ce fichier n'a le droit d'UTILISER les jetons de `charte.css`, jamais
 * d'en REDÉFINIR un : la charte est la source unique, et le garde-fou de
 * `cloudflare/assembler-portail-ci.sh` refuse le déploiement sinon.
 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;               /* le minimum confortable en plein soleil */
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0 0 .4rem; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; color: var(--ink-2); }

.ecran { padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); }
.ecran[hidden] { display: none; }

/* ---------- bandeau d'état ------------------------------------------ */
.bandeau {
  position: sticky; top: 0; z-index: 20;
  padding: .6rem 1rem;
  font-size: .95rem; font-weight: 600;
  text-align: center;
  background: var(--surface-2); color: var(--ink-2);
  border-bottom: 1px solid var(--line);
}
.bandeau.attente { background: var(--accent-soft); color: var(--accent-deep); }
.bandeau.hors-reseau { background: var(--s-alloc); color: var(--sheet); }
.bandeau.conflit { background: var(--s-avis); color: var(--sheet); }

/* ---------- cartes et formulaires ----------------------------------- */
.carte {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.entete-auth { text-align: center; margin: 2rem 0 1.5rem; }
.sous-titre { color: var(--ink-2); margin: 0; }
.note { color: var(--ink-3); font-size: .9rem; }
.facultatif { color: var(--ink-3); font-weight: 400; font-size: .85rem; }

label { display: block; margin-bottom: .9rem; color: var(--ink-2); font-size: .9rem; }
input, textarea, select {
  display: block; width: 100%;
  min-height: 48px;
  margin-top: .3rem; padding: .6rem .8rem;
  font: inherit; color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line-2); border-radius: 10px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  min-height: 48px;
  border-radius: 10px;
  cursor: pointer;
}
.primaire {
  width: 100%;
  background: var(--accent-deep); color: var(--sheet);
  border: 1px solid var(--accent-deep);
  font-weight: 600;
}
.primaire:active { background: var(--accent); }
.secondaire {
  width: 100%;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2);
}
.grand { min-height: 56px; font-size: 1.05rem; }
.lien {
  background: none; border: none; color: var(--accent-deep);
  padding: .5rem; min-height: 44px;
}
.lien.fort { font-weight: 700; }

.message { margin: .6rem 0 0; padding: .6rem .8rem; border-radius: 8px;
           background: var(--surface-2); color: var(--ink-2); font-size: .92rem; }
.message.erreur { background: var(--s-avis); color: var(--sheet); }

/* ---------- verrou NIP ---------------------------------------------- */
.nip-points { display: flex; justify-content: center; gap: .9rem; margin: 1.2rem 0; }
.nip-point {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--ink-3);
}
.nip-point.plein { background: var(--accent-deep); border-color: var(--accent-deep); }

.pave { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-top: 1rem; }
.pave button {
  min-height: 64px; font-size: 1.4rem; font-family: var(--serif);
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink);
}
.pave button:active { background: var(--accent-soft); }
.pave button.vide { visibility: hidden; }

/* ---------- onglets -------------------------------------------------- */
.onglets { display: flex; gap: .4rem; margin-bottom: 1rem; }
.onglet {
  flex: 1; min-height: 48px;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--line-2);
}
.onglet.actif {
  background: var(--sheet); color: var(--ink);
  border-color: var(--accent); font-weight: 600;
}

/* ---------- la journée ----------------------------------------------- */
.barre-date { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; }
.barre-date .jour { flex: 1; text-align: center; font-family: var(--serif); font-size: 1.15rem; }
.barre-date button { width: 48px; background: var(--surface); border: 1px solid var(--line-2); }

.bloc {
  background: var(--sheet); border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px; padding: .8rem; margin-bottom: .7rem;
}
.bloc.approuve { border-left-color: var(--ink-3); background: var(--surface); color: var(--ink-2); }
.bloc.attente { border-left-color: var(--s-alloc); }
.bloc.conflit { border-left-color: var(--s-avis); }
.bloc-haut { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.bloc-projet { font-weight: 600; }
.bloc-droite { text-align: right; }
.bloc-heures { font-family: var(--serif); font-size: 1.2rem; white-space: nowrap; }
.bloc-plage { font-size: .8rem; color: var(--ink-3); white-space: nowrap; }
.bloc-code { color: var(--ink-2); font-size: .92rem; }
.bloc-note { margin: .4rem 0 0; color: var(--ink-2); font-size: .92rem; }
.bloc-etat { display: inline-block; margin-top: .4rem; font-size: .82rem;
             padding: .15rem .5rem; border-radius: 999px;
             background: var(--surface-2); color: var(--ink-2); }
.bloc-etat.attente { background: var(--accent-soft); color: var(--accent-deep); }
.bloc-etat.conflit { background: var(--s-avis); color: var(--sheet); }

.total-jour {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: .8rem; margin-bottom: 1rem;
  background: var(--surface-2); border-radius: 10px;
  font-family: var(--serif); font-size: 1.25rem;
}
.vide-jour { text-align: center; color: var(--ink-3); padding: 2rem 1rem; }

/* ---------- la jauge de la journee (rail fixe a gauche) --------------- */
/* Simon, 2026-08-28 : « une colonne a gauche de l'ecran, qui reste visible
   meme pendant qu'on entre un bloc d'heure. Une jauge de la journee. »

   Elle tient TOUJOURS dans la hauteur de l'ecran : la journee entiere d'un
   coup d'oeil, sans defiler. C'est ce qui en fait une jauge et non un
   calendrier — on y lit un remplissage, pas un horaire. */
:root { --jauge-l: 3.1rem; }

.jauge {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: var(--jauge-l);
  z-index: 30;                    /* au-dessus de la feuille de saisie */
  padding: .5rem .3rem calc(.5rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-right: 1px solid var(--line-2);
  overflow: hidden;
}
.jauge[hidden] { display: none; }

.jauge-piste {
  position: relative;
  height: 100%;
}
.jau-trait { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.jau-trait.heure { border-top-color: var(--line-2); }
/* Le code, et rien d'autre (Simon, 2026-08-28). C'est ce qu'on cherche a lire
   d'un coup d'oeil : quel travail occupe quelle part de la journee. */
.jau-code {
  display: block;
  padding: 1px 2px;
  font-family: var(--mono); font-size: .62rem; line-height: 1.1;
  color: var(--ink); font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.jau-bloc {
  position: absolute; left: 1px; right: 1px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent-deep);
}
.jau-bloc.approuve { background: var(--surface-2); border-left-color: var(--ink-3); }
.jau-bloc.attente  { border-left-color: var(--s-alloc); }
.jau-bloc.conflit  { border-left-color: var(--s-avis); }

/* Le bloc en cours de saisie : il apparait dans la jauge pendant qu'on tourne
   les molettes. C'est la raison d'etre du rail — voir le bloc se poser. */
.jau-bloc.apercu {
  background: var(--accent);
  border-left-color: var(--accent-deep);
  outline: 1px solid var(--accent-deep);
  opacity: .85;
}
.jau-trou {
  position: absolute; left: 2px; right: 1px;
  border-radius: 3px;
  background: repeating-linear-gradient(
    45deg, transparent, transparent 3px,
    var(--s-avis) 3px, var(--s-avis) 6px);
  opacity: .35;
}

/* Tout le reste de l'ecran se decale du rail. */
#vue-app { padding-left: calc(var(--jauge-l) + .8rem); }
#bandeau { padding-left: calc(var(--jauge-l) + 1rem); }

/* ---------- la semaine ------------------------------------------------ */
.semaine-jour {
  display: flex; justify-content: space-between; align-items: center;
  padding: .8rem; margin-bottom: .5rem;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 10px;
}
.semaine-jour.vide { background: var(--surface); color: var(--ink-3); }
.semaine-jour .h { font-family: var(--serif); font-size: 1.1rem; }
.semaine-total { font-family: var(--serif); font-size: 1.35rem;
                 padding: .9rem; background: var(--accent-soft);
                 color: var(--accent-deep); border-radius: 10px; margin-top: .8rem;
                 display: flex; justify-content: space-between; }

/* ---------- feuille de saisie : une etape a la fois ------------------- */
/* Panneau NON MODAL : une <dialog> modale passe dans le « top layer » et
   masquerait la jauge, y compris son fond. Ici la feuille se pose a DROITE du
   rail, qui reste entierement lisible pendant la saisie. */
.feuille {
  position: fixed;
  left: var(--jauge-l); right: 0; bottom: 0;
  z-index: 25;
  padding: 0;
  border: none; border-top: 1px solid var(--line-2);
  border-radius: 14px 14px 0 0;
  background: var(--sheet); color: var(--ink);
  max-height: 88vh;
  box-shadow: 0 -8px 24px rgba(35, 32, 27, .18);
}
.feuille[hidden] { display: none; }
.feuille form {
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
.feuille-entete {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  gap: .5rem; margin: -1rem -1rem 1rem; padding: .4rem .5rem;
  border-bottom: 1px solid var(--line); background: var(--surface);
  border-radius: 14px 14px 0 0;
}
.feuille-entete strong { font-family: var(--serif); font-size: 1.05rem; }
#feuille-ok:disabled { color: var(--ink-3); }

.etapes { display: flex; flex-direction: column; gap: .9rem; }
.etape[hidden] { display: none; }
.etape h3 { margin-bottom: .5rem; }

/* Une etape repondue se replie sur une seule ligne : le menuisier ne voit
   jamais les choix deja faits, seulement celui qu'il doit faire. */
.etape-repliee {
  display: flex; align-items: baseline; gap: .6rem;
  width: 100%; min-height: 52px; padding: .6rem .8rem;
  text-align: left;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink);
}
.etape-repliee[hidden] { display: none; }
.etape-nom { color: var(--ink-3); font-size: .8rem; text-transform: uppercase;
             letter-spacing: .05em; flex: 0 0 5.5rem; }
.etape-valeur { flex: 1; font-weight: 600; }
.etape-changer { color: var(--accent-deep); font-size: .9rem; }
.etape-ouverte[hidden] { display: none; }

.choix { max-height: 38vh; overflow-y: auto; margin-top: .5rem; }
.choix button {
  display: block; width: 100%; text-align: left;
  min-height: 52px; padding: .6rem .8rem; margin-bottom: .4rem;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink);
}
.choix button.choisi { background: var(--accent-soft); border-color: var(--accent); }
.choix .code-num { font-family: var(--mono); font-size: .85rem; color: var(--ink-2); }
.choix .frequent { float: right; font-size: .75rem; color: var(--accent-deep); }

/* Categories : six pastilles, lisibles au pouce. */
.categories { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.categorie {
  display: flex; flex-direction: column; align-items: flex-start; gap: .15rem;
  min-height: 68px; padding: .6rem .7rem; text-align: left;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink);
}
.categorie.choisi { background: var(--accent-soft); border-color: var(--accent); }
.categorie-num { font-family: var(--mono); font-size: .8rem; color: var(--ink-3); }
.categorie-lib { font-weight: 600; line-height: 1.2; }

/* Avis de changement : une case, jamais une categorie parcourable. */
.etape-avis { padding: .2rem 0; }
.case { display: flex; align-items: center; gap: .6rem; margin: 0; color: var(--ink); }
.case input[type="checkbox"] { width: 24px; height: 24px; min-height: 24px; margin: 0; flex: 0 0 auto; }
.case input:disabled + span { color: var(--ink-3); }
.case .mono-label { font-family: var(--mono); color: var(--accent-deep); }

/* Plage horaire : quatre molettes crantees, au pouce (Simon 2026-08-28).
   Un champ `type="time"` obligeait a viser deux fois — le champ, puis le
   selecteur du systeme. La molette se fait d'un geste, sans quitter l'ecran. */
.plage { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.molette-groupe { display: flex; flex-direction: column; gap: .3rem; }
.molette-etiquette {
  color: var(--ink-2); font-size: .9rem; padding-left: .2rem;
}
.molette-paire {
  position: relative;
  display: flex; align-items: stretch; justify-content: center; gap: .1rem;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 10px; overflow: hidden;
}
.molette-sep {
  display: flex; align-items: center;
  font-family: var(--serif); font-size: 1.3rem; color: var(--ink-3);
}

/* Trois crans visibles ; celui du milieu est le choix. */
.molette {
  --cran: 44px;
  flex: 1;
  height: calc(var(--cran) * 3);
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  overscroll-behavior: contain;   /* la feuille ne defile pas derriere */
}
.molette::-webkit-scrollbar { display: none; }
/* Un cran vide en haut et en bas, pour que le PREMIER et le DERNIER puissent
   atteindre le centre. Sans ca, on ne peut jamais choisir 00 ni 23. */
.molette-piste { padding-block: var(--cran); }
.molette .cran {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: var(--cran); min-height: var(--cran);
  scroll-snap-align: center;
  background: none; border: none; border-radius: 0;
  font-family: var(--serif); font-size: 1.25rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.molette .cran.actif { color: var(--ink); font-weight: 600; }
.molette .cran:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Le bandeau du centre : il montre le cran retenu, et ne bouge pas. */
.molette-bande {
  position: absolute; left: 0; right: 0; top: 44px; height: 44px;
  border-top: 1px solid var(--accent); border-bottom: 1px solid var(--accent);
  background: rgba(154, 107, 63, .07);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .molette { scroll-behavior: auto; }
}
.ligne-pause {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; margin: .8rem 0 0; padding: .5rem .8rem;
  background: var(--surface-2); border-radius: 10px; color: var(--ink-2);
}
.ligne-pause[hidden] { display: none; }
.pause-champ { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.ligne-pause input { width: 5rem; min-height: 44px; margin: 0; text-align: center; }

.resume {
  margin-top: .8rem; padding: .7rem .8rem;
  background: var(--accent-soft); border-radius: 10px;
  font-size: .95rem; color: var(--accent-deep); font-weight: 600;
}
.resume[hidden] { display: none; }

/* Écrans larges : on garde une colonne étroite, l'app reste une app de poche. */
/* Ecrans larges : on garde une colonne etroite — l'app reste une app de
   poche — mais la jauge suit le bord de cette colonne, pas celui de l'ecran. */
@media (min-width: 40rem) {
  .ecran, .bandeau { max-width: 37rem; margin-inline: auto; }
  .jauge { left: max(0px, calc(50vw - 18.5rem)); }
  .feuille { left: max(var(--jauge-l), calc(50vw - 18.5rem + var(--jauge-l)));
             right: max(0px, calc(50vw - 18.5rem)); }
}
