/* ============================================================================
   MPA · la feuille de style

   MOBILE D'ABORD. Tout est dessine pour un pouce : cibles de 44 px au minimum,
   saisie dans une feuille qui remonte du bas, listes plutot que tableaux. Le
   large ecran n'ajoute que de la place, jamais une autre organisation.

   AUCUN BLANC PUR SUR FOND SOMBRE, AUCUN NOIR PUR SUR FOND CLAIR : le texte
   clair est un gris bleute, le texte sombre un bleu nuit.
============================================================================ */

:root {
  --fond: #F6F4F1;
  --surface: #FDFCFB;
  --surface-2: #EFEBE6;
  --texte: #1D2430;
  --texte-doux: #5E6675;
  --bord: #E3DDD6;
  --accent: #2E6B5E;
  --accent-doux: #E4EDEA;
  --danger: #B4574A;
  --ok: #3E7D53;
  --ombre: 0 1px 2px rgba(29, 36, 48, .06), 0 6px 18px rgba(29, 36, 48, .07);
  --r: 14px;
  --gouttiere: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #14181E;
    --surface: #1C222B;
    --surface-2: #252D38;
    --texte: #DFE5EC;
    --texte-doux: #96A0AE;
    --bord: #2E3742;
    --accent: #5FAE97;
    --accent-doux: #23332E;
    --danger: #D4796A;
    --ok: #6FB587;
    --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }
/* `hidden` doit l'emporter : .feuille et .voile posent un display. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { fill: currentColor; stroke: none; }

/* ---------------------------------------------------------------- En-tete -- */

.entete {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gouttiere) 10px;
  background: color-mix(in srgb, var(--fond) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--bord);
}

.marque {
  font-weight: 750;
  letter-spacing: .06em;
  font-size: 15px;
  color: var(--accent);
  flex: none;
}

.bouton-icone {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--texte-doux);
  cursor: pointer;
}
.bouton-icone:hover { background: var(--surface-2); }
.bouton-icone svg path { stroke: currentColor; fill: none; }

/* ------------------------------------------------------------- Personnes -- */

.personnes {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.personnes::-webkit-scrollbar { display: none; }

.puce {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px 0 6px;
  border: 1px solid var(--bord);
  border-radius: 19px;
  background: var(--surface);
  color: var(--texte-doux);
  font-size: 14.5px;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
}
.puce[aria-selected="true"] {
  border-color: transparent;
  background: var(--pastille, var(--accent));
  color: #FDFCFB;
  box-shadow: var(--ombre);
}
@media (prefers-color-scheme: dark) {
  .puce[aria-selected="true"] { color: #10141A; }
}

.initiale {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--pastille, var(--accent));
  color: #FDFCFB;
  font-size: 12px;
  font-weight: 700;
}
.puce[aria-selected="true"] .initiale {
  background: rgba(253, 252, 251, .22);
  color: inherit;
}

/* -------------------------------------------------------------- Sections -- */

.sections {
  display: flex;
  gap: 4px;
  padding: 10px var(--gouttiere) 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.sections::-webkit-scrollbar { display: none; }

.onglet {
  flex: none;
  height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--texte-doux);
  font-size: 14.5px;
  font-weight: 560;
  cursor: pointer;
}
.onglet[aria-selected="true"] { background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }

/* ------------------------------------------------------------------ Vues -- */

main { padding: 12px var(--gouttiere) 0; max-width: 760px; margin: 0 auto; }

.carte {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--ombre);
}
.carte > h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--texte-doux); margin-bottom: 10px; }

.vide { color: var(--texte-doux); font-size: 14.5px; padding: 6px 0; }

/* ---------------------------------------------------------------- Courbe -- */

.courbe-tete {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.valeur-actuelle { font-size: 30px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.valeur-actuelle .u { font-size: 16px; font-weight: 600; color: var(--texte-doux); margin-left: 2px; }
.sous-valeur { font-size: 14px; color: var(--texte-doux); white-space: nowrap; }

/* LE RANG DE SEGMENTS DEFILE PLUTOT QUE D'ELARGIR SA CARTE. Avec `flex: 1`
   seul, un libelle long (« P. crânien ») impose sa largeur minimale au rang,
   le rang a la carte, la carte a la page : tout l'ecran deborde a cause d'un
   mot. `flex: 1 0 auto` laisse grandir sans jamais forcer le retrecissement,
   et le conteneur defile quand le compte n'y est pas. */
.segments {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.segments::-webkit-scrollbar { display: none; }
.segments button {
  flex: 1 0 auto;
  height: 32px;
  min-width: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--texte-doux);
  font-size: 13.5px;
  font-weight: 580;
  cursor: pointer;
  white-space: nowrap;
}
.segments button[aria-selected="true"] { background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }

.cadre-courbe { position: relative; width: 100%; height: 260px; margin-top: 10px; }
@media (min-width: 640px) { .cadre-courbe { height: 320px; } }
.cadre-courbe svg { width: 100%; height: 100%; display: block; touch-action: pan-y; }

.grille line { stroke: var(--bord); stroke-width: 1; }
text.axe { fill: var(--texte-doux); font-size: 10.5px; }
.bande { stroke: none; }
.bande.z2 { fill: var(--accent); opacity: .15; }
.bande.z3 { fill: var(--accent); opacity: .07; }
.mediane { stroke: var(--texte-doux); stroke-width: 1; stroke-dasharray: 3 4; opacity: .8; }
.serie { stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.point { stroke: var(--surface); stroke-width: 1.6; }
.point.dernier { stroke-width: 2.4; }
.objectif { stroke: var(--danger); stroke-width: 1.4; stroke-dasharray: 5 4; }
text.objectif-txt { fill: var(--danger); font-size: 10.5px; font-weight: 600; }
.bulle-fond { fill: var(--texte); opacity: .93; }
text.bulle-txt { fill: var(--surface); font-size: 12px; font-weight: 600; }

.legende { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 12.5px; color: var(--texte-doux); }
.legende i { display: inline-block; width: 16px; height: 9px; border-radius: 2px; vertical-align: -1px; margin-right: 5px; }

/* --------------------------------------------------------------- Listes --- */

.liste { list-style: none; margin: 0; padding: 0; }
.liste li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--bord);
}
.liste li:first-child { border-top: 0; }
.liste .quand { flex: none; width: 74px; font-size: 12.5px; color: var(--texte-doux); padding-top: 2px; }
.liste .quoi { flex: 1; min-width: 0; }
.liste .quoi strong { font-weight: 600; }
.liste .detail { display: block; font-size: 13.5px; color: var(--texte-doux); margin-top: 2px; }
.liste .agir { flex: none; }

/* Le journal des progres : le texte prend toute la largeur, l'entete porte
   le mois, l'age et le bouton. */
.liste li.mois { display: block; padding: 13px 0; }
.mois-tete { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.mois-nom { font-size: 13px; font-weight: 700; text-transform: capitalize; }
.mois-age { flex: 1; font-size: 12.5px; color: var(--texte-doux); white-space: nowrap; }
.mois-texte { margin: 0; font-size: 15.5px; }
.mois-parole { margin: 4px 0 0; font-size: 13.5px; color: var(--texte-doux); }

.etiquette {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--texte-doux);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.etiquette.alerte { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.etiquette.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

/* --------------------------------------------------------------- Boutons -- */

.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--bord);
  border-radius: 11px;
  background: var(--surface);
  color: var(--texte);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.bouton.plein { background: var(--accent); border-color: transparent; color: #FDFCFB; }
@media (prefers-color-scheme: dark) { .bouton.plein { color: #10141A; } }
.bouton.large { width: 100%; }
.bouton.discret { border: 0; background: transparent; color: var(--texte-doux); min-height: 36px; padding: 0 8px; }
.bouton.danger { color: var(--danger); }
.bouton:disabled { opacity: .5; cursor: default; }

.fab {
  position: fixed;
  right: var(--gouttiere);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 25;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #FDFCFB;
  box-shadow: 0 4px 16px rgba(29, 36, 48, .28);
  cursor: pointer;
}
@media (prefers-color-scheme: dark) { .fab { color: #10141A; } }
.fab svg path { stroke: currentColor; fill: none; }

/* --------------------------------------------------------------- Feuille -- */

.voile {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(20, 24, 30, .42);
  backdrop-filter: blur(2px);
}

.feuille {
  position: fixed;
  z-index: 41;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 30px rgba(20, 24, 30, .24);
  animation: monter .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes monter { from { transform: translateY(14px); opacity: .4; } }
@media (min-width: 680px) {
  .feuille { left: 50%; right: auto; bottom: 24px; width: 560px; transform: translateX(-50%); border-radius: 18px; }
  @keyframes monter { from { transform: translateX(-50%) translateY(14px); opacity: .4; } }
}

.feuille-poignee { width: 38px; height: 4px; border-radius: 2px; background: var(--bord); margin: 8px auto 0; }
.feuille-entete { display: flex; align-items: center; gap: 8px; padding: 10px 14px 6px; }
.feuille-entete h2 { flex: 1; font-size: 17px; }
.feuille-corps { overflow-y: auto; padding: 4px 16px calc(env(safe-area-inset-bottom) + 18px); }

/* ------------------------------------------------------------ Formulaires - */

.champ { display: block; margin-bottom: 12px; }
.champ > span { display: block; font-size: 13px; font-weight: 600; color: var(--texte-doux); margin-bottom: 5px; }
.champ input, .champ select, .champ textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--bord);
  border-radius: 11px;
  background: var(--fond);
  color: var(--texte);
  font-size: 16px; /* en dessous de 16 px, iOS zoome a la mise au point */
}
.champ textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.champ input:focus, .champ select:focus, .champ textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions { display: flex; gap: 10px; margin-top: 6px; }
.actions .bouton { flex: 1; }

/* ------------------------------------------------------------------ Diete - */

.jour-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.jour-nav .bouton-icone { border: 1px solid var(--bord); border-radius: 11px; width: 44px; height: 44px; }
.jour-nav .jour-titre { flex: 1; text-align: center; font-weight: 650; }
.jour-nav .jour-titre small { display: block; font-weight: 500; font-size: 12.5px; color: var(--texte-doux); }

.groupe-titre {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--texte-doux);
  font-weight: 700;
  margin: 16px 0 4px;
}
.repas-titre { font-size: 13.5px; font-weight: 650; color: var(--texte); margin: 10px 0 2px; }

.coche {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 6px 4px;
  border: 0;
  border-top: 1px solid var(--bord);
  background: transparent;
  text-align: left;
  font-size: 15.5px;
  cursor: pointer;
}
.coche .case {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid var(--bord);
  border-radius: 8px;
  color: transparent;
}
.coche[aria-pressed="true"] .case { background: var(--ok); border-color: var(--ok); color: #FDFCFB; }
.coche[aria-pressed="true"] .case svg path { stroke: currentColor; fill: none; }
.coche .nom { flex: 1; }

.compteur { display: flex; align-items: center; gap: 10px; min-height: 50px; border-top: 1px solid var(--bord); padding: 6px 4px; }
.compteur .nom { flex: 1; font-size: 15.5px; }
.compteur .cible { font-size: 12.5px; color: var(--texte-doux); display: block; }
.pas { display: flex; align-items: center; gap: 2px; }
.pas button {
  width: 38px; height: 38px;
  border: 1px solid var(--bord);
  background: var(--surface);
  color: var(--texte);
  font-size: 19px;
  font-weight: 600;
  cursor: pointer;
}
.pas button:first-child { border-radius: 10px 0 0 10px; }
.pas button:last-child { border-radius: 0 10px 10px 0; }
.pas input {
  width: 58px; height: 38px;
  border: 1px solid var(--bord);
  border-left: 0; border-right: 0;
  background: var(--fond);
  color: var(--texte);
  text-align: center;
  font-size: 16px;
  font-weight: 650;
}
.pas input.atteint { color: var(--ok); }
.pas input.rate { color: var(--danger); }

.semaine { display: flex; gap: 5px; margin-top: 4px; }
.semaine button {
  flex: 1;
  min-width: 0;
  padding: 7px 2px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  text-align: center;
}
.semaine button[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.semaine .j { display: block; font-size: 11px; color: var(--texte-doux); }
.semaine .n { display: block; font-size: 15px; font-weight: 650; }
.semaine .pastille { display: block; height: 4px; border-radius: 2px; margin-top: 5px; background: var(--bord); }

/* ------------------------------------------------------------------ Toast - */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  z-index: 60;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 11px;
  background: var(--texte);
  color: var(--surface);
  font-size: 14.5px;
  font-weight: 560;
  box-shadow: var(--ombre);
}

/* ------------------------------------------------------------------ Divers - */

.rangee { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pile { display: flex; flex-direction: column; gap: 8px; }
.muet { color: var(--texte-doux); }
.petit { font-size: 13px; }
.nowrap { white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
