/* Socle : couleurs (§ 8.8 du plan), mise en page, classes partagées (docs/INTERFACES.md § 8),
   en-tête, onglets, toasts, bandeau démo, message de mise à jour, connexion (cx-).
   Chaque lot ajoute son fichier : composants.css, saisie.css, analyse.css. */

:root {
  color-scheme: light dark;

  --fond: #f6f3f4;
  --surface: #ffffff;
  --encre: #231a1f;
  --encre-2: #5c5157;
  --encre-3: #756a70;
  --trait: #e7e0e3;
  --trait-fort: #8a7f85;          /* bord des champs (contraste 3:1) */
  --accent: #0e6b6b;
  --sur-accent: #ffffff;
  --accent-doux: #e2efee;         /* fond léger pour ce qui est choisi */

  --degre-1: #eb9aab;
  --degre-2: #dc6480;
  --degre-3: #b92a4c;
  --degre-4: #76102d;
  --sur-degre-1: #231a1f;
  --sur-degre-2: #231a1f;
  --sur-degre-3: #ffffff;
  --sur-degre-4: #ffffff;

  --levre: #f4e3e7;
  --levre-contour: #d9b9c1;
  --serie-prec: #9d9298;
  --mieux: #006300;
  --moins-bien: #b3261e;
  --sur-moins-bien: #ffffff;

  --ombre: 0 1px 2px rgb(35 26 31 / 6%), 0 2px 10px rgb(35 26 31 / 6%);
  --ombre-forte: 0 4px 12px rgb(35 26 31 / 18%), 0 12px 32px rgb(35 26 31 / 14%);

  --marge: 16px;
  --rayon: 12px;
  --toucher: 44px;
  --colonne: 520px;
  --hauteur-onglets: 56px;
  --haut-sur: env(safe-area-inset-top, 0px);
  --bas-sur: env(safe-area-inset-bottom, 0px);
  --gauche-sur: env(safe-area-inset-left, 0px);
  --droite-sur: env(safe-area-inset-right, 0px);

  --police: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #141012;
    --surface: #1e191c;
    --encre: #f3edf0;
    --encre-2: #c4b9bf;
    --encre-3: #958990;
    --trait: #332b2f;
    --trait-fort: #7d7077;
    --accent: #5cc2bd;
    --sur-accent: #062221;
    --accent-doux: #173433;

    /* En sombre, l'échelle s'inverse : plus c'est fort, plus c'est clair. */
    --degre-1: #8e3349;
    --degre-2: #b8455f;
    --degre-3: #e05a79;
    --degre-4: #ff94aa;
    --sur-degre-1: #ffffff;
    --sur-degre-2: #ffffff;
    --sur-degre-3: #1a0a10;
    --sur-degre-4: #1a0a10;

    --levre: #3a2a31;
    --levre-contour: #5a414b;
    --serie-prec: #736a6f;
    --mieux: #0ca30c;
    --moins-bien: #f07a7a;
    --sur-moins-bien: #1a0a10;

    --ombre: 0 1px 2px rgb(0 0 0 / 40%);
    --ombre-forte: 0 4px 12px rgb(0 0 0 / 50%), 0 12px 32px rgb(0 0 0 / 40%);
  }
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--fond);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--fond);
  color: var(--encre);
  font-family: var(--police);
  font-size: 1.0625rem;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.25;
}

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent);
}

img,
svg {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
}

input,
select,
textarea {
  accent-color: var(--accent);
}

/* Champs en 16 px au moins : l'iPhone ne zoome pas. */
input[type="text"],
input[type="search"],
input[type="date"],
input[type="number"],
input[type="tel"],
input[type="password"],
input[type="email"],
select,
textarea {
  max-width: 100%;
  min-height: var(--toucher);
  padding: 8px 12px;
  border: 1px solid var(--trait-fort);
  border-radius: 10px;
  background: var(--surface);
  color: var(--encre);
  font-size: max(16px, 1em);
}

textarea {
  min-height: 96px;
  line-height: 1.4;
  resize: vertical;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- mise en page ---------- */

.haut {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--haut-sur);
  background: var(--fond);
}

.entete {
  border-bottom: 1px solid var(--trait);
}

.entete-int {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: var(--colonne);
  min-height: 52px;
  margin: 0 auto;
  padding: 0 calc(var(--marge) - 8px) 0 var(--marge);
  padding-left: max(var(--marge), var(--gauche-sur));
  padding-right: max(calc(var(--marge) - 8px), var(--droite-sur));
}

.entete-nom {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.entete-attente {
  display: inline-flex;
  align-items: center;
  min-height: var(--toucher);
  padding: 0 4px;
  border: 0;
  border-radius: 999px;
  background: none;
}

.ecran {
  display: block;
  max-width: var(--colonne);
  margin: 0 auto;
  padding: 8px var(--marge) calc(var(--hauteur-onglets) + var(--bas-sur) + 32px);
  padding-left: max(var(--marge), var(--gauche-sur));
  padding-right: max(var(--marge), var(--droite-sur));
}

.ecran:focus {
  outline: none;
}

/* Plein écran (fiche poussée, journal, réglages, connexion) : ni en-tête ni onglets. */
body.plein-ecran .haut {
  position: static;
  padding-top: 0;
}

body.plein-ecran .entete,
body.plein-ecran .onglets {
  display: none;
}

body.plein-ecran .ecran {
  padding-top: 0;
  padding-bottom: calc(var(--bas-sur) + 32px);
}

.onglets {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  padding: 0 var(--droite-sur) var(--bas-sur) var(--gauche-sur);
  border-top: 1px solid var(--trait);
  background: var(--surface);
}

.onglets-int {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: var(--colonne);
  margin: 0 auto;
}

.onglet {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--hauteur-onglets);
  color: var(--encre-2);
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
}

/* Anneau de focus dans l'onglet : sinon il sort de l'écran à gauche, à droite et en bas. */
.onglet:focus-visible {
  outline-offset: -4px;
  border-radius: 10px;
}

.onglet[aria-current="page"] {
  color: var(--accent);
  font-weight: 800;
}

.onglet[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 28%;
  right: 28%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}

.onglet svg,
.bouton-icone svg,
.bouton-retour svg,
.cx-effacer svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.onglet[aria-current="page"] svg {
  stroke-width: 2.4;
}

.bouton-icone {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: var(--toucher);
  height: var(--toucher);
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--accent);
}

.bouton-icone:active {
  background: var(--accent-doux);
}

/* ---------- barre du haut des écrans en plein écran ---------- */

/* Grille 1fr · titre · 1fr : le titre reste centré quand il tient, se décale un peu sinon (au lieu d'être coupé). */
.barre-haut {
  position: sticky;
  top: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: 1fr minmax(0, auto) 1fr;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  margin: 0 calc(-1 * var(--marge)) 12px;
  padding: var(--haut-sur) calc(var(--marge) - 8px) 0;
  border-bottom: 1px solid var(--trait);
  background: var(--fond);
}

.barre-haut h1 {
  min-width: 0;
  overflow: hidden;
  font-size: 1.0625rem;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.barre-haut-gauche,
.barre-haut-droite {
  display: flex;
  align-items: center;
}

.barre-haut-droite {
  justify-content: flex-end;
}

.bouton-retour {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: var(--toucher);
  padding: 0 8px 0 2px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--accent);
  font-weight: 600;
}

.bouton-retour:active {
  background: var(--accent-doux);
}

/* ---------- classes partagées ---------- */

.titre-ecran {
  margin: 12px 0 16px;
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.carte,
.rubrique {
  margin: 0 0 12px;
  padding: 16px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  background: var(--surface);
  box-shadow: var(--ombre);
}

.rubrique > h2,
.carte > h2 {
  margin: 0 0 12px;
  font-size: 1.125rem;
  font-weight: 700;
}

.bouton,
.bouton-principal,
.bouton-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--toucher);
  padding: 10px 18px;
  border: 1.5px solid transparent;
  border-radius: var(--rayon);
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
}

.bouton {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
}

.bouton-principal {
  min-height: 52px;
  background: var(--accent);
  color: var(--sur-accent);
  font-weight: 700;
}

.bouton-danger {
  background: var(--moins-bien);
  color: var(--sur-moins-bien);
}

.bouton:active {
  background: var(--accent-doux);
}

.bouton-principal:active,
.bouton-danger:active {
  filter: brightness(0.9);
}

.bouton:disabled,
.bouton-principal:disabled,
.bouton-danger:disabled,
.bouton-lien:disabled {
  opacity: 0.5;
}

.bouton-lien {
  display: inline-flex;
  align-items: center;
  min-height: var(--toucher);
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pleine-largeur {
  width: 100%;
}

.pastille {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--trait);
  color: var(--encre);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.degre-1 {
  background-color: var(--degre-1);
  color: var(--sur-degre-1);
}

.degre-2 {
  background-color: var(--degre-2);
  color: var(--sur-degre-2);
}

.degre-3 {
  background-color: var(--degre-3);
  color: var(--sur-degre-3);
}

.degre-4 {
  background-color: var(--degre-4);
  color: var(--sur-degre-4);
}

.erreur-champ {
  margin: 8px 0 0;
  color: var(--moins-bien);
  font-size: 0.9375rem;
  font-weight: 600;
}

.aide {
  margin: 4px 0 0;
  color: var(--encre-2);
  font-size: 0.9375rem;
}

.puces {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.visuellement-cache {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.chiffres {
  font-variant-numeric: tabular-nums;
}

.vide {
  margin: 0 0 12px;
  padding: 24px 16px;
  border: 1.5px dashed var(--trait);
  border-radius: var(--rayon);
  color: var(--encre-2);
  text-align: center;
}

.pile {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pile > * {
  margin-top: 0;
  margin-bottom: 0;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-doux);
  color: var(--encre);
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Confirmation dans la page (ui.confirmation). */
.confirmation {
  margin: 12px 0;
  padding: 16px;
  border: 1px solid var(--trait);
  border-left: 4px solid var(--trait-fort);
  border-radius: var(--rayon);
  background: var(--surface);
  box-shadow: var(--ombre);
}

.confirmation.danger {
  border-left-color: var(--moins-bien);
}

.confirmation-message {
  margin: 0 0 12px;
  font-weight: 600;
}

/* ---------- états de l'écran ---------- */

.chargement {
  padding: 48px 0;
  color: var(--encre-2);
  text-align: center;
  animation: apparaitre 0.2s ease-out 0.4s both;
}

.indisponible {
  margin-top: 16px;
}

.indisponible p {
  color: var(--encre-2);
}

@keyframes apparaitre {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ---------- bandeau démo ---------- */

.bandeau-demo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 8px;
  padding: 0 var(--marge);
  background: var(--encre);
  color: var(--fond);
  font-size: 0.875rem;
  font-weight: 700;
}

.bandeau-quitter {
  min-height: var(--toucher);
  padding: 0 6px;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.bandeau-demo :focus-visible,
.toast :focus-visible {
  outline-color: currentColor;
}

/* Bouton collé en haut de l'écran : l'anneau est dessiné à l'intérieur, sinon il sort de l'écran. */
.bandeau-quitter:focus-visible {
  outline-offset: -3px;
  border-radius: 6px;
}

/* En sombre, un bandeau clair ferait une bande éblouissante en haut de chaque écran. */
@media (prefers-color-scheme: dark) {
  .bandeau-demo {
    border-bottom: 1px solid var(--trait);
    background: var(--accent-doux);
    color: var(--encre);
  }
}

/* ---------- toasts et message de mise à jour ---------- */

.toasts {
  position: fixed;
  right: 0;
  bottom: calc(var(--hauteur-onglets) + var(--bas-sur) + 12px);
  left: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 var(--marge);
  pointer-events: none;
}

body.plein-ecran .toasts {
  bottom: calc(var(--bas-sur) + 16px);
}

body.maj-visible .toasts {
  bottom: calc(var(--hauteur-onglets) + var(--bas-sur) + 84px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: calc(var(--colonne) - 2 * var(--marge));
  min-height: 48px;
  padding: 8px 12px 8px 16px;
  border-radius: var(--rayon);
  background: var(--encre);
  box-shadow: var(--ombre-forte);
  color: var(--fond);
  font-size: 0.9375rem;
  font-weight: 600;
  pointer-events: auto;
  animation: toast-entree 0.2s ease-out;
}

.toast-texte {
  flex: 1;
  min-width: 0;
}

.toast-ok .toast-texte::before {
  content: "✓\00a0";
}

.toast-erreur {
  background: var(--moins-bien);
  color: var(--sur-moins-bien);
}

.toast-action {
  flex: none;
  min-height: var(--toucher);
  padding: 0 4px;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@keyframes toast-entree {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.maj {
  position: fixed;
  right: var(--marge);
  bottom: calc(var(--hauteur-onglets) + var(--bas-sur) + 12px);
  left: var(--marge);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(var(--colonne) - 2 * var(--marge));
  margin: 0 auto;
  padding: 8px 4px 8px 16px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  background: var(--surface);
  box-shadow: var(--ombre-forte);
  color: var(--encre);
}

body.plein-ecran .maj {
  bottom: calc(var(--bas-sur) + 16px);
}

.maj-texte {
  flex: 1;
  min-width: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.25;
}

.maj .bouton-principal {
  min-height: var(--toucher);
  padding: 8px 14px;
  font-size: 0.9375rem;
}

.maj .bouton-icone {
  color: var(--encre-2);
}

.noscript {
  max-width: var(--colonne);
  margin: 24px auto;
  padding: 0 var(--marge);
}

/* ---------- connexion (cx-) ---------- */

.cx {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 360px;
  margin: 0 auto;
  padding: calc(24px + var(--haut-sur)) 0 16px;
  text-align: center;
}

.cx-logo {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  border-radius: 16px;
}

.cx-titre {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 800;
}

.cx-aide {
  min-height: 1.45em;
  margin: 0 0 20px;
  color: var(--encre-2);
}

.cx-points {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 0 0 12px;
}

.cx-point {
  width: 16px;
  height: 16px;
  border: 2px solid var(--encre-2);
  border-radius: 50%;
}

.cx-point.plein {
  border-color: var(--encre);
  background: var(--encre);
}

.cx-points.secoue {
  animation: cx-secoue 0.4s ease-in-out;
}

@keyframes cx-secoue {
  0%,
  100% {
    transform: none;
  }

  20%,
  60% {
    transform: translateX(-8px);
  }

  40%,
  80% {
    transform: translateX(8px);
  }
}

.cx-message {
  min-height: 3em;
  margin: 0 0 12px;
  font-weight: 600;
}

.cx-message.erreur {
  color: var(--moins-bien);
}

.cx-pave {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  justify-content: center;
  gap: 14px 22px;
}

.cx-touche {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 1px solid var(--trait);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--ombre);
  color: var(--encre);
  font-size: 1.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cx-touche:active {
  background: var(--accent-doux);
}

.cx-effacer {
  border-color: transparent;
  background: none;
  box-shadow: none;
  color: var(--accent);
}

.cx-touche:disabled {
  opacity: 0.45;
}

/* ---------- mouvement réduit ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
