/* GardeManger — design chaleureux, mobile-first */
:root {
  --bg: #fff6ea;
  --surface: #ffffff;
  --surface-2: #fff0dc;
  --ink: #2d2118;
  --muted: #7d6b5c;
  --line: #f0e2cf;
  --brand: #e4572e;
  --brand-dark: #c8431d;
  --brand-ink: #ffffff;
  --brand-soft: #ffe5da;
  --ok: #2f9461;       --ok-soft: #dcf4e4;
  --soon: #b8860b;     --soon-soft: #fff3c9;
  --urgent: #e07b12;   --urgent-soft: #ffe8cc;
  --bad: #d3342f;      --bad-soft: #ffe0de;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(80, 45, 10, .06), 0 6px 18px rgba(80, 45, 10, .07);
  --shadow-lg: 0 10px 40px rgba(60, 30, 5, .22);
  --tab-h: 64px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1511; --surface: #2a211b; --surface-2: #33281f; --ink: #f7ecdd; --muted: #b6a493; --line: #403327;
    --brand: #f0663a; --brand-dark: #ff7d55; --brand-soft: #4a2a1f;
    --ok: #52c486; --ok-soft: #1f3a2b; --soon: #e6bd4a; --soon-soft: #403517;
    --urgent: #f59a3d; --urgent-soft: #46301a; --bad: #ff6b66; --bad-soft: #4a2423;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 800; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.shell { min-height: 100dvh; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 900; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.brand-logo { width: 28px; height: 28px; }
.spacer { flex: 1; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent; font-size: 1.25rem;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); }
main { max-width: 760px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface);
  border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(80, 45, 10, .06);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .72rem; font-weight: 700; color: var(--muted); position: relative;
}
.tab .tab-emoji { font-size: 1.4rem; filter: grayscale(.6); transition: transform .15s, filter .15s; }
.tab[aria-current="page"] { color: var(--brand); }
.tab[aria-current="page"] .tab-emoji { filter: none; transform: translateY(-2px) scale(1.08); }
.tab .badge-dot {
  position: absolute; top: 8px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--brand); color: #fff; font-size: .68rem; display: grid; place-items: center;
}

@media (min-width: 900px) {
  .shell { padding: 0 0 0 220px; }
  .tabbar {
    inset: 0 auto 0 0; width: 220px; height: auto; flex-direction: column; justify-content: flex-start;
    padding: 84px 12px 12px; border-top: 0; border-right: 1px solid var(--line); box-shadow: none; gap: 4px;
  }
  .tab { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 14px; font-size: 1rem; border-radius: var(--radius-sm); }
  .tab[aria-current="page"] { background: var(--brand-soft); }
  .tab .tab-emoji { font-size: 1.3rem; }
  .tab .badge-dot { position: static; margin-left: auto; }
  .topbar { padding-left: 24px; }
  main { padding: 24px; max-width: 980px; }
}

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px;
  border-radius: 999px; border: 2px solid transparent; font-weight: 800; background: var(--brand); color: var(--brand-ink);
  transition: transform .08s, background .15s; text-align: center;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.soft { background: var(--brand-soft); color: var(--brand-dark); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.green { background: var(--ok); color: #fff; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .9rem; }
.btn.block { width: 100%; }

.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 800; font-size: .85rem; color: var(--muted); }
.input, select.input {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: var(--radius-sm); border: 2px solid var(--line);
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--brand); }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 14px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; margin: 0 -16px; padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--surface); font-weight: 700; font-size: .92rem; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip .n { opacity: .7; font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .input { text-align: center; font-weight: 800; font-size: 1.1rem; }
.stepper button {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface);
  font-size: 1.4rem; font-weight: 800; line-height: 1;
}
.stepper button:active { background: var(--brand-soft); }

/* ---------- En-têtes de page ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head p { color: var(--muted); font-size: .92rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); text-align: center; }
.stat b { display: block; font-size: 1.7rem; font-weight: 900; line-height: 1.1; }
.stat span { font-size: .78rem; color: var(--muted); font-weight: 700; }
.stat.warn b { color: var(--urgent); } .stat.bad b { color: var(--bad); }

.section-title { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; }
.section-title .count { color: var(--muted); font-weight: 700; font-size: .9rem; }

/* ---------- Cartes de stock ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.item {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 12px 12px 12px 14px; border: 0; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  overflow: hidden; min-height: 128px; transition: transform .1s;
}
.item::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--line); }
.item.exp-fresh::before { background: var(--ok); }
.item.exp-soon::before { background: #e9c01f; }
.item.exp-urgent::before { background: var(--urgent); }
.item.exp-expired::before { background: var(--bad); }
.item:active { transform: scale(.97); }
.item-emoji { font-size: 2.1rem; line-height: 1.1; margin-bottom: 4px; }
.item-name { font-weight: 800; line-height: 1.2; }
.item-qty { color: var(--muted); font-size: .9rem; font-weight: 600; }
.item .pill { margin-top: auto; }
.item.expired-card { background: var(--bad-soft); }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800; background: var(--surface-2); color: var(--muted); }
.pill.fresh { background: var(--ok-soft); color: var(--ok); }
.pill.soon { background: var(--soon-soft); color: var(--soon); }
.pill.urgent { background: var(--urgent-soft); color: var(--urgent); }
.pill.expired { background: var(--bad-soft); color: var(--bad); }

.urgent-strip {
  background: linear-gradient(135deg, var(--urgent-soft), var(--bad-soft)); border-radius: var(--radius);
  padding: 14px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.urgent-strip h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.urgent-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.mini {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 14px; background: var(--surface);
  border: 0; box-shadow: var(--shadow); font-weight: 700; font-size: .9rem; text-align: left;
}
.mini small { display: block; font-weight: 700; color: var(--urgent); font-size: .74rem; }
.mini.expired small { color: var(--bad); }
.mini .e { font-size: 1.5rem; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); z-index: 25;
  height: 58px; padding: 0 22px 0 18px; border-radius: 999px; border: 0; background: var(--brand); color: #fff;
  font-weight: 900; font-size: 1.05rem; box-shadow: 0 8px 24px rgba(228, 87, 46, .45); display: flex; align-items: center; gap: 8px;
}
.fab:hover { background: var(--brand-dark); }
.fab .plus { font-size: 1.6rem; line-height: 1; margin-top: -2px; }
@media (min-width: 900px) { .fab { right: 32px; bottom: 32px; } }

/* ---------- Recettes ---------- */
.recipes { display: grid; gap: 12px; }
.recipe {
  position: relative; display: flex; gap: 14px; padding: 14px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); align-items: flex-start;
}
.recipe-emoji {
  flex: none; width: 64px; height: 64px; border-radius: 18px; background: var(--surface-2); display: grid; place-items: center; font-size: 2.2rem;
}
.recipe.can .recipe-emoji { background: var(--ok-soft); }
.recipe-body { flex: 1; min-width: 0; display: grid; gap: 4px; }
.recipe-title { font-weight: 800; line-height: 1.25; padding-right: 30px; }
.recipe-meta { color: var(--muted); font-size: .85rem; font-weight: 600; }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 2px 0; }
.meter span { display: block; height: 100%; width: var(--w, 0%); border-radius: 4px; background: var(--urgent); transition: width .3s; }
.meter.full span { background: var(--ok); }
.meter.mid span { background: #e9c01f; }
.recipe-status { font-size: .88rem; font-weight: 700; }
.recipe-status.ok { color: var(--ok); }
.recipe-status.miss { color: var(--ink); }
.recipe-save { font-size: .82rem; font-weight: 700; color: var(--urgent); }
.badge { display: inline-block; vertical-align: middle; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: .68rem; font-weight: 900; background: #ede0ff; color: #6a35c4; }
@media (prefers-color-scheme: dark) { .badge { background: #3a2a5c; color: #c9aaff; } }
.fav-btn { position: absolute; top: 6px; right: 6px; }
.fav-btn[aria-pressed="true"] { color: #f5b301; }

.detail-hero { text-align: center; padding: 8px 0 16px; }
.detail-hero .big { font-size: 4rem; line-height: 1.1; }
.detail-hero h1 { margin: 6px 0; }
.back { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; color: var(--muted); margin-bottom: 8px; padding: 6px 0; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.ing-list { list-style: none; margin: 0; padding: 0; }
.ing-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ing-list li:last-child { border-bottom: 0; }
.ing-list .st { flex: none; width: 28px; text-align: center; font-size: 1.1rem; }
.ing-list .nm { flex: 1; font-weight: 700; }
.ing-list .nm small { display: block; font-weight: 600; color: var(--muted); }
.ing-list .qt { color: var(--muted); font-weight: 700; white-space: nowrap; }
.ing-list li.missing .nm { color: var(--bad); }
.ing-list li.partial .nm { color: var(--urgent); }
.steps { margin: 0; padding-left: 0; list-style: none; counter-reset: s; display: grid; gap: 12px; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; }
.steps li::before {
  content: counter(s); flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff;
  font-weight: 900; display: grid; place-items: center; font-size: .9rem; margin-top: 1px;
}
.actions-bar {
  position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px); display: flex; gap: 10px; margin-top: 18px;
  padding: 10px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
  border-radius: 999px; box-shadow: var(--shadow-lg); z-index: 15;
}
.actions-bar .btn { flex: 1; }
@media (min-width: 900px) { .actions-bar { bottom: 16px; } }

/* ---------- Courses ---------- */
.shop-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); margin-bottom: 8px;
}
.check {
  flex: none; width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); background: transparent; display: grid;
  place-items: center; color: transparent; font-weight: 900; padding: 0;
}
.check[aria-checked="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.shop-row .e { font-size: 1.6rem; }
.shop-row .nm { flex: 1; font-weight: 700; min-width: 0; }
.shop-row .nm small { display: block; color: var(--muted); font-weight: 600; }
.shop-row.done .nm { text-decoration: line-through; color: var(--muted); }

/* ---------- Feuille modale ---------- */
.backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(30, 15, 5, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--bg); border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .22s cubic-bezier(.2, .9, .3, 1); box-shadow: var(--shadow-lg);
}
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
@media (min-width: 700px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 26px; padding-bottom: 22px; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.picks { display: grid; gap: 6px; margin-top: 10px; max-height: 40dvh; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: var(--surface); text-align: left; font-weight: 700; }
.pick:hover, .pick:focus-visible { background: var(--brand-soft); }
.pick small { display: block; color: var(--muted); font-weight: 600; }
.pick .e { font-size: 1.5rem; }
.pick.create { border: 2px dashed var(--brand); background: transparent; color: var(--brand-dark); }
.selected { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--surface); border-radius: var(--radius-sm); margin-bottom: 14px; }
.selected .e { font-size: 2rem; }
.loc-chips { display: flex; gap: 8px; }
.loc-chips .chip { flex: 1; justify-content: center; }

/* ---------- Divers ---------- */
.empty { text-align: center; padding: 40px 20px; display: grid; gap: 10px; justify-items: center; }
.empty .big { font-size: 3.5rem; }
.empty p { color: var(--muted); max-width: 32ch; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 84px); transform: translateX(-50%); z-index: 200;
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 999px; font-weight: 700; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-lg); animation: toast-in .2s;
}
.toast.error { background: var(--bad); color: #fff; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-weight: 700; font-size: .92rem; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--surface-2); color: var(--muted); }

.switch { position: relative; width: 56px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--line); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(24px); }
.switch input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 2px; }

.user-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }

/* ---------- Connexion ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 28px; padding: 28px 24px; box-shadow: var(--shadow-lg); display: grid; gap: 16px; }
.auth-card .logo { font-size: 3.2rem; text-align: center; }
.auth-card h1 { text-align: center; }
.auth-card .tag { text-align: center; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.stepper > div:last-child { flex: none; width: 104px; }
@keyframes toast-in { from { transform: translate(-50%, 20px); opacity: 0; } }

/* Recherche + tri */
.toolbar { display: grid; grid-template-columns: 1fr; gap: 8px; }
.toolbar .sort { font-weight: 700; }
@media (min-width: 600px) { .toolbar { grid-template-columns: 1fr 250px; } }

/* Sélection multiple de recettes */
.recipe.selectable { cursor: pointer; user-select: none; border: 2px solid transparent; }
.recipe.selectable:focus-visible { outline: 3px solid var(--brand); }
.recipe.picked { border-color: var(--bad); background: color-mix(in srgb, var(--bad-soft) 55%, var(--surface)); }
.sel-box {
  position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line);
  display: grid; place-items: center; color: transparent; font-weight: 900; background: var(--surface);
}
.recipe.picked .sel-box { background: var(--bad); border-color: var(--bad); color: #fff; }
.actions-bar .btn:disabled { opacity: .45; }

/* Import Marmiton */
.page-head .row { flex-wrap: wrap; justify-content: flex-end; }
.cand { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; border: 2px solid transparent; }
.cand.picked { border-color: var(--ok); background: color-mix(in srgb, var(--ok-soft) 45%, var(--surface)); }
.cand.already { opacity: .6; }
.cand-head { display: flex; gap: 12px; align-items: flex-start; }
.cand-head .check { margin-top: 4px; }
.cand-head .check:disabled { opacity: .35; cursor: default; }
.cand-details { margin-top: 14px; }
.cand .ing-list li { align-items: flex-start; }
.cand .ing-list .nm small { font-size: .78rem; }

/* Barre d'actions collée en bas, y compris quand elle est dans un conteneur */
.sticky-wrap { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px); z-index: 15; }
.sticky-wrap .actions-bar { position: static; }
@media (min-width: 900px) { .sticky-wrap { bottom: 16px; } }
.cand-head .recipe-title { padding-right: 0; }

/* En-têtes de page : les boutons passent à la ligne plutôt que de couper le titre */
.page-head { flex-wrap: wrap; align-items: flex-end; }
.page-head > div:first-child { flex: 1 1 220px; }
.page-head .row { justify-content: flex-start; }
@media (min-width: 600px) { .page-head .row { justify-content: flex-end; } }
