/* Recettes : interface mobile d'abord, clair et sombre. */
:root {
  --bg: #f7f6f2;
  --card: #ffffff;
  --text: #1d1f1c;
  --muted: #61665f;
  --line: #e2e0d8;
  --accent: #2f7d4f;
  --accent-soft: #e2f1e7;
  --warn: #8a5a00;
  --danger: #b3261e;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141614;
    --card: #1e211e;
    --text: #ecede9;
    --muted: #a3a89f;
    --line: #333833;
    --accent: #5cc189;
    --accent-soft: #23382b;
    --warn: #e6b450;
    --danger: #f2b8b5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* « hidden » gagne toujours, même sur un élément qui a son propre display (toast, onglets, bandeaux). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* En-tête */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 4px; }
button.icon {
  min-width: 40px; height: 40px; padding: 0 8px;
  border: 0; border-radius: 10px; background: transparent;
  font-size: 1.3rem; cursor: pointer;
}
button.icon:active { background: var(--accent-soft); }
button.icon.on { color: var(--accent); }
.back { font-size: 2rem; line-height: 1; }

/* Bandeaux */
.busy, .offline { padding: 8px 16px; font-size: .9rem; background: var(--accent-soft); }
.offline { background: #fff3cd; color: #5c4400; }
@media (prefers-color-scheme: dark) { .offline { background: #3d3214; color: #f4dc9a; } }
.bar { height: 3px; margin-top: 6px; border-radius: 2px; background: linear-gradient(90deg, var(--accent) 30%, transparent 30%) 0 0 / 200% 100%; animation: slide 1.1s linear infinite; }
@keyframes slide { to { background-position: -200% 0; } }

main { padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; }
.empty { color: var(--muted); padding: 24px 4px; }

/* Onglets */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs a { flex: 1; text-align: center; padding: 14px 4px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a.on { color: var(--accent); }

/* Formulaires */
input[type=text], input[type=url], input[type=email], input[type=password], input[type=search], textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
textarea { min-height: 90px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; }
.stack > * + * { margin-top: 12px; }
.login { max-width: 360px; margin: 10vh auto 0; }

/* Recettes */
.search { margin-bottom: 10px; }
.cards { list-style: none; margin: 0; padding: 0; }
.card {
  display: flex; align-items: center; gap: 12px;
  margin: 8px 0; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; -webkit-user-select: none; user-select: none;
}
.card.sel { border-color: var(--accent); background: var(--accent-soft); }
.card .body { flex: 1; min-width: 0; }
.card .t { font-weight: 600; }
.card .meta, .muted { color: var(--muted); font-size: .88rem; }
.card .fav { color: var(--accent); }
.card input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }

.fab {
  position: fixed; right: 16px; z-index: 4;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  padding: 14px 20px; border-radius: 28px; box-shadow: 0 4px 14px rgb(0 0 0 / .2);
}

/* Fiche */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip { padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); font-size: .88rem; }
.warn { color: var(--warn); font-size: .9rem; margin: 4px 0; }
h2 { font-size: 1.05rem; margin: 22px 0 8px; }
h3 { font-size: .95rem; margin: 14px 0 4px; color: var(--accent); }
.ings { list-style: none; margin: 0; padding: 0; }
.ings li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ings .q { color: var(--muted); white-space: nowrap; }
.steps { padding-left: 1.4em; }
.steps li { margin: 8px 0; }
.steps b { display: block; }
.hero { width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius); margin-bottom: 8px; }

/* Liste d'épicerie */
.group { margin: 18px 0 4px; font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.items { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.items li + li { border-top: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.item input { width: 24px; height: 24px; flex: none; accent-color: var(--accent); }
.item .body { flex: 1; min-width: 0; }
.item .n { display: block; overflow-wrap: anywhere; }
.item .q { color: var(--accent); font-size: .9rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.item.done .n { text-decoration: line-through; color: var(--muted); }
.item .d { color: var(--muted); font-size: .82rem; }
.add { margin: 4px 0 8px; }
.add input { flex: 1; }

/* Toast et dialogue */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 10;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  max-width: 560px; margin: 0 auto; padding: 12px 16px; border-radius: 10px;
  background: #2b2f2b; color: #fff;
}
dialog { width: min(92vw, 420px); border: 0; border-radius: 16px; padding: 20px; background: var(--card); color: var(--text); }
dialog .dlg-title { margin-top: 0; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog .row { justify-content: flex-end; margin-top: 16px; }

/* Tags */
.tagrow { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.tagrow::-webkit-scrollbar { display: none; }
button.chip { border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.chip.tag { background: var(--card); border-color: var(--line); color: var(--text); }
.chip.tag.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips.tags .chip { display: inline-flex; align-items: center; gap: 4px; }
.chip .x { border: 0; background: transparent; padding: 0 2px; cursor: pointer; color: var(--muted); font-size: .8rem; }
.chip.add-tag { background: transparent; border: 1px dashed var(--line); color: var(--accent); }
.card .cardtags { color: var(--accent); font-size: .8rem; margin-top: 2px; }

/* Édition de recette */
button.icon.sm { min-width: 30px; height: 30px; font-size: .95rem; color: var(--muted); }
.rowtools { display: inline-flex; gap: 2px; margin-left: 6px; flex: none; }
.steps .rowtools { margin-left: 4px; vertical-align: middle; }
.addrow { margin-top: 8px; }
.warn .icon.sm { vertical-align: middle; }
label.field { display: block; margin-top: 10px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
label.check input { width: 22px; height: 22px; accent-color: var(--accent); }
select { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font: inherit; }
dialog { max-height: 90vh; overflow-y: auto; }

/* Toast avec action */
.toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toast-action { border: 0; background: transparent; color: #8fe0b0; font-weight: 700; cursor: pointer; padding: 4px 6px; }

/* Glisser pour retirer (liste d'épicerie) */
.items { overflow: hidden; }
li.swipe { position: relative; touch-action: pan-y; background: var(--danger); }
li.swipe::after { content: "Retirer"; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: #fff; font-weight: 700; z-index: 0; }
li.swipe > .item { position: relative; z-index: 1; background: var(--card); }
.hint { font-size: .82rem; margin: 0 0 4px; }

/* Spéciaux */
.deal { margin-top: 4px; font-size: .85rem; color: var(--text); cursor: pointer; }
.deal-tag { display: inline-block; padding: 0 6px; border-radius: 6px; background: #fde68a; color: #5c4400; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
@media (prefers-color-scheme: dark) { .deal-tag { background: #5c4a12; color: #fde68a; } }
.deal-more { margin-top: 4px; padding-left: 8px; border-left: 2px solid var(--line); color: var(--muted); }
.deal-card { align-items: flex-start; cursor: default; }
.deal-card .thumb { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.tabs a { font-size: .9rem; }

/* Importations par lots */
.banner { display: block; margin: 0 0 10px; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); text-decoration: none; font-weight: 600; }
.status-icon { width: 24px; text-align: center; font-size: 1.1rem; flex: none; }
.card.failed .meta { color: var(--danger); }

/* Découvrir */
.disc-filters { display: flex; gap: 8px; align-items: center; }
.disc-filters select { flex: 1; min-width: 0; padding: 8px; }
.disc-count { margin: 8px 0; font-variant-numeric: tabular-nums; }
.disc-stage { position: relative; min-height: 58vh; }
.disc-card {
  position: absolute; inset: 0; overflow: hidden auto; touch-action: pan-y;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .12); -webkit-user-select: none; user-select: none;
  transition: transform .18s ease-out, opacity .18s;
}
.disc-card.next { transform: scale(.96) translateY(8px); opacity: .7; pointer-events: none; }
.disc-card.dragging { transition: none; cursor: grabbing; }
.disc-card.fly-right { transform: translateX(120%) rotate(14deg) !important; opacity: 0; }
.disc-card.fly-left { transform: translateX(-120%) rotate(-14deg) !important; opacity: 0; }
.disc-img { display: block; width: 100%; aspect-ratio: 4 / 3; max-height: 36vh; object-fit: cover; background: var(--accent-soft); pointer-events: none; }
.disc-body { padding: 12px 16px 16px; }
.disc-body h2 { margin: 0 0 4px; font-size: 1.2rem; text-wrap: balance; }
.disc-ings { margin: 8px 0 10px; padding-left: 1.1em; }
.disc-ings li { margin: 3px 0; }
.stamp {
  position: absolute; top: 18px; padding: 4px 12px; border: 3px solid; border-radius: 8px;
  font-weight: 800; font-size: 1.2rem; text-transform: uppercase; letter-spacing: .04em;
  opacity: 0; pointer-events: none; background: var(--card);
}
.stamp.keep { left: 16px; color: var(--accent); transform: rotate(-12deg); }
.stamp.pass { right: 16px; color: var(--danger); transform: rotate(12deg); }
.disc-btns { display: flex; justify-content: center; align-items: center; gap: 22px; margin: 14px 0 6px; }
.disc-btn {
  width: 62px; height: 62px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  font-size: 1.7rem; cursor: pointer; box-shadow: 0 2px 8px rgb(0 0 0 / .1);
}
.disc-btn.pass { color: var(--danger); }
.disc-btn.keep { color: var(--accent); }
.disc-btn.undo { width: 46px; height: 46px; font-size: 1.2rem; color: var(--muted); }
.disc-btn:disabled { opacity: .35; cursor: default; }
.disc-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.center { text-align: center; }
@media (prefers-reduced-motion: reduce) { .disc-card { transition: none; } }

/* Photo d'une fiche */
.fabs {
  position: fixed; right: 16px; z-index: 4; display: flex; gap: 10px; align-items: center;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}
.fabs .fab { position: static; }
.fab.ghost-fab { background: var(--card); color: var(--text); border: 1px solid var(--line); padding: 14px 16px; }
.scan-thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.scan-thumbs figure { margin: 0; width: 96px; }
.scan-thumbs img { width: 96px; height: 128px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.scan-thumbs figcaption { font-size: .8rem; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.scan-photos { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.scan-photos img { height: 220px; border-radius: 8px; border: 1px solid var(--line); display: block; }

/* Semaine */
.week-banner { font-weight: 500; }
.cards li.plan { position: relative; margin: 8px 0; border-radius: var(--radius); background: var(--accent); touch-action: pan-y; overflow: hidden; }
.cards li.plan::before { content: "＋ Semaine"; position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: #fff; font-weight: 700; }
.cards li.plan > .card { position: relative; margin: 0; }
.card .planned { font-size: 1rem; }
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.week-nav a.icon { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--accent); font-size: 1.8rem; min-width: 44px; height: 44px; }
.week-title { display: flex; flex-direction: column; align-items: center; text-align: center; }
.chip.scale { border: 1px solid var(--line); background: var(--card); color: var(--accent); font-weight: 700; cursor: pointer; min-width: 44px; }
a.btn { text-decoration: none; }
