:root {
  --bg: #faf7f2; --card: #ffffff; --ink: #1f1c18; --muted: #6f685e; --line: #ebe4d8;
  --brand: #d9480f; --brand-hover: #b93c0b; --brand-soft: #fdece2; --brand-ink: #fff;
  --ok: #2b8a3e; --ok-soft: #e6f4ea; --warn: #8a5a00; --warn-soft: #fff3d1; --danger: #c92a2a;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171513; --card: #211e1b; --ink: #f1ece4; --muted: #a89f93; --line: #353029;
    --brand: #ff7a3d; --brand-hover: #ff915e; --brand-soft: #3a2519; --brand-ink: #1b0d05;
    --ok: #69c584; --ok-soft: #1d3324; --warn: #f3c768; --warn-soft: #3a2f14; --danger: #ff7b7b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font); }
a { color: inherit; }
img { max-width: 100%; display: block; }
[x-cloak] { display: none !important; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 480px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 1000; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; gap: 6px; height: 56px; }
.logo { font-weight: 800; font-size: 1.25rem; text-decoration: none; letter-spacing: -.02em; margin-right: auto; display: flex; align-items: center; gap: 6px; }
.logo b { color: var(--brand); }
.nav-link { display: inline-flex; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 10px; text-decoration: none; color: var(--muted); font-size: .95rem; white-space: nowrap; }
.nav-link:hover { background: var(--brand-soft); color: var(--ink); }
.nav-link svg { width: 20px; height: 20px; }
@media (max-width: 640px) {
  .nav-link .label { display: none; }
  .nav-link { padding: 8px 7px; }
  .topbar .wrap { gap: 2px; }
}
/* 小屏手机：上传按钮只显示相机图标，避免顶栏溢出 */
@media (max-width: 420px) {
  .topbar .upload-btn .label-long { display: none; }
  .topbar .upload-btn { width: 38px; height: 38px; padding: 0; border-radius: 50%; margin-left: 4px; }
  .logo { font-size: 1.1rem; }
}

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 9px 16px; border-radius: 999px; font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--brand-soft); border-color: transparent; }
.btn-sm { padding: 5px 12px; font-size: .85rem; }
.btn-lg { padding: 13px 24px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { width: 34px; height: 34px; padding: 0; border-radius: 50%; }

label.field { display: block; }
label.field > span { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea.input { resize: vertical; min-height: 70px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }
.error { color: var(--danger); font-size: .875rem; }
.flash { padding: 10px 14px; border-radius: 10px; background: var(--ok-soft); color: var(--ok); margin: 16px 0; }
.alert { padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }

/* ---------- home ---------- */
.hero { padding: 40px 0 24px; text-align: center; }
.hero h1 { font-size: clamp(1.7rem, 5vw, 2.6rem); letter-spacing: -.02em; }
.hero p { color: var(--muted); margin: 0 auto 20px; max-width: 560px; }
.searchbox { display: flex; gap: 8px; max-width: 620px; margin: 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 6px 6px 18px; box-shadow: var(--shadow); }
.searchbox input { flex: 1; border: 0; background: transparent; font: inherit; color: var(--ink); min-width: 0; outline: none; }
.hero-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
/* 手机上横向滑动，不占多行 */
@media (max-width: 640px) {
  .hscroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .hscroll::-webkit-scrollbar { display: none; }
  .hscroll > * { flex: none; }
}
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); text-decoration: none; font-size: .9rem; cursor: pointer; color: var(--ink); font-family: inherit; }
.chip:hover, .chip.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.section { margin: 32px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }

.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.how .card { padding: 16px; }
.how .num { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 800; display: grid; place-items: center; margin-bottom: 8px; }
@media (max-width: 640px) { .how { grid-template-columns: 1fr; } }

/* ---------- restaurant cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.rcard { display: block; text-decoration: none; overflow: hidden; transition: transform .15s; }
.rcard:hover { transform: translateY(-2px); }
.rcard .thumb { aspect-ratio: 16/10; background: var(--brand-soft) center/cover no-repeat; display: grid; place-items: center; font-size: 2rem; }
.rcard .body { padding: 12px 14px; }
.rcard .name { font-weight: 700; }
.rcard .meta { color: var(--muted); font-size: .85rem; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- restaurant page ---------- */
.rhead { display: grid; grid-template-columns: 1fr 320px; gap: 20px; margin: 24px 0; }
@media (max-width: 800px) { .rhead { grid-template-columns: 1fr; } }
.rhead h1 { margin-bottom: 4px; }
.facts { display: grid; gap: 6px; margin: 14px 0; font-size: .95rem; }
.facts div { display: flex; gap: 8px; }
.facts svg { width: 18px; height: 18px; flex: none; margin-top: 3px; color: var(--muted); }
.minimap { height: 200px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); z-index: 0; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.menu-tools { position: sticky; top: 56px; z-index: 50; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--line); }
.menu-tools .input { padding: 8px 12px; border-radius: 999px; }
.secnav { display: flex; gap: 4px; overflow-x: auto; margin-top: 8px; scrollbar-width: none; }
.secnav::-webkit-scrollbar { display: none; }
.secnav a { white-space: nowrap; font-size: .85rem; padding: 4px 10px; border-radius: 999px; text-decoration: none; color: var(--muted); }
.secnav a:hover { background: var(--brand-soft); color: var(--brand); }
.freshness { margin: 14px 0; font-size: .9rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.msection { margin: 18px 0 8px; scroll-margin-top: 200px; }
.msection h3 { font-size: 1.1rem; padding-bottom: 6px; border-bottom: 2px solid var(--ink); display: inline-block; }
.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.item .info { flex: 1; min-width: 0; }
.item .iname { font-weight: 600; }
.item .idesc { color: var(--muted); font-size: .9rem; }
.crop-btn { border: 0; background: none; cursor: pointer; font-size: .85rem; padding: 0 4px; opacity: .55; vertical-align: 1px; }
.crop-btn:hover, .crop-btn.on { opacity: 1; }
.dish-crop { display: block; margin-top: 6px; }
.dish-crop svg { display: block; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.ocr-note { margin: 4px 0 0; }
.item .price { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .item .price { white-space: normal; max-width: 34%; text-align: right; overflow-wrap: anywhere; } }
.tag { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; margin-left: 4px; vertical-align: 2px; white-space: nowrap; }
.tag-signature { background: #fff0c2; color: #8a5a00; }
.tag-spicy { background: #ffe0e0; color: #c92a2a; }
.tag-vegetarian { background: #e3f6e8; color: #2b8a3e; }
.tag-new { background: #e3edff; color: #1c5fd6; }
@media (prefers-color-scheme: dark) {
  .tag-signature { background: #3d3112; color: #f3c768; } .tag-spicy { background: #3d1a1a; color: #ff8f8f; }
  .tag-vegetarian { background: #173020; color: #7ad596; } .tag-new { background: #182a4a; color: #8db4ff; }
}
.qty { display: flex; align-items: center; gap: 4px; flex: none; }
.qty .btn { width: 30px; height: 30px; padding: 0; border-radius: 50%; font-size: 1.1rem; }
.qty .n { min-width: 18px; text-align: center; font-weight: 700; }
.originals { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 16px 0; }
.originals img { border-radius: 10px; border: 1px solid var(--line); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* calculator */
.calcbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.calcbar .btn { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.has-calcbar { padding-bottom: 80px; }

/* modal / sheet */
.overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px; }
@media (min-width: 600px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.order-list { list-style: none; padding: 0; margin: 0; }
.order-list li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 1.1rem; }
.order-big li { font-size: 1.5rem; font-weight: 700; }
.totals { margin-top: 12px; display: grid; gap: 4px; }
.totals div { display: flex; justify-content: space-between; }
.totals .grand { font-size: 1.25rem; font-weight: 800; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: 12px; }
.qr img, .qr svg { width: 220px; height: 220px; image-rendering: pixelated; }

/* ---------- upload wizard ---------- */
.steps { display: flex; gap: 6px; margin: 20px 0; }
.steps div { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps div.on { background: var(--brand); }
.dropzone { display: grid; place-items: center; text-align: center; gap: 8px; padding: 36px 16px; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer; }
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dropzone svg { width: 40px; height: 40px; color: var(--brand); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs .t { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--card); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.thumbs .x { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; line-height: 1; }
.thumbs .rot { position: absolute; bottom: 2px; right: 2px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; font-size: 16px; line-height: 1; }
.thumbs img.busy { opacity: .4; }
.thumbs .t { width: 96px; height: 96px; }
.thumbs img { object-fit: contain; background: #fff; }
.progress { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; }
.progress div { height: 100%; background: var(--brand); transition: width .3s; }
.pick { display: block; width: 100%; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font: inherit; cursor: pointer; }
.pick:hover, .pick.on { border-color: var(--brand); background: var(--brand-soft); }
.picker-map { height: 240px; border-radius: 12px; border: 1px solid var(--line); z-index: 0; }
.results { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.results button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: .9rem; cursor: pointer; }
.results button:last-child { border-bottom: 0; }
.results button:hover { background: var(--brand-soft); }

/* editor */
.editor-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.editor-wrap .ref { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
@media (max-width: 900px) { .editor-wrap { grid-template-columns: 1fr; } .editor-wrap .ref { position: static; max-height: none; } }
.esec { padding: 12px; margin-bottom: 12px; }
.esec-head { display: flex; gap: 6px; align-items: center; }
.esec-head .input { font-weight: 700; }
.eitem { display: grid; grid-template-columns: 1fr 110px auto; gap: 6px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.eitem .full { grid-column: 1 / -1; }
.eitem .crop { display: block; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.eitem .input { padding: 7px 10px; font-size: 16px; } /* ≥16px：iOS 聚焦时不自动放大 */
.eitem .ctrl { display: flex; gap: 2px; }
.eitem .tagpick { display: flex; gap: 4px; flex-wrap: wrap; grid-column: 1 / -1; }
.tagpick label { font-size: .75rem; display: inline-flex; gap: 3px; align-items: center; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.tagpick input { margin: 0; }
@media (max-width: 560px) { .eitem { grid-template-columns: 1fr 90px; } .eitem .ctrl { grid-column: 1 / -1; justify-content: flex-end; } }

/* tables (admin / my) */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-wrap { overflow-x: auto; }

/* map page */
.map-full { position: fixed; top: 57px; left: 0; right: 0; bottom: 0; z-index: 0; }
.map-float { position: fixed; z-index: 500; right: 12px; bottom: 24px; display: flex; flex-direction: column; gap: 8px; }
.leaflet-popup-content { font: 14px/1.4 var(--font); }
.leaflet-popup-content a.btn { color: var(--brand-ink); margin-top: 6px; }
.pager { display: flex; gap: 8px; justify-content: center; margin: 20px 0; }

footer.site { border-top: 1px solid var(--line); margin-top: 48px; padding: 24px 0 40px; color: var(--muted); font-size: .875rem; }
footer.site .wrap { display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between; }

@media print {
  .topbar, footer.site, .menu-tools, .qty, .calcbar, .noprint, .minimap { display: none !important; }
  body { background: #fff; color: #000; }
  .item { break-inside: avoid; }
}

/* ---------- phone tweaks ---------- */
@media (max-width: 560px) {
  .grid-2.keep-2 { grid-template-columns: 1fr 1fr; }
  .hide-phone { display: none !important; }
  .hero { padding: 28px 0 8px; }
  .section { margin: 22px 0; }
  .rhead { margin: 16px 0; gap: 12px; }
  .minimap { height: 150px; }
  /* 列表卡片改为横排：缩略图在左，一屏能看到更多餐厅 */
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .rcard { display: flex; align-items: stretch; }
  .rcard:hover { transform: none; }
  .rcard .thumb { width: 96px; min-height: 96px; aspect-ratio: auto; flex: none; font-size: 1.6rem; }
  .rcard .body { padding: 10px 12px; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
  .rcard .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
