/* Cocotte — mobile d'abord. Vert sauge, moutarde pour ce qui demande l'attention. */
:root {
  --bg: #F4F6EF;
  --surface: #FBFCF8;
  --surface-2: #E3EBDD;
  --ink: #1E2B23;
  --ink-2: #46574B;
  --muted: #5E6F62;
  --line: #DDE4D7;
  --line-strong: #CBD6C4;
  --accent: #2F6B3F;
  --on-accent: #F4F6EF;
  --tag-ink: #2F5A3A;
  --warn-bg: #F2D98C;
  --warn-ink: #1E2B23;
  --dark-card: #1E2B23;
  --dark-card-ink: #F4F6EF;
  --dark-card-muted: #C9D6CB;
  --highlight: #F2D98C;
  --danger: #A33A2B;
  --shadow: 0 1px 3px rgba(30, 43, 35, .16);
  --font-display: 'Rubik', 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'Nunito Sans', 'Segoe UI', Roboto, Arial, sans-serif;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141B16;
    --surface: #1D2620;
    --surface-2: #26332A;
    --ink: #EEF2EA;
    --ink-2: #C3CFC5;
    --muted: #9DB1A2;
    --line: #2C3A30;
    --line-strong: #3A4B3F;
    --accent: #7FBF8C;
    --on-accent: #10180F;
    --tag-ink: #BFE0C6;
    --warn-bg: #D9B654;
    --warn-ink: #1A1A10;
    --dark-card: #26332A;
    --dark-card-ink: #F4F6EF;
    --dark-card-muted: #C3CFC5;
    --highlight: #E7C766;
    --danger: #F08A7A;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--font-body);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) max(16px, env(safe-area-inset-right, 0px)) calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + 24px) max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
main.no-tabs { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); }

h1 { margin: 0; font: 700 28px/1.15 var(--font-display); text-wrap: balance; }
h2 { margin: 0; font: 600 20px/1.2 var(--font-display); }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
.label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 0; }

.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* Boutons */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 16px var(--font-display); text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:disabled { opacity: .5; }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line-strong); }
.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid currentColor; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--accent); font-weight: 700; text-decoration: underline; min-height: 44px; padding: 0 4px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 12px; border: 1.5px solid var(--line-strong);
  background: var(--bg); display: inline-flex; align-items: center; justify-content: center; color: var(--accent);
}
.icon-btn.round { border-radius: 50%; background: var(--accent); color: var(--on-accent); border: 0; width: 48px; height: 48px; }
.icon-btn.plain { border: 0; background: transparent; color: var(--ink); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Champs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.input, select.input, textarea.input {
  min-height: 46px; border: 1.5px solid var(--line-strong); border-radius: 12px; background: var(--surface);
  padding: 0 12px; width: 100%; font-size: 16px;
}
textarea.input { padding: 10px 12px; min-height: 96px; resize: vertical; }
.search { display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 1.5px solid var(--line-strong); border-radius: 14px; background: var(--surface); min-height: 48px; color: var(--muted); }
.search input { border: 0; outline: none; background: transparent; flex: 1; min-width: 0; font-size: 16px; color: var(--ink); }

/* Puces */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 700;
  background: var(--surface); color: var(--ink); border: 1.5px solid var(--line-strong);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.tag { font-size: 12px; font-weight: 700; color: var(--tag-ink); background: var(--surface-2); padding: 3px 8px; border-radius: 999px; }
.pill-warn { font-size: 12px; font-weight: 700; color: var(--warn-ink); background: var(--warn-bg); padding: 4px 10px; border-radius: 999px; }

/* Segments */
.segments { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 14px; }
.segments button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); font-weight: 700; font-size: 14px; }
.segments button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* Cartes recette */
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 10px;
}
.card a.card-main { display: flex; gap: 12px; align-items: center; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.thumb {
  width: 76px; height: 76px; flex: none; border-radius: 12px; object-fit: cover; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.card-title { margin: 0; font: 600 16px/1.25 var(--font-display); }
.card .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.empty strong { color: var(--ink); font: 600 18px var(--font-display); }

/* Éditeur de recette */
.photo {
  position: relative; height: 180px; border-radius: 18px; overflow: hidden; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo .btn { position: absolute; right: 10px; bottom: 10px; min-height: 36px; font-size: 14px; padding: 0 12px; background: rgba(20, 30, 24, .62); color: #F4F6EF; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.ing { display: grid; grid-template-columns: 64px 76px minmax(0, 1fr) 44px; gap: 6px; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.ing .input { min-height: 40px; padding: 0 8px; font-size: 15px; }
.ing select.input { grid-column: 1 / 4; font-size: 14px; color: var(--muted); }
.ing .icon-btn { grid-row: 1 / 3; grid-column: 4; border: 0; background: transparent; color: var(--muted); }

/* Planning */
.week-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; }
.counter { display: flex; align-items: center; gap: 14px; background: var(--dark-card); color: var(--dark-card-ink); border-radius: 16px; padding: 12px 16px; }
.counter b { font: 700 32px/1 var(--font-display); color: var(--highlight); font-variant-numeric: tabular-nums; }
.counter span { color: var(--dark-card-muted); font-size: 14px; }
.grid-week { display: grid; grid-template-columns: 52px repeat(2, minmax(0, 1fr)); gap: 8px; align-items: stretch; }
.grid-week .day { display: flex; flex-direction: column; justify-content: center; font-size: 13px; font-weight: 700; }
.grid-week .day small { font-weight: 400; color: var(--muted); font-size: 12px; }
.grid-week .day.today { color: var(--accent); }
.slot {
  min-height: 58px; border-radius: 12px; padding: 6px 10px; text-align: left; font-size: 13px; line-height: 1.25;
  display: flex; align-items: center; gap: 8px; overflow: hidden;
}
.slot.recipe { background: var(--surface); border: 1.5px solid var(--line-strong); font-weight: 700; }
.slot.other { background: var(--surface-2); border: 1.5px solid var(--surface-2); color: var(--ink-2); font-style: italic; font-weight: 600; }
.slot.free { background: transparent; border: 1.5px dashed var(--line-strong); color: var(--muted); font-weight: 600; }
.slot img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex: none; }
.slot .portions { display: block; font-weight: 400; font-style: normal; color: var(--muted); font-size: 12px; }

/* Courses */
.group { display: flex; flex-direction: column; gap: 6px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 12px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item button.check { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; background: none; border: 0; padding: 0; text-align: left; min-height: 44px; }
.box { width: 24px; height: 24px; flex: none; border-radius: 7px; border: 2px solid var(--muted); display: flex; align-items: center; justify-content: center; }
.box svg { width: 14px; height: 14px; stroke-width: 3.5; stroke: var(--on-accent); }
.item.have .box { background: var(--accent); border-color: var(--accent); }
.item .name { font-weight: 700; font-size: 15px; display: block; }
.item .why { font-size: 12px; color: var(--muted); display: block; }
.item .qty { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; }
.item.have .name, .item.have .qty { color: var(--muted); text-decoration: line-through; }
.item .icon-btn { border: 0; background: transparent; color: var(--muted); width: 36px; }

/* Barre d'onglets */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
}
#tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 84px; min-height: 52px; justify-content: center; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; }
#tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; }
#tabs svg { width: 24px; height: 24px; }

/* Barre d'action collée en bas, au-dessus des onglets */
.sticky-action {
  position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + 8px);
  display: flex; flex-direction: column; gap: 6px; padding: 8px 0;
  background: var(--bg);
  box-shadow: 0 -10px 12px -6px var(--bg);
}
main.no-tabs .sticky-action { bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); }

/* Feuille du bas */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 12, .45); z-index: 40; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88dvh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: 0 -4px 24px rgba(0, 0, 0, .25);
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 16px) max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 14px; max-width: 640px; margin: 0 auto;
  animation: up .18s ease-out;
}
#sheet::before { content: ""; width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); align-self: center; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
.pick-list { display: flex; flex-direction: column; gap: 8px; max-height: 42dvh; overflow-y: auto; }
.pick {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 10px; border-radius: 12px;
  background: var(--surface); border: 1.5px solid var(--line); text-align: left; width: 100%;
}
.pick[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.pick img, .pick .thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper output { font: 700 20px var(--font-display); min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px);
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + 16px);
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow);
}
#toast.error { background: var(--danger); color: #FFF; }

.login { min-height: 80dvh; justify-content: center; max-width: 420px; }
.logo { font: 700 40px var(--font-display); color: var(--accent); margin: 0; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
