:root {
  --bg: #f6f1e7;
  --surface: #fffaf0;
  --surface-2: #f0e8d8;
  --ink: #23291f;
  --muted: #5d6656;
  --accent: #a4502d;
  --accent-ink: #fffaf0;
  --sage: #2f3b2f;
  --sage-ink: #f3ead8;
  --line: #e2d8c4;
  --good: #3f6b3a;
  --bad: #a3322a;
  --warn-bg: #fbecd9;
  --focus: #c66a3f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(35, 41, 31, .06), 0 4px 16px rgba(35, 41, 31, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b16; --surface: #1f251e; --surface-2: #283026; --ink: #ede5d4; --muted: #a9b19f;
    --accent: #d9825a; --accent-ink: #171b16; --sage: #0f130e; --sage-ink: #ede5d4; --line: #343c32;
    --good: #8fc286; --bad: #f08a80; --warn-bg: #3a2c1f; --focus: #e89a72;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.55 Inter, system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 500; line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: clamp(28px, 4vw, 38px); letter-spacing: -.01em; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 0 0 1em; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 760px) { .wrap { padding: 0 28px; } }

/* --- top bar --- */
.topbar { background: var(--sage); color: var(--sage-ink); }
.topbar .wrap { display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
.brand { font-family: Fraunces, Georgia, serif; font-style: italic; font-size: 20px; color: var(--sage-ink); text-decoration: none; margin-right: auto; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a, .nav button {
  color: var(--sage-ink); text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: 15px;
  background: none; border: 0; font: inherit; cursor: pointer;
}
.nav a:hover, .nav button:hover { background: rgba(255, 255, 255, .08); }
.nav a.active { background: rgba(255, 255, 255, .14); }
.nav .badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 4px; }

main { padding: 28px 0 64px; }

/* --- messages --- */
.messages { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; }
.messages li { padding: 10px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.messages .success { border-color: var(--good); }
.messages .error { border-color: var(--bad); background: var(--warn-bg); }

/* --- layout helpers --- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.grid { display: grid; gap: 20px; }
@media (min-width: 900px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.side { grid-template-columns: 2fr 1fr; align-items: start; }
}
.stack > * + * { margin-top: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }

/* --- buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  padding: 9px 16px; border-radius: 999px; font: 500 15px/1.2 Inter, system-ui, sans-serif;
  text-decoration: none; cursor: pointer; min-height: 40px;
}
.btn:hover { filter: brightness(1.07); }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--surface-2); filter: none; }
.btn.danger { background: transparent; color: var(--bad); border-color: currentColor; }
.btn.small { padding: 5px 12px; min-height: 32px; font-size: 14px; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
.linkish.danger { color: var(--bad); }
form.inline { display: inline; }

/* --- forms --- */
label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=email], input[type=url], input[type=number], input[type=date], input[type=search],
input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg);
  color: var(--ink); font: inherit; min-height: 40px;
}
textarea { resize: vertical; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); vertical-align: -3px; }
.field { margin-bottom: 14px; }
.field.check label { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.field .help { font-size: 13px; color: var(--muted); margin-top: 4px; }
.field .errors { color: var(--bad); font-size: 14px; margin: 4px 0 0; padding: 0; list-style: none; }
.form-errors { color: var(--bad); }
.fields { display: grid; gap: 0 16px; }
@media (min-width: 640px) { .fields.cols-2 { grid-template-columns: 1fr 1fr; } .fields.cols-3 { grid-template-columns: repeat(3, 1fr); } }
.checks ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checks ul label { font-weight: 400; display: flex; gap: 8px; align-items: center; }

/* --- lists and tables --- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; padding-top: 0; }
.list-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.tile-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.tile { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: inherit; text-decoration: none; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile .ph { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-family: Fraunces, Georgia, serif; font-style: italic; }
.tile .ph img { width: 100%; height: 100%; object-fit: cover; }
.tile .body { padding: 12px 14px 14px; }
.tile h3 { margin: 0 0 4px; font-size: 17px; }
.chip { display: inline-block; font-size: 12.5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink); margin: 2px 4px 2px 0; }
.chip.love { background: #dfe9d6; color: #2d4a28; }
.chip.like { background: #e9eedf; color: #3d4a2e; }
.chip.avoid { background: #f6e3cf; color: #7a4416; }
.chip.allergy { background: #f6d6d2; color: #8a2119; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .chip.love { background: #2c3d27; color: #cfe6c6; }
  .chip.like { background: #323a29; color: #d8e2c8; }
  .chip.avoid { background: #45331f; color: #f3d2ae; }
  .chip.allergy { background: #4d2320; color: #ffc9c2; }
}
.status { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.status.sent { border-color: var(--accent); color: var(--accent); }
.status.approved { border-color: var(--good); color: var(--good); }

table.plain { width: 100%; border-collapse: collapse; }
table.plain th, table.plain td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
table.plain th { font-size: 13px; color: var(--muted); font-weight: 500; border-top: 0; }

/* --- recipe --- */
.recipe-hero { display: grid; gap: 20px; margin-bottom: 24px; }
@media (min-width: 820px) { .recipe-hero.has-photo { grid-template-columns: 1.1fr 1fr; align-items: start; } }
.recipe-hero img { border-radius: var(--radius); aspect-ratio: 4 / 3; object-fit: cover; width: 100%; }
.facts { display: flex; gap: 8px 22px; flex-wrap: wrap; color: var(--muted); font-size: 15px; margin: 8px 0 14px; }
.facts strong { color: var(--ink); font-weight: 600; }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li { padding: 7px 0; border-top: 1px dashed var(--line); }
.ingredients li:first-child { border-top: 0; }
.ingredients .amt { font-weight: 600; }
.steps { padding-left: 1.4em; margin: 0; }
.steps li { margin-bottom: 12px; padding-left: 4px; }
.scaler { display: flex; align-items: center; gap: 8px; }
.scaler input { width: 80px; }

.ing-table { width: 100%; border-collapse: collapse; }
.ing-table td { padding: 4px 3px; vertical-align: top; }
.ing-table th { font-size: 12.5px; color: var(--muted); font-weight: 500; text-align: left; padding: 0 3px 4px; }
.ing-table input, .ing-table select { min-height: 36px; padding: 6px 8px; }
.ing-table .c-amt { width: 80px; } .ing-table .c-unit { width: 90px; } .ing-table .c-sec { width: 150px; } .ing-table .c-x { width: 36px; }
@media (max-width: 720px) {
  .ing-table thead { display: none; }
  .ing-table tr { display: grid; grid-template-columns: 80px 1fr 36px; gap: 4px; padding: 8px 0; border-top: 1px solid var(--line); }
  .ing-table td { padding: 0; }
  .ing-table .c-amt, .ing-table .c-unit, .ing-table .c-sec { width: auto; }
  .ing-table td.c-name { grid-column: 2 / 3; grid-row: 1; }
  .ing-table td.c-x { grid-column: 3; grid-row: 1; }
  .ing-table td.c-unit { grid-column: 1; grid-row: 2; }
  .ing-table td.c-note { grid-column: 2 / 4; grid-row: 2; }
  .ing-table td.c-sec { grid-column: 1 / 4; grid-row: 3; }
}
.step-row { display: grid; grid-template-columns: 28px 1fr 36px; gap: 8px; align-items: start; margin-bottom: 8px; }
.step-row .n { font-family: Fraunces, Georgia, serif; font-size: 18px; color: var(--muted); padding-top: 8px; text-align: right; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; }
.icon-btn:hover { color: var(--bad); border-color: var(--bad); }

/* --- tabs (recipe importer) --- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; font: 500 15px Inter, system-ui, sans-serif; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--accent); }
.busy { display: none; align-items: center; gap: 10px; color: var(--muted); margin-top: 12px; }
form.is-busy .busy { display: flex; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* --- menu planner --- */
.dish { display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.dish:first-of-type { border-top: 0; }
.dish .thumb { width: 72px; height: 54px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.dish .meta { font-size: 13.5px; color: var(--muted); }
.dish .actions { display: flex; gap: 4px; }
.day-label { font-family: Fraunces, Georgia, serif; font-size: 17px; margin: 18px 0 2px; color: var(--accent); }
.day-label:first-child { margin-top: 0; }
.share-box { display: flex; gap: 8px; }
.share-box input { font-size: 14px; }

/* --- shopping --- */
.shop-section h3 { font-size: 15px; font-family: Inter, system-ui, sans-serif; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 6px; }
.shop-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.shop-item label { flex: 1; display: flex; gap: 12px; align-items: flex-start; font-weight: 400; font-size: 16px; margin: 0; cursor: pointer; }
.shop-item input[type=checkbox] { width: 22px; height: 22px; margin-top: 1px; flex: none; }
.shop-item .name { font-weight: 500; }
.shop-item .used { display: block; font-size: 13px; color: var(--muted); }
.shop-item.done .name, .shop-item.done .amount { text-decoration: line-through; color: var(--muted); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.progress span { display: block; height: 100%; background: var(--good); }

/* --- photos --- */
.photo-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.photo-grid a { display: block; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); color: inherit; text-decoration: none; }
.photo-grid img { aspect-ratio: 1; object-fit: cover; width: 100%; }
.photo-grid .cap { padding: 6px 9px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-pick { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
.photo-pick img { aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.photo-pick button { padding: 0; border: 2px solid transparent; border-radius: 10px; background: none; cursor: pointer; }
.photo-pick button.current { border-color: var(--accent); }

/* --- welcome --- */
.welcome { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--sage); color: var(--sage-ink); text-align: center; }
.welcome h1 { font-size: clamp(36px, 7vw, 60px); font-weight: 400; }
.welcome h1 em { color: #e09a72; }
.welcome p { color: #d9d2c0; max-width: 30em; margin: 0 auto 28px; }

/* --- tag badges (recipe editor) --- */
.tag-box { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; min-height: 40px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--bg); cursor: text; }
.tag-box:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.tag-box .tag { display: inline-flex; align-items: center; gap: 2px; padding: 3px 4px 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; line-height: 1.2; }
.tag-box .tag button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1;
  width: 22px; height: 22px; border-radius: 50%; padding: 0; }
.tag-box .tag button:hover { color: var(--bad); background: var(--surface); }
.tag-box input { border: 0; outline: 0; background: transparent; width: auto; flex: 1 1 140px; min-width: 120px; min-height: 28px; padding: 2px 4px; }
.tag-box input:focus-visible { outline: 0; }

details.more summary { cursor: pointer; color: var(--accent); }
.danger-zone { border-color: var(--bad); }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .btn { margin-top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- categories and meals --- */
.chip.cat { background: transparent; border: 1px solid var(--accent); color: var(--accent); text-decoration: none; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 18px; }
.filter-chips a { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: 14px; background: var(--surface); }
.filter-chips a:hover { border-color: var(--accent); }
.filter-chips a[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.checks ul:has(.check-row) { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.meal-dishes { list-style: none; padding: 0; margin: 4px 0 0; }
.meal-dishes li { padding: 1px 0; }
.meal-dish { display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: start; padding: 12px 0; border-top: 1px solid var(--line); }
.meal-dish:first-of-type { border-top: 0; padding-top: 0; }
.meal-dish .thumb { width: 72px; height: 54px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.meal-dish .meta { margin: 2px 0; }
.meal-dish .actions { display: flex; gap: 4px; }
.meal-dish select { max-width: 260px; }
@media (max-width: 560px) { .meal-dish { grid-template-columns: 1fr auto; } .meal-dish .thumb { display: none; } }
.add-dish { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.add-dish h3 { margin-bottom: 8px; }
.add-dish select { max-width: 340px; }
