/* =====================================================================
   Thème « Apple » — actif quand <html data-theme="apple">
   Valeurs reprises des Human Interface Guidelines d'Apple (couleurs système,
   Large Title 34 pt, Body 17 pt, listes « inset grouped », barre d'onglets iOS 26).
   Références : developer.apple.com/design/human-interface-guidelines,
   forkco.github.io/dna (jetons iOS en CSS), github.com/trovster/fitness-visualisations (anneaux).
   La police Inter est conservée (rendu des chiffres apprécié).
   ===================================================================== */

html[data-theme="apple"] {
  --sys-blue: #0071e3; /* bleu Apple un peu plus foncé : texte blanc lisible (≥ 4,5:1) */ --sys-green: #34c759; --sys-red: #ff3b30; --sys-orange: #ff9500; --sys-pink: #ff2d55;
  --bg: #f2f2f7; --fg: #000; --muted: rgba(118,118,128,.12); --muted-fg: #6c6c70; --blue-text: #0066cc; --border: rgba(60,60,67,.12);
  --empty: rgba(118,118,128,.14); --radius: 22px; --accent: var(--sys-green);
  --spring: cubic-bezier(.32,1.4,.6,1);
  /* Dégradé du haut, changé selon l'onglet (comme Santé / Forme) */
  --wash-a: rgba(52,199,89,.32); --wash-b: rgba(48,176,199,.28);
  background: var(--bg);
}
html[data-theme="apple"][data-tab="food"] { --wash-a: rgba(255,45,85,.26); --wash-b: rgba(255,149,0,.26); }
html[data-theme="apple"][data-tab="settings"] { --wash-a: rgba(88,86,214,.24); --wash-b: rgba(0,122,255,.22); }

html[data-theme="apple"] body { background: transparent; font-size: 17px; letter-spacing: -.2px; }
html[data-theme="apple"] body::before {
  content: ""; position: fixed; left: 0; right: 0; top: 0; height: 46vh; z-index: -1; pointer-events: none;
  background:
    radial-gradient(70% 90% at 0% 0%, var(--wash-a), transparent 70%),
    radial-gradient(70% 90% at 100% 10%, var(--wash-b), transparent 70%);
  -webkit-mask-image: linear-gradient(#000 40%, transparent); mask-image: linear-gradient(#000 40%, transparent);
  transition: background .6s;
}

/* Gros titre + petite barre de titre qui apparaît au défilement */
html[data-theme="apple"] header.page { margin: 8px 0 18px; }
html[data-theme="apple"] h1 { font-size: 34px; font-weight: 700; letter-spacing: -.8px; }
html[data-theme="apple"] .eyebrow { font-size: 13px; font-weight: 600; color: var(--muted-fg); text-transform: uppercase; letter-spacing: .2px; }
.compact-bar { display: none; }
html[data-theme="apple"] .compact-bar {
  display: flex; align-items: flex-end; justify-content: center; position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  height: calc(env(safe-area-inset-top) + 44px); padding-bottom: 11px; font-weight: 600; font-size: 17px;
  background: rgba(242,242,247,.72); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border-bottom: .5px solid rgba(60,60,67,.18); opacity: 0; transform: translateY(-6px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
html[data-theme="apple"] .compact-bar.show { opacity: 1; transform: none; }

html[data-theme="apple"] .section-title { text-transform: none; letter-spacing: -.3px; font-size: 20px; font-weight: 700; color: var(--fg); margin: 26px 4px 10px; }

/* Cartes « inset grouped » : blanches, sans bordure ni ombre */
html[data-theme="apple"] .card { border: 0; box-shadow: none; border-radius: var(--radius); background: #fff; padding: 16px; }
html[data-theme="apple"] .name { font-size: 17px; font-weight: 600; }
html[data-theme="apple"] .meta { font-size: 15px; color: var(--muted-fg); }
html[data-theme="apple"] .meta svg.lucide { color: var(--sys-orange); }

/* Boutons capsule iOS 26 */
html[data-theme="apple"] .btn { border-radius: 999px; font-size: 17px; font-weight: 600; transition: transform .3s var(--spring), opacity .15s; }
html[data-theme="apple"] .btn { min-height: 44px; }
html[data-theme="apple"] .btn:active { transform: scale(.95); opacity: .8; }
html[data-theme="apple"] .btn-primary { background: var(--sys-blue); color: #fff; }
html[data-theme="apple"] .btn-outline, html[data-theme="apple"] .btn-secondary { background: var(--muted); color: var(--blue-text); border: 0; box-shadow: none; }
html[data-theme="apple"] .btn-ghost { color: var(--blue-text); }
html[data-theme="apple"] .btn-block { height: 52px; }
html[data-theme="apple"] #add-habit-btn { background: #fff; }

/* Cocher : rond comme dans Rappels */
html[data-theme="apple"] .check { width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(60,60,67,.6); background: transparent; color: transparent;
  transition: transform .4s var(--spring), background .2s, border-color .2s; }
html[data-theme="apple"] .check.on { border-color: transparent; color: #fff; }
html[data-theme="apple"] .check:active { transform: scale(.85); }

html[data-theme="apple"] .sq { border-radius: 3.5px; }
/* Carré du jour : anneau intérieur (un contour extérieur se faisait couper au bord de la grille) */
html[data-theme="apple"] .sq.today { outline: none; box-shadow: inset 0 0 0 1.5px var(--sys-blue); }

/* Champs remplis gris, sans bordure */
html[data-theme="apple"] input { background: var(--muted); border: 0; border-radius: 12px; height: 44px; font-size: 17px; }
html[data-theme="apple"] input:focus { box-shadow: 0 0 0 2px var(--sys-blue); }
html[data-theme="apple"] select { background-color: var(--muted); border: 0; border-radius: 12px; height: 44px; font-size: 17px; }
html[data-theme="apple"] select:focus { box-shadow: 0 0 0 2px var(--sys-blue); }
html[data-theme="apple"] .calc-out, html[data-theme="apple"] .calc-rows div { border-top-color: rgba(60,60,67,.18); }
html[data-theme="apple"] .calc-rows div:first-child { border-top: 0; }
html[data-theme="apple"] label.field { font-size: 13px; color: var(--muted-fg); text-transform: uppercase; letter-spacing: .2px; font-weight: 500; }

html[data-theme="apple"] .badge { background: #fff; font-weight: 600; font-size: 13px; padding: 4px 10px; }
html[data-theme="apple"] .thumb { border-radius: 12px; }
/* Listes iOS : séparateurs fins décalés (après l'image ou la pastille), jamais au-dessus du premier
   ni sous le dernier élément, et mêmes marges en haut et en bas */
html[data-theme="apple"] .meal, html[data-theme="apple"] .list-row { border-top: 0; position: relative; }
html[data-theme="apple"] .meal + .meal::before, html[data-theme="apple"] .list-row + .list-row::before {
  content: ""; position: absolute; top: 0; right: 0; height: .5px; background: rgba(60,60,67,.22);
}
html[data-theme="apple"] .meal + .meal::before { left: 60px; }
html[data-theme="apple"] .list-row + .list-row::before { left: 22px; }
html[data-theme="apple"] .meal:first-child, html[data-theme="apple"] .list-row:first-child { padding-top: 2px; }
html[data-theme="apple"] .meal:last-child, html[data-theme="apple"] .list-row:last-child { padding-bottom: 2px; }
/* Feuille « Ajouter un repas » */
html[data-theme="apple"] .food-row + .food-row::before { height: .5px; background: rgba(60,60,67,.22); }
html[data-theme="apple"] .food-row .add { color: var(--blue-text); }
html[data-theme="apple"] .food-row .x { color: #8a8a8e; }
html[data-theme="apple"] .btn.strong { color: var(--blue-text); }
html[data-theme="apple"] .chip { background: #fff; }
html[data-theme="apple"] .chip.on { background: var(--sys-blue); color: #fff; }
html[data-theme="apple"] .qty { border-radius: 16px; }
html[data-theme="apple"] .item input { font-size: 16px; height: 44px; }
html[data-theme="apple"] #analysis input:not(.switch) { background: rgba(118,118,128,.12); }
html[data-theme="apple"] .qty input { background: #fff !important; }

/* Une seule ligne de détail par repas, coupée proprement */
html[data-theme="apple"] .meal .meta { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Corbeille des repas en gris discret (le rouge reste dans Réglages) */
html[data-theme="apple"] .meal .btn-ghost { color: #8a8a8e; }
html[data-theme="apple"] .swatch { border-radius: 50%; }

/* ---------- Anneau d'activité (kcal) ---------- */
.ring-wrap { display: none; }
html[data-theme="apple"] .ring-wrap { display: flex; align-items: center; gap: 18px; }
html[data-theme="apple"] #tab-food .stat, html[data-theme="apple"] #tab-food .bar { display: none; }
.ring { width: 112px; height: 112px; transform: rotate(-90deg); flex-shrink: 0; }
.ring circle { fill: none; stroke-width: 16; stroke-linecap: round; }
.ring .track { stroke: rgba(255,45,85,.16); }
.ring .val { stroke: url(#ringGrad); transition: stroke-dashoffset .9s var(--spring); }
.ring-num { font-size: 34px; font-weight: 700; letter-spacing: -1px; font-variant-numeric: tabular-nums; line-height: 1; color: var(--sys-pink); }
.ring-sub { font-size: 15px; color: var(--muted-fg); margin-top: 4px; }

/* ---------- Analyse du repas en feuille (sheet) ---------- */
.sheet-dim { display: none; }
html[data-theme="apple"] .sheet-dim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 20; opacity: 0; pointer-events: none; transition: opacity .3s; }
html[data-theme="apple"] .sheet-dim.show { opacity: 1; pointer-events: auto; }
html[data-theme="apple"] #analysis {
  position: fixed; left: 8px; right: 8px; bottom: 8px; margin: 0 auto !important; max-width: 544px; z-index: 21;
  max-height: 86vh; overflow: auto; border-radius: 32px; padding: 26px 18px calc(env(safe-area-inset-bottom) + 18px);
  background: #fff;
  box-shadow: 0 -10px 40px rgba(0,0,0,.12); animation: sheetUp .45s var(--spring);
}
/* Poignée : reste en haut de la feuille, par-dessus l'en-tête collant */
html[data-theme="apple"] #analysis::before { content: ""; position: sticky; display: block; z-index: 3; top: -18px; width: 36px; height: 5px; margin: -18px auto 13px; border-radius: 3px; background: rgba(60,60,67,.3); }
@keyframes sheetUp { from { transform: translateY(100%); } }

/* ---------- Barre d'onglets flottante iOS 26 ---------- */
html[data-theme="apple"] body { padding-bottom: calc(env(safe-area-inset-bottom) + 110px); }
html[data-theme="apple"] nav {
  left: 50%; right: auto; bottom: calc(env(safe-area-inset-bottom) + 10px); transform: translateX(-50%);
  width: min(92vw, 360px); padding: 5px; gap: 2px; border: 0; border-radius: 999px;
  background: rgba(250,250,252,.62); -webkit-backdrop-filter: blur(24px) saturate(200%); backdrop-filter: blur(24px) saturate(200%);
  box-shadow: inset 0 .5px 0 rgba(255,255,255,.9), 0 0 0 .5px rgba(0,0,0,.06), 0 10px 30px -8px rgba(0,0,0,.2);
  transition: transform .5s var(--spring), opacity .3s;
}
html[data-theme="apple"] nav.away { transform: translate(-50%, 140%); opacity: 0; }
html[data-theme="apple"] nav button { border-radius: 999px; padding: 8px 4px; color: #1c1c1e; font-size: 11px; font-weight: 600; transition: background .3s, color .2s; }
html[data-theme="apple"] nav button.active { color: var(--blue-text); background: rgba(118,118,128,.14); }

/* Toast en capsule en haut */
html[data-theme="apple"] .toast {
  top: auto; bottom: calc(env(safe-area-inset-bottom) + 84px); border-radius: 999px; padding: 12px 18px; background: rgba(28,28,30,.92);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); font-weight: 600;
  transform: translate(-50%, 16px) scale(.92); transition: opacity .25s, transform .5s var(--spring);
}
html[data-theme="apple"] .toast.show { transform: translate(-50%, 0) scale(1); }
html[data-theme="apple"] .toast.has-undo { top: auto; bottom: calc(env(safe-area-inset-bottom) + 84px); }
html[data-theme="apple"] body.sheet-open .toast { top: calc(env(safe-area-inset-top) + 10px); bottom: auto; }

/* Contrôle segmenté iOS */
html[data-theme="apple"] .seg { border-radius: 12px; background: var(--muted); padding: 2px; gap: 0; }
html[data-theme="apple"] .seg.seg4 button { font-size: 12.5px; padding: 0 2px; }
html[data-theme="apple"] .seg button { height: 44px; border-radius: 8px; font-size: 13px; color: #000; }
html[data-theme="apple"] .seg button.on { box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 3px 1px rgba(0,0,0,.04); }

html[data-theme="apple"] section:not(.hidden) .card { animation: rise .45s var(--spring) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { html[data-theme="apple"] .card, html[data-theme="apple"] #analysis { animation: none !important; } }

/* Habitudes : pastille « J'ai fait hier » */
html[data-theme="apple"] .pill { background: rgba(118,118,128,.12); color: var(--blue-text); }
/* Un seul anneau de focus sur les champs ; carrés pâles lisibles sur blanc */
html[data-theme="apple"] input:focus-visible { outline: none; }
html[data-theme="apple"] .sq { box-shadow: inset 0 0 0 1px rgba(60,60,67,.06); }
html[data-theme="apple"] .sq.sel { box-shadow: 0 0 0 2px var(--fg); }
/* --- Corrections issues des tests --- */
/* Bouton « + » rond, de la même hauteur que « Photographier » */
html[data-theme="apple"] #manual-btn { width: 52px !important; height: 52px; }
/* En-tête de la feuille (Annuler / Enregistrer) toujours visible en défilant */
html[data-theme="apple"] .sheet-head { top: -26px; background: #fff; margin: -26px -18px 12px; padding: 30px 10px 6px; }
/* Légende et repère du carré « au-dessus » en orange */
html[data-theme="apple"] .legend { font-size: 12px; }
