/* =====================================================================
   MACRO — feuille de style unique.
   Thème sombre par défaut, clair au basculement. Tous les tons dérivent
   des variables ci-dessous : changer le thème ne touche qu'à :root.
   ===================================================================== */

@font-face {
  font-family: 'Inter';
  src: url('assets/fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  /* — Marque : vert « frais » vers cyan, l'énergie sans le côté fluo — */
  --brand:        #7ee081;
  --brand-2:      #35d0c0;
  --brand-ink:    #0a1a12;
  --brand-glow:   rgba(126, 224, 129, .22);
  --grad-brand:   linear-gradient(135deg, #7ee081 0%, #35d0c0 100%);

  /* — Macronutriments : une couleur = un nutriment, partout — */
  --c-kcal:    #7ee081;
  --c-protein: #5b9dff;
  --c-carbs:   #ffb340;
  --c-fat:     #ff6b9d;
  --c-fiber:   #a78bfa;
  --c-water:   #38bdf8;

  /* — Sémantique — */
  --ok:      #4ade80;
  --warn:    #fbbf24;
  --danger:  #fb7185;
  --info:    #60a5fa;

  /* — Surfaces (sombre) : échelle d'élévation canvas < carte < champ < popover — */
  --bg:        #0a0d12;
  --bg-2:      #0d1117;
  --surface:   #12161f;
  --surface-2: #171c27;
  --surface-3: #1e2532;
  --rail:      #0c1017;
  --border:    rgba(255, 255, 255, .075);
  --border-2:  rgba(255, 255, 255, .14);
  --ink:       #f2f5f8;
  --ink-2:     rgba(242, 245, 248, .72);
  --ink-3:     rgba(242, 245, 248, .52);
  --ink-4:     rgba(242, 245, 248, .32);
  --hover:       rgba(255, 255, 255, .045);
  --active:      rgba(255, 255, 255, .08);
  --active-hover: rgba(255, 255, 255, .12);   /* survol d'un élément DÉJÀ actif : doit monter, pas descendre */
  --pop-hover:   rgba(255, 255, 255, .07);    /* item de popover / menu */
  --field-hover: rgba(255, 255, 255, .02);    /* champ survolé, posé sur surface-2 */
  --btn-hover:   #212836;                     /* bouton survolé : distinct de surface-3 (popovers) */
  --overlay:   rgba(4, 6, 10, .66);
  --glass:     rgba(13, 17, 23, .72);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .32);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, .3), 0 12px 28px -14px rgba(0, 0, 0, .6);
  --shadow-3: 0 8px 24px rgba(0, 0, 0, .34), 0 32px 64px -24px rgba(0, 0, 0, .7);
  --ring:     0 0 0 3px rgba(126, 224, 129, .22);

  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-xl: 26px; --r-full: 999px;
  --sp: 4px;
  --rail-w: 244px;
  --ease: cubic-bezier(.32, .72, 0, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

:root[data-theme='light'] {
  --bg:        #f4f6f8;
  --bg-2:      #eef1f5;
  --surface:   #ffffff;
  --surface-2: #f5f7fa;
  --surface-3: #ffffff;
  --rail:      #eef1f5;
  --border:    rgba(9, 15, 26, .09);
  --border-2:  rgba(9, 15, 26, .16);
  --ink:       #0d1420;
  --ink-2:     rgba(13, 20, 32, .74);
  --ink-3:     rgba(13, 20, 32, .56);
  --ink-4:     rgba(13, 20, 32, .34);
  --hover:       rgba(9, 15, 26, .045);
  --active:      rgba(9, 15, 26, .075);
  --active-hover: rgba(9, 15, 26, .11);
  --pop-hover:   rgba(9, 15, 26, .06);
  --field-hover: #eef1f6;
  --btn-hover:   #e9edf3;
  --overlay:   rgba(20, 26, 38, .34);
  --glass:     rgba(255, 255, 255, .78);
  --brand:     #22a06b;
  --brand-2:   #0ea5a5;
  --brand-glow: rgba(34, 160, 107, .18);
  --grad-brand: linear-gradient(135deg, #22a06b 0%, #0ea5a5 100%);
  --c-kcal:    #22a06b;
  --c-protein: #2b6ff5;
  --c-carbs:   #d98207;
  --c-fat:     #e0457b;
  --c-fiber:   #7c5cf6;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-2: 0 1px 3px rgba(16, 24, 40, .08), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --shadow-3: 0 8px 28px -8px rgba(16, 24, 40, .18), 0 24px 56px -28px rgba(16, 24, 40, .28);
  --ring:     0 0 0 3px rgba(34, 160, 107, .18);
}

/* ------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
/* Taille de base de toute icône du sprite ; les règles contextuelles ci-dessous l'affinent. */
.ico { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--brand-glow); }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Barres de défilement discrètes */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-4); background-clip: content-box; }

/* =================================================== structure app */
.app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100dvh; }

/* Halo de marque très diffus en fond : donne de la profondeur sans image */
.app::before {
  content: ''; position: fixed; inset: -20% -10% auto -10%; height: 60vh; pointer-events: none; z-index: 0;
  background: radial-gradient(60% 60% at 20% 0%, var(--brand-glow), transparent 70%),
              radial-gradient(50% 50% at 85% 5%, rgba(53, 208, 192, .12), transparent 70%);
  opacity: .8;
}

/* ------------------------------------------------------------- rail */
.rail {
  position: sticky; top: 0; height: 100dvh; z-index: 20;
  display: flex; flex-direction: column; gap: 2px;
  padding: 18px 12px 12px;
  background: var(--rail); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px; background: var(--grad-brand);
  display: grid; place-items: center; color: var(--brand-ink); flex: none;
  box-shadow: 0 4px 14px -4px var(--brand-glow);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-name { font-weight: 700; letter-spacing: -.02em; font-size: 17px; }
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase; font-weight: 600; }

.nav-group { font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-4); padding: 16px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 12px; border-radius: var(--r-sm); color: var(--ink-2);
  font-size: 14px; font-weight: 500; transition: background .16s, color .16s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item.is-active { background: var(--active); color: var(--ink); font-weight: 600; }
.nav-item.is-active:hover { background: var(--active-hover); }
.nav-item.is-active svg { color: var(--brand); opacity: 1; }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; background: var(--danger); color: #fff; }
.rail-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.rail-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm); width: 100%; }
.rail-user:hover { background: var(--hover); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--grad-brand); color: var(--brand-ink); font-weight: 700; font-size: 12px; }

/* ------------------------------------------------------------- main */
.main { position: relative; z-index: 1; min-width: 0; max-width: 100vw; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: 12px; padding: 14px 26px;
  background: var(--glass); backdrop-filter: blur(18px) saturate(160%); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; font-weight: 680; letter-spacing: -.025em; overflow-wrap: anywhere; }
.topbar .sub { font-size: 12.5px; color: var(--ink-3); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.view { padding: 26px; max-width: 1240px; width: 100%; margin: 0 auto; flex: 1; }
.view.is-enter > * { animation: rise .38s var(--ease-out) both; }   /* uniquement au changement de vue */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ================================================== composants base */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink);
  font-size: 14px; font-weight: 560; white-space: nowrap;
  transition: background .16s, border-color .16s, transform .12s var(--ease), box-shadow .16s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--btn-hover); border-color: var(--border-2); }
.btn:active { transform: scale(.975); }
.btn--primary { background: var(--grad-brand); color: var(--brand-ink); border-color: transparent; font-weight: 650;
  box-shadow: 0 2px 10px -2px var(--brand-glow); }
.btn--primary:hover { background: var(--grad-brand); filter: brightness(1.08); box-shadow: 0 4px 18px -4px var(--brand-glow); }
.btn--primary:active { background: var(--grad-brand); filter: brightness(.96); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--hover); color: var(--ink); }
.btn--danger { color: var(--danger); }
.btn--ghost.btn--danger { color: var(--ink-4); }
.btn--ghost.btn--danger:hover { color: var(--danger); }
.btn--danger:hover { background: rgba(251, 113, 133, .12); border-color: rgba(251, 113, 133, .3); }
.btn--sm { height: 31px; padding: 0 10px; font-size: 13px; border-radius: 9px; }
.btn--icon { width: 38px; padding: 0; }
.btn--icon.btn--sm { width: 31px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-3); }
.input, .select, textarea.input {
  height: 40px; padding: 0 12px; width: 100%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--ink); font-size: 14.5px; transition: border-color .16s, box-shadow .16s, background .16s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--ink-4); }
.input:hover, .select:hover { border-color: var(--border-2); background: var(--field-hover); }
.input:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }
.select { appearance: none; cursor: pointer; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 14px center, right 9px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.select option { background: var(--surface-3); color: var(--ink); }
.hint { font-size: 12px; color: var(--ink-4); }

.search { position: relative; flex: 1 1 200px; min-width: 0; max-width: 420px; }
.search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-4); pointer-events: none; }
.search .input { padding-left: 36px; }

.switch { position: relative; width: 40px; height: 23px; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--border-2); transition: background .2s, border-color .2s; flex: none; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: var(--ink-3); transition: transform .22s var(--ease), background .2s; }
.switch[aria-checked='true'] { background: var(--grad-brand); border-color: transparent; }
.switch[aria-checked='true']::after { transform: translateX(17px); background: #fff; }

.seg { display: inline-flex; min-width: 0; max-width: 100%; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; }
.seg button .ico { width: 15px; height: 15px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 560; color: var(--ink-3); transition: background .16s, color .16s; }
.seg button:hover { color: var(--ink); background: var(--hover); }
.seg button.is-active:hover { background: var(--surface-3); }
.seg button.is-active { background: var(--surface-3); color: var(--ink); box-shadow: var(--shadow-1); }
:root[data-theme='light'] .seg button.is-active { background: #fff; }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; font-weight: 560; color: var(--ink-2); }
.chip--brand { background: var(--brand-glow); border-color: transparent; color: var(--brand); }
.chip--warn { background: rgba(251, 191, 36, .14); border-color: transparent; color: var(--warn); }
.chip--danger { background: rgba(251, 113, 133, .14); border-color: transparent; color: var(--danger); }
.chip button { display: grid; place-items: center; opacity: .6; }
.chip button:hover { opacity: 1; }

/* ------------------------------------------------------------ cartes */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; box-shadow: var(--shadow-1); position: relative;
}
.card--pad0 { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head > .ico { color: var(--ink-3); }
.card-head h2 { font-size: 15px; font-weight: 640; letter-spacing: -.01em; }
.card-head .spacer { margin-left: auto; }
.card-sub { font-size: 12.5px; color: var(--ink-3); }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
/* Empilement vertical sûr : piste bornée, donc aucun enfant ne peut pousser la page. */
.stack { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
.stack--lg { gap: 16px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--dash { grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); align-items: start; }

.stat { display: flex; flex-direction: column; gap: 3px; }
.stat-label { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-4); }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.stat-value small { font-size: 13px; font-weight: 560; color: var(--ink-3); letter-spacing: 0; }
.stat-delta { font-size: 12.5px; font-weight: 600; }
.stat-delta.up { color: var(--ok); } .stat-delta.down { color: var(--danger); } .stat-delta.flat { color: var(--ink-3); }

/* ---------------------------------------------------- anneau calorie */
.ring-wrap { display: grid; place-items: center; position: relative; }
.ring { transform: rotate(-90deg); overflow: visible; }
.ring circle { fill: none; stroke-linecap: round; }
.ring .track { stroke: var(--surface-2); }
:root[data-theme='light'] .ring .track { stroke: #e8ecf1; }
.ring .bar { transition: stroke-dashoffset .9s var(--ease-out); filter: drop-shadow(0 0 8px var(--brand-glow)); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 1px; }
.ring-kcal { font-size: 38px; font-weight: 750; letter-spacing: -.04em; line-height: 1; }
.ring-of { font-size: 12.5px; color: var(--ink-3); font-weight: 560; }
.ring-note { font-size: 12px; font-weight: 640; color: var(--brand); margin-top: 4px; }
.ring-note.over { color: var(--warn); }

/* barre de macro */
.macro-row { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; align-items: baseline; margin-bottom: 12px; }
.macro-name { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 7px; }
.chip .ico { width: 14px; height: 14px; }
.macro-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.macro-val { font-size: 12.5px; color: var(--ink-3); font-weight: 560; }
.macro-val b { color: var(--ink); font-weight: 660; }
.macro-bar { grid-column: 1 / -1; height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
:root[data-theme='light'] .macro-bar { background: #e8ecf1; }
.macro-bar i { display: block; height: 100%; border-radius: 99px; transition: width .8s var(--ease-out); }

/* ------------------------------------------------------------- repas */
.meal { border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.meal + .meal { margin-top: 12px; }
.meal-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface-2); }
:root[data-theme='light'] .meal-head { background: var(--surface-2); }
.meal-icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2); flex: none; }
.meal-icon svg { width: 15px; height: 15px; }
.meal-title { font-size: 14px; font-weight: 620; }
.meal-kcal { margin-left: auto; font-size: 13px; font-weight: 640; color: var(--ink-2); }
.entry { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); transition: background .14s; }
.entry:hover { background: var(--hover); }
.entry.is-planned { opacity: .62; }
.entry.is-planned .entry-name::after { content: 'prévu'; margin-left: 8px; font-size: 10px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--info); border: 1px solid currentColor; border-radius: 4px; padding: 1px 4px; vertical-align: middle; }
.entry-main { min-width: 0; flex: 1; }
.entry-name { font-size: 14px; font-weight: 540; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-meta { font-size: 12px; color: var(--ink-4); }
.entry-macros { display: flex; gap: 10px; font-size: 11.5px; color: var(--ink-3); }
.entry-macros b { font-weight: 640; color: var(--ink-2); }
.entry-kcal { font-size: 14px; font-weight: 650; min-width: 62px; text-align: right; }
.entry-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .16s; }
.entry:hover .entry-actions, .entry:focus-within .entry-actions { opacity: 1; }
@media (hover: none) { .entry-actions { opacity: 1; } }
.meal-add { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; border-top: 1px dashed var(--border);
  color: var(--ink-4); font-size: 13.5px; font-weight: 560; transition: color .16s, background .16s; }
.meal-add:hover { color: var(--brand); background: var(--hover); }
.meal-add svg { width: 15px; height: 15px; }

/* --------------------------------------------------------- calendrier */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-4); padding-bottom: 4px; }
.cal-day {
  position: relative; aspect-ratio: 1 / .92; min-width: 0; overflow: hidden; border-radius: var(--r); padding: 8px;
  background: var(--surface); border: 1px solid var(--border); text-align: left;
  display: flex; flex-direction: column; gap: 4px; transition: transform .16s var(--ease), border-color .16s, background .16s;
}
.cal-day:hover { transform: translateY(-2px); border-color: var(--border-2); box-shadow: var(--shadow-2); }
.cal-day.is-out { opacity: .32; }
.cal-day.is-today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.cal-day.is-selected { background: var(--surface-3); border-color: var(--brand); }
.cal-num { font-size: 12.5px; font-weight: 640; color: var(--ink-2); }
.cal-kcal { font-size: 13.5px; font-weight: 700; letter-spacing: -.02em; margin-top: auto; }
.cal-fill { position: absolute; inset: auto 0 0 0; height: 3px; border-radius: 0 0 var(--r) var(--r); background: var(--grad-brand); opacity: .85; transition: width .5s var(--ease-out); }
.cal-dots { display: flex; gap: 3px; }
.cal-dots i { width: 4px; height: 4px; border-radius: 50%; }
.cal-heat { position: absolute; inset: 0; border-radius: var(--r); pointer-events: none; opacity: var(--heat, 0); background: var(--grad-brand); }

/* ------------------------------------------------------------ listes */
.list { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }
.row { display: flex; align-items: center; gap: 14px; padding: 12px 16px; transition: background .14s; }
.row + .row { border-top: 1px solid var(--border); }
.row:hover { background: var(--hover); }
.row:has(.row-actions:hover) { background: var(--hover); }
.row-main { min-width: 0; flex: 1 1 auto; }
.row-title { font-size: 14.5px; font-weight: 570; display: flex; align-items: center; gap: 8px; }
.row-sub { font-size: 12.5px; color: var(--ink-4); }
.row-actions { display: flex; gap: 4px; }
.row-num { font-size: 13.5px; font-weight: 620; text-align: right; }
.row-num small { display: block; font-size: 11px; font-weight: 500; color: var(--ink-4); }
.thumb .ico { width: 17px; height: 17px; }
.thumb { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); font-size: 16px; }

.table-head { display: flex; gap: 14px; padding: 9px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-4); }

.empty { display: grid; place-items: center; gap: 10px; padding: 56px 20px; text-align: center; color: var(--ink-3); }
.empty-icon .ico { width: 24px; height: 24px; }
.empty-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-4); }
.empty h3 { font-size: 15px; font-weight: 620; color: var(--ink); }
.empty p { font-size: 13.5px; max-width: 340px; }

/* ------------------------------------------------------- graphiques */
.chart-host svg { overflow: visible; }
.chart-host .grid-line { stroke: var(--border); stroke-width: 1; }
.chart-host .target-line { stroke: var(--ink-4); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-host .area { opacity: .5; }
.chart-host .line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-host .dot { transition: r .16s; }
.chart-host text { font-size: 10.5px; fill: var(--ink-4); font-weight: 560; }
.chart-host .bar { transition: opacity .16s; }
.chart-host .bar:hover { opacity: .8; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); font-weight: 560; }
.legend i { width: 9px; height: 9px; border-radius: 3px; }

/* ------------------------------------------------- modale & tiroir */
.scrim { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(4px); z-index: 100; animation: fade .22s ease both; }
@keyframes fade { from { opacity: 0; } }
.modal {
  position: fixed; z-index: 101; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px)); max-height: min(86dvh, 860px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-xl); box-shadow: var(--shadow-3);
  animation: pop .3s var(--ease-out) both;
}
.modal--wide { width: min(880px, calc(100vw - 32px)); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(.97); } }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px; padding: 18px 20px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16.5px; font-weight: 660; letter-spacing: -.02em; }
.modal-body { padding: 18px 20px; display: grid; gap: 14px; }
.modal-foot { position: sticky; bottom: 0; display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px;
  background: var(--surface); border-top: 1px solid var(--border); }

/* --------------------------------------------------------- palette */
.palette { position: fixed; z-index: 101; left: 50%; top: 12dvh; transform: translateX(-50%);
  width: min(620px, calc(100vw - 24px)); background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--r-lg); box-shadow: var(--shadow-3); overflow: hidden; animation: pop2 .26s var(--ease-out) both; }
@keyframes pop2 { from { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(.98); } }
.palette-input { width: 100%; height: 54px; padding: 0 18px; background: none; border: 0; font-size: 16px; }
.palette-input:focus { outline: none; }
.palette-list { max-height: 54dvh; overflow: auto; border-top: 1px solid var(--border); padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border-radius: var(--r-sm); text-align: left; }
.palette-item:hover { background: var(--pop-hover); }
.palette-item[aria-selected='true'] { background: var(--active); }
.palette-item .ico { width: 17px; height: 17px; color: var(--ink-3); }
.palette-item .kcal { margin-left: auto; font-size: 12.5px; color: var(--ink-3); font-weight: 600; }
.palette-sec { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); padding: 10px 12px 4px; }

/* ---------------------------------------------------------- toasts */
.toasts { position: fixed; z-index: 200; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 24px); }
.toast { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: var(--r); font-size: 13.5px; font-weight: 560;
  background: var(--surface-3); border: 1px solid var(--border-2); box-shadow: var(--shadow-3); animation: toastIn .34s var(--ease-out) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.toast.out { animation: toastOut .24s ease both; }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.97); } }
.toast--ok svg { color: var(--ok); } .toast--err svg { color: var(--danger); }
.toast .ico { width: 17px; height: 17px; }

/* ------------------------------------------------------ chargement */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------- auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.auth::before { content: ''; position: absolute; inset: -30%; background:
  radial-gradient(40% 40% at 30% 20%, var(--brand-glow), transparent 70%),
  radial-gradient(40% 40% at 70% 80%, rgba(53, 208, 192, .16), transparent 70%); animation: drift 18s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate3d(4%, -3%, 0) scale(1.08); } }
.auth-card { position: relative; width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 30px; box-shadow: var(--shadow-3); animation: pop .4s var(--ease-out) both; }
.auth-card h1 { font-size: 23px; font-weight: 700; letter-spacing: -.03em; margin-bottom: 4px; }
.auth-card p.lede { font-size: 13.5px; color: var(--ink-3); margin-bottom: 22px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--ink-3); margin-top: 16px; }
.auth-switch button { color: var(--brand); font-weight: 620; }
.err { font-size: 13px; color: var(--danger); background: rgba(251, 113, 133, .1); border: 1px solid rgba(251, 113, 133, .25);
  padding: 9px 12px; border-radius: var(--r-sm); }

/* --------------------------------------------------- barre mobile */
.tabbar { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }
  .view { padding: 16px 14px 92px; }
  /* Écran étroit : titre sur une ligne, actions sur la suivante — sinon elles se chevauchent. */
  .topbar { padding: 12px 14px; flex-wrap: wrap; row-gap: 10px; }
  .topbar > div:first-child { flex: 1 1 100%; }
  .topbar h1 { font-size: 17px; }
  .topbar-actions { width: 100%; margin-left: 0; }
  .topbar-actions .seg { flex: 1; justify-content: center; }
  .topbar-actions .seg button { flex: 1; }
  .grid--dash, .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabbar {
    position: fixed; z-index: 30; bottom: 0; left: 0; right: 0; display: grid; grid-auto-flow: column;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--glass); backdrop-filter: blur(20px) saturate(160%); border-top: 1px solid var(--border);
  }
  .tabbar button { display: grid; justify-items: center; gap: 3px; padding: 6px 0; color: var(--ink-4); font-size: 10.5px; font-weight: 600; }
  .tabbar button svg { width: 21px; height: 21px; }
  .tabbar button.is-active { color: var(--brand); }
  .tabbar button:active { background: var(--hover); border-radius: 12px; }
  .fab { position: fixed; z-index: 31; right: 18px; bottom: calc(78px + env(safe-area-inset-bottom)); width: 54px; height: 54px;
    border-radius: 18px; background: var(--grad-brand); color: var(--brand-ink); display: grid; place-items: center;
    box-shadow: 0 8px 24px -6px var(--brand-glow), var(--shadow-3); }
  .fab svg { width: 24px; height: 24px; }
  .modal { top: auto; bottom: 0; left: 0; right: 0; transform: none; width: 100%; max-height: 92dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0; animation: sheet .32s var(--ease-out) both; }
  @keyframes sheet { from { transform: translateY(100%); } }
  .palette { top: 8px; }
}
@media (min-width: 901px) { .fab { display: none; } }

/* =====================================================================
   CONTRÔLES DE FORMULAIRE CUSTOM
   Tout contrôle natif (select, date, number, checkbox) est remplacé au
   rendu par enhance() : l'élément d'origine reste dans le DOM, masqué,
   pour porter la valeur (les formulaires continuent de fonctionner).
   ===================================================================== */

.mf-native { position: absolute !important; width: 1px; height: 1px; opacity: 0; pointer-events: none; margin: -1px; }

/* ------------------------------------------------------------- select */
.msel { position: relative; min-width: 0; }
.msel__btn {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 40px; padding: 0 10px 0 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 14.5px; font-weight: 500; text-align: left; color: var(--ink);
  transition: border-color .16s, background .16s, box-shadow .16s;
}
.msel__btn:hover { border-color: var(--border-2); background: var(--field-hover); }
.msel[data-open='true'] .msel__btn { border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }
.msel__val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msel__val--empty { color: var(--ink-4); }
.msel__chev { width: 14px; height: 14px; flex: none; opacity: .45; transition: transform .2s var(--ease), opacity .16s; }
.msel__btn:hover .msel__chev { opacity: .8; }
.msel[data-open='true'] .msel__chev { transform: rotate(180deg); opacity: .9; }
.msel--sm .msel__btn { height: 32px; font-size: 13px; padding: 0 8px 0 10px; border-radius: 9px; }
.msel--auto { width: max-content; max-width: 100%; }

.msel__pop {
  position: absolute; z-index: 60; top: calc(100% + 6px); left: 0; min-width: 100%; max-width: min(340px, 90vw);
  padding: 5px; background: var(--surface-3); border: 1px solid var(--border-2); border-radius: var(--r);
  box-shadow: var(--shadow-3); max-height: 300px; overflow: auto;
  opacity: 0; transform: translateY(-6px) scale(.98); pointer-events: none;
  transition: opacity .16s var(--ease-out), transform .16s var(--ease-out);
}
.msel[data-open='true'] .msel__pop { opacity: 1; transform: none; pointer-events: auto; }
.msel__pop--up { top: auto; bottom: calc(100% + 6px); }
.msel__pop--right { left: auto; right: 0; }
.msel__opt {
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border-radius: 9px;
  font-size: 14px; text-align: left; color: var(--ink-2); transition: background .12s, color .12s;
}
.msel__opt:hover, .msel__opt.is-cursor { background: var(--pop-hover); color: var(--ink); }
.msel__opt[aria-selected='true'] { color: var(--ink); font-weight: 600; }
.msel__opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msel__opt-check { width: 15px; height: 15px; flex: none; color: var(--brand); opacity: 0; }
.msel__opt[aria-selected='true'] .msel__opt-check { opacity: 1; }
.msel__search { position: sticky; top: -5px; z-index: 1; margin: -5px -5px 5px; padding: 5px; background: var(--surface-3); border-bottom: 1px solid var(--border); }
.msel__search input { width: 100%; height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink); font-size: 13.5px; }
.msel__search input:focus { outline: none; border-color: var(--brand); }
.msel__empty { padding: 14px; text-align: center; font-size: 13px; color: var(--ink-4); }

/* ------------------------------------------------------- nombre (pas) */
.mnum { display: flex; align-items: center; gap: 0; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); overflow: hidden; transition: border-color .16s, box-shadow .16s, background .16s; }
.mnum:hover { border-color: var(--border-2); }
.mnum:focus-within { border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }
.mnum input { flex: 1; min-width: 0; height: 38px; padding: 0 4px 0 12px; border: 0; background: none;
  font-size: 14.5px; font-variant-numeric: tabular-nums; text-align: left; }
.mnum input:focus { outline: none; }
.mnum input::-webkit-outer-spin-button, .mnum input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.mnum input[type='number'] { appearance: textfield; }
.mnum__unit { font-size: 12.5px; color: var(--ink-4); padding-right: 6px; white-space: nowrap; }
/* Incrémenteurs empilés : deux fois moins larges qu'une paire côte à côte, ce qui laisse
   respirer les champs étroits (grille des 4 objectifs macro). */
.mnum__steps { display: flex; flex-direction: column; width: 26px; flex: none; border-left: 1px solid var(--border); }
.mnum__step { flex: 1; display: grid; place-items: center; color: var(--ink-3); transition: background .14s, color .14s; }
.mnum__step + .mnum__step { border-top: 1px solid var(--border); }
.mnum__step:hover { background: var(--pop-hover); color: var(--ink); }
.mnum__step:active { background: var(--active); }
.mnum__step svg { width: 11px; height: 11px; }

/* -------------------------------------------------------------- date */
.mdate { position: relative; }
.mdate__btn { display: flex; align-items: center; gap: 9px; width: 100%; height: 40px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 14.5px; color: var(--ink); text-align: left; transition: border-color .16s, background .16s, box-shadow .16s; }
.mdate__btn:hover { border-color: var(--border-2); background: var(--field-hover); }
.mdate[data-open='true'] .mdate__btn { border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }
.mdate__btn .ico { width: 15px; height: 15px; color: var(--ink-4); }
.mdate__val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdate__val--empty { color: var(--ink-4); }
.mdate__clear { opacity: .4; }
.mdate__clear:hover { opacity: 1; color: var(--danger); }
.mdate__pop { position: absolute; z-index: 60; top: calc(100% + 6px); left: 0; width: 268px; padding: 12px;
  background: var(--surface-3); border: 1px solid var(--border-2); border-radius: var(--r); box-shadow: var(--shadow-3);
  opacity: 0; transform: translateY(-6px) scale(.98); pointer-events: none;
  transition: opacity .16s var(--ease-out), transform .16s var(--ease-out); }
.mdate[data-open='true'] .mdate__pop { opacity: 1; transform: none; pointer-events: auto; }
.mdate__pop--up { top: auto; bottom: calc(100% + 6px); }
.mdate__pop--right { left: auto; right: 0; }
.mdate__head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.mdate__title { flex: 1; text-align: center; font-size: 13.5px; font-weight: 620; }
.mdate__nav { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: var(--ink-3); }
.mdate__nav:hover { background: var(--pop-hover); color: var(--ink); }
.mdate__nav svg { width: 14px; height: 14px; }
.mdate__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mdate__dow { text-align: center; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-4); padding-bottom: 4px; }
.mdate__cell { height: 30px; border-radius: 8px; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-2); transition: background .12s, color .12s; }
.mdate__cell:hover { background: var(--pop-hover); color: var(--ink); }
.mdate__cell.is-out { opacity: .3; }
.mdate__cell.is-today { box-shadow: inset 0 0 0 1px var(--border-2); font-weight: 700; }
.mdate__cell.is-sel { background: var(--grad-brand); color: var(--brand-ink); font-weight: 700; }
.mdate__foot { display: flex; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.mdate__foot button { flex: 1; height: 28px; border-radius: 8px; font-size: 12.5px; font-weight: 560; color: var(--ink-2); }
.mdate__foot button:hover { background: var(--pop-hover); color: var(--ink); }

/* ---------------------------------------------------------- checkbox */
.mcheck { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; }
.mcheck__box { width: 19px; height: 19px; border-radius: 6px; flex: none; display: grid; place-items: center;
  background: var(--surface-2); border: 1.5px solid var(--border-2); transition: background .16s, border-color .16s, transform .12s var(--ease); }
.mcheck:hover .mcheck__box { border-color: var(--brand); }
.mcheck__box svg { width: 12px; height: 12px; color: var(--brand-ink); opacity: 0; transform: scale(.6); transition: opacity .14s, transform .18s var(--ease-out); }
.mcheck[aria-checked='true'] .mcheck__box { background: var(--grad-brand); border-color: transparent; }
.mcheck[aria-checked='true'] .mcheck__box svg { opacity: 1; transform: none; }
.mcheck:active .mcheck__box { transform: scale(.92); }

/* ------------------------------------------------- infobulle de graphe */
.chart-host { position: relative; width: 100%; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; padding: 8px 11px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--border-2); box-shadow: var(--shadow-3);
  font-size: 12.5px; line-height: 1.45; white-space: nowrap; opacity: 0; transform: translate(-50%, -100%) translateY(-8px);
  transition: opacity .12s; font-variant-numeric: tabular-nums;
}
.chart-tip.is-on { opacity: 1; }
.chart-tip b { font-weight: 660; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 7px; }
.chart-tip .tip-row i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.chart-tip .tip-head { font-weight: 640; margin-bottom: 3px; color: var(--ink); }
.chart-tip .tip-sub { color: var(--ink-3); }
.chart-host svg { display: block; }
.chart-host .hit { fill: transparent; cursor: pointer; }
.chart-host .hit:hover + .bar, .chart .bar.is-on { opacity: .82; }
.chart-host .cursor-line { stroke: var(--border-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
.chart-host .cursor-line.is-on { opacity: 1; }
.chart-host .dot.is-on { r: 5; }
.donut-seg { transition: opacity .16s; cursor: pointer; }
.donut-seg.is-dim { opacity: .32; }

/* =====================================================================
   RESPONSIVE — l'app est d'abord utilisée au téléphone.
   Trois paliers : ≤ 1100 px (desktop étroit), ≤ 900 px (tablette/mobile,
   rail remplacé par la barre d'onglets), ≤ 620 px (téléphone).
   ===================================================================== */

@media (min-width: 901px) and (max-width: 1100px) {
  :root { --rail-w: 208px; }
  .view { padding: 20px; }
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--dash { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
}

@media (max-width: 900px) {
  /* La barre de titre peut déborder si les actions portent du texte : on autorise le repli
     et on laisse les libellés se tronquer plutôt que pousser la page. */
  .topbar-actions { flex-wrap: wrap; }
  .topbar-actions .btn { min-width: 0; }
  .topbar-actions .btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .card { padding: 16px; border-radius: var(--r-lg); }
  .grid { gap: 12px; }
}

@media (max-width: 620px) {
  /* Cases du calendrier : sans aspect-ratio, la largeur minimale n'est plus imposée par la
     hauteur du contenu — la semaine tient enfin dans 360 px. */
  .cal { gap: 4px; }
  .cal-day { aspect-ratio: auto; min-height: 62px; padding: 6px 5px; border-radius: 12px; }
  .cal-num { font-size: 11px; }
  .cal-kcal { font-size: 11.5px; letter-spacing: -.03em; }
  .cal-dots i { width: 3px; height: 3px; }
  .cal-dow { font-size: 9.5px; }

  /* Lignes de liste : deux niveaux plutôt que des colonnes fixes intenables. */
  .table-head { display: none; }
  /* La vignette reste sur la ligne du titre ; seuls les chiffres et les actions passent dessous. */
  .row { flex-wrap: wrap; gap: 6px 10px; padding: 11px 14px; }
  .row-main { flex: 1 1 calc(100% - 50px); order: 1; }
  .row .thumb { order: 0; width: 34px; height: 34px; }
  .row-num { width: auto !important; order: 2; text-align: left; font-size: 13px; display: flex; align-items: baseline; gap: 5px; }
  .row-num small { display: inline; font-size: 11px; }
  .row-actions { order: 3; margin-left: auto; gap: 2px; }
  .row-actions .btn { width: 34px; height: 34px; }      /* cibles tactiles confortables */

  /* Repas : la quantité et les macros passent sous le nom. */
  .entry { flex-wrap: wrap; padding: 11px 14px; gap: 4px 10px; }
  .entry-main { flex: 1 1 auto; }
  .entry-kcal { min-width: 0; }
  .entry-actions { opacity: 1; flex: 1 1 100%; justify-content: flex-end; }
  .entry-actions .btn { width: 34px; height: 34px; }
  .meal-add { padding: 12px 14px; }

  /* Densité générale : on récupère de la largeur utile. */
  .view { padding: 14px 12px 96px; }
  .card { padding: 14px; }
  .grid--3, .grid--2 { grid-template-columns: 1fr; }
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 23px; }
  .topbar { padding: 10px 12px; }
  /* Le sélecteur de thème vit aussi dans Réglages : sur mobile on le retire de la barre pour
     garder les actions sur une seule ligne. */
  .topbar-actions [data-act='theme'] { display: none; }
  .seg { overflow-x: auto; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .chip { height: 28px; }
  .btn { height: 40px; }                                  /* ≥ 40 px : confort au pouce */
  .btn--sm { height: 34px; }
  .btn--icon { width: 40px; }
  .btn--icon.btn--sm { width: 34px; }

  .modal-body { padding: 16px 14px; }
  .modal-head, .modal-foot { padding-left: 14px; padding-right: 14px; }
  .msel__pop, .mdate__pop { max-width: calc(100vw - 28px); }
}

/* Très petits écrans : on protège la lisibilité des nombres. */
@media (max-width: 380px) {
  .ring-kcal { font-size: 34px; }
  .stat-value { font-size: 21px; }
  .cal-kcal { font-size: 10.5px; }
}
