/* ==========================================================================
   styles.css — Trophea
   Interface pensée pour iPhone : cibles tactiles généreuses, safe-area,
   pas de survol, contraste élevé en extérieur.
   ========================================================================== */

:root {
  --bg:        #0b0e13;
  --bg-2:      #131820;
  --carte:     #171d27;
  --carte-2:   #1e2530;
  --bord:      #2a3341;
  --txt:       #eef2f7;
  --txt-2:     #97a3b6;
  --txt-3:     #5f6b7d;

  --prot:      #ff6b6b;
  --gluc:      #4dabf7;
  --lip:       #ffd43b;
  --kcal:      #51cf66;

  --ok:        #51cf66;
  --warn:      #ffa94d;
  --bad:       #ff6b6b;
  --accent:    #5b8cff;

  --r:         16px;
  --r-s:       10px;
  --sp:        16px;

  --safe-t:    env(safe-area-inset-top, 0px);
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --nav-h:     58px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:      #f2f4f8;
    --bg-2:    #ffffff;
    --carte:   #ffffff;
    --carte-2: #f6f8fb;
    --bord:    #e2e8f0;
    --txt:     #0f172a;
    --txt-2:   #64748b;
    --txt-3:   #94a3b8;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, select, textarea {
  background: var(--carte-2);
  border: 1px solid var(--bord);
  border-radius: var(--r-s);
  padding: 11px 13px;
  width: 100%;
  font-size: 16px; /* < 16px déclenche le zoom auto sur iOS */
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* --------------------------------------------------------------- En-tête */

header {
  position: sticky; top: 0; z-index: 50;
  padding: calc(var(--safe-t) + 14px) var(--sp) 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--bord);
}
header h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
header .sous { color: var(--txt-2); font-size: 13px; margin-top: 2px; }

main { padding: var(--sp); max-width: 680px; margin: 0 auto; }
.vue { display: none; }
.vue.actif { display: block; animation: entree .22s ease; }
@keyframes entree { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- Cartes */

.carte {
  background: var(--carte);
  border: 1px solid var(--bord);
  border-radius: var(--r);
  padding: var(--sp);
  margin-bottom: 14px;
}
.carte h2 {
  margin: 0 0 12px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--txt-2);
}
.carte h3 { margin: 0 0 8px; font-size: 17px; font-weight: 650; }

.rangee { display: flex; align-items: center; gap: 12px; }
.entre  { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pousse { margin-left: auto; }

/* -------------------------------------------------------------- Anneau kcal */

.anneau { display: flex; align-items: center; gap: 20px; }
.anneau svg { width: 116px; height: 116px; flex-shrink: 0; transform: rotate(-90deg); }
.anneau .piste { fill: none; stroke: var(--carte-2); stroke-width: 11; }
.anneau .jauge { fill: none; stroke: var(--kcal); stroke-width: 11; stroke-linecap: round;
                 transition: stroke-dasharray .6s cubic-bezier(.4,0,.2,1); }
.anneau .centre { font-size: 30px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.anneau .centre small { display: block; font-size: 12px; font-weight: 500; color: var(--txt-2); margin-top: 3px; }

/* --------------------------------------------------------------- Macros */

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.macro { background: var(--carte-2); border-radius: var(--r-s); padding: 11px; text-align: center; }
.macro .nom { font-size: 11px; color: var(--txt-2); text-transform: uppercase; letter-spacing: .5px; }
.macro .val { font-size: 19px; font-weight: 700; margin: 3px 0; letter-spacing: -0.3px; }
.macro .cible { font-size: 11px; color: var(--txt-3); }
.macro .barre { height: 4px; background: var(--bord); border-radius: 2px; margin-top: 7px; overflow: hidden; }
.macro .barre i { display: block; height: 100%; border-radius: 2px; transition: width .5s ease; }
.macro.p .val, .macro.p .barre i { color: var(--prot); background: var(--prot); }
.macro.g .val, .macro.g .barre i { color: var(--gluc); background: var(--gluc); }
.macro.l .val, .macro.l .barre i { color: var(--lip);  background: var(--lip); }
.macro .val { background: none !important; }

/* ------------------------------------------------------- Navigation jour */

.barre-jour {
  display: flex; align-items: stretch; gap: 8px;
  background: var(--carte); border: 1px solid var(--bord);
  border-radius: var(--r); padding: 6px; margin-bottom: 14px;
}
.barre-jour > button {
  display: grid; place-items: center;
  color: var(--txt-2); border-radius: var(--r-s);
  min-width: 46px; font-size: 26px; line-height: 1;
}
.barre-jour > button:active { background: var(--carte-2); }
.barre-jour .milieu { flex: 1; min-width: 0; padding: 6px 4px; }
.barre-jour .milieu .lib {
  font-size: 16.5px; font-weight: 650; color: var(--txt); letter-spacing: -0.2px;
  text-transform: capitalize;
}
.barre-jour .milieu .dat { font-size: 12px; color: var(--txt-2); margin-top: 1px; }

/* ------------------------------------------------------------- Exercices */

.bloc-exo {
  background: var(--carte-2); border: 1px solid var(--bord);
  border-radius: var(--r-s); padding: 12px; margin-bottom: 10px;
}
.serie { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.serie .num {
  width: 22px; height: 22px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--bord); border-radius: 50%;
  font-size: 11px; font-weight: 700; color: var(--txt-2);
}
/* Largeur fixe : sans elle, le champ mange toute la ligne et le libellé
   voisin s'empile lettre à lettre sur plusieurs lignes. */
.serie input[type="number"] { width: 76px; flex: 0 0 76px; padding: 8px 6px; text-align: center; }
.serie input[type="text"] { flex: 1; min-width: 0; padding: 8px 10px; }
.serie .unite { font-size: 12px; color: var(--txt-3); white-space: nowrap; }
.serie .pdc { font-size: 12px; color: var(--txt-3); flex: 1; white-space: nowrap; }
.serie button { flex-shrink: 0; }

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

.liste { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--carte-2);
  border: 1px solid transparent;
  border-radius: var(--r-s);
  padding: 11px 13px;
  text-align: left;
  width: 100%;
}
.item:active { background: var(--bord); }
.item .vign {
  width: 42px; height: 42px; border-radius: 9px; flex-shrink: 0;
  background: var(--bord); object-fit: cover;
  display: grid; place-items: center; font-size: 19px;
  overflow: hidden;   /* une photo distante ne doit jamais déborder de sa case */
}
.item .corps { min-width: 0; flex: 1; }
.item .titre {
  font-size: 14.5px; font-weight: 550; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.item .meta { font-size: 12px; color: var(--txt-2); margin-top: 2px; }
.item .fin { text-align: right; flex-shrink: 0; font-size: 13px; color: var(--txt-2); }

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

.btn {
  background: var(--accent); color: #fff;
  border-radius: var(--r-s); padding: 13px 18px;
  font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:active { opacity: .75; }
.btn.plein  { width: 100%; }
.btn.fant   { background: var(--carte-2); color: var(--txt); border: 1px solid var(--bord); }
.btn.danger { background: var(--bad); }
.btn.petit  { padding: 8px 13px; font-size: 13.5px; border-radius: 8px; }

.puces { display: flex; flex-wrap: wrap; gap: 8px; }
.puce {
  background: var(--carte-2); border: 1px solid var(--bord);
  border-radius: 999px; padding: 7px 14px; font-size: 13.5px; color: var(--txt-2);
}
.puce.actif { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------ Navigation */

nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex;
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--bord);
}
nav button {
  flex: 1; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--txt-3); font-size: 10px; font-weight: 600;
}
nav button svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.9; }
nav button.actif { color: var(--accent); }

/* --------------------------------------------------------------- Alertes */

.alerte {
  display: flex; gap: 10px; align-items: flex-start;
  border-radius: var(--r-s); padding: 11px 13px; font-size: 13.5px;
  margin-bottom: 8px; line-height: 1.4;
}
.alerte.ok   { background: color-mix(in srgb, var(--ok) 13%, transparent);   color: var(--ok); }
.alerte.warn { background: color-mix(in srgb, var(--warn) 13%, transparent); color: var(--warn); }
.alerte.bad  { background: color-mix(in srgb, var(--bad) 13%, transparent);  color: var(--bad); }

/* --------------------------------------------------------- Micronutriments */

.micro { display: flex; align-items: center; gap: 11px; padding: 8px 0; border-bottom: 1px solid var(--bord); }
.micro:last-child { border-bottom: none; }
.micro .nom  { font-size: 13.5px; width: 120px; flex-shrink: 0; font-weight: 500; }
.micro .jauge { flex: 1; height: 6px; background: var(--carte-2); border-radius: 3px; overflow: hidden; }
.micro .jauge i { display: block; height: 100%; border-radius: 3px; transition: width .5s ease; }
.micro .pct  { font-size: 12px; width: 46px; text-align: right; color: var(--txt-2); font-variant-numeric: tabular-nums; }
.micro.ok    .jauge i { background: var(--ok); }
.micro.moyen .jauge i { background: var(--warn); }
.micro.bas   .jauge i { background: var(--bad); }
/* Donnée partielle : hachures, pour distinguer « je ne sais pas » de « il en manque ». */
.micro.inconnu .jauge i {
  background: repeating-linear-gradient(45deg,
    var(--txt-3) 0 4px, transparent 4px 8px);
}
.micro.inconnu .pct { color: var(--txt-3); font-style: italic; }

/* ---------------------------------------------------------------- Modale */

.modale {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.55);
  display: none; align-items: flex-end;
  backdrop-filter: blur(3px);
}
.modale.ouvert { display: flex; }
.modale .feuille {
  background: var(--bg-2);
  border-radius: 22px 22px 0 0;
  width: 100%; max-height: 92vh;
  padding: 8px var(--sp) calc(var(--sp) + var(--safe-b));
  overflow-y: auto;
  animation: monte .28s cubic-bezier(.32,.72,0,1);
  -webkit-overflow-scrolling: touch;
}
@keyframes monte { from { transform: translateY(100%); } }
.poignee { width: 38px; height: 5px; background: var(--bord); border-radius: 3px; margin: 6px auto 14px; }

/* ----------------------------------------------------------------- Repas */

.repas { background: var(--carte); border: 1px solid var(--bord); border-radius: var(--r); overflow: hidden; margin-bottom: 14px; }
.repas .tete { padding: 13px var(--sp); border-bottom: 1px solid var(--bord); }
.repas .tete .nom { font-size: 16.5px; font-weight: 650; }
.repas .tete .kcal { font-size: 13px; color: var(--txt-2); margin-top: 2px; }
.repas .contenu { padding: 10px var(--sp) var(--sp); }
.ingr { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--bord); }
.ingr:last-child { border-bottom: none; }
.ingr .ph {
  width: 46px; height: 46px; border-radius: 9px; flex-shrink: 0;
  background: var(--carte-2); display: grid; place-items: center; font-size: 20px;
  overflow: hidden;
}
/* Les vignettes distantes sont de tailles très variables : on les contraint
   strictement, sinon une image haute repousse la ligne suivante. */
.ingr .ph img, .item .vign img {
  display: block; width: 100%; height: 100%; object-fit: cover;
}
.ingr .nom { font-size: 14px; line-height: 1.3; flex: 1; min-width: 0; }
.ingr .qte { font-size: 14px; font-weight: 650; color: var(--accent); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.ingr .role { font-size: 11px; color: var(--txt-3); text-transform: uppercase; letter-spacing: .4px; }

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

.vide { text-align: center; padding: 44px 20px; color: var(--txt-2); }
.vide .emoji { font-size: 46px; display: block; margin-bottom: 12px; opacity: .65; }
.vide p { margin: 0 0 16px; font-size: 14.5px; line-height: 1.5; }

.champ { margin-bottom: 14px; }
.champ label { display: block; font-size: 13px; color: var(--txt-2); margin-bottom: 6px; font-weight: 500; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.stat { text-align: center; padding: 12px 6px; background: var(--carte-2); border-radius: var(--r-s); }
.stat .v { font-size: 21px; font-weight: 700; letter-spacing: -0.4px; }
.stat .l { font-size: 11px; color: var(--txt-2); margin-top: 2px; }
.grille3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grille2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.charge { margin-top: 10px; }
.charge .barre { height: 8px; background: var(--carte-2); border-radius: 4px; overflow: hidden; display: flex; }
.charge .barre i { display: block; height: 100%; }

.sep { height: 1px; background: var(--bord); margin: 16px 0; }
.mini { font-size: 12px; color: var(--txt-3); line-height: 1.5; }

.chargement { text-align: center; padding: 60px 20px; color: var(--txt-2); }
.spin {
  width: 30px; height: 30px; margin: 0 auto 14px;
  border: 3px solid var(--bord); border-top-color: var(--accent);
  border-radius: 50%; animation: tourne .8s linear infinite;
}
@keyframes tourne { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
