/* ============================================================
   我家菜单 · 样式
   布局：左侧固定分类栏 + 右侧内容区（只有右侧滚动）
   ============================================================ */

:root {
  --bg: #faf6ef;
  --panel: #fffdf9;
  --accent: #e8590c;
  --accent-soft: #fce8dc;
  --ink: #3a332b;
  --muted: #9a9084;
  --line: #ece4d8;
  --shadow: 0 2px 10px rgba(60, 50, 20, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;               /* 整页不滚，只滚右栏 */
}

button { font-family: inherit; }

/* ---------- 整体布局 ---------- */
.layout { display: flex; height: 100vh; }

/* ---------- 左侧分类栏 ---------- */
.sidebar {
  flex: 0 0 172px;
  display: flex;
  flex-direction: column;
  background: #f1e9dc;
  border-right: 1px solid var(--line);
}

.side-header { padding: 16px 16px 8px; display:flex }

.logo { font-size: 24px; line-height: 1; }

.logo-text { margin-top: 4px; font-size: 13px; font-weight: 700; letter-spacing: 1px; }

.category-list { overflow-y: auto; padding: 4px 10px 12px; }

.cat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  margin: 2px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
  text-align: left;
}

.cat-btn:hover { background: rgba(232, 89, 12, 0.08); }

.cat-btn.active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
  font-weight: 600;
}

.cat-emoji { font-size: 17px; }

/* ---------- 右侧内容区 ---------- */
.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.main-header {
  position: sticky;
  top: 12px;
  z-index: 5;
  margin: 12px 16px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.header-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.header-title h1 {
  display: none;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.header-actions {
  display: none;                  /* 桌面才显示，见下方媒体查询 */
  align-items: center;
  gap: 8px;
}

.random-btn {
  border: 1px solid transparent;
  border-radius: 999px;
  background: #f4e5d8;
  color: #8e4f21;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.08s ease, background 0.15s ease, color 0.15s ease;
}

.random-btn:hover {
  background: #ecd3bf;
}

.random-btn:active { transform: scale(0.97); }

/* 今日菜单按钮：绿色区分 */
.random-btn.menu-btn { background: #e1efe1; color: #366b3c; }
.random-btn.menu-btn:hover { background: #cee1ce; }
.random-btn.menu-btn:active { transform: scale(0.97); }

.header-filters {
  display: none;
}

/* ---------- 卡片网格 ---------- */
.dish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 14px 16px 20px;
  align-content: start;
}

.dish-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.dish-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.media, .media-lg {
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media { aspect-ratio: 4 / 3; }

.ph-emoji { font-size: 40px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.12)); }

.card-info { padding: 8px 10px 10px; }

.card-name { font-size: 15px; font-weight: 600; }

.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.chips-wrap span {
  background: #f3ead9;
  color: #7a6f5a;
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 11.5px;
}

.empty-tip {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 手机悬浮随机球 ---------- */
.float-random {
  display: none;
  position: fixed;
  right: 18px;
  bottom: 24px;
  z-index: 20;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(232, 89, 12, 0.4);
}

/* 第二颗悬浮球（今日菜单），叠在上方 */
.float-random.float-menu {
  bottom: 92px;
  background: #2f9e44;
  box-shadow: 0 4px 14px rgba(47, 158, 68, 0.4);
}

/* ---------- 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(30, 25, 18, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 40px rgba(30, 25, 18, 0.3);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 253, 249, 0.9);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}

.modal-title {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

.modal-body { text-align: center; }

.media-lg {
  aspect-ratio: 16 / 10;
  border-radius: 12px;
}

.ph-emoji-lg { font-size: 72px; }

.modal-name { font-size: 20px; font-weight: 700; margin-top: 10px; }

.modal-meta {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.modal-body .chips-wrap {
  justify-content: center;
  margin-top: 10px;
}

.modal-body .chips-wrap span {
  font-size: 13px;
  padding: 3px 12px;
  border-radius: 999px;
}

.modal-note {
  margin-top: 10px;
  font-size: 13px;
  color: #8a7a5c;
  background: #faf3e3;
  border-radius: 10px;
  padding: 8px 12px;
}

.modal-empty {
  padding: 30px 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.modal-again {
  display: block;
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
}

.modal-again:active { transform: scale(0.98); }

/* ---------- 今日菜单弹层 ---------- */
.menu-list { text-align: left; }

.menu-part {
  background: #faf6ee;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  margin-top: 10px;
}

.menu-part:first-child { margin-top: 0; }

.menu-part-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.menu-item-name {
  font-size: 15.5px;
  font-weight: 600;
}

/* 小缩略图：有图显示图，无图显示分类图标 */
.menu-thumb {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ph-emoji-sm { font-size: 26px; }

/* ---------- 平板 / 桌面 ---------- */
@media (min-width: 700px) {
  .header-actions { display: flex; }
  .dish-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
}

/* ---------- 手机 ---------- */
@media (max-width: 699px) {
  .sidebar { flex: 0 0 86px; }
  .side-header { padding: 12px 8px 4px; text-align: center; }
  .logo { font-size: 20px; }
  .logo-text { font-size: 11px; letter-spacing: 0; }
  .header-actions { display: none; }   /* 手机用悬浮球 */
  .cat-btn {
    flex-direction: column;
    gap: 2px;
    padding: 8px 4px;
    font-size: 13px;
    text-align: center;
  }
  .cat-emoji { font-size: 19px; }
  .dish-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; padding: 10px 12px 80px; }
  .card-name { font-size: 14px; }
  .float-random { display: block; }
}

/* ---------- 打印：自动只保留主区菜品，避免卡片被分页截断 ---------- */
@media print {
  .sidebar, .main-header, .float-random { display: none !important; }
  body { overflow: visible; }
  .layout { display: block; height: auto; }
  .main { height: auto; overflow: visible; }

  /* 关键：每张菜卡作为一个整体，不被分页截断 */
  .dish-card {
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: auto;
  }

  /* 卡片内部图片、标题、标签也避免被单独拆开 */
  .dish-card .media,
  .dish-card .card-name,
  .dish-card .chips-wrap {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* 打印时：A4横向，4列×3行=12道菜。用物理单位 mm 锁卡片尺寸，避免 px 被缩放吃掉 */
  @page { size: A4 landscape; margin: 8mm; }
  html, body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .dish-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 5mm;
    padding: 0;
  }
  .dish-card {
    display: flex;
    flex-direction: column;
    box-shadow: none;
    border: 1px solid #e5ddd0;
    border-radius: 8px;
    height: 60mm;            /* 每行60mm × 3行 + 2×5mm间距 = 190mm < A4横向内容高(≈194mm)，必放3行 */
  }
  .dish-card .media {
    aspect-ratio: auto;
    height: 45mm;
    flex: 0 0 45mm;
    border-radius: 8px 8px 0 0;
  }
  .card-info {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 2px 6px;
  }
  .card-name { font-size: 12px; }
  .chips-wrap { margin-top: 2px; gap: 2px; }
  .chips-wrap span { font-size: 9px; padding: 1px 4px; }
}
