/* =========================================================================
   A3789 — chantier : socle graphique
   Charte TAHAUKU BNB : brique #94301c en ACCENT, texte #111111,
   DejaVu Sans, sobre et dense. Pas de degrade, pas d'ombre gratuite.
   Aucune ressource externe : la police est celle du poste.
   ========================================================================= */

:root {
  /* Accent brique : deux roles distincts pour tenir le contraste.
     -texte = filets, titres, liens ; -fond = aplats avec texte blanc. */
  --accent-texte: #94301c;
  --accent-fond: #94301c;
  --accent-fond-texte: #ffffff;
  --accent-voile: #f3e7e4;

  --encre: #111111;
  --encre-doux: #43403e;
  --encre-faible: #635f5c;

  --fond: #f4f2f0;
  --surface: #ffffff;
  --surface-2: #faf9f8;
  --surface-3: #eeebe8;

  --filet: #d3cec9;
  --filet-fort: #a9a29b;

  --ok: #1c6640;
  --alerte: #7d5300;
  --echec: #a3201a;

  --cible: 44px;          /* cible tactile minimale */
  /* Hauteur reservee sous la zone des messages courts. La visionneuse la
     recalcule a l'ouverture d'apres la hauteur reelle de son pied, pour que
     le bandeau ne vienne jamais recouvrir la rangee d'etat de relecture. */
  --toast-bas: 16px;
  --rayon: 2px;           /* angles francs, pas d'arrondi mou */
  --gouttiere: 12px;
  --police: "DejaVu Sans", "Verdana", Arial, Helvetica, sans-serif;
  --mono: "DejaVu Sans Mono", "Courier New", monospace;
}

/* Theme sombre : seules les valeurs changent, jamais les regles. */
:root[data-theme="sombre"] {
  --accent-texte: #e58a74;
  --accent-fond: #a4351f;
  --accent-fond-texte: #ffffff;
  --accent-voile: #2a1c19;

  --encre: #ecebe9;
  --encre-doux: #c3bfbb;
  --encre-faible: #9d9894;

  --fond: #16181b;
  --surface: #1e2125;
  --surface-2: #24272c;
  --surface-3: #2c3036;

  --filet: #3a3f45;
  --filet-fort: #5a6069;

  --ok: #62c58e;
  --alerte: #d7a63c;
  --echec: #f08379;
}

/* ---- remise a zero mesuree ---- */
*, *::before, *::after { box-sizing: border-box; }
/* Un « display » pose plus loin l'emporterait sinon sur l'attribut hidden. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--police);
  font-size: 15px;
  line-height: 1.45;
  color: var(--encre);
  background: var(--fond);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; font-weight: 700; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .7em; }
a { color: var(--accent-texte); }
img { max-width: 100%; }
ul, ol { margin: 0 0 .7em; padding-left: 1.4em; }

/* Le focus doit toujours se voir : il travaille aussi au clavier. */
:focus-visible {
  outline: 2px solid var(--accent-texte);
  outline-offset: 2px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* =========================== boutons ================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  min-height: var(--cible); min-width: var(--cible);
  padding: 0 12px;
  font: inherit; font-weight: 600;
  color: var(--encre);
  background: var(--surface);
  border: 1px solid var(--filet-fort);
  border-radius: var(--rayon);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-primaire {
  background: var(--accent-fond);
  border-color: var(--accent-fond);
  color: var(--accent-fond-texte);
}
.btn-primaire:hover { background: var(--accent-fond); filter: brightness(1.08); }
.btn-discret { border-color: transparent; background: transparent; }
.btn-discret:hover { background: var(--surface-3); }
.btn-danger { color: var(--echec); border-color: var(--echec); background: var(--surface); }
.btn-petit { min-height: 36px; padding: 0 9px; font-size: .9rem; }
.btn-icone { padding: 0; width: var(--cible); }
.btn-large { width: 100%; }

/* Retour d'etat PORTE PAR LE BOUTON, jamais par un survol. */
.btn[data-etat="cours"] { color: var(--encre-faible); border-style: dashed; }
.btn[data-etat="ok"] { color: var(--ok); border-color: var(--ok); background: var(--surface); }
.btn[data-etat="echec"] { color: var(--echec); border-color: var(--echec); background: var(--surface); }
.btn-primaire[data-etat="ok"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-primaire[data-etat="echec"] { background: var(--echec); border-color: var(--echec); color: #fff; }

.groupe-btn { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* segments (choix exclusif) */
.segments { display: inline-flex; border: 1px solid var(--filet-fort); border-radius: var(--rayon); overflow: hidden; }
.segments .btn { border: 0; border-right: 1px solid var(--filet); border-radius: 0; }
.segments .btn:last-child { border-right: 0; }
.segments .btn[aria-pressed="true"] { background: var(--accent-fond); color: var(--accent-fond-texte); }

/* =========================== champs =================================== */
.champ { display: block; margin-bottom: 12px; }
.champ > .libelle { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; color: var(--encre-doux); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="search"], select, textarea {
  width: 100%;
  min-height: var(--cible);
  padding: 8px 10px;
  font: inherit;
  color: var(--encre);
  background: var(--surface);
  border: 1px solid var(--filet-fort);
  border-radius: var(--rayon);
}
textarea { resize: vertical; line-height: 1.5; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent-fond); }
select { appearance: auto; }
.aide { font-size: .85rem; color: var(--encre-faible); }

/* =========================== structures =============================== */
.carte {
  background: var(--surface);
  border: 1px solid var(--filet);
  border-radius: var(--rayon);
}
.carte-titre {
  padding: 8px 12px;
  border-bottom: 1px solid var(--filet);
  background: var(--surface-2);
  font-weight: 700;
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--encre-doux);
}
.barre-outils {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px; border-bottom: 1px solid var(--filet); background: var(--surface-2);
}
.espaceur { flex: 1 1 auto; }

.vide {
  padding: 28px 16px; text-align: center; color: var(--encre-faible);
}

/* filet brique : la signature de la maison */
.filet-brique { border-top: 3px solid var(--accent-texte); }

/* =========================== bandeaux ================================= */
.bandeau {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px;
  border: 1px solid var(--alerte);
  border-left: 4px solid var(--alerte);
  background: var(--surface);
  color: var(--encre);
  font-size: .9rem;
}
.bandeau strong { color: var(--alerte); }

/* =========================== modales ================================== */
.voile {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.modale {
  background: var(--surface);
  border: 1px solid var(--filet-fort);
  border-top: 3px solid var(--accent-texte);
  border-radius: var(--rayon);
  width: min(560px, 100%);
  max-height: 92vh;
  display: flex; flex-direction: column;
}
.modale-tete { padding: 10px 14px; border-bottom: 1px solid var(--filet); display: flex; align-items: center; gap: 8px; }
.modale-tete h2 { margin: 0; font-size: 1.05rem; }
.modale-corps { padding: 14px; overflow: auto; }
.modale-pied { padding: 10px 14px; border-top: 1px solid var(--filet); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); }
/* Rappel de la route reellement appelee, sous une confirmation de
   suppression : discret, mais verifiable. */
.rappel-route { margin-top: .5em; font-family: var(--mono); font-size: .78rem; }
@media (max-width: 640px) {
  .voile { align-items: flex-end; padding: 0; }
  .modale { width: 100%; max-height: 88vh; border-radius: 0; }
  .modale-pied .btn { flex: 1 1 140px; }
}

/* liste d'actions (menu tactile plein format) */
.liste-actions { list-style: none; margin: 0; padding: 0; }
.liste-actions li { border-bottom: 1px solid var(--filet); }
.liste-actions li:last-child { border-bottom: 0; }
.liste-actions .btn { width: 100%; justify-content: flex-start; border: 0; border-radius: 0; min-height: 48px; }

/* =========================== messages ================================= */
/* Les messages s'empilent VERS LE HAUT depuis leur ancrage bas : le dernier
   arrive reste au ras de l'ancrage, aucun n'est rogne par le bord de la
   fenetre, et la pile ne peut pas depasser la hauteur utile. */
#toasts {
  position: fixed; z-index: 90; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--toast-bas) + env(safe-area-inset-bottom));
  max-height: 60vh; overflow: hidden;
  display: flex; flex-direction: column-reverse; gap: 6px; align-items: center;
  pointer-events: none; width: min(560px, 94vw);
}
.toast {
  width: 100%;
  padding: 10px 12px;
  background: var(--encre);
  color: var(--fond);
  border-left: 4px solid var(--accent-texte);
  border-radius: var(--rayon);
  font-size: .92rem;
}
.toast[data-type="ok"] { border-left-color: var(--ok); }
.toast[data-type="echec"] { border-left-color: var(--echec); }

/* =========================== coquille ================================= */
.barre-haute {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 3px solid var(--accent-texte);
}
.marque { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.marque b { color: var(--accent-texte); letter-spacing: .02em; }
.marque span { color: var(--encre-faible); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sur ecran etroit, ce libelle se replie sur sa seule icone : la barre du
   haut doit rester lisible, et le bouton garde sa cible tactile pleine. */
@media (max-width: 760px) {
  .barre-haute .libelle-long { display: none; }
}
/* Sous 480 px la barre du haut est pleine a ras bord : le sous-titre de la
   marque s'efface pour laisser respirer les boutons. Le nom de la societe
   reste sur l'ecran de connexion et dans le titre de l'onglet. */
@media (max-width: 480px) {
  .marque > span { display: none; }
}

.onglets {
  display: flex; gap: 2px; background: var(--surface); border-bottom: 1px solid var(--filet);
  overflow-x: auto;
}
.onglets .btn {
  border: 0; border-bottom: 3px solid transparent; border-radius: 0;
  color: var(--encre-doux); font-weight: 600;
}
.onglets .btn[aria-current="page"] {
  color: var(--accent-texte); border-bottom-color: var(--accent-texte); background: var(--accent-voile);
}

main#vue { padding: var(--gouttiere); }

/* Sur telephone la navigation passe en bas : le pouce y arrive. */
@media (max-width: 760px) {
  .onglets {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    border-top: 1px solid var(--filet); border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .onglets .btn { flex: 1 1 0; border-bottom: 0; border-top: 3px solid transparent; font-size: .8rem; }
  .onglets .btn[aria-current="page"] { border-top-color: var(--accent-texte); }
  main#vue { padding: 8px 8px 78px; }
  /* La barre d'onglets occupe le bas de l'ecran : les messages passent
     au-dessus d'elle. Valeur posee sur la variable, pour que la visionneuse
     puisse la remplacer par sa propre mesure quand elle est ouverte. */
  :root { --toast-bas: 76px; }
}

/* =========================== connexion ================================ */
#ecran-connexion {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.bloc-connexion { width: min(380px, 100%); }
.bloc-connexion .carte { padding: 18px; border-top: 3px solid var(--accent-texte); }
