/* Manger à la maison — crème & terracotta, mobile d'abord */
:root {
  --cream: #FAF6EF;
  --paper: #FFFDF9;
  --sand: #EFE6D8;
  --line: #E3D7C5;
  --ink: #3A2E28;
  --muted: #7A6A5E;
  --terra: #B8562F;
  --terra-dark: #964322;
  --terra-soft: #F6E4DA;
  --green: #4F7A4A;
  --green-soft: #E6F0E1;
  --amber: #8A5A00;
  --amber-soft: #FBEFD3;
  --red: #A3322A;
  --red-soft: #F8E1DE;
  --blue: #3F5E7A;
  --blue-soft: #E3ECF3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(58, 46, 40, .06), 0 2px 8px rgba(58, 46, 40, .05);
  --tabbar-h: 64px;
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
[hidden] { display: none !important; }
a { color: var(--terra-dark); }
h1, h2 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
small { font-size: .85em; color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); margin: 0 0 1rem; }
:focus-visible { outline: 3px solid var(--terra); outline-offset: 2px; border-radius: 6px; }

/* ─── Barre du haut ──────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .25rem;
  min-height: 52px; padding: 0 1rem; padding-top: env(safe-area-inset-top);
  background: rgba(250, 246, 239, .92);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-weight: 600; color: var(--terra-dark); font-size: 1.05rem; }
.back {
  display: grid; place-items: center; width: 44px; height: 44px; margin-left: -.75rem;
  color: var(--ink); border-radius: 50%;
}
.back svg { width: 24px; height: 24px; }
.back:hover { background: var(--sand); }

main { max-width: 720px; margin: 0 auto; padding: 1.25rem 1rem; }

/* ─── Barre d'onglets ────────────────────────────────────────────────── */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 500;
}
.tabbar svg { width: 26px; height: 26px; }
.tabbar a[aria-current="page"] { color: var(--terra); font-weight: 700; }

/* ─── Messages ───────────────────────────────────────────────────────── */
.flash {
  max-width: 720px; margin: .75rem auto 0; padding: .75rem 1rem;
  border-radius: var(--radius); font-weight: 500;
  width: calc(100% - 2rem);
  animation: fade 4s ease forwards;
}
.flash-ok { background: var(--green-soft); color: var(--green); }
.flash-err { background: var(--red-soft); color: var(--red); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: .55; } }

.callout {
  border-radius: var(--radius); padding: .9rem 1rem; margin: 0 0 1.25rem;
  background: var(--sand);
}
.callout h2 { font-family: var(--sans); font-size: 1rem; margin: 0 0 .35rem; }
.callout ul { margin: 0; padding-left: 1.1rem; }
.callout p { margin: 0 0 .75rem; }
.callout p:last-child { margin: 0; }
.callout-fodmap-modere { background: var(--amber-soft); }
.callout-fodmap-eleve { background: var(--red-soft); }
.callout-gluten { background: var(--blue-soft); }
.callout-todo { background: var(--terra-soft); }
.callout-err { background: var(--red-soft); color: var(--red); }
.callout-err:focus { outline: none; }

/* ─── Boutons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 48px; padding: 0 1.2rem;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--paper); color: var(--ink);
  font: 600 1rem var(--sans); text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--terra); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--terra); border-color: var(--terra); color: #fff; }
.btn-primary:hover { background: var(--terra-dark); border-color: var(--terra-dark); }
.btn-small { min-height: 40px; padding: 0 1rem; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-ghost { border-style: dashed; background: transparent; color: var(--terra-dark); width: 100%; }
.btn-danger { color: var(--red); border-color: var(--red-soft); background: transparent; }
.btn-danger:hover { border-color: var(--red); }
.link { background: none; border: 0; padding: .5rem; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; }

/* ─── En-têtes de page, sections ─────────────────────────────────────── */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.section-title {
  font-family: var(--sans); font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 1.5rem 0 .6rem;
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.5rem 0 .5rem; }
.section-head h2 { margin: 0; }
.count {
  display: inline-block; min-width: 1.5em; padding: 0 .45em; border-radius: 999px;
  background: var(--sand); color: var(--muted); font-size: .8rem; text-align: center; letter-spacing: 0;
}
.count-alert { background: var(--terra); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }

/* ─── Filtres ────────────────────────────────────────────────────────── */
.filters { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.search {
  display: flex; align-items: center; gap: .5rem;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 999px;
  padding: 0 1rem; min-height: 48px;
}
.search:focus-within { border-color: var(--terra); }
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.filters .search input[type=search] { border: 0; box-shadow: none; padding: 0; outline: 0; background: transparent; font: inherit; width: 100%; min-height: 44px; color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip, .chip-radio span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 1rem;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--paper);
  font: 500 .95rem var(--sans); color: var(--ink); cursor: pointer;
}
.chip[aria-pressed="true"], .chip-radio input:checked + span {
  background: var(--terra); border-color: var(--terra); color: #fff;
}
.chip[aria-pressed="true"]::before { content: '✓'; margin-right: .35rem; }
.chip-radio input { position: absolute; opacity: 0; pointer-events: none; }
.chip-radio input:focus-visible + span { outline: 3px solid var(--terra); outline-offset: 2px; }

.segmented { display: flex; background: var(--sand); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented > a, .segmented > label { flex: 1; }
.segmented > a, .segmented label span {
  display: flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; padding: 0 .5rem; border-radius: 9px;
  color: var(--muted); text-decoration: none; font-weight: 500; text-align: center; cursor: pointer; font-size: .95rem;
}
.segmented > a[aria-selected="true"], .segmented input:checked + span { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); font-weight: 700; }
.segmented > a[aria-disabled="true"] { pointer-events: none; opacity: .5; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:focus-visible + span { outline: 3px solid var(--terra); }

/* ─── Listes de cartes ───────────────────────────────────────────────── */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > a { display: flex; flex-direction: column; gap: .4rem; padding: .9rem 1rem; color: inherit; text-decoration: none; min-height: 56px; justify-content: center; }
.card > a:hover { background: #FFF8F0; border-radius: var(--radius); }
.recipe-name { font-weight: 700; font-size: 1.05rem; }
.list.compact .recipe-name { font-weight: 500; font-size: 1rem; }
.list.compact .card > a { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: .7rem 1rem; }
.meta { display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--muted); font-size: .85rem; }

/* ─── Pastilles ──────────────────────────────────────────────────────── */
.tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap;
}
.tag svg { width: 14px; height: 14px; }
.tag-ok { background: var(--green-soft); color: var(--green); }
.tag-warn { background: var(--blue-soft); color: var(--blue); }
.tag-fodmap-modere { background: var(--amber-soft); color: var(--amber); }
.tag-fodmap-eleve { background: var(--red-soft); color: var(--red); }
.tag-todo { background: var(--terra-soft); color: var(--terra-dark); }
.tag-meat { background: var(--sand); color: var(--ink); }
.tag-stock { background: var(--sand); color: var(--muted); }

/* ─── Fiche recette ──────────────────────────────────────────────────── */
.recipe-detail h1 { margin-bottom: .4rem; }
.recipe-detail > .tags { margin-bottom: 1rem; }
.ingredients { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.ingredients li { display: flex; gap: .75rem; padding: .65rem 1rem; border-top: 1px solid var(--line); align-items: baseline; }
.ingredients li:first-child { border-top: 0; }
.ingredients .qty { flex: 0 0 7.5rem; font-weight: 700; color: var(--terra-dark); font-variant-numeric: tabular-nums; }
.ingredients .ing { flex: 1; }
.ingredients .note, .callout .note { display: block; }
.ingredients li.stock { color: var(--muted); }
.ingredients li.stock .qty { color: var(--muted); }
.ingredients.optional { background: transparent; border-style: dashed; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 0 0 1rem 2.5rem; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: -.1rem;
  width: 1.8rem; height: 1.8rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--terra-soft); color: var(--terra-dark); font-weight: 700; font-size: .9rem;
}
.recipe-detail section + section { margin-top: .5rem; }
.recipe-detail section > h2 { margin-top: 1.5rem; }
.recipe-detail .callout h2 { margin-top: 0; }
.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 999px; background: var(--paper); }
.stepper button {
  width: 44px; height: 40px; border: 0; background: none; font-size: 1.3rem; color: var(--terra-dark); cursor: pointer; border-radius: 999px;
}
.stepper output { min-width: 4.5rem; text-align: center; font-weight: 600; font-size: .9rem; }
.stepper.modified { border-color: var(--terra); }
.actions { margin-top: 2rem; display: flex; gap: .75rem; }

/* ─── Formulaires ────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 1.1rem; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.field { display: flex; flex-direction: column; gap: .4rem; }
.field > span, legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: .4rem; }
.field-row { display: flex; gap: 1rem; }
.field-row .field { flex: 0 0 12rem; }
input:not([type=radio]):not([type=checkbox]), select, textarea {
  width: 100%; min-height: 48px; padding: .6rem .85rem;
  font: inherit; color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px;
  appearance: none; -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m7 10 5 5 5-5' fill='none' stroke='%237A6A5E' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .5rem center; background-size: 20px; padding-right: 2rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--terra); outline: none; box-shadow: 0 0 0 3px var(--terra-soft); }
input[aria-invalid="true"] { border-color: var(--red); }
input[readonly] { background: var(--sand); color: var(--muted); }
textarea { resize: vertical; line-height: 1.5; }
.error { color: var(--red); margin: -.5rem 0 0; font-weight: 500; }
.indent { margin-left: 1rem; padding-left: 1rem; border-left: 3px solid var(--sand); margin-top: -.4rem; }
.input-unit { display: flex; align-items: center; gap: .5rem; }
.input-unit input { max-width: 8rem; }
.form-actions { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + .5rem); z-index: 5; }
.form-actions .btn-primary { width: 100%; box-shadow: 0 4px 14px rgba(184, 86, 47, .3); }

.switch { display: flex; align-items: center; gap: .75rem; min-height: 48px; cursor: pointer; font-weight: 500; }
.switch input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 48px; height: 28px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .15s;
}
.switch input::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .15s;
}
.switch input:checked { background: var(--terra); }
.switch input:checked::after { transform: translateX(20px); }

/* Lignes d'ingrédients : nom en pleine largeur, puis quantité / unité / × */
.rows { display: grid; gap: .6rem; margin-bottom: .6rem; }
.row-ing {
  display: grid; gap: .4rem;
  grid-template-columns: 1fr 1.4fr 44px;
  grid-template-areas: "nom nom nom" "q u del" "note note note" "hint hint hint";
  padding: .6rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
.r-nom { grid-area: nom; }
.r-q { grid-area: q; }
.r-u { grid-area: u; }
.r-del { grid-area: del; width: 44px; height: 48px; border: 0; background: none; font-size: 1.5rem; color: var(--muted); cursor: pointer; border-radius: 10px; }
.r-del:hover { background: var(--red-soft); color: var(--red); }
.r-note { grid-area: note; }
.r-hint { grid-area: hint; color: var(--terra-dark); }
.r-hint-err { color: var(--red); font-weight: 600; }
@media (min-width: 600px) {
  .row-ing { grid-template-columns: 1fr 5.5rem 9rem 44px; grid-template-areas: "nom q u del" "note note note note" "hint hint hint hint"; }
}

.danger-zone { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.logout { text-align: center; margin-top: 2.5rem; }

/* ─── Connexion ──────────────────────────────────────────────────────── */
body.auth { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--paper); border: 1px solid var(--line); border-radius: 20px; padding: 2rem 1.5rem; box-shadow: var(--shadow); }
.auth-card h1 { color: var(--terra-dark); text-align: center; }
.auth-card .muted { text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 1rem; }

@media (min-width: 720px) {
  h1 { font-size: 2.1rem; }
  .filters { flex-direction: row; align-items: center; }
  .filters .search { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
