:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #22201c;
  --muted: #6b655c;
  --line: #e6e0d6;
  --accent: #c0392b;
  --accent-soft: #fbe9e6;
  --chip: #f1ece4;
  --warn: #9a6700;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #211f24;
    --text: #efeae2;
    --muted: #a39d93;
    --line: #35323a;
    --accent: #ff7b6b;
    --accent-soft: #3a2320;
    --chip: #2c2a31;
    --warn: #e2b33c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; font-size: 1.1rem; display: inline-flex; align-items: center; gap: 6px; }
.brand .logo { width: 22px; height: 22px; }
.top nav { display: flex; gap: 4px; }
.top nav a { padding: 6px 12px; border-radius: 999px; color: var(--muted); }
.top nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { display: flex; flex: 1 1 320px; gap: 8px; }
.search input { flex: 1; min-width: 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); }
.filters { display: flex; gap: 8px; }
select { padding: 9px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); }
button { padding: 9px 16px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
button.ghost { background: var(--chip); color: var(--text); font-weight: 500; }
button.danger { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button:disabled { opacity: .5; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--chip); color: var(--text); font-size: .92rem; border: 1px solid transparent; cursor: pointer; }
.chip .n { color: var(--muted); margin-left: 4px; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip.active .n { color: inherit; }

.muted { color: var(--muted); font-size: .92rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-top: 10px; }
.card { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform .12s; }
.card:hover { transform: translateY(-2px); }
.card .cover { aspect-ratio: 4 / 5; background: var(--chip); object-fit: cover; width: 100%; display: block; }
.card .cover.empty { display: grid; place-items: center; font-size: 2.5rem; color: var(--muted); }
.card .body { padding: 10px 12px 12px; display: grid; gap: 4px; }
.card h3 { margin: 0; font-size: 1rem; line-height: 1.3; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: .82rem; color: var(--muted); }
.badge { padding: 1px 8px; border-radius: 999px; background: var(--chip); }
.badge.cat { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.pager { display: flex; justify-content: center; gap: 8px; margin: 20px 0; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* recipe detail */
.recipe { display: grid; gap: 20px; }
.recipe .hero { display: grid; grid-template-columns: minmax(0, 320px) 1fr; gap: 20px; align-items: start; }
.recipe .hero img { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); aspect-ratio: 4/5; object-fit: cover; }
.recipe h1 { margin: 0 0 6px; font-size: 1.6rem; line-height: 1.2; }
.recipe .meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.recipe .desc { margin: 0 0 10px; }
.recipe .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.recipe .cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 24px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 10px; font-size: 1.1rem; }
.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; align-items: baseline; }
.ingredients li:last-child { border-bottom: 0; }
.ingredients .qty { min-width: 72px; font-variant-numeric: tabular-nums; font-weight: 600; }
.ingredients .qty.est { color: var(--warn); }
.ingredients .group { margin-top: 10px; font-style: italic; color: var(--muted); border: 0; }
.ingredients .note { color: var(--muted); font-size: .9rem; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 12px; }
.steps li::marker { font-weight: 700; color: var(--accent); }
.steps img { display: block; margin-top: 8px; max-width: 220px; border-radius: 8px; }
.legend { color: var(--warn); font-size: .85rem; margin-top: 8px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos img { height: 120px; border-radius: 8px; }
details.transcript { margin-top: 12px; }
details.transcript pre { white-space: pre-wrap; font: inherit; color: var(--muted); font-size: .9rem; }

/* imports */
.jobs { width: 100%; border-collapse: collapse; font-size: .92rem; }
.jobs th, .jobs td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.jobs td.url { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { padding: 2px 8px; border-radius: 999px; background: var(--chip); font-size: .82rem; white-space: nowrap; }
.status.done { background: #e3f4e6; color: #1b6e2a; }
.status.failed { background: var(--accent-soft); color: var(--accent); }
.status.running { background: #fff4d6; color: var(--warn); }
@media (prefers-color-scheme: dark) { .status.done { background: #1f3a26; color: #8fd49c; } .status.running { background: #3a3012; } }
.err { color: var(--accent); font-size: .85rem; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow); z-index: 3; }

@media (max-width: 720px) {
  .recipe .hero, .recipe .cols { grid-template-columns: 1fr; }
  .recipe .hero img { max-width: 100%; aspect-ratio: 4/3; }
  .jobs th:nth-child(3), .jobs td:nth-child(3) { display: none; }
}

/* upload */
input[type="file"] { flex: 1; min-width: 0; padding: 7px 10px; border: 1px dashed var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font-size: .9rem; }
progress { width: 100%; height: 8px; margin-top: 8px; accent-color: var(--accent); }

/* open categories */
.cat-edit { display: flex; gap: 6px; align-items: center; margin-left: 6px; }
.cat-edit input { padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .85rem; width: 240px; max-width: 50vw; }
button.small { padding: 5px 12px; font-size: .85rem; }

/* cards refactor */
.chips.sub { margin-top: 0; }
.chip.small { font-size: .85rem; padding: 4px 10px; }
.facts { border-collapse: collapse; width: 100%; font-size: .95rem; }
.facts th { text-align: left; color: var(--muted); font-weight: 500; padding: 5px 10px 5px 0; vertical-align: top; white-space: nowrap; }
.facts td { padding: 5px 0; }
.est { color: var(--warn); font-weight: 700; }
ul.plain, ul.pros, ul.cons { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
ul.pros li::marker { content: "+ "; color: #1b6e2a; }
ul.cons li::marker { content: "− "; color: var(--accent); }
a.link { color: var(--accent); font-weight: 600; }
.search select { padding: 9px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); }

/* token gate */
.gate { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 10; padding: 16px; }
.gate-box { width: min(420px, 100%); display: grid; gap: 10px; }
.gate-box input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }

/* schema-driven body + editor */
.stack { display: grid; gap: 20px; align-content: start; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stack > .panel.wide { grid-column: 1 / -1; }
.cols > .stack { grid-template-columns: 1fr; }
.facts tr.group th { padding-top: 12px; color: var(--text); font-weight: 600; }
.ingredients li .note { color: var(--muted); font-size: .9rem; }
.editor { display: grid; gap: 16px; }
.editor label { display: grid; gap: 4px; margin: 8px 0; font-size: .92rem; color: var(--muted); }
.editor label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 0; }
.editor input[type="text"], .editor input[type="number"], .editor textarea, .editor select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.editor input[type="checkbox"] { width: auto; }
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 500; padding: 4px; }
.edit-table td { padding: 3px; vertical-align: top; }
.edit-table td.row-tools { white-space: nowrap; }
.edit-table button.small { padding: 4px 8px; }
.editor .actions { display: flex; gap: 8px; }
@media (max-width: 720px) { .edit-table thead { display: none; } .edit-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 8px 0; border-bottom: 1px solid var(--line); } .edit-table td.row-tools { grid-column: 1 / -1; } }
