:root {
  --bg: #f5f6f2;
  --card: #ffffff;
  --ink: #1f2a24;
  --muted: #6d7a72;
  --line: #e5e8e2;
  --brand: #2e7d5b;
  --brand-dark: #24634899;
  --brand-soft: #e6f1eb;
  --danger: #c0492f;
  --accent: #e8a13a;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(31, 42, 36, 0.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
}
#app { max-width: 720px; margin: 0 auto; min-height: 100dvh; }

/* ---- Layout ---- */
.screen { padding: 16px 16px calc(96px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: 14px 16px 10px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.topbar h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.topbar .sub { color: var(--muted); font-size: 13px; }

/* ---- Bottom nav ---- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 720px; margin: 0 auto;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(1.4) blur(10px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-b);
}
.nav button {
  background: none; border: none; padding: 9px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px; cursor: pointer; font-weight: 600;
}
.nav button .ic { font-size: 20px; line-height: 1; }
.nav button.active { color: var(--brand); }

/* ---- Cards & lists ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.chip {
  display: inline-block; font-size: 12px; font-weight: 600;
  background: var(--brand-soft); color: var(--brand);
  padding: 3px 9px; border-radius: 999px;
}
.chip.gray { background: #eef0ec; color: var(--muted); }
.chip.ok { background: var(--brand-soft); color: var(--brand); }

/* Créneau de repas déjà acheté */
.day-card .slot.bought .assigned { color: var(--muted); }
.day-card .slot.bought { opacity: 0.75; }

/* ---- Buttons ---- */
.btn {
  appearance: none; border: none; cursor: pointer; font: inherit; font-weight: 600;
  background: var(--brand); color: #fff; border-radius: 12px;
  padding: 12px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.gray { background: #eceee9; color: var(--ink); }
.btn.danger { background: #fbe9e5; color: var(--danger); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.iconbtn {
  border: none; background: #eceee9; color: var(--ink); border-radius: 10px;
  width: 38px; height: 38px; font-size: 18px; cursor: pointer; display: grid; place-items: center;
}
.iconbtn.danger { background: #fbe9e5; color: var(--danger); }

/* ---- Forms ---- */
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.field { margin-bottom: 12px; }
.inline { display: flex; gap: 8px; }
.inline > * { min-width: 0; }

/* ---- Sections ---- */
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 4px 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---- Shopping list ---- */
.shop-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.shop-item:last-child { border-bottom: none; }
.check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line);
  display: grid; place-items: center; flex: none; color: #fff; font-size: 15px;
}
.shop-item.done .check { background: var(--brand); border-color: var(--brand); }
.shop-item.done .name { text-decoration: line-through; color: var(--muted); }
/* Article introuvable en magasin */
.shop-item.unavail { cursor: default; }
.shop-item.unavail .check { border-color: var(--danger); font-size: 13px; }
.shop-item.unavail .name, .shop-item.unavail .qty { color: var(--muted); text-decoration: line-through; }
/* Article couvert par le stock maison */
.shop-item.home .check { border-color: var(--brand); background: var(--brand-soft); font-size: 13px; }
.shop-item.home .name, .shop-item.home .qty { color: var(--muted); }
.qty { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---- Login ---- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; }
.brandmark { text-align: center; margin-bottom: 20px; }
.brandmark .logo { font-size: 46px; }
.brandmark h1 { margin: 6px 0 2px; font-size: 24px; }

/* ---- Planning grid ---- */
.day-card .slot { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.day-card .slot + .slot { border-top: 1px dashed var(--line); }
.slot-label { width: 44px; font-size: 20px; text-align: center; flex: none; }
.assigned { font-weight: 600; }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,28,24,0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--card); width: 100%; max-width: 720px;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + var(--safe-b));
  max-height: 92dvh; overflow-y: auto; animation: slideup .18s ease;
}
@keyframes slideup { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 2px 0 14px; font-size: 19px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

/* ---- Budget bars ---- */
.bar-track { background: #eef0ec; border-radius: 8px; height: 10px; overflow: hidden; margin-top: 6px; }
.bar-fill { background: var(--brand); height: 100%; border-radius: 8px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.stat { background: var(--brand-soft); border-radius: 14px; padding: 12px; }
.stat .v { font-size: 24px; font-weight: 800; color: var(--brand); }
.stat .l { font-size: 12px; color: var(--brand); font-weight: 600; }

.toast {
  position: fixed; bottom: calc(80px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: #1f2a24; color: #fff; padding: 11px 16px; border-radius: 12px; z-index: 60;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: slideup .18s ease;
}
.spinner { text-align: center; color: var(--muted); padding: 30px; }

/* ---- Tags (ajout d'article) ---- */
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 14px; }
.tag {
  appearance: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 13px; border-radius: 999px;
}
.tag:active { transform: translateY(1px); }
.tag.sel { background: var(--brand); color: #fff; border-color: var(--brand); }
.note-tag {
  display: inline-block; font-size: 12px; font-weight: 600;
  background: var(--brand-soft); color: var(--brand);
  padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}
.shop-item.done .note-tag { background: #eef0ec; color: var(--muted); }

/* Case à cocher inline (longue conservation) */
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); cursor: pointer; margin: 2px 0 0; }
.chk input { width: auto; margin: 0; }

/* Propositions hors menu (étape de génération) */
.hm-prop { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.hm-prop:last-child { border-bottom: none; }
.hm-prop input { width: auto; margin: 0; flex: none; }
.hm-reason { display: inline-block; font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 6px; }
.hm-reason.due { color: var(--brand); }

/* DLC à vérifier sous le nom de l'article */
.dlc { font-size: 12px; font-weight: 600; color: var(--accent); margin-top: 2px; }
.shop-item.done .dlc { color: var(--muted); }
