/* =====================================================================
   Nutri Journal — système visuel

   Parti pris : l'interface est monochrome. Les seules couleurs saturées
   sont les trois macros, pour qu'un coup d'œil suffise à les distinguer
   sans lire les légendes. Aucun anneau de progression : les quantités se
   comparent sur des réglettes horizontales, avec un repère de cible.
   ===================================================================== */

:root {
  /* Encre et papier : neutres teintés de vert, pas de gris bleuté ni de crème. */
  --paper: #F4F6F3;
  --surface: #FFFFFF;
  --sunken: #E9EDE8;
  --ink: #14201C;
  --ink-2: #4A5751;
  --ink-3: #7C8A83;
  --rule: #DBE1DB;
  --rule-strong: #BDC7BF;

  --protein: #3B4E9B;
  --carbs: #A26C15;
  --fat: #93356A;

  --danger: #A32D25;
  --positive: #2E6B4F;

  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: ui-serif, "New York", Georgia, "Iowan Old Style", serif;

  --r-sm: 7px;
  --r-md: 11px;
  --r-lg: 16px;

  --pad: 16px;
  --shadow: 0 1px 2px rgb(20 32 28 / .06), 0 6px 20px -12px rgb(20 32 28 / .22);

  --nav-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F1512;
    --surface: #171E1A;
    --sunken: #0B100E;
    --ink: #E6ECE7;
    --ink-2: #A3AFA8;
    --ink-3: #74827A;
    --rule: #2A342E;
    --rule-strong: #3D4A43;

    --protein: #8D9BE6;
    --carbs: #D6A140;
    --fat: #D97CAC;

    --danger: #E88A80;
    --positive: #6FBF97;

    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px -12px rgb(0 0 0 / .7);
    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

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

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

/* --- Typographie ----------------------------------------------------- */

/* Les chiffres sont la matière première de l'app : chasse fixe partout,
   pour qu'ils s'alignent en colonne et ne dansent pas à chaque mise à jour. */
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

.label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.serif { font-family: var(--font-display); font-weight: 500; }

.muted { color: var(--ink-2); }
.tertiary { color: var(--ink-3); }
.small { font-size: 13px; }

/* --- Ossature -------------------------------------------------------- */

#app { min-height: 100dvh; }

.shell {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 var(--pad) 40px;
}

.page-wide { max-width: 940px; }

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

.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 40;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--rule);
}

.nav a {
  flex: 1;
  display: grid;
  place-items: center;
  gap: 3px;
  text-decoration: none;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 8px 0;
}

.nav a[aria-current="page"] { color: var(--ink); }
.nav svg { width: 22px; height: 22px; stroke-width: 1.6; }

@media (min-width: 860px) {
  .shell { display: grid; grid-template-columns: 216px 1fr; padding-bottom: 0; }
  .nav {
    position: sticky;
    inset: 0 auto 0 0;
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    gap: 2px;
    padding: 24px 12px;
    border-top: 0;
    border-right: 1px solid var(--rule);
    backdrop-filter: none;
    background: var(--surface);
  }
  .nav a {
    flex: none;
    grid-auto-flow: column;
    justify-content: start;
    gap: 12px;
    padding: 11px 12px;
    border-radius: var(--r-sm);
    font-size: 14px;
  }
  .nav a[aria-current="page"] { background: var(--sunken); }
  .nav .nav-brand {
    font-family: var(--font-display);
    font-size: 19px;
    color: var(--ink);
    padding: 4px 12px 20px;
    letter-spacing: -.01em;
  }
}

.nav-brand { display: none; }
@media (min-width: 860px) { .nav-brand { display: block; } }

/* --- Barre de date --------------------------------------------------- */

.datebar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 calc(var(--pad) * -1);
  padding: 10px var(--pad);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}

.datebar-title {
  flex: 1;
  text-align: center;
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -.01em;
}

.datebar-title small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* --- Bandeau « il reste » : l'élément signature ----------------------- */

.remaining {
  padding: 22px 0 18px;
  border-bottom: 1px solid var(--rule);
}

.remaining-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.remaining-kcal {
  font-size: clamp(44px, 15vw, 60px);
  font-weight: 680;
  letter-spacing: -.045em;
  line-height: .95;
  font-variant-numeric: tabular-nums;
}

.remaining-kcal span { font-size: .34em; font-weight: 600; letter-spacing: -.01em; margin-left: 6px; }
.remaining.is-over .remaining-kcal { color: var(--danger); }

.remaining-sub { text-align: right; font-size: 13px; color: var(--ink-2); }
.remaining-sub b { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }

.macro-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 20px;
}

.macro {
  display: grid;
  gap: 7px;
}

.macro-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.macro-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--macro);
}

.macro-value {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.macro-target { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* La réglette : une piste, un remplissage, un repère de cible.
   Le dépassement se poursuit visiblement au-delà du repère plutôt que
   de saturer la barre — on veut voir DE COMBIEN on a dépassé. */
.track {
  position: relative;
  height: 7px;
  border-radius: 4px;
  background: var(--sunken);
  overflow: hidden;
}

.track-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--macro);
  transition: width .35s cubic-bezier(.4, 0, .2, 1);
}

.track-over {
  position: absolute;
  inset: 0 0 0 auto;
  height: 100%;
  background: repeating-linear-gradient(
    -45deg,
    var(--macro) 0 3px,
    color-mix(in srgb, var(--macro) 45%, var(--surface)) 3px 6px
  );
}

.track-tick {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--ink);
  opacity: .5;
}

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

.meal {
  border-bottom: 1px solid var(--rule);
  padding: 18px 0;
}

.meal.is-skipped { opacity: .48; }

.meal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.meal-name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -.012em;
  flex: 1;
}

.meal-time { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.meal-kcal {
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.meal-kcal small { font-weight: 500; color: var(--ink-3); }

.entries { display: grid; gap: 1px; margin-bottom: 12px; }

.entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--surface);
  border-radius: var(--r-sm);
  text-align: left;
  width: 100%;
  border: 0;
  cursor: pointer;
}

.entry:hover { background: var(--sunken); }

.entry-main { flex: 1; min-width: 0; }

.entry-label {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-qty { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.entry-macros {
  display: flex;
  gap: 9px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.entry-macros b { font-weight: 600; }

.meal-bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }

/* --- Contrôles ------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s;
}

.btn:hover { background: var(--sunken); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.btn-primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--paper)); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--sunken); }

.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }

.btn-sm { min-height: 36px; padding: 0 11px; font-size: 13px; }

.btn-icon { min-height: 40px; width: 40px; padding: 0; border-color: transparent; background: transparent; }
.btn-icon:hover { background: var(--sunken); }
.btn-icon svg { width: 20px; height: 20px; stroke-width: 1.7; }

.btn-add {
  width: 100%;
  justify-content: flex-start;
  border-style: dashed;
  color: var(--ink-2);
  background: transparent;
}

.field { display: grid; gap: 6px; }

.field > label { font-size: 13px; font-weight: 600; color: var(--ink-2); }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 15px;
}

.textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.input.num-input { font-variant-numeric: tabular-nums; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: transparent; }

.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row > .shrink { flex: 0 0 auto; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 24px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }

.scroller {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(var(--pad) * -1);
  padding: 0 var(--pad);
}

.scroller::-webkit-scrollbar { display: none; }

/* --- Feuille modale (bottom sheet) ----------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgb(10 16 14 / .42);
  animation: fade .16s ease;
}

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 61;
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
  background: var(--paper);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow);
  animation: rise .22s cubic-bezier(.32, .72, 0, 1);
}

@media (min-width: 720px) {
  .sheet {
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(var(--sheet-width, 600px), 92vw);
    max-height: 84dvh;
    border-radius: var(--r-lg);
    animation: pop .18s cubic-bezier(.32, .72, 0, 1);
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--rule);
}

.sheet-title { flex: 1; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.sheet-body { flex: 1; overflow-y: auto; padding: var(--pad); -webkit-overflow-scrolling: touch; }
.sheet-foot {
  padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  background: var(--surface);
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }
@keyframes pop { from { transform: translate(-50%, -46%); opacity: 0; } }

/* --- Résultats de recherche ------------------------------------------ */

.result {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  margin-bottom: 1px;
}

.result:hover { background: var(--sunken); }
.result[aria-pressed="true"] { border-color: var(--ink); background: var(--sunken); }

.result-main { flex: 1; min-width: 0; }
.result-name { font-size: 14px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-meta { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.result-tick {
  width: 22px; height: 22px;
  border: 1.5px solid var(--rule-strong);
  border-radius: 6px;
  display: grid; place-items: center;
  flex: 0 0 auto;
}

.result[aria-pressed="true"] .result-tick { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.result-tick svg { width: 14px; height: 14px; opacity: 0; }
.result[aria-pressed="true"] .result-tick svg { opacity: 1; }

.tray { display: grid; gap: 8px; }

.tray-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--sunken);
  border-radius: var(--r-sm);
}

.tray-item .tray-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-item input { width: 74px; min-height: 36px; text-align: right; }
.tray-item select { min-height: 36px; width: auto; padding: 0 6px; }

/* --- Bibliothèque de recettes : la respiration éditoriale ------------- */

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 16px;
}

.recipe-card {
  display: grid;
  gap: 9px;
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
}

.recipe-thumb {
  aspect-ratio: 4 / 3;
  border-radius: var(--r-md);
  background: var(--sunken);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.recipe-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.recipe-thumb svg { width: 26px; height: 26px; color: var(--ink-3); stroke-width: 1.3; }

.recipe-name {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  line-height: 1.22;
  letter-spacing: -.008em;
}

.recipe-meta { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.recipe-hero {
  margin: 0 calc(var(--pad) * -1) 20px;
  aspect-ratio: 16 / 10;
  background: var(--sunken);
  overflow: hidden;
}

.recipe-hero img { width: 100%; height: 100%; object-fit: cover; display: block; }

.recipe-title {
  font-family: var(--font-display);
  font-size: clamp(27px, 7vw, 34px);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -.018em;
}

.ingredient-line {
  display: flex;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
}

.ingredient-qty {
  flex: 0 0 84px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink-2);
}

.ingredient-warn { color: var(--danger); font-size: 12px; }

.steps { counter-reset: step; display: grid; gap: 16px; }

.step { display: grid; grid-template-columns: 26px 1fr; gap: 12px; }

.step::before {
  counter-increment: step;
  content: counter(step);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 13px;
  color: var(--ink-3);
  padding-top: 2px;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: var(--pad);
}

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--rule);
  margin-bottom: 16px;
  font-size: 14px;
}

.banner p { flex: 1; }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--ink-2);
  display: grid;
  gap: 14px;
  justify-items: center;
}

.empty h2 { font-family: var(--font-display); font-size: 20px; font-weight: 500; color: var(--ink); }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 26px 0 12px;
}

.section-head h2 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: rise .2s cubic-bezier(.32, .72, 0, 1);
}

.toast.is-error { background: var(--danger); }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid color-mix(in srgb, var(--ink) 22%, transparent);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading { display: grid; place-items: center; padding: 60px 0; }

.scanner-view {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #000;
}

.scanner-view video { width: 100%; height: 100%; object-fit: cover; display: block; }

.scanner-frame {
  position: absolute;
  inset: 22% 12%;
  border: 2px solid rgb(255 255 255 / .85);
  border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / .35);
}

/* --- Connexion ------------------------------------------------------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login form { width: min(340px, 100%); display: grid; gap: 14px; }

.login h1 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -.02em;
  line-height: 1.1;
}
