:root {
  --bg: #f7f1e8;
  --surface: #fffdf9;
  --surface-2: #f0e8dc;
  --text: #2b231c;
  --muted: #7a6d60;
  --line: #e6dccd;
  --accent: #c0532f;
  --accent-soft: #f6e0d6;
  --accent-text: #ffffff;
  --done: #a99c8e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .07);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1814;
    --surface: #26201b;
    --surface-2: #322a23;
    --text: #f3ebe1;
    --muted: #b0a394;
    --line: #3a3129;
    --accent: #e57a52;
    --accent-soft: #452a1f;
    --accent-text: #1c1814;
    --done: #74685c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
img { display: block; }

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border-radius: 14px; border: 1px solid transparent;
  font-weight: 600; text-decoration: none;
  transition: transform .1s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn.danger { background: none; color: var(--accent); border-color: var(--line); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%; border: 0;
  background: var(--surface); color: var(--text);
  font-size: 20px; line-height: 1;
  box-shadow: var(--shadow);
}

/* ---------- Liste ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(18px + env(safe-area-inset-top)) 16px 6px;
}
.top h1 { font: 700 34px/1.1 var(--serif); margin: 0; letter-spacing: -.01em; }
.top .count { color: var(--muted); font-size: 15px; margin: 2px 0 0; }

.search { padding: 10px 16px 4px; }
.search input {
  width: 100%; height: 48px; padding: 0 16px 0 44px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%237a6d60' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='9' cy='9' r='6'/%3E%3Cpath d='m14 14 4 4'/%3E%3C/svg%3E") no-repeat 14px center;
  outline: none;
}
.search input:focus { border-color: var(--accent); }

.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.grid {
  list-style: none; margin: 0; padding: 12px 16px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px;
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.card:active { transform: scale(.97); }
.card .ph { aspect-ratio: 4 / 3; }
.card .body { padding: 10px 12px 12px; }
.card h3 {
  margin: 0; font: 600 16px/1.25 var(--sans);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.ph {
  width: 100%; object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--muted); font: 600 34px var(--serif);
}

.empty { text-align: center; padding: 60px 28px; color: var(--muted); }
.empty .big { font-size: 56px; margin-bottom: 8px; }
.empty h2 { color: var(--text); font: 600 22px var(--serif); margin: 0 0 8px; }
.empty p { margin: 0; }

.fab {
  position: fixed; z-index: 5;
  left: 50%; transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 26px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 17px;
  box-shadow: 0 8px 24px rgba(192, 83, 47, .35);
}
.fab:active { transform: translateX(-50%) scale(.96); }

/* ---------- Fiche recette ---------- */
.hero { position: relative; }
.hero .ph { aspect-ratio: 4 / 3; max-height: 46vh; font-size: 64px; }
.hero.no-img .ph { aspect-ratio: auto; height: calc(110px + env(safe-area-inset-top)); font-size: 0; }
.hero-bar {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 0;
}
.recipe {
  position: relative; margin-top: -22px;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 22px 16px 0;
}
.hero.no-img + .recipe { margin-top: -10px; }
.recipe .cat {
  margin: 0 0 4px; color: var(--accent);
  font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.recipe h1 { font: 700 30px/1.15 var(--serif); margin: 0; letter-spacing: -.01em; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(98px, 1fr)); gap: 8px;
  margin: 18px 0 0;
}
.fact {
  background: var(--surface); border-radius: 16px; padding: 10px 12px;
  box-shadow: var(--shadow);
}
.fact .label { display: block; color: var(--muted); font-size: 13px; font-weight: 500; }
.fact .value { display: block; font-size: 17px; font-weight: 700; margin-top: 2px; line-height: 1.25; }
.fact.servings { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 22px; font-weight: 600; line-height: 1;
}
.stepper output { min-width: 44px; text-align: center; font-size: 22px; font-weight: 700; }
.scaled-note { color: var(--accent); font-size: 13px; font-weight: 600; }

.quick { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 0; }
.quick .btn { min-height: 42px; font-size: 15px; padding: 0 14px; }
.quick .btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: 30px 0 10px;
}
.section-title h2 { font: 700 22px var(--serif); margin: 0; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 6px 0; }

.ingredients { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.ingredients li + li { border-top: 1px solid var(--line); }
.ingredients label { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; cursor: pointer; }
.ingredients input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 24px; height: 24px; margin: 1px 0 0;
  border: 2px solid var(--line); border-radius: 8px; background: var(--bg);
  display: grid; place-items: center;
}
.ingredients input:checked { background: var(--accent); border-color: var(--accent); }
.ingredients input:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-text); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.ingredients input:checked + span { color: var(--done); text-decoration: line-through; }
.ingredients b { font-weight: 700; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps li {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); cursor: pointer;
  transition: opacity .2s ease;
}
.steps .num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 15px;
}
.steps p { margin: 3px 0 0; }
.steps li.done { opacity: .5; }
.steps li.done .num { background: var(--accent); color: var(--accent-text); }

.notes { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); white-space: pre-wrap; margin: 0; }
.danger-zone { margin: 36px 0 0; }

/* ---------- Formulaire ---------- */
.form-top {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.form-top h1 { font: 700 18px var(--serif); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.form-top .btn { min-height: 40px; padding: 0 14px; }
.form { padding: 16px; display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: 13px; font-weight: 400; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 48px; padding: 11px 14px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  outline: none; font-size: 17px;
}
.field textarea { min-height: 140px; resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 14px; background: var(--surface-2); }

/* ---------- Fenêtres ---------- */
.sheet-dialog {
  width: 100%; max-width: 560px; margin: auto auto 0;
  border: 0; padding: 0; border-radius: 24px 24px 0 0;
  background: var(--bg); color: var(--text);
}
@media (min-width: 600px) { .sheet-dialog { margin: auto; border-radius: 24px; } }
.sheet-dialog::backdrop { background: rgba(20, 12, 6, .45); }
.dialog-body { padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { font: 700 22px var(--serif); margin: 0; }
.dialog-head .icon-btn { box-shadow: none; background: var(--surface-2); width: 36px; height: 36px; font-size: 15px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.status { margin: 0; min-height: 1.4em; font-size: 15px; color: var(--muted); }
.status.error { color: var(--accent); }
.hint { margin: 0; color: var(--muted); font-size: 15px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 600;
  box-shadow: var(--shadow); white-space: nowrap;
  animation: toast 2.4s ease forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: .01s !important; }
}

/* ---------- Assistant ---------- */
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-left { display: flex; align-items: center; gap: 12px; }
.btn.pill { min-height: 44px; border-radius: 999px; padding: 0 14px; font-size: 15px; box-shadow: var(--shadow); border: 0; }
.icon-btn.plain { box-shadow: none; background: none; font-size: 22px; cursor: pointer; }
.muted { color: var(--muted); padding: 8px 0; }

.chat-intro { padding: 4px 16px 8px; display: grid; gap: 12px; }
.chat-intro p { margin: 0; color: var(--muted); }
.chat-list { list-style: none; margin: 0; padding: 8px 16px; display: grid; gap: 10px; }
.chat-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px 14px; border-radius: 16px; background: var(--surface);
  box-shadow: var(--shadow); color: inherit; text-decoration: none;
}
.chat-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-date { grid-row: 1; grid-column: 2; color: var(--muted); font-size: 13px; }
.chat-preview { grid-column: 1 / -1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-view { min-height: 100dvh; display: flex; flex-direction: column; margin-bottom: calc(-110px - env(safe-area-inset-bottom)); }
.chat-top {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.chat-top .icon-btn { width: 40px; height: 40px; box-shadow: none; background: var(--surface-2); font-size: 18px; }
.chat-head { flex: 1; min-width: 0; }
.chat-head h1 { margin: 0; font: 700 18px var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-recipe { font-size: 13px; text-decoration: none; }

.messages { flex: 1; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.model { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.model .bubble { background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble h4 { margin: 10px 0 4px; font: 700 16px var(--serif); }
.bubble code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.bubble.error { color: var(--accent); }
.msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.msg-imgs img { width: 140px; height: 140px; object-fit: cover; border-radius: 14px; }
.msg .link-btn { padding: 6px 4px 0; }
.recipe-offer {
  margin-top: 8px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--accent);
  background: var(--accent-soft); display: grid; gap: 8px;
}
.recipe-offer span { font-weight: 600; }
.recipe-offer .btn { min-height: 40px; font-size: 15px; }
.tips { display: flex; flex-wrap: wrap; gap: 8px; margin: auto 0 0; }
.tips .chip { height: auto; min-height: 36px; padding: 6px 14px; text-align: left; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer {
  position: sticky; bottom: 0; z-index: 4;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 140px;
  padding: 11px 14px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 17px; line-height: 1.35;
}
.composer textarea:focus { border-color: var(--accent); }
.composer .send { background: var(--accent); color: var(--accent-text); box-shadow: none; font-size: 18px; }
.composer .send[disabled] { opacity: .5; }
#mic.listening { background: var(--accent-soft); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px transparent; transform: scale(1.06); } }
.pending { display: flex; gap: 8px; flex-wrap: wrap; }
.pending:not(:empty) { padding-bottom: 8px; }
.pending-img { position: relative; }
.pending-img img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; }
.pending-img button {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: var(--text); color: var(--bg); font-size: 12px; line-height: 1;
}

/* Deux boutons en bas de la liste */
.fab-bar {
  position: fixed; z-index: 5; left: 0; right: 0;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex; justify-content: center; gap: 10px; padding: 0 16px;
  pointer-events: none;
}
.fab-bar .fab { position: static; transform: none; pointer-events: auto; display: inline-flex; align-items: center; text-decoration: none; }
.fab-bar .fab:active { transform: scale(.96); }
.fab.secondary { background: var(--surface); color: var(--text); box-shadow: var(--shadow), 0 8px 24px rgba(60, 40, 20, .12); }
