/* La Dalle : un classeur de recettes à onglets, feuilles blanches sur papier légèrement vert */

:root {
  --paper: #F3F6F0;
  --sheet: #FFFFFF;
  --ink: #18221A;
  --muted: #5E6B5F;
  --line: #DCE3D8;
  --basil: #2F6B3A;
  --basil-soft: #E1EDDF;
  --on-basil: #FFFFFF;
  --danger: #B3261E;
  --danger-soft: #F9DEDC;
  --prot: #C8325A;
  --gluc: #D99A12;
  --lip: #3A6FB0;
  --tab-pdj: #F6E3A6;
  --tab-dej: #CFE5C9;
  --tab-din: #E2D3EA;
  --tab-snk: #CFDDF0;
  --shadow: 0 1px 2px rgba(24,34,26,.06), 0 6px 20px rgba(24,34,26,.07);
  --f-display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", ui-sans-serif, system-ui, sans-serif;
  --f-data: "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #111611; --sheet: #1A211B; --ink: #E5ECE3; --muted: #9AA79A; --line: #2C362D;
    --basil: #7DBB7F; --basil-soft: #233424; --on-basil: #0E160F;
    --danger: #F2B8B5; --danger-soft: #4A1E1B;
    --prot: #E0587C; --gluc: #B98A1E; --lip: #5E90D6;
    --tab-pdj: #4A3F1C; --tab-dej: #24402A; --tab-din: #3C2C45; --tab-snk: #243650;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--f-body); font-size: 15px; line-height: 1.55;
}
img { max-width: 100%; display: block; }
a { color: var(--basil); }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.1; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(28px, 5vw, 40px); font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; }
p { margin: 0; }
[hidden] { display: none !important; }
.num { font-family: var(--f-data); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.eyebrow { font-family: var(--f-data); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sub { font-family: var(--f-display); font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* --- Structure --- */
.appbar {
  position: sticky; top: 0; z-index: 20; background: var(--sheet); border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 20px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}
.logo { font-family: var(--f-display); font-weight: 800; font-size: 20px; letter-spacing: -.02em; color: var(--ink); text-decoration: none; white-space: nowrap; }
.logo span { color: var(--basil); }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 14px; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { background: var(--basil-soft); color: var(--basil); }
.avatar {
  margin-left: auto; width: 34px; height: 34px; border-radius: 50%; background: var(--basil); color: var(--on-basil);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; text-decoration: none; flex: none;
}
main {
  max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px;
  padding: 24px max(16px, env(safe-area-inset-right)) 96px max(16px, env(safe-area-inset-left));
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* Navigation en bas d'écran sur téléphone */
@media (max-width: 720px) {
  .appbar .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--sheet);
    border-top: 1px solid var(--line); justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .nav a { flex: 1; text-align: center; padding: 8px 4px; font-size: 13px; }
}

/* --- Boutons et champs --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  font: 700 14px var(--f-body); background: var(--basil); color: var(--on-basil); text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--paper); filter: none; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.danger:hover { background: var(--danger-soft); filter: none; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; width: 32px; height: 32px;
  border-radius: 8px; font-size: 18px; line-height: 1; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--paper); color: var(--ink); }
:is(a, button, input, select, textarea, summary):focus-visible { outline: 2px solid var(--basil); outline-offset: 2px; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
input, select, textarea {
  font: 15px var(--f-body); color: var(--ink); background: var(--sheet);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--basil); box-shadow: 0 0 0 3px var(--basil-soft); }
input[type="checkbox"] { width: auto; accent-color: var(--basil); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.search { flex: 1; min-width: 200px; background: var(--sheet); }

/* --- Panneaux --- */
.panel { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.empty h2 { color: var(--ink); }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 14px; font-size: 14px; }

/* --- Onglets du classeur --- */
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--ink); overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; font: 700 14px var(--f-display); padding: 9px 16px 7px; border-radius: 10px 10px 0 0; cursor: pointer;
  color: var(--ink); background: var(--sheet); display: flex; gap: 8px; align-items: center; white-space: nowrap;
}
.tab .c { font-family: var(--f-data); font-weight: 400; font-size: 12px; color: var(--muted); }
.tab.pdj { background: var(--tab-pdj); } .tab.dej { background: var(--tab-dej); }
.tab.din { background: var(--tab-din); } .tab.snk { background: var(--tab-snk); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--sheet); }
.tab[aria-selected="true"] .c { color: var(--sheet); opacity: .7; }

.chip { display: inline-block; border-radius: 99px; padding: 2px 10px; font-weight: 700; font-size: 12px; color: var(--ink); background: var(--paper); }
.chip.pdj { background: var(--tab-pdj); } .chip.dej { background: var(--tab-dej); }
.chip.din { background: var(--tab-din); } .chip.snk { background: var(--tab-snk); }

/* --- Cartes recettes --- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--sheet);
  display: flex; flex-direction: column; color: inherit; text-decoration: none; transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.kcal { font-family: var(--f-data); font-size: 13px; white-space: nowrap; }
.kcal b { font-size: 17px; font-weight: 500; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.fav { color: var(--gluc); }

.photo { position: relative; aspect-ratio: 16 / 10; background: var(--basil-soft); display: grid; place-items: center; overflow: hidden; }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo.pdj { background: var(--tab-pdj); } .photo.dej { background: var(--tab-dej); }
.photo.din { background: var(--tab-din); } .photo.snk { background: var(--tab-snk); }
.plate { width: 46%; aspect-ratio: 1; border-radius: 50%; background: var(--sheet); box-shadow: 0 6px 16px rgba(0,0,0,.12), inset 0 0 0 10px var(--paper); opacity: .9; }

/* --- Macros --- */
.mbar { display: flex; gap: 2px; height: 8px; border-radius: 99px; overflow: hidden; background: var(--line); }
.mbar:has(b) { background: transparent; }
.mbar b { display: block; height: 100%; }
.mbar .p, .dot.p { background: var(--prot); } .mbar .g, .dot.g { background: var(--gluc); } .mbar .l, .dot.l { background: var(--lip); }
/* Les valeurs restent en couleur d'encre ; la pastille de couleur porte l'identité de la macro */
.mtext { display: flex; gap: 12px; font-family: var(--f-data); font-size: 12px; font-variant-numeric: tabular-nums; flex-wrap: wrap; color: var(--ink); }
.mtext span, .c-p, .c-g, .c-l { display: inline-flex; align-items: center; gap: 5px; }
.mtext span::before, .c-p::before, .c-g::before, .c-l::before { content: ""; width: 8px; height: 8px; border-radius: 2px; flex: none; }
.mtext .p::before, .c-p::before { background: var(--prot); }
.mtext .g::before, .c-g::before { background: var(--gluc); }
.mtext .l::before, .c-l::before { background: var(--lip); }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* --- Dialogues --- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--sheet); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 16, 11, .5); }
.dlg { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--sheet); padding: 10px 18px; border-radius: 10px; font-weight: 700;
  z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }

/* --- Liste d'aliments (réutilisée par plusieurs pages) --- */
.food-list { display: flex; flex-direction: column; }
.food-row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 4px; border-bottom: 1px dashed var(--line); text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0;
  font: inherit; color: inherit; width: 100%;
}
button.food-row { cursor: pointer; } button.food-row:hover { background: var(--paper); }
.thumb { width: 44px; height: 44px; border-radius: 8px; background: var(--paper); object-fit: contain; display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; color: var(--muted); }
.food-name { font-weight: 700; }
.food-sub { font-size: 12px; color: var(--muted); }
.nutri { display: inline-block; font: 700 11px var(--f-body); color: #fff; border-radius: 4px; padding: 0 5px; text-transform: uppercase; }
.nutri.a { background: #038141; } .nutri.b { background: #85BB2F; } .nutri.c { background: #C9A800; } .nutri.d { background: #EE8100; } .nutri.e { background: #E63E11; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* --- Sélecteur d'aliments --- */
.picker { position: relative; }
.picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15; background: var(--sheet);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 340px; overflow-y: auto; padding: 0 8px;
}
.picker-group { font: 700 11px var(--f-data); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 10px 4px 2px; }

/* --- Choix de plusieurs jours --- */
.day-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.day-pick label { cursor: pointer; }
.day-pick input { position: absolute; opacity: 0; pointer-events: none; }
.day-pick span { display: block; text-align: center; padding: 7px 4px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-weight: 700; }
.day-pick input:checked + span { background: var(--basil); border-color: var(--basil); color: var(--on-basil); }
.day-pick input:focus-visible + span { outline: 2px solid var(--basil); outline-offset: 2px; }

/* --- Transitions entre les pages --- */
/* Fondu natif du navigateur d'une page à l'autre ; la barre de navigation reste en place */
@view-transition { navigation: auto; }
.appbar { view-transition-name: appbar; }
.appbar .nav { view-transition-name: nav; }
::view-transition-old(root) { animation: vt-out .14s ease-in both; }
::view-transition-new(root) { animation: vt-in .22s ease-out both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

/* Le contenu apparaît une fois les données chargées, au lieu de s'afficher vide puis rempli */
main, .cook-main { transition: opacity .2s ease-out, transform .2s ease-out; }
body.loading main, body.loading .cook-main { opacity: 0; transform: translateY(6px); }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  main, .cook-main { transition: none; }
  body.loading main, body.loading .cook-main { transform: none; }
}

/* Boutons radio et cases cachés derrière un libellé stylé : sans taille, ils débordaient de la page */
input[type="radio"], input[type="checkbox"] { width: auto; }
.cat-pick input, .day-pick input, .cards-pick input, .seg input { width: 1px; height: 1px; margin: 0; }
