/* ============================================================
 * app.css  —  简约风格 / 手机优先
 *   规则：一个强调色、无渐变、无粒子、无毛玻璃；
 *   所有可点区域 ≥ 44px；数字用 tabular-nums 防止跳动。
 * ============================================================ */

:root {
  --bg: #f5f5f2;
  --card: #ffffff;
  --ink: #16181a;
  --ink-2: #4b5157;
  --muted: #8a9099;
  --line: #e7e7e2;
  --line-2: #f0f0ec;
  --accent: #0e7c66;
  --accent-weak: #e8f3f0;
  --warn: #9a5b00;
  --warn-weak: #fdf3e3;
  --danger: #b42318;
  --danger-weak: #fdecea;
  --radius: 14px;
  --radius-sm: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101112;
    --card: #1a1c1e;
    --ink: #f2f3f4;
    --ink-2: #b9bfc6;
    --muted: #7e858d;
    --line: #2a2d30;
    --line-2: #232628;
    --accent: #3ecfae;
    --accent-weak: #14312b;
    --warn: #e6b064;
    --warn-weak: #33281a;
    --danger: #ff8a7a;
    --danger-weak: #3a1f1c;
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

body {
  padding-bottom: calc(64px + var(--safe-b));
  overscroll-behavior-y: contain;
}

.app { max-width: 520px; margin: 0 auto; padding: 0 16px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  max-width: 520px; margin: 0 auto;
  background: var(--bg);
  border-bottom: 1px solid var(--line-2);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar .sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--muted); font-weight: 600;
  letter-spacing: .3px; margin-bottom: 10px;
}
.card-title .more { font-size: 13px; color: var(--accent); font-weight: 600; background: none; border: 0; padding: 4px; }

/* ---------- 主数字 ---------- */
.hero { padding: 20px 16px 16px; }
.hero .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.hero .num {
  font-size: 54px; font-weight: 700; letter-spacing: -1.5px;
  line-height: 1.05; margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.hero .num small { font-size: 17px; font-weight: 600; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.hero .num.over { color: var(--danger); }
.hero .sub { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.hero .sub b { color: var(--ink); font-weight: 650; }

.bar { height: 8px; border-radius: 999px; background: var(--line-2); overflow: hidden; margin-top: 14px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.bar > i.over { background: var(--danger); }

.strip { display: flex; gap: 18px; margin-top: 14px; }
.strip .item { flex: 1; }
.strip .item .k { font-size: 12px; color: var(--muted); }
.strip .item .v { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.strip .item .v small { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  font-size: 16px; font-weight: 600; font-family: inherit;
  cursor: pointer; width: 100%;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--line); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.sm { min-height: 38px; font-size: 14px; padding: 0 12px; width: auto; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* ---------- 列表 ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line-2);
}
.list li:first-child { border-top: 0; }
.list li .grow { flex: 1; min-width: 0; }
.list li .name { font-size: 15px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li .meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.list li .kcal { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.list li .del {
  width: 32px; height: 32px; border-radius: 8px; border: 0;
  background: transparent; color: var(--muted); font-size: 16px; line-height: 1;
  cursor: pointer; flex: none; opacity: .65;
}
.list li .del:active { opacity: 1; }

.meal-group { border-top: 1px solid var(--line-2); }
.meal-group:first-child { border-top: 0; }
.meal-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 16px 4px;
  font-size: 13px; font-weight: 650; color: var(--ink-2);
}
.meal-head .sum { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.meal-group .list li { padding-left: 16px; padding-top: 8px; padding-bottom: 8px; border-top: 0; }

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

/* ---------- 提示条 ---------- */
.banner {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13px; line-height: 1.5;
  margin: 12px 0;
}
.banner.warn { background: var(--warn-weak); color: var(--warn); }
.banner.danger { background: var(--danger-weak); color: var(--danger); }
.banner.info { background: var(--accent-weak); color: var(--accent); }
.banner .x { margin-left: auto; background: none; border: 0; color: inherit; font-size: 16px; padding: 0 2px; }

/* ---------- 表单 ---------- */
.field { margin: 14px 0; }
.field > label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.input, select.input {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink);
  font-size: 16px; font-family: inherit;
  -webkit-appearance: none; appearance: none;
}
.input:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

.seg {
  display: flex; gap: 6px; padding: 4px;
  background: var(--line-2); border-radius: var(--radius-sm);
}
.seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-2);
  font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar .inner { display: flex; width: 100%; max-width: 520px; }
.tabbar button {
  flex: 1; min-height: 56px; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--muted);
  font-family: inherit; cursor: pointer;
}
.tabbar button .ico { font-size: 19px; line-height: 1; }
.tabbar button.on { color: var(--accent); }

/* ---------- 底部弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.32);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.sheet-mask.open { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-width: 520px;
  background: var(--bg); border-radius: 18px 18px 0 0;
  max-height: 92vh; overflow-y: auto;
  padding: 8px 16px calc(16px + var(--safe-b));
  transform: translateY(12px); transition: transform .2s ease;
}
.sheet-mask.open .sheet { transform: translateY(0); }
.sheet .grab {
  width: 36px; height: 4px; border-radius: 2px; background: var(--line);
  margin: 6px auto 12px;
}
.sheet h2 { font-size: 17px; margin: 0 0 4px; font-weight: 650; }
.sheet .lead { font-size: 13px; color: var(--muted); margin: 0 0 8px; }

/* ---------- 拍照草稿 ---------- */
.preview {
  width: 100%; max-height: 40vh; object-fit: cover;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--line-2); display: block;
  transition: max-height .2s ease;
}
/* 认出结果后把照片收成一条，别让用户为了看菜名往下滚半屏 */
.preview.result { max-height: 104px; }
.dish {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; border-top: 1px solid var(--line-2);
}
.dish:first-child { border-top: 0; }
.dish .info { flex: 1; min-width: 0; }
.dish input.name {
  width: 100%; border: 0; background: transparent; color: var(--ink);
  font-size: 15px; font-weight: 600; font-family: inherit; padding: 2px 0;
}
.dish .winfo { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper button {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 17px; line-height: 1; cursor: pointer;
}
.stepper input {
  width: 56px; height: 34px; text-align: center;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--card); color: var(--ink);
  font-size: 15px; font-variant-numeric: tabular-nums; font-family: inherit;
}
.dish .del {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  border: 1px solid var(--line); background: var(--card);
  color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer;
}
.total-line {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 0 4px; font-size: 14px; color: var(--ink-2);
}
.total-line b { font-size: 22px; font-variant-numeric: tabular-nums; }

.footnote { font-size: 12px; color: var(--muted); line-height: 1.55; margin-top: 10px; }

/* ---------- 加载 ---------- */
.loading { display: flex; align-items: center; gap: 10px; padding: 18px 0; color: var(--ink-2); font-size: 14px; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  .bar > i, .sheet, .sheet-mask { transition: none; }
}

/* ---------- 引导页 ---------- */
.onboard { padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b)); max-width: 520px; margin: 0 auto; }
.onboard h1 { font-size: 24px; margin: 8px 0 6px; letter-spacing: -.4px; }
.onboard .lead { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.onboard .actions { margin-top: 22px; display: grid; gap: 10px; }

/* ---------- 历史 ---------- */
.hist-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line-2); }
.hist-item:first-child { border-top: 0; }
.hist-item .d { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hist-item .m { font-size: 12px; color: var(--muted); }
.hist-item .k { margin-left: auto; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(76px + var(--safe-b));
  transform: translate(-50%, 8px);
  background: #1c1f22; color: #fff;
  padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 60; max-width: 88vw;
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }
.mt0 { margin-top: 0; }
.tiny { font-size: 12px; color: var(--muted); }
