/* Carnet de recettes — « étiquette de bocal »: vert bouteille, craie, une touche de tomate.
   La source de chaque recette est l'élément marquant (.source-tag). */
:root {
  --bg: #f6f7f3; --surface: #fff; --text: #1b1f1d; --muted: #5c655f;
  --accent: #1f4d3f; --accent-text: #f6f7f3; --accent-soft: #dde7dd; --accent-hover: #17392f;
  --mark: #d2452b; --border: #dfe3dc; --danger: #b5361f;
  --radius: 12px; --radius-sm: 8px; --radius-tag: 4px;
  --font-title: "Young Serif", Georgia, "Times New Roman", serif;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131916; --surface: #1c2420; --text: #e9eeea; --muted: #a2aea6;
    --accent: #8fd1ae; --accent-text: #10201a; --accent-soft: #263129; --accent-hover: #a9e0c4;
    --mark: #f0765e; --border: #2f3a34; --danger: #f2877f;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--font-body);
}
h1, h2, h3 { font-family: var(--font-title); font-weight: 400; line-height: 1.2; }
a { color: var(--accent); }
.topbar {
  display: flex; align-items: center; gap: 1.75rem; padding: .7rem 1.5rem;
  background: var(--accent); color: var(--accent-text);
}
.topbar[hidden] { display: none; }
.brand { font-family: var(--font-title); font-size: 1.25rem; color: var(--accent-text); text-decoration: none; }
#nav { display: flex; gap: 1.1rem; flex: 1; }
#nav a { color: var(--accent-text); opacity: .75; text-decoration: none; padding: .15rem 0; border-bottom: 2px solid transparent; }
#nav a:hover { opacity: 1; }
#nav a[aria-current="page"] { opacity: 1; border-bottom-color: var(--mark); }
.session { display: flex; align-items: center; gap: .75rem; color: var(--accent-text); opacity: .85; font-size: .9rem; }
.topbar button.link { color: var(--accent-text); }
.session select { width: auto; padding: .3rem .5rem; color: var(--text); background: var(--surface); }
.inline-form label.inline { margin-left: 0; white-space: nowrap; }
.session select[hidden] { display: none; }
main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }
h1 { margin: 0 0 1rem; font-size: 2rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
}
.auth { max-width: 420px; margin: 8vh auto 0; }
label { display: block; font-weight: 600; margin-bottom: .35rem; }
input[type="email"], input[type="text"], input[type="url"], input[type="number"], input:not([type]) {
  width: 100%; padding: .6rem .75rem; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
input:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }
button.primary:not(.button) {
  margin-top: 1rem; width: 100%; padding: .65rem 1rem; font: inherit; font-weight: 600;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: var(--radius-sm); cursor: pointer;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.primary:not(.button):disabled { opacity: .6; cursor: wait; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }
.notice { margin-top: 1rem; padding: .75rem 1rem; border-radius: var(--radius-sm); background: var(--accent-soft); border: 1px solid transparent; }
.notice.error { color: var(--danger); background: var(--surface); border-color: var(--danger); }
.muted { color: var(--muted); }

/* --- Administration ------------------------------------------------------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tabs { display: flex; gap: 1.25rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.tabs a { padding: .5rem 0; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--mark); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table th, .table td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .85rem; color: var(--muted); font-weight: 600; background: var(--accent-soft); }
.table input:not([type="checkbox"]), .table select, .ordered input, .inline-form input, .toolbar input, select {
  width: 100%; padding: .4rem .6rem; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
}
.table .actions { white-space: nowrap; }
.table .actions > * + * { margin-left: .75rem; }
button.link.danger { color: var(--danger); }
button.link:disabled { color: var(--muted); cursor: default; text-decoration: none; opacity: .5; }
button.primary.compact { width: auto; margin: 0; padding: .45rem 1rem; }
.inline-form { display: flex; gap: .75rem; margin-top: 1rem; max-width: 520px; }
.toolbar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.toolbar input { max-width: 360px; }
.ingredients td:nth-child(1) { min-width: 180px; } .ingredients td:nth-child(2) { min-width: 240px; }
.ingredients td:nth-child(5) { width: 110px; }
.list-section { margin-bottom: 1.5rem; }
.list-section h2 { margin: 0 0 .25rem; font-size: 1.15rem; }
.ordered { list-style: none; padding: 0; margin: 1rem 0 0; }
.ordered li { display: flex; align-items: center; gap: .75rem; padding: .35rem 0; }
.ordered li input { max-width: 320px; }

/* --- Recettes ------------------------------------------------------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.page-head h1, .page-head h2 { margin: 0; }
.page-head .actions { display: flex; gap: .5rem; }
a.button, button.button {
  display: inline-block; padding: .5rem 1rem; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
a.button:hover, button.button:hover:not(:disabled) { border-color: var(--accent); }
a.button.primary, button.button.primary { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
a.button.primary:hover, button.button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.button.danger { color: var(--danger); }
button.button:disabled { opacity: .5; cursor: not-allowed; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.filters[hidden] { display: none; }
.filters .search { flex: 1 1 260px; max-width: 420px; padding: .5rem .75rem; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.filters select { width: auto; min-width: 180px; padding: .45rem .6rem; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.25rem; }
.recipe-card { display: flex; flex-direction: column; padding: 0; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.recipe-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.recipe-media { position: relative; margin-bottom: 1rem; }
.recipe-media .recipe-photo { border-radius: var(--radius) var(--radius) 0 0; }
.recipe-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.placeholder { display: grid; place-items: center; font-family: var(--font-title); font-size: 4rem; background: var(--accent-soft); color: var(--accent); }
.recipe-card-body { padding: .35rem 1.1rem 1.1rem; }
.recipe-card-body h2 { margin: 0 0 .55rem; font-size: 1.2rem; }
.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .5rem; }
.badge { padding: .1rem .6rem; font-size: .8rem; font-weight: 500; border-radius: 999px; color: var(--accent); background: var(--accent-soft); }

/* Étiquette de source: la raison d'être de l'app, collée comme sur un bocal. */
.source-tag {
  display: inline-block; max-width: 100%; padding: .3rem .7rem .3rem 1.7rem; position: relative;
  font-size: .85rem; font-weight: 600; line-height: 1.3; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-tag);
  box-shadow: 0 1px 2px rgb(0 0 0 / .08); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}
.source-tag::before {
  content: ""; position: absolute; left: .5rem; top: 50%; width: .5rem; height: .5rem; margin-top: -.25rem;
  border-radius: 50%; background: var(--bg); border: 2px solid var(--mark);
}
a.source-tag:hover { border-color: var(--accent); text-decoration: underline; }
.recipe-media .source-tag { position: absolute; left: .8rem; bottom: -.9rem; max-width: calc(100% - 1.6rem); transform: rotate(-1.2deg); }
.empty { text-align: center; padding: 3rem 1.5rem; border-style: dashed; }
.empty h2, .empty-title { margin: 0 0 .5rem; font-size: 1.3rem; }
.recipe-layout { display: grid; grid-template-columns: minmax(280px, 2fr) 3fr; gap: 2.5rem; align-items: start; }
.recipe-hero { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); margin-bottom: 1rem; }
.recipe-hero.placeholder { font-size: 6rem; }
.recipe-main h1 { margin-bottom: .5rem; }
.source { margin: .5rem 0 1.25rem; }
.ingredient-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.ingredient-list li { display: grid; grid-template-columns: 7rem 1fr; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.amount { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.recipe-main h2, .recipe-steps h2 { font-size: 1.35rem; }
/* Ingrédients toujours visibles à côté des étapes, pendant qu'on cuisine. */
@media (min-width: 821px) { .recipe-main { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; } }
.steps { padding: 0; margin: 0; list-style: none; counter-reset: step; max-width: 60ch; }
.steps li { counter-increment: step; position: relative; padding-left: 2.6rem; margin-bottom: 1.2rem; }
.steps li::before { content: counter(step); position: absolute; left: 0; top: -.1rem; font: 1.5rem/1.2 var(--font-title); color: var(--mark); }

/* --- Formulaire de recette ------------------------------------------------ */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.field.wide { grid-column: 1 / -1; }
.field { margin-bottom: .75rem; }
#recipe-form input[type="text"], #recipe-form input[type="number"], #recipe-form select, #recipe-form textarea,
.line input, .line select {
  width: 100%; padding: .5rem .65rem; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
fieldset { margin: 0 0 1.25rem; padding: 1rem 1.25rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
legend { padding: 0 .5rem; font-family: var(--font-title); font-size: 1.2rem; font-weight: 400; }
.line { display: grid; grid-template-columns: 6rem 9rem 1fr 1fr auto; gap: .5rem; margin-bottom: .5rem; }
.step { display: grid; grid-template-columns: 1fr auto; gap: .5rem; margin-bottom: .5rem; align-items: start; }
.photo-preview { display: block; max-width: 240px; border-radius: 8px; margin-bottom: .75rem; }
label.inline { display: inline-flex; gap: .4rem; align-items: center; margin-left: 1rem; font-weight: 400; }
.form-actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; gap: .75rem;
  margin: 1.5rem -1.5rem 0; padding: .85rem 1.5rem; background: var(--surface); border-top: 1px solid var(--border);
}
.dirty-flag { margin-left: auto; font-size: .9rem; color: var(--mark); font-weight: 600; }
.dirty-flag[hidden] { display: none; }
#errors ul { margin: 0; padding-left: 1.2rem; }
#draft-banner button { margin-left: .75rem; }

/* --- Rattachement, brouillons, demandes ------------------------------------ */
.status.ok { color: #2a6b45; } .status.warn { color: #b26a00; } .status.bad { color: var(--danger); }
@media (prefers-color-scheme: dark) { .status.ok { color: #7bd88f; } .status.warn { color: #f0b255; } }
.line-block { margin-bottom: .6rem; }
.line-block .line { margin-bottom: .2rem; }
.line-status { min-height: 1.1rem; font-size: .85rem; padding-left: .25rem; }
.create-panel { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .4rem 0 .6rem; padding: .6rem; background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; }
.create-panel[hidden] { display: none; }
.create-panel input:not([type="checkbox"]), .create-panel select { width: auto; min-width: 170px; padding: .4rem .6rem; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.quick { margin-bottom: 1rem; padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.quick summary { cursor: pointer; font-weight: 600; }
.quick textarea { width: 100%; margin: .6rem 0; padding: .5rem .65rem; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.notice.warn { border-color: #b26a00; }
.notice ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.count { margin-left: .35rem; padding: 0 .45rem; font-size: .75rem; font-weight: 700; color: #fff; background: var(--mark); border-radius: 999px; }
.count[hidden] { display: none; }
.draft { margin-bottom: 1rem; }
.draft h2 { margin: 0; font-size: 1.1rem; }
.panel-row td { background: var(--bg); }
.merge-panel { margin-top: .4rem; white-space: normal; }
.merge-panel input { width: auto; min-width: 160px; }

.servings { display: flex; align-items: center; gap: .5rem; margin: .5rem 0; }
.servings input { width: 4.5rem; }
.servings input[aria-invalid="true"] { border-color: var(--danger, #b3261e); }

.basket-list { list-style: none; padding: 0; display: grid; gap: .5rem; }
.basket-item { display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; border: 1px solid var(--border, #ddd); border-radius: 8px; }
.basket-item > a { flex: 1; }
.basket-item input { width: 4.5rem; }
#basket-dialog input { width: 5rem; }

.shopping-items { list-style: none; padding: 0; margin: 0 0 1rem; }
.shopping-items li { display: flex; align-items: center; gap: .75rem; padding: .35rem 0; border-bottom: 1px solid var(--border, #ddd); }
.shopping-items .item-name { flex: 1; }
.shopping-items .amount { color: var(--muted); font-weight: 600; }
.free-form input, .free-form select { width: auto; margin-right: .5rem; }
.removed, .recipe-shopping { margin: 1rem 0; }

.export-actions { display: inline-flex; gap: .5rem; flex-wrap: wrap; }

.shopping-items + .shopping-items { margin-top: 1rem; }
.aisle h2 { margin: 1.5rem 0 .4rem; padding-bottom: .3rem; font-size: 1.2rem; border-bottom: 2px solid var(--accent-soft); }

@media (prefers-reduced-motion: reduce) { .recipe-card { transition: none; } .recipe-card:hover { transform: none; } }
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; gap: .75rem 1.25rem; }
  .recipe-layout { grid-template-columns: 1fr; gap: 1.5rem; }
  .line { grid-template-columns: 1fr 1fr; }
}

/* Notifications */
#toasts { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 20; display: grid; gap: .5rem; max-width: min(28rem, calc(100vw - 2.5rem)); }
.toast { padding: .7rem 1rem; color: var(--accent-text); background: var(--accent); border-radius: var(--radius-sm); box-shadow: 0 6px 18px rgb(0 0 0 / .22); animation: toast-in .2s ease-out; }
.toast a { color: inherit; font-weight: 700; }
@keyframes toast-in { from { opacity: 0; transform: translateY(.5rem); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* Illustration des états vides */
.illustration { display: block; margin: 0 auto 1rem; }
.illustration .jar { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.5; }
.illustration .jar-lid { fill: var(--accent); }
.illustration .jar-label { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
.illustration .jar-hole { fill: none; stroke: var(--mark); stroke-width: 2; }
.illustration .jar-line { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; opacity: .55; }
