/* ==========================================================================
   Grocery Manager — feuille de style de l'app shell
   Aucune dépendance externe, aucune police distante, aucun framework.
   Le JavaScript ne fournit que le contenu de #app et bascule les classes.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Jetons (tokens)
   Contraste AA vérifié sur le thème clair (docs/2.0/ui_ux.md § 5.1).
   -------------------------------------------------------------------------- */
:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface-2: #EFECE4;
  --text: #1C1B18;
  --text-muted: #5F5B52;
  --primary: #1F6F4A;
  --primary-text: #FFFFFF;
  --primary-soft: #E6F0EA;
  --danger: #B3261E;
  --danger-soft: #FBE9E7;
  --warn: #8A5A00;
  --warn-bg: #FFF8E1;
  --border: #DDD8CC;
  --skeleton: #EDEAE2;
  --focus: #1F6F4A;

  /* Dimensions */
  --topbar-h: 56px;
  --nav-h: 64px;
  --radius: 12px;
  --radius-lg: 16px;
  --gap: 16px;
  --pad: 16px;

  /* Typographie : pile système uniquement */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-key: 28px;      /* chiffre clé : budget restant */
  --fs-title: 22px;    /* titre d'écran */
  --fs-body: 17px;     /* corps */
  --fs-small: 15px;    /* secondaire */
  --fs-micro: 13px;    /* badges */

  /* Mouvement */
  --t-fast: 120ms ease-out;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12130F;
    --surface: #1B1D18;
    --surface-2: #242720;
    --text: #F2F0E8;
    --text-muted: #B9B4A6;
    --primary: #4FB985;
    --primary-text: #0E1611;
    --primary-soft: #1E2E25;
    --danger: #FF8A80;
    --danger-soft: #3A1D1B;
    --warn: #FFD07A;
    --warn-bg: #33290F;
    --border: #3A3D34;
    --skeleton: #26291F;
    --focus: #7BD3A6;
  }
}

/* --------------------------------------------------------------------------
   2. Remise à zéro minimale
   -------------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }

/* `hidden` natif prioritaire sur tout display de composant */
[hidden] { display: none !important; }

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

/* Aucun scroll horizontal, jamais (acceptation § 14) */
#app-shell, #login-screen, #app, #topbar, #nav { max-width: 100%; }

/* --------------------------------------------------------------------------
   3. Structure : topbar / contenu / nav
   -------------------------------------------------------------------------- */
#app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar"
    "main";
  min-height: 100dvh;
}

#topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: 8px var(--pad);
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

#topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-title);
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#btn-logout {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 6px 10px;
  font-size: var(--fs-small);
  font-weight: 600;
}

/* Téléphones étroits : le titre garde la priorité sur le bouton */
@media (max-width: 430px) {
  #topbar { gap: 8px; padding-inline: 12px; }
  #topbar-title { font-size: 18px; }
  #btn-logout { padding: 6px 6px; font-size: var(--fs-micro); }
}

#app {
  grid-area: main;
  padding: var(--pad);
  /* La nav basse ne doit jamais masquer le dernier élément */
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 32px);
  overflow-x: hidden;
}

#app:focus { outline: none; }

/* --------------------------------------------------------------------------
   4. Navigation basse (mobile et tablette)
   -------------------------------------------------------------------------- */
#nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  min-height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#nav button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: var(--fs-micro);
  font-weight: 500;
  cursor: pointer;
  position: relative;
}

.nav-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.nav-label { line-height: 1.1; }

/* Onglet actif : couleur + graisse + soulignement (jamais la couleur seule) */
#nav button.active,
#nav button[aria-current="page"] {
  color: var(--primary);
  font-weight: 700;
}

#nav button.active .nav-icon,
#nav button[aria-current="page"] .nav-icon { stroke-width: 2.4; }

#nav button.active::after,
#nav button[aria-current="page"]::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}

#nav button:active { background: var(--primary-soft); }

/* --------------------------------------------------------------------------
   5. Écran de connexion
   -------------------------------------------------------------------------- */
#login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 20px calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
}

.login-brand svg {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  color: var(--primary);
}

.login-box h1 {
  font-size: var(--fs-title);
  font-weight: 600;
  margin-bottom: 4px;
}

.login-help {
  color: var(--text-muted);
  font-size: var(--fs-small);
  margin-bottom: 20px;
}

#login-form {
  display: grid;
  gap: 10px;
  text-align: left;
}

#login-form label {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text-muted);
}

.login-note {
  margin-top: 16px;
  font-size: var(--fs-micro);
  color: var(--text-muted);
}

#login-error {
  margin-top: 2px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--fs-small);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   6. Champs de formulaire
   -------------------------------------------------------------------------- */
input[type="password"],
input[type="text"],
input[type="number"],
input[type="search"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: var(--fs-body);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--primary);
}

/* --------------------------------------------------------------------------
   7. Boutons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 44px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-body);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}

.btn:active { transform: translateY(1px); }

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-primary:active { background: var(--primary); filter: brightness(0.94); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding-inline: 12px;
}

.btn-ghost:active { background: var(--surface-2); }

/* Bouton pleine largeur, collant en bas au-dessus de la nav */
.btn-block {
  display: flex;
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.icon-btn svg,
.icon-btn .lock-icon { width: 22px; height: 22px; }

.icon-btn:active { background: var(--surface-2); }

/* --------------------------------------------------------------------------
   8. Bandeaux, badges, états
   -------------------------------------------------------------------------- */
.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-bottom: var(--gap);
  background: var(--danger-soft);
  border-left: 4px solid var(--danger);
  color: var(--text);
  font-size: var(--fs-small);
  font-weight: 600;
}

.error-banner .btn { margin-left: auto; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-micro);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Cadenas de repas verrouillé : la couleur ne porte pas seule le sens,
   le libellé/titre de l'élément doit dire « verrouillé ». */
.lock-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex: 0 0 auto;
}

.meal-card.locked .lock-icon,
.locked > .lock-icon {
  color: var(--warn);
}

/* Squelette de chargement : jamais de spinner plein écran sur le contenu */
.loading {
  position: relative;
  min-height: 88px;
  border-radius: var(--radius);
}

/* Voile animé uniquement si le conteneur n'a pas déjà ses propres lignes */
.loading:empty::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(100deg, var(--skeleton) 30%, var(--surface-2) 50%, var(--skeleton) 70%);
  background-size: 240% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton-line {
  height: 16px;
  margin: 10px 0;
  border-radius: 8px;
  background: linear-gradient(100deg, var(--skeleton) 30%, var(--surface-2) 50%, var(--skeleton) 70%);
  background-size: 240% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton-line:nth-child(2n) { width: 88%; }
.skeleton-line:nth-child(3n) { width: 64%; }
.skeleton-line:first-of-type { height: 28px; width: 46%; }

@keyframes shimmer {
  from { background-position: 130% 0; }
  to   { background-position: -110% 0; }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state h2,
.empty-state strong {
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
}

.empty-state p {
  max-width: 34ch;
  font-size: var(--fs-body);
}

.empty-title {
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
}

/* Dialogue de choix (remplacement d'un repas) réutilisant #confirm-dialog */
.choice-title {
  display: block;
  margin-bottom: 12px;
  font-size: var(--fs-body);
  font-weight: 600;
}

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

.choice-list .choice-item {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: var(--surface);
  border-color: var(--border);
}

.retry-row {
  display: flex;
  justify-content: center;
  margin: 8px 0 16px;
}

/* --------------------------------------------------------------------------
   9. Cartes repas / semaine
   -------------------------------------------------------------------------- */
.meal-card {
  display: block;
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  color: var(--text);
}

.meal-card + .meal-card { margin-top: 8px; }

.meal-card .meal-name {
  display: block;
  font-size: var(--fs-body);
  font-weight: 600;
  line-height: 1.3;
}

.meal-card .meal-meta {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

/* Repas verrouillé : fond doux + bordure d'accent, pas seulement l'icône */
.meal-card.locked {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.meal-card.locked .meal-name { color: var(--primary); }

.day-block {
  margin-bottom: var(--gap);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.day-block > header,
.day-block > summary,
.day-block .day-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 16px;
  background: var(--surface-2);
  font-size: var(--fs-small);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.meal-type {
  display: inline-block;
  min-width: 64px;
  color: var(--text-muted);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Rangée jour : type de repas + nom + actions */
.day-block .meal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 4px 12px 4px 16px;
  border-top: 1px solid var(--border);
}

.day-block .meal-row:first-of-type { border-top: 0; }
.day-block .day-title + .meal-row { border-top: 0; }

/* --------------------------------------------------------------------------
   10. Liste de courses
   -------------------------------------------------------------------------- */
.shopping-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 56px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.shopping-item:first-child { border-top: 1px solid var(--border); }

/* Case 24 px dans une cible 48 px */
.shopping-item input[type="checkbox"],
.shopping-item .check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--primary);
}

.shopping-item .item-label,
.shopping-item .item-name {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-body);
  font-weight: 500;
}

/* Libellé cliquable qui occupe la ligne, la case restant sur la gauche */
.shopping-item .item-body {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  cursor: pointer;
}

.shopping-item .item-meta {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-weight: 400;
}

/* Détails (requête, quantité, conditionnement) sur une seule ligne compacte */
.shopping-item .item-query,
.shopping-item .item-qty,
.shopping-item .item-pack {
  display: inline;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-weight: 400;
  line-height: 1.35;
}

.shopping-item .item-query + .item-qty::before,
.shopping-item .item-qty + .item-pack::before { content: " · "; }

.shopping-item .item-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.shopping-item .item-price {
  flex: 0 0 auto;
  margin-left: 4px;
  font-size: var(--fs-body);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

.shopping-item .item-price.unknown {
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-weight: 500;
}

/* Prix de démonstration : signalé en ambre, jamais présenté comme constaté */
.shopping-item .item-price.price-demo {
  margin-top: 0;
  color: var(--warn);
  font-size: var(--fs-micro);
  font-weight: 600;
}

/* Coché : barré + atténué, la ligne reste lisible */
.shopping-item.checked .item-label,
.shopping-item.checked .item-name {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  opacity: 0.6;
}

.shopping-item.checked { background: var(--bg); }

/* Mention obligatoire sur tout total : « estimation · prix de démo » */
.price-demo {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: var(--fs-micro);
}

/* --------------------------------------------------------------------------
   11. Recettes
   -------------------------------------------------------------------------- */
.recipe-list {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr);
}

.recipe-card {
  display: block;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
}

.recipe-card .recipe-name {
  font-size: var(--fs-body);
  font-weight: 600;
}

.recipe-card .recipe-meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

.ingredient-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  min-height: 44px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-body);
  list-style: none;
}

.ingredient-row .ingredient-qty,
.ingredient-row .qty {
  flex: 0 0 84px;
  width: 84px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ingredient-row .ingredient-name {
  flex: 1 1 auto;
  min-width: 0;
}

.ingredient-row .ingredient-note {
  flex: 0 0 100%;
  color: var(--text-muted);
  font-size: var(--fs-micro);
}

.ingredient-row .cost {
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.step-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-body);
  list-style: none;
}

.step-row .step-number,
.step-row .step-num {
  color: var(--text-muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.step-row .step-text { min-width: 0; }

/* --------------------------------------------------------------------------
   12. Budget et statistiques
   -------------------------------------------------------------------------- */
.budget-bar {
  position: relative;
  width: 100%;
  height: 8px;
  margin: 8px 0 6px;
  background: var(--skeleton);
  border-radius: 999px;
  overflow: hidden;
}

.budget-bar .fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease-out, background var(--t-fast);
}

.budget-bar .fill.warn,
.budget-bar.warn .fill { background: var(--warn); }

.budget-bar .fill.over,
.budget-bar.over .fill { background: var(--danger); }

.budget-caption {
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

.budget-amount {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.budget-amount .amount {
  font-size: var(--fs-key);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.budget-amount .amount-sub {
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

.budget-amount.over .amount { color: var(--danger); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-card .stat-label {
  display: block;
  color: var(--text-muted);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.stat-card .stat-value {
  display: block;
  margin-top: 4px;
  font-size: var(--fs-key);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-card .stat-unit {
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   13. Voile de chargement, toast, dialogue
   -------------------------------------------------------------------------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(18, 19, 15, 0.45);
  color: #FFFFFF;
  text-align: center;
}

#overlay p {
  font-size: var(--fs-body);
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid rgba(255, 255, 255, 0.35);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 50;
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  background: #1C1B18;
  color: #FFFFFF;
  border-radius: 10px;
  font-size: var(--fs-small);
  font-weight: 600;
  text-align: center;
}

#toast button {
  margin-left: 8px;
  padding: 4px 8px;
  min-height: 44px;
  background: none;
  border: 0;
  color: #9BE3BE;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

#confirm-dialog {
  width: min(92vw, 380px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
}

#confirm-dialog::backdrop { background: rgba(18, 19, 15, 0.55); }

#confirm-text {
  font-size: var(--fs-body);
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions .btn { min-width: 96px; }

/* --------------------------------------------------------------------------
   13 bis. Composants produits par web/js (markup réel des vues)
   Toutes les classes ci-dessous sont émises par js/views.js et js/ui.js ;
   aucune logique ici, seulement la mise en forme.
   -------------------------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--text-muted); }

.view { display: block; }

/* Marqueurs de vue : une seule colonne par défaut, le CSS gère le reste */
.view-accueil,
.view-menus,
.view-courses,
.view-budget,
.view-recettes,
.view-recette { display: block; }

.view-title {
  font-size: var(--fs-title);
  font-weight: 600;
  line-height: 1.2;
}

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  margin-bottom: 12px;
}

.view-subtitle {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

.view-note {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: var(--fs-small);
  line-height: 1.45;
}

.section-title {
  margin: 20px 0 8px;
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.breadcrumb {
  display: flex;
  align-items: center;
  min-height: 44px;
  margin-bottom: 2px;
  font-size: var(--fs-small);
}

.breadcrumb a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.breadcrumb a:hover { text-decoration: underline; }

/* Grille de la semaine : jours empilés, jamais de matrice 7 colonnes */
.week-grid {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.day-meals { padding: 0; }

.day-meals .meal-card {
  margin: 0;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
}

.day-meals .day-empty {
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

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

.meal-card a.meal-name {
  color: inherit;
  text-decoration: none;
  display: block;
}

.meal-card a.meal-name:hover { text-decoration: underline; }

.meal-card.is-empty {
  background: var(--bg);
  border-style: dashed;
}

.meal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 8px;
}

.btn-small {
  min-height: 44px;
  padding: 6px 14px;
  font-size: var(--fs-small);
}

/* Variantes de badge */
.badge-locked,
.badge-demo {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-tag {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 500;
}

.badge-current {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge .lock-icon {
  width: auto;
  height: auto;
  font-size: 12px;
  line-height: 1;
}

.stat-hint {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--fs-micro);
}

.stat-card.stat-over .stat-value { color: var(--danger); }

/* Rayons de courses */
.shopping-group {
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface-2);
  font-size: var(--fs-small);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.group-total {
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.shopping-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.shopping-list .shopping-item:first-child { border-top: 0; }

.shopping-item.unresolved { border-left: 3px solid var(--warn); }

.courses-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text-muted);
}

.courses-total strong {
  color: var(--text);
  font-size: var(--fs-title);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.courses-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.unresolved-block {
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--warn-bg);
  border-left: 4px solid var(--warn);
  border-radius: 8px;
}

.unresolved-title {
  font-size: var(--fs-small);
  font-weight: 700;
}

.unresolved-list {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

.unresolved-list li { padding: 2px 0; }

/* Accueil */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.warning-list {
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--warn-bg);
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  font-size: var(--fs-small);
  list-style: none;
}

.warning-list li { padding: 2px 0; }

/* Menus */
.plan-selector {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.plan-selector label {
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-weight: 600;
}

.regenerate-banner {
  margin: 12px 0 16px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.regenerate-banner p {
  color: var(--text-muted);
  font-size: var(--fs-small);
}

.regenerate-banner .btn {
  width: 100%;
  margin-top: 10px;
}

/* Recettes */
.recipe-card {
  color: inherit;
  text-decoration: none;
}

.recipe-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.recipe-notes {
  color: var(--text-muted);
  font-size: var(--fs-small);
  line-height: 1.5;
}

.ingredient-list,
.step-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.utensils {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.portions-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.portions-control label {
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-weight: 600;
}

.portions-control input { width: 96px; }

.search-form { margin: 4px 0 8px; }

/* Budget / historique */
.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
}

.history-row:first-child { border-top: 0; }

.history-row.current { background: var(--primary-soft); }

.history-row > a {
  flex: 1 1 auto;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  font-size: var(--fs-body);
}

.history-row > a:hover { text-decoration: underline; }

.history-cost {
  flex: 0 0 auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   14. Tablette (640 – 1024 px)
   -------------------------------------------------------------------------- */
@media (min-width: 640px) {
  :root { --pad: 24px; --gap: 20px; }

  #app {
    width: 100%;
    max-width: 720px;
    margin-inline: auto;
  }

  .recipe-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .regenerate-banner .btn { width: auto; }

  #nav { justify-content: center; }

  #nav button {
    flex: 0 1 160px;
    max-width: 180px;
  }
}

/* --------------------------------------------------------------------------
   15. Ordinateur (> 1024 px) : contenu centré, nav passée en haut
   -------------------------------------------------------------------------- */
@media (min-width: 1025px) {
  :root { --pad: 32px; }

  #app-shell {
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "topbar"
      "nav"
      "main";
    max-width: 980px;
    margin-inline: auto;
    border-inline: 1px solid var(--border);
  }

  #topbar { padding-inline: 24px; }

  #nav {
    position: static;
    grid-area: nav;
    justify-content: flex-start;
    gap: 4px;
    min-height: 48px;
    padding: 0 12px;
    background: var(--bg);
    border-top: 0;
    border-bottom: 1px solid var(--border);
  }

  #nav button {
    flex: 0 0 auto;
    min-height: 48px;
    flex-direction: row;
    gap: 8px;
    padding: 8px 16px;
    font-size: var(--fs-small);
  }

  #nav button.active::after,
  #nav button[aria-current="page"]::after {
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100%;
    height: 3px;
    border-radius: 3px 3px 0 0;
  }

  #app {
    padding: 24px 32px 64px;
    max-width: 900px;
  }

  #toast { bottom: 24px; }

  .btn:hover, .icon-btn:hover, .recipe-card:hover, .shopping-item:hover { background: var(--surface-2); }
  .btn-primary:hover { background: var(--primary); filter: brightness(1.06); }
  #nav button:hover { color: var(--primary); }

  .recipe-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  /* Deux jours côte à côte : la grille 7×3 reste lisible sur grand écran */
  .week-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }

  .quick-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  .courses-actions { display: flex; justify-content: flex-end; }
}

/* --------------------------------------------------------------------------
   16. Mouvement réduit et impression
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
