:root {
  --bg: #f6f1e8;
  --card: #fffdf9;
  --ink: #2b2622;
  --muted: #8a7f74;
  --accent: #d9553f;
  --accent-ink: #fff;
  --line: #e8ded2;
  --shadow: 0 10px 30px rgba(80, 50, 20, .08);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --card: #211b16;
    --ink: #f4ede3;
    --muted: #b3a597;
    --line: #33291f;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 50% -200px, rgba(217, 85, 63, .10), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 3px solid rgba(217, 85, 63, .35);
  outline-offset: 2px;
}
a { color: inherit; }
h1, h2, h3, p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 20px;
}
.brand h1 { font-size: 17px; letter-spacing: .5px; }
.brand p { margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 14px; color: var(--muted); max-width: 7em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 14px 16px calc(120px + var(--safe-bottom));
}
main.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.content { min-width: 0; }

/* 左侧分类栏（桌面端类似门店电子菜单） */
.sidebar {
  position: sticky;
  top: 76px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sidebar-head { margin-bottom: 10px; }
.sidebar-head h2 { font-size: 15px; letter-spacing: .5px; }
.sidebar .chips {
  flex-direction: column;
  gap: 6px;
  overflow: visible;
  padding: 10px 0 0;
}
.sidebar .chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  text-align: left;
}
.sidebar .chip .count { margin-left: auto; }
.sidebar-actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.sidebar-actions .primary, .sidebar-actions .ghost { width: 100%; }

/* 今晚菜单：支持换行铺开，不隐藏超出的菜 */
.tonight {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-head h2 { font-size: 16px; }
.tonight-list { display: flex; flex-wrap: wrap; gap: 10px; padding-bottom: 4px; }
.tonight-item { flex: 0 0 82px; text-align: center; }
.tonight-item img, .tonight-item .no-image {
  width: 82px; height: 102px; border-radius: 12px; object-fit: cover; display: block;
}
.tonight-item .name {
  margin-top: 6px; font-size: 12px; line-height: 1.25;
  overflow-wrap: anywhere; word-break: break-word;
}

/* 随机入口 */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-radius: 22px;
  background: linear-gradient(135deg, #fff7ee, #f1e1cd);
  border: 1px solid #ead9c5;
  margin-bottom: 14px;
}
@media (prefers-color-scheme: dark) {
  .hero { background: linear-gradient(135deg, #2a211a, #201a15); border-color: var(--line); }
}
.hero h2 { font-size: 19px; margin-bottom: 4px; }

/* 搜索与分类 */
.toolbar { margin-bottom: 14px; }
.search-wrap { display: flex; gap: 8px; margin-bottom: 12px; }
#search {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}
#sort {
  flex: 0 0 auto;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 13px;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 4px; }
.chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 13px;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip .count { opacity: .65; margin-left: 4px; font-size: 11px; }

/* 卡片墙 */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.dish-card {
  text-align: left;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .16s ease, box-shadow .16s ease;
}
.dish-card:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(80, 50, 20, .14); }
.photo-wrap { position: relative; aspect-ratio: 4 / 5; background: #e9dfd2; }
.photo-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-wrap .no-image {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #eadfd0, #dccbb7);
  color: #9b8874; font-size: 44px; font-weight: 800;
}
.photo-wrap .badge {
  position: absolute; left: 8px; top: 8px;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, .52); color: #fff;
  font-size: 11px; backdrop-filter: blur(4px);
}
.dish-body { padding: 10px 11px 12px; }
.dish-name {
  font-size: 14px; font-weight: 650; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 2.6em;
}
.dish-meta { display: flex; justify-content: space-between; gap: 6px; margin-top: 6px; font-size: 11px; color: var(--muted); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* 浮动新增 */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 30;
  width: 58px; height: 58px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-size: 32px; line-height: 1;
  box-shadow: 0 12px 28px rgba(217, 85, 63, .38);
}

/* 按钮 */
.primary, .ghost, .danger {
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 650;
  border: 1px solid transparent;
  transition: filter .15s ease, background .15s ease;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.05); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.ghost:hover { background: rgba(127, 100, 70, .08); }
.danger { color: #b23a2e; border-color: rgba(178, 58, 46, .35); }
.small-btn { padding: 6px 10px; font-size: 13px; }
.big { padding: 12px 18px; font-size: 16px; white-space: nowrap; }

/* 弹层 */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(28, 20, 12, .48);
  backdrop-filter: blur(2px);
}
.sheet {
  position: relative;
  width: 100%; max-width: 540px; max-height: 92vh;
  overflow: auto;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  background: var(--card);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
}
.sheet h2 { margin: 6px 0 14px; font-size: 21px; }
.close {
  position: absolute; right: 12px; top: 12px;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: rgba(127, 100, 70, .10); color: var(--ink);
  font-size: 22px; line-height: 1;
}
.detail-image {
  width: 100%; aspect-ratio: 4 / 5; max-height: 56vh;
  object-fit: cover; border-radius: 16px; background: #e9dfd2;
}
.detail-body { padding-top: 14px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.family-list { margin: 12px 0 4px; border-top: 1px solid var(--line); }
.family-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
}
.family-form { margin-top: 16px; }
.family-form h3 { font-size: 15px; margin-bottom: 4px; }
.family-form .primary { width: 100%; margin-top: 16px; padding: 12px; }
.admin-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.admin-section h3 { font-size: 15px; margin-bottom: 4px; }
.admin-section .primary { width: 100%; margin-top: 12px; padding: 12px; }
.admin-sheet { max-width: 620px; }
.tabs { display: flex; gap: 6px; margin: 4px 0 14px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 8px 14px; border: 0; border-bottom: 2px solid transparent;
  background: transparent; color: var(--muted); font-weight: 650;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-pane { min-height: 120px; }
.batch-bar { display: flex; gap: 16px; align-items: center; margin-bottom: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; }
.check input { width: auto; margin: 0; }
.batch-fields { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.batch-fields input { flex: 1 1 120px; margin: 0; padding: 9px; }
.dish-admin-list { max-height: 45vh; overflow: auto; border-top: 1px solid var(--line); }
.dish-admin-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.dish-admin-item input { width: auto; margin: 0; }
.dish-admin-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dish-admin-item .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.dish-admin-item.deleted { opacity: .55; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
a.ghost { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; padding: 10px 14px; border-radius: 12px; }
.import-report {
  max-height: 220px; overflow: auto; margin-top: 10px; padding: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  font-size: 12px; white-space: pre-wrap;
}
.mini-list { display: grid; gap: 6px; margin-top: 8px; }
.mini-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 13px;
}
.mini-item img, .mini-item .no-image {
  width: 38px; height: 48px; border-radius: 7px; object-fit: cover; flex: 0 0 auto;
}
.mini-item .grow { flex: 1; min-width: 0; }
.mini-item .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.stats-box { display: grid; gap: 12px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-card { padding: 10px; border: 1px solid var(--line); border-radius: 10px; text-align: center; background: var(--bg); }
.stat-card strong { display: block; font-size: 20px; }
.history-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.history-filters input { margin: 0; padding: 8px; flex: 1 1 120px; }
#avoid-tags { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); margin-top: 6px; }
#me-btn { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 骨架屏 */
.skeleton-grid { margin-bottom: 12px; }
.skeleton-card { border-radius: var(--radius); overflow: hidden; background: var(--card); border: 1px solid var(--line); }
.skeleton-img { aspect-ratio: 4 / 5; background: linear-gradient(90deg, #eadfd0 25%, #f3ebe0 50%, #eadfd0 75%); background-size: 200% 100%; animation: pulse 1.4s infinite; }
.skeleton-line { height: 14px; margin: 12px; border-radius: 7px; background: #eadfd0; }
@keyframes pulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* 底部导航 */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: none; gap: 4px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(0,0,0,.08);
}
.bottom-nav button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 8px 4px; border-radius: 10px; font-size: 12px; font-weight: 650;
}
.bottom-nav button.active { color: var(--accent); background: rgba(217, 85, 63, .08); }
.bottom-nav .nav-add { font-size: 20px; color: var(--accent); }
#fav-btn.active { color: var(--accent); border-color: var(--accent); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  padding: 3px 9px; border-radius: 999px;
  background: rgba(217, 85, 63, .10); color: var(--accent);
  font-size: 12px;
}
.form-note { margin-top: 8px; }

/* 表单 */
label { display: block; margin: 12px 0 0; font-size: 14px; font-weight: 600; }
label input {
  display: block; width: 100%; margin-top: 6px;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--ink);
}
label input[type="file"] { padding: 9px; font-weight: 400; }
.preview { width: 100%; max-height: 240px; object-fit: cover; border-radius: 14px; margin-top: 12px; }
.crop-box { margin-top: 12px; }
.crop-image { display: block; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 14px; }
.crop-label { margin-top: 8px; font-weight: 500; color: var(--muted); }
.crop-label input { width: 100%; margin-top: 4px; }
#dish-form .primary { width: 100%; margin-top: 18px; padding: 13px; }
.camera-btn { width: 100%; margin-top: 12px; padding: 12px; }
.camera-sheet video {
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 60vh;
  object-fit: cover;
  background: #000;
  border-radius: 14px;
  margin-top: 6px;
}
.camera-actions { display: flex; gap: 10px; margin-top: 14px; }
.camera-actions button { flex: 1; }

/* 登录 / 初始化 */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-card {
  width: min(92vw, 390px);
  padding: 26px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
}
.big-logo { width: 54px; height: 54px; border-radius: 17px; font-size: 26px; margin-bottom: 14px; }
.auth-card h1 { font-size: 23px; margin-bottom: 6px; }
.auth-card form { margin-top: 8px; }
.auth-card .primary { width: 100%; margin-top: 18px; padding: 13px; }
.error { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(178, 58, 46, .10); color: #b23a2e; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 100;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

@media (max-width: 899px) {
  main.layout {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 10px;
    padding: 10px 10px calc(110px + var(--safe-bottom));
  }
  /* 手机端分类固定在左侧，像门店电子菜单一样随页面滚动保持可见。 */
  .sidebar {
    position: sticky;
    top: 68px;
    align-self: start;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    padding: 8px 6px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
  }
  .sidebar-head { display: none; }
  .sidebar .chips {
    flex-direction: column;
    gap: 4px;
    overflow: visible;
    max-height: none;
    padding: 0;
  }
  .sidebar .chip {
    width: 100%;
    flex-direction: column;
    gap: 1px;
    padding: 8px 4px;
    border-radius: 10px;
    font-size: 12px;
    text-align: center;
  }
  .sidebar .chip .count { margin-left: 0; font-size: 10px; }
  .sidebar-actions { display: none; }
  .hero { flex-direction: column; align-items: stretch; gap: 10px; }
  .hero .big { width: 100%; }
}

@media (max-width: 380px) {
  main.layout { grid-template-columns: 92px minmax(0, 1fr); gap: 8px; }
  .sidebar { padding: 6px 4px; }
  .sidebar .chip { font-size: 11px; padding: 7px 3px; }
}

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .modal { align-items: center; padding: 24px; }
  .sheet { border-radius: 24px; padding: 24px; }
  .fab { right: 28px; bottom: 28px; }
}

@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 899px) {
  .bottom-nav { display: flex; }
  .fab { bottom: calc(84px + var(--safe-bottom)); }
  .toast { bottom: calc(150px + var(--safe-bottom)); }
}

.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.family-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.tonight-group + .tonight-group { margin-top: 10px; }
.group-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tonight-row { display: flex; flex-wrap: wrap; gap: 10px; }
.tonight-item { position: relative; }
.tonight-sub { font-size: 10px; color: var(--muted); margin-top: 2px; min-height: 14px; }
.tonight-remove {
  position: absolute; right: -4px; top: -4px; width: 20px; height: 20px;
  border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 14px; line-height: 1; padding: 0;
}
.fav-mark {
  position: absolute; right: 8px; top: 8px; width: 22px; height: 22px;
  border-radius: 50%; background: rgba(217, 85, 63, .92); color: #fff;
  display: grid; place-items: center; font-size: 12px;
}
button.mini-item { width: 100%; text-align: left; color: var(--ink); cursor: pointer; }
.stats-box h3 { font-size: 14px; margin: 10px 0 2px; }
.grid-sentinel { height: 1px; }

.tonight-group { flex: 1 1 100%; }
.tonight-open { border: 0; background: transparent; padding: 0; color: inherit; display: block; width: 100%; }
.tonight-open:not(button) { cursor: default; }

.dish-admin-item { margin: 0; }

#block-btn.active { color: #b23a2e; border-color: rgba(178, 58, 46, .55); }

.mushroom-mark {
  position: absolute; left: 8px; bottom: 8px;
  padding: 3px 8px; border-radius: 999px;
  background: #5b7a3a; color: #fff;
  font-size: 11px; font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.mushroom-tag { background: rgba(91, 122, 58, .16); color: #4c6b2f; }
