/* ============================================================
 * 家庭菜单 — 样式
 * 移动端优先。针对 iOS 做了：安全区、禁止聚焦放大、
 * 去掉点击高亮、dvh 高度、弹层滚动隔离。
 * ============================================================ */

/* ---------- 主题变量 ---------- */
:root {
  --brand:        #e8590c;
  --brand-soft:   #fff0e6;
  --brand-dark:   #c2410c;
  --bg:           #f7f5f2;
  --surface:      #ffffff;
  --surface-2:    #f2efeb;
  --text:         #241f1a;
  --text-2:       #6b6259;
  --text-3:       #9c9288;
  --line:         #e7e1da;
  --green:        #2f9e44;
  --red:          #e03131;
  --amber:        #f08c00;

  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --shadow:    0 1px 2px rgba(36,31,26,.06), 0 4px 14px rgba(36,31,26,.06);
  --shadow-lg: 0 -8px 40px rgba(36,31,26,.16);

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand:      #ff8a3d;
    --brand-soft: #35251a;
    --brand-dark: #ffab6b;
    --bg:         #17140f;
    --surface:    #211d18;
    --surface-2:  #2b2620;
    --text:       #f2ece5;
    --text-2:     #b5aa9c;
    --text-3:     #8a7f72;
    --line:       #372f27;
    --green:      #51cf66;
    --red:        #ff6b6b;
    --shadow:     0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    --shadow-lg:  0 -8px 40px rgba(0,0,0,.6);
  }
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; min-height: 100dvh; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }

/* 输入框字号 ≥16px，否则 iOS 聚焦时页面会被放大 */
.input, .textarea, .select { font-size: 16px; }

/* ---------- 主框架 ---------- */
.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar__left  { display: flex; flex-direction: column; min-width: 0; }
.topbar__title { font-size: 19px; font-weight: 700; letter-spacing: -.2px; }
.topbar__sub   { font-size: 12px; color: var(--text-3); }
.topbar__right { display: flex; align-items: center; gap: 8px; flex: none; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; background: var(--surface-2); color: var(--text);
  transition: transform .12s ease, background .15s;
}
.icon-btn:active { transform: scale(.9); }

.badge {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand);
  font-weight: 600; white-space: nowrap;
}
.badge--warn { background: #fff3bf; color: #8a5a00; }

.view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(var(--tabbar-h) + var(--safe-b) + 24px);
}

/* ---------- 底部导航 ---------- */
.tabbar {
  flex: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative;
  height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-3); font-size: 11px;
  transition: color .15s;
}
.tab__i { font-size: 20px; line-height: 1; filter: grayscale(1) opacity(.55); transition: filter .15s; }
.tab.is-on { color: var(--brand); font-weight: 600; }
.tab.is-on .tab__i { filter: none; }
.tab__badge {
  position: absolute; top: 4px; left: 50%; margin-left: 4px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: var(--r);
  font-size: 15px; font-weight: 600;
  background: var(--surface-2); color: var(--text);
  transition: transform .1s ease, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--brand); color: #fff; }
.btn--danger  { background: var(--red); color: #fff; }
.btn--ghost   { background: transparent; color: var(--brand); }
.btn--block   { display: flex; width: 100%; }
.btn--sm      { padding: 7px 13px; font-size: 13px; border-radius: var(--r-sm); }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block; font-size: 13px; color: var(--text-2);
  margin-bottom: 6px; font-weight: 500;
}
.input, .textarea, .select {
  width: 100%; padding: 11px 13px;
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line); border-radius: var(--r);
  outline: none; transition: border-color .15s;
  -webkit-appearance: none; appearance: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--brand); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.select { background-image: none; }
.input--code {
  text-align: center; letter-spacing: 8px; font-size: 24px;
  font-weight: 700; text-transform: uppercase; padding-left: 20px;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }

.emoji-row { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-opt {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; background: var(--surface-2);
  border: 2px solid transparent; transition: all .15s;
}
.emoji-opt.is-on { border-color: var(--brand); background: var(--brand-soft); transform: scale(1.06); }

/* ---------- 引导页 ---------- */
.onboard {
  min-height: 100vh; min-height: 100dvh;
  padding: calc(var(--safe-t) + 44px) 22px calc(var(--safe-b) + 30px);
  display: flex; flex-direction: column; align-items: center;
  max-width: 460px; margin: 0 auto;
}
.onboard__logo  { font-size: 62px; line-height: 1; margin-bottom: 10px; }
.onboard__title { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.onboard__sub   { font-size: 14px; color: var(--text-2); margin-bottom: 26px; }
.onboard__card {
  width: 100%; background: var(--surface); border-radius: var(--r-lg);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.onboard__hint {
  font-size: 12px; color: var(--text-3); text-align: center;
  margin-top: 18px; line-height: 1.7;
}

/* ---------- 卡片 / 通用 ---------- */
.card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 15px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
.card__title { font-size: 15px; font-weight: 700; }

.section-title {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  margin: 18px 2px 8px; display: flex; align-items: center; justify-content: space-between;
}
.divider { height: 1px; background: var(--line); margin: 12px 0; }

.empty { text-align: center; padding: 46px 20px; color: var(--text-3); }
.empty__icon { font-size: 44px; display: block; margin-bottom: 10px; opacity: .8; }
.empty__text { font-size: 14px; line-height: 1.7; }

/* ---------- 工具条 / 搜索 / 分段 ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.search { flex: 1; position: relative; }
.search .input { padding-left: 34px; }
.search::before {
  content: '🔍'; position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%); font-size: 13px; opacity: .5;
}

.seg {
  display: flex; gap: 4px; overflow-x: auto; padding: 2px;
  background: var(--surface-2); border-radius: 999px;
  margin-bottom: 12px; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg__item {
  flex: none; padding: 7px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap;
}
.seg__item.is-on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.chip--brand { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---------- 菜谱网格 ---------- */
.dish-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
@media (min-width: 620px) { .dish-grid { grid-template-columns: repeat(3, 1fr); } }

.dish-card {
  background: var(--surface); border-radius: var(--r-lg);
  overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform .12s ease;
}
.dish-card:active { transform: scale(.975); }
.dish-card__photo {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
  background: var(--surface-2);
}
.dish-card__ph {
  width: 100%; aspect-ratio: 4 / 3;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; background: var(--brand-soft);
}
.dish-card__body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.dish-card__name { font-size: 14px; font-weight: 700; line-height: 1.3; }
.dish-card__meta { font-size: 11px; color: var(--text-3); margin-top: auto; }

/* ---------- 今天吃什么 ---------- */
.pick {
  background: var(--surface); border-radius: var(--r-xl);
  padding: 26px 20px; text-align: center;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.pick__photo {
  width: 132px; height: 132px; border-radius: 50%; object-fit: cover;
  margin: 0 auto 14px; display: block; background: var(--surface-2);
}
.pick__ph {
  width: 132px; height: 132px; border-radius: 50%; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 54px; background: var(--brand-soft);
}
.pick__label { font-size: 12px; color: var(--text-3); letter-spacing: 2px; }
.pick__name  { font-size: 27px; font-weight: 800; letter-spacing: -.5px; margin: 4px 0 6px; }
.pick__desc  { font-size: 13px; color: var(--text-2); line-height: 1.6; }

.vote-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.vote-row:last-child { border-bottom: none; }
.vote__name { flex: 1; font-size: 14px; font-weight: 600; }
.vote__who  { font-size: 11px; color: var(--text-3); }
.vote__count { font-size: 15px; font-weight: 800; color: var(--brand); min-width: 28px; text-align: right; }

/* ---------- 周计划 ---------- */
.week { display: flex; flex-direction: column; gap: 11px; }
.week__day {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 12px 13px; box-shadow: var(--shadow);
}
.week__day.is-today { outline: 2px solid var(--brand); outline-offset: -2px; }
.week__head {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 9px;
}
.week__head b { font-size: 15px; }
.week__head span { font-size: 12px; color: var(--text-3); }

.meal-slot { margin-bottom: 9px; }
.meal-slot:last-child { margin-bottom: 0; }
.meal-slot__label {
  font-size: 11px; color: var(--text-3); margin-bottom: 5px;
  display: flex; align-items: center; gap: 5px;
}
.plan-item {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-soft); color: var(--brand);
  border-radius: 999px; padding: 5px 6px 5px 12px;
  font-size: 13px; font-weight: 600; margin: 0 6px 6px 0;
}
.plan-item__x {
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.08); color: inherit;
  font-size: 12px; line-height: 18px; text-align: center;
}
.plan-add {
  display: inline-flex; align-items: center;
  border: 1.5px dashed var(--line); color: var(--text-3);
  border-radius: 999px; padding: 5px 13px; font-size: 13px;
}

/* ---------- 点菜 ---------- */
.order {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface); border-radius: var(--r);
  padding: 12px 13px; margin-bottom: 9px; box-shadow: var(--shadow);
}
.order--done { opacity: .5; }
.order__main { flex: 1; min-width: 0; }
.order__name { font-size: 15px; font-weight: 700; }
.order__meta { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.order__note {
  font-size: 12px; color: var(--text-2); margin-top: 4px;
  background: var(--surface-2); border-radius: 8px; padding: 4px 8px;
  display: inline-block;
}
.status-pill {
  font-size: 11px; font-weight: 700; padding: 4px 10px;
  border-radius: 999px; white-space: nowrap;
}
.status-pill--pending { background: #fff3bf; color: #8a5a00; }
.status-pill--cooking { background: #ffe3bf; color: #b35309; }
.status-pill--done    { background: #d3f9d8; color: #2b8a3e; }

/* ---------- 采购清单 ---------- */
.shop-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; background: var(--surface);
  border-radius: var(--r); margin-bottom: 8px; box-shadow: var(--shadow);
}
.shop-item.is-done { opacity: .45; }
.shop-item.is-done .shop-item__name { text-decoration: line-through; }
.shop-item__name { flex: 1; font-size: 15px; font-weight: 600; }
.shop-item__qty  { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.check {
  width: 25px; height: 25px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: transparent; transition: all .15s;
}
.check.is-on { background: var(--green); border-color: var(--green); color: #fff; }

.shop-add-row { display: flex; gap: 8px; margin-bottom: 14px; }
.shop-add-row .input { flex: 1; }

/* ---------- 设置 ---------- */
.settings-group {
  background: var(--surface); border-radius: var(--r-lg);
  overflow: hidden; margin-bottom: 14px; box-shadow: var(--shadow);
}
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 15px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row__label { flex: 1; font-size: 15px; }
.row__value { font-size: 13px; color: var(--text-3); }
.row--tap:active { background: var(--surface-2); }

.code-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 26px; font-weight: 800; letter-spacing: 7px;
  color: var(--brand); text-align: center; padding: 16px;
  background: var(--brand-soft); border-radius: var(--r);
  user-select: all; -webkit-user-select: all;
}

/* ---------- 底部弹层 ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20,16,12,.45);
  opacity: 0; transition: opacity .22s;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.sheet-backdrop.is-on { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  max-height: 92vh; max-height: 92dvh;
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.32,.72,0,1);
  padding-bottom: var(--safe-b);
}
.sheet.is-on { transform: translateY(0); }
.sheet__grip {
  width: 38px; height: 4px; border-radius: 999px;
  background: var(--line); margin: 9px auto 0; flex: none;
}
.sheet__head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 16px 8px;
}
.sheet__title { font-size: 17px; font-weight: 700; }
.sheet__body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 4px 16px 16px;
}
.sheet__foot {
  flex: none; padding: 11px 16px;
  border-top: 1px solid var(--line);
  display: flex; gap: 9px;
}
.sheet__foot .btn { flex: 1; }

/* ---------- 提示条 ---------- */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 20px;
}
.toast {
  max-width: 100%;
  background: rgba(30,25,20,.94); color: #fff;
  padding: 10px 16px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500;
  opacity: 0; transform: translateY(10px);
  transition: opacity .22s, transform .22s;
  box-shadow: 0 6px 24px rgba(0,0,0,.28);
}
.toast--in { opacity: 1; transform: translateY(0); }
.toast--error { background: rgba(200,38,38,.96); }

/* 照片选择预览 */
.photo-pick {
  width: 100%; aspect-ratio: 4 / 3; border-radius: var(--r);
  border: 1.5px dashed var(--line); background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--text-3); font-size: 13px; overflow: hidden;
  position: relative;
}
.photo-pick img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick__hint { font-size: 12px; }

/* 成分行 */
.ing-row { display: flex; gap: 7px; margin-bottom: 7px; align-items: center; }
.ing-row .input { padding: 9px 11px; font-size: 14px; }
.ing-row__del {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  background: var(--surface-2); color: var(--text-3); font-size: 15px;
}

.spinner {
  width: 22px; height: 22px; margin: 40px auto;
  border: 2.5px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-full {
  position: fixed; inset: 0; z-index: 70;
  background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
