/* ─────────────────────────────────────────────────────────────
 * Cafe Audit · Editorial · v0.4
 * Single stylesheet for all pages: form, results, products.
 * Uses local fonts under /static/fonts/.
 * ─────────────────────────────────────────────────────────── */

:root {
  --bg: #faf7f0;
  --bg-2: #f3eee2;
  --paper: #ffffff;
  --ink: #1a1612;
  --ink-soft: #3b342a;
  --muted: #7a705f;
  --line: #d8d0bc;
  --line-strong: #1a1612;
  --accent: #b45309;
  --bad: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --serif-zh: "Noto Serif SC", "Songti SC", serif;
  --serif-en: "EB Garamond", Georgia, serif;
  --sans: "Inter Tight", -apple-system, "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #14110d;
  --bg-2: #1c1813;
  --paper: #1c1813;
  --ink: #f0e9d8;
  --ink-soft: #d6cdba;
  --muted: #8a8073;
  --line: #2e2820;
  --line-strong: #f0e9d8;
  --accent: #f59e0b;
  --bad: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14110d;
    --bg-2: #1c1813;
    --paper: #1c1813;
    --ink: #f0e9d8;
    --ink-soft: #d6cdba;
    --muted: #8a8073;
    --line: #2e2820;
    --line-strong: #f0e9d8;
    --accent: #f59e0b;
    --bad: #f87171;
    --warn: #fbbf24;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
html { transition: background .18s ease; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: color .18s ease, background .18s ease;
}
::selection { background: var(--ink); color: var(--bg); }

.wrap { width: min(1080px, calc(100% - 64px)); margin: 0 auto; }

/* ── Masthead ─────────────────────────────────────────────── */
.masthead { border-bottom: 1px solid var(--line-strong); }
.masthead .wrap {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 16px 0 14px; flex-wrap: wrap; gap: 12px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .mark { font-family: var(--serif-en); font-style: italic; font-size: 22px; font-weight: 600; color: var(--accent); }
.brand strong { font-family: var(--serif-zh); font-weight: 700; font-size: 16px; letter-spacing: 0.02em; color: var(--ink); text-decoration: none; }
.brand a { color: inherit; text-decoration: none; display: flex; align-items: baseline; gap: 10px; }
.brand small { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; margin-left: 4px; }

.nav { display: flex; gap: 24px; align-items: baseline; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding-bottom: 4px; border-bottom: 1px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a.active { color: var(--ink); border-bottom-color: var(--ink); }

/* ── Theme switcher ───────────────────────────────────────── */
.theme-switch { display: inline-flex; align-items: stretch; border: 1px solid var(--line); margin-left: 16px; }
.theme-switch button {
  background: transparent; border: 0; padding: 4px 10px;
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); cursor: pointer;
  border-right: 1px solid var(--line);
}
.theme-switch button:last-child { border-right: 0; }
.theme-switch button:hover { color: var(--ink); }
.theme-switch button.active { background: var(--ink); color: var(--bg); }

/* ── Header (form & results pages) ────────────────────────── */
header { padding: 64px 0 48px; border-bottom: 1px solid var(--line-strong); position: relative; }
.eyebrow { display: flex; align-items: center; gap: 14px; font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 15px; letter-spacing: 0.02em; margin: 0 0 18px; }
.eyebrow .rule { flex: 1; height: 1px; background: var(--line); }
.eyebrow .vol { font-family: var(--mono); font-style: normal; font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink); }

h1 { font-family: var(--serif-zh); font-weight: 700; font-size: 72px; line-height: 1.05; margin: 0; letter-spacing: -0.025em; white-space: nowrap; }
@media (max-width: 880px) { h1 { font-size: 56px; white-space: normal; } }
@media (max-width: 600px) { h1 { font-size: 44px; } }
h1 .accent { color: var(--accent); font-style: normal; }
.lede { font-family: var(--serif-en); font-style: italic; font-weight: 400; font-size: 24px; color: var(--ink-soft); margin: 18px 0 0; max-width: 50ch; line-height: 1.4; }

.meta { display: grid; grid-template-columns: repeat(3, max-content); gap: 56px; margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
.meta dt { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; margin: 0; }
.meta dd { margin: 6px 0 0; font-family: var(--serif-zh); font-weight: 500; font-size: 18px; color: var(--ink); font-feature-settings: "tnum"; }

/* sub page header (smaller, with crumb) */
header.sub { padding: 56px 0 40px; }
header.sub h1 { font-size: 56px; line-height: 1; }
.crumb { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; margin: 0 0 18px; }
.crumb a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
.crumb a:hover { color: var(--ink); }
.stat-row { display: grid; grid-template-columns: repeat(4, max-content); gap: 56px; margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--line); }
.stat-row dt { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; margin: 0; }
.stat-row dd { margin: 6px 0 0; font-family: var(--serif-zh); font-weight: 600; font-size: 22px; color: var(--ink); font-feature-settings: "tnum"; }
.stat-row dd.bad { color: var(--bad); }
.stat-row dd.ok { color: var(--ok); }

/* ── Catalog status bar (form page only) ──────────────────── */
.catalog-bar { border-bottom: 1px solid var(--line); }
.catalog-bar a { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 0; color: inherit; text-decoration: none; }
.catalog-bar:hover { background: var(--bg-2); }
.catalog-bar .left { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.catalog-bar .icon { font-family: var(--serif-en); font-style: italic; font-size: 20px; color: var(--accent); }
.catalog-bar .title { font-family: var(--serif-zh); font-weight: 600; font-size: 15px; }
.catalog-bar .stat { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.catalog-bar .stat b { color: var(--ink); font-weight: 500; }
.catalog-bar .arrow { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 16px; }

/* ── Section ──────────────────────────────────────────────── */
section { padding: 64px 0; border-bottom: 1px solid var(--line); position: relative; }
.sec-head { display: grid; grid-template-columns: 120px 1fr; gap: 32px; align-items: baseline; margin-bottom: 40px; }
.sec-num { font-family: var(--serif-en); font-style: italic; font-size: 56px; line-height: 1; color: var(--accent); margin: 0; }
.sec-num small { display: block; font-family: var(--mono); font-style: normal; font-size: 10px; letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; margin-top: 6px; }
.sec-title h2 { font-family: var(--serif-zh); font-weight: 700; font-size: 40px; margin: 0; letter-spacing: -0.015em; }
.sec-title h2.smaller { font-size: 36px; }
.sec-title .en { font-family: var(--serif-en); font-style: italic; font-weight: 400; color: var(--muted); font-size: 22px; display: block; margin-top: 4px; }
.sec-title p { color: var(--muted); font-size: 15px; max-width: 56ch; margin: 12px 0 0; }
.sec-body { padding-left: 152px; }

/* ── Form fields ─────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 56px; }
.field { margin-bottom: 28px; }
.field label { display: flex; align-items: baseline; gap: 10px; font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 10px; }
.field label .req { color: var(--accent); font-style: normal; }
/* All text-y inputs share the same baseline. font-size: 16px keeps iOS Safari
   from auto-zooming on focus (anything < 16 triggers the zoom). */
.field input, .field textarea {
  width: 100%; padding: 14px 0; border: 0; border-bottom: 1px solid var(--ink); background: transparent;
  font-family: var(--sans); font-size: 16px; color: var(--ink); border-radius: 0;
}
.field input[type="number"] { font-family: var(--mono); font-size: 20px; font-weight: 500; }
.field input[type="file"] { font-family: var(--mono); font-size: 13px; }
.field textarea {
  min-height: 140px; padding: 12px 0; resize: vertical;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
}
.field input:focus, .field textarea:focus { outline: none; border-bottom-color: var(--accent); border-bottom-width: 2px; padding-bottom: 13px; }
.field input[type="file"]::file-selector-button {
  padding: 6px 12px; margin-right: 12px; background: var(--ink); color: var(--bg); border: 0;
  font: inherit; font-size: 12px; font-family: var(--mono); cursor: pointer;
}
.field .help { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 14px; margin-top: 8px; line-height: 1.5; }

.submit-row { padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.submit-note { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 14px; max-width: 32ch; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 10px; padding: 14px 26px; background: var(--ink); color: var(--bg); border: 0; font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; text-decoration: none; transition: background .15s; }
.btn:hover { background: var(--accent); }
.btn .arrow { font-family: var(--serif-en); font-style: italic; font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 18px; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
.btn-ghost:hover { background: var(--ink); color: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 11px; }

/* ── Error banner ─────────────────────────────────────────── */
.error-banner {
  padding: 16px 20px; background: var(--paper); border: 1px solid var(--bad);
  border-left: 4px solid var(--bad); margin: 24px 0 0;
  font-family: var(--serif-en); font-style: italic; color: var(--bad); font-size: 15px;
}
.error-banner b { font-family: var(--mono); font-style: normal; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; margin-right: 8px; }

/* ── Results summary & table ──────────────────────────────── */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); margin: 0 0 32px; }
.metric { padding: 28px 24px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric .lbl { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }
.metric .num { font-family: var(--serif-zh); font-weight: 700; font-size: 56px; line-height: 1; margin-top: 14px; font-feature-settings: "tnum"; letter-spacing: -0.02em; }
.metric .delta { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 14px; margin-top: 8px; }
.metric.bad .num { color: var(--bad); }
.metric.ok .num { color: var(--ok); }
.metric.warn .num { color: var(--warn); }

.table-tools { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.table-tools h3 { font-family: var(--serif-zh); font-weight: 600; font-size: 22px; margin: 0; }
.table-tools .filters { display: flex; gap: 6px; align-items: center; font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; flex-wrap: wrap; }
.filter-pill { padding: 4px 10px; border: 1px solid var(--line); cursor: pointer; background: transparent; font: inherit; color: inherit; }
.filter-pill.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.filter-pill:hover:not(.active) { color: var(--ink); border-color: var(--ink); }
.filter-pill[disabled] { cursor: default; opacity: 0.4; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; padding: 12px 14px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); font-family: var(--mono); font-weight: 500; font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); background: var(--bg-2); }
tbody td { padding: 16px 14px; border-bottom: 1px solid var(--line); font-feature-settings: "tnum"; vertical-align: top; }
tbody td.mono { font-family: var(--mono); font-size: 12px; }
tbody tr.issue td:first-child { box-shadow: inset 3px 0 0 0 var(--bad); padding-left: 18px; }
tbody tr.warn-row td:first-child { box-shadow: inset 3px 0 0 0 var(--warn); padding-left: 18px; }
tbody tr.pass td:first-child { box-shadow: inset 3px 0 0 0 var(--ok); padding-left: 18px; }
tbody.hide-pass tr.is-pass { display: none; }

/* ── Coupon-rule cards (main page §02) ── */
.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.rule-card { border: 1px solid var(--line); padding: 18px 20px; background: var(--paper); }
.rule-card .rule-name { font-family: var(--serif-zh); font-weight: 700; font-size: 18px; margin-bottom: 8px; letter-spacing: -0.005em; }
.rule-card .rule-allowed { font-size: 14px; color: var(--ink-soft); margin-bottom: 6px; }
.rule-card .rule-extra { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

/* ── Catalog page §02 extras (collapsed by default) ── */
details.extras { border-top: 1px solid var(--line); padding-top: 24px; }
details.extras summary { cursor: pointer; padding: 12px 0; user-select: none; list-style: none; }
details.extras summary::-webkit-details-marker { display: none; }
details.extras summary::before { content: "▸"; color: var(--muted); display: inline-block; margin-right: 10px; transition: transform .15s; }
details.extras[open] summary::before { transform: rotate(90deg); }
details.extras .sec-body { padding-left: 28px; }
.extras-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.extras-card { padding: 16px; border: 1px solid var(--line); background: var(--paper); }
.extras-card h4 { font-family: var(--serif-zh); font-weight: 600; font-size: 15px; margin: 0 0 6px; }
.extras-card p { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 4px; }

.tag { display: inline-block; padding: 3px 10px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; border: 1px solid currentColor; }
.tag.bad { color: var(--bad); }
.tag.warn { color: var(--warn); }
.tag.ok { color: var(--ok); }

/* ── Products: OCR zone ───────────────────────────────────── */
.ocr-zone { border: 1px solid var(--ink); padding: 56px 32px; text-align: center; background: var(--paper); position: relative; }
.ocr-zone::before, .ocr-zone::after { content: ""; position: absolute; width: 14px; height: 14px; border: 1px solid var(--ink); }
.ocr-zone::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.ocr-zone::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }
.ocr-mark { font-family: var(--serif-en); font-style: italic; font-size: 28px; color: var(--accent); margin-bottom: 14px; }
.ocr-zone .pull { font-family: var(--serif-zh); font-weight: 600; font-size: 26px; margin: 0 0 6px; }
.ocr-zone .sub { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 16px; margin: 0 0 24px; }
.ocr-actions { display: inline-flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.ocr-aside { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); text-align: left; }
.ocr-aside .alt h4 { font-family: var(--serif-zh); font-weight: 600; font-size: 14px; margin: 0 0 6px; }
.ocr-aside .alt p { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 14px; margin: 0 0 10px; line-height: 1.5; }

.cat-tools { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 12px; }
.cat-tools h3 { font-family: var(--serif-zh); font-weight: 600; font-size: 22px; margin: 0; }
.cat-tools .filters { display: flex; gap: 6px; align-items: center; font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; flex-wrap: wrap; }

tbody tr.uncategorized td:first-child { box-shadow: inset 3px 0 0 0 var(--accent); padding-left: 18px; }
tbody tr.disallowed td:first-child { box-shadow: inset 3px 0 0 0 var(--bad); padding-left: 18px; }
.dish-name { font-family: var(--serif-zh); font-weight: 500; font-size: 15px; }
.dish-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; display: block; }

/* ── Catalog row: editable name + delete ── */
.dish-name-input {
  font-family: var(--serif-zh); font-weight: 500; font-size: 15px;
  border: 1px solid transparent; background: transparent; color: var(--ink);
  padding: 4px 8px; margin: -4px -8px 0; width: calc(100% + 16px);
  box-sizing: border-box; transition: border-color .12s, background .12s;
}
.dish-name-input:hover { border-color: var(--line); background: var(--paper); }
.dish-name-input:focus { outline: none; border-color: var(--accent); background: var(--paper); border-radius: 2px; }

.row-action { vertical-align: middle; text-align: right; }
.row-del {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em;
  padding: 4px 10px; background: transparent; color: var(--muted);
  border: 1px solid var(--line); cursor: pointer; min-width: 44px;
  transition: color .12s, border-color .12s, background .12s;
}
.row-del:hover { color: var(--bad); border-color: var(--bad); }

tbody tr.to-delete { opacity: 0.45; }
tbody tr.to-delete .dish-name-input { text-decoration: line-through; pointer-events: none; }
tbody tr.to-delete select { pointer-events: none; }
tbody tr.to-delete .row-del { color: var(--accent); border-color: var(--accent); background: var(--bg-2); }
tbody tr.to-delete .dish-meta::after { content: " · 待删除"; color: var(--bad); font-weight: 600; }

select { padding: 8px 12px; border: 1px solid var(--ink); background: var(--bg); color: var(--ink); font: inherit; font-size: 13px; min-width: 180px; cursor: pointer; }
select:focus { outline: none; border-color: var(--accent); border-width: 2px; padding: 7px 11px; }
select option { font-family: var(--sans); }

.save-bar { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--ink); padding: 16px 0; margin-top: 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.save-bar .note { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 14px; }
.save-bar .note b { font-family: var(--mono); font-style: normal; color: var(--ink); font-size: 12px; padding: 2px 8px; background: var(--bg-2); margin-right: 4px; }

/* ── Footer ───────────────────────────────────────────────── */
.colophon { padding: 48px 0 80px; display: grid; grid-template-columns: 120px 1fr auto; gap: 32px; align-items: baseline; }
.colophon .ornament { font-family: var(--serif-en); font-size: 32px; color: var(--accent); text-align: center; }
.colophon .text { font-family: var(--serif-en); font-style: italic; color: var(--muted); font-size: 15px; max-width: 60ch; }
.colophon .credit { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }

@media (max-width: 820px) {
  h1 { font-size: 48px; }
  header.sub h1 { font-size: 36px; }
  .sec-head { grid-template-columns: 1fr; gap: 12px; }
  .sec-body { padding-left: 0; }
  .sec-num { font-size: 36px; }
  .two-col, .summary { grid-template-columns: 1fr 1fr; }
  .meta, .stat-row { grid-template-columns: 1fr 1fr; gap: 16px; }
  .nav { gap: 14px; }
  .ocr-aside { grid-template-columns: 1fr; }
  .colophon { grid-template-columns: 1fr; }
}
