:root {
  --bg: #f6f8f5;
  --card: #ffffff;
  --ink: #17211b;
  --muted: #6b7a70;
  --line: #e5eae4;
  --green: #1f9d61;
  --green-soft: #e9f6ef;
  --red: #d93b3b;
  --red-soft: #fdecec;
  --orange: #d96e00;
  --orange-soft: #fff2e0;
  --yellow: #a97b00;
  --yellow-soft: #fdf6db;
  --shadow: 0 1px 2px rgba(20, 40, 30, .05), 0 6px 18px rgba(20, 40, 30, .05);
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.45;
  max-width: 520px; margin: 0 auto;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
h3 { margin: 0; font-size: 17px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- 登录 ---------- */
.login {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-logo { font-size: 52px; line-height: 1; margin-bottom: 10px; }
.login-box h1 { font-size: 22px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 6px 0 26px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 26px; height: 16px; }
.pin-dot { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid #c6d2c8; background: transparent; transition: .12s; }
.pin-dot.on { background: var(--ink); border-color: var(--ink); }
.pin-dots.err .pin-dot { border-color: var(--red); background: var(--red-soft); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button {
  height: 62px; border-radius: 16px; border: 1px solid var(--line); background: #fff;
  font-size: 24px; font-weight: 500; color: var(--ink); box-shadow: var(--shadow);
}
.keypad button:active { background: var(--green-soft); border-color: var(--green); }
.keypad button.fn { font-size: 15px; color: var(--muted); box-shadow: none; background: transparent; border-color: transparent; }
.login-tip { margin-top: 26px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.login-tip code { background: #eef1ec; padding: 1px 5px; border-radius: 5px; }

/* ---------- 顶栏 ---------- */
header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 8px;
  padding: 14px 16px 6px;
}
header .date { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-size: 18px; line-height: 1;
}
.offline {
  margin: 6px 16px 0; padding: 8px 12px; border-radius: 10px;
  background: var(--yellow-soft); color: var(--yellow); font-size: 12px;
}
main { padding: 10px 16px 16px; }
.section { display: none; }
.section.active { display: block; }

/* ---------- 库存 ---------- */
.stats { display: flex; gap: 8px; margin: 6px 0 12px; }
.stat { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.stat .n { font-size: 20px; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat.red .n { color: var(--red); }
.stat.orange .n { color: var(--orange); }
.search { width: 100%; margin: 0 0 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 14px; color: var(--ink); outline: none; }
.search:focus { border-color: var(--green); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 13px; border-radius: 99px; background: #fff; border: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.item { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.d-red { background: var(--red); } .d-orange { background: var(--orange); }
.d-yellow { background: #e0b800; } .d-green { background: var(--green); } .d-gray { background: #b9c4bc; }
.item .body { flex: 1; min-width: 0; }
.item .nm { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item .meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #eef2ee; color: var(--muted); font-weight: 500; }
.tag.open { background: #eef3fb; color: #3558a0; }
.exp { font-size: 12px; font-weight: 600; white-space: nowrap; }
.exp.red { color: var(--red); } .exp.orange { color: var(--orange); }
.exp.yellow { color: var(--yellow); } .exp.green { color: var(--green); } .exp.gray { color: #96a39a; }
.minus { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 20px; line-height: 1; font-weight: 300; }
.minus:active { background: #f0f3f0; }
.more { flex: none; width: 28px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; font-size: 14px; line-height: 1.7; }

/* ---------- 卡片 / 菜品 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.card.tips { background: #fbfcfb; box-shadow: none; }
.dish-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.dish-name { font-size: 18px; font-weight: 700; }
.dish-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.why { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.uses { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.use { font-size: 12px; padding: 3px 8px; border-radius: 8px; background: var(--red-soft); color: var(--red); font-weight: 600; }
.use.soon { background: var(--orange-soft); color: var(--orange); }
.need { font-size: 12px; padding: 3px 8px; border-radius: 8px; background: #f2f4f2; color: var(--muted); }
.need.miss { background: var(--orange-soft); color: var(--orange); font-weight: 600; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.btn { flex: 1; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 14px; font-weight: 600; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); font-weight: 500; }
.btn:active { filter: brightness(.96); }
.hint { font-size: 12.5px; color: var(--muted); margin: 2px 0 8px; line-height: 1.5; }
.hint b { color: var(--red); }
.leftover-card { background: #fff8ec; border: 1px solid #f2dfbc; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.leftover-card .t { font-weight: 700; font-size: 14px; color: #8a5a00; }
.leftover-card .d { font-size: 12.5px; color: #9a7a3a; margin-top: 3px; }

.role { font-size: 11px; padding: 1px 7px; border-radius: 6px; font-weight: 600; vertical-align: 2px; }
.role.main { background: #fde9e3; color: #b8462a; }
.role.side { background: var(--green-soft); color: var(--green); }
.role.alt { background: #eef2ee; color: var(--muted); }
.defrost { margin-top: 8px; font-size: 12.5px; color: #2f6d8f; background: #eaf4fa; border-radius: 10px; padding: 7px 10px; line-height: 1.45; }
a.btn { text-decoration: none; text-align: center; display: inline-flex; align-items: center; justify-content: center; }
.fridge-tip { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---------- 购物 ---------- */
.shop-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; background: #fff; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; }
.shop-item .nm { flex: 1; }
.shop-item .why { font-size: 11.5px; color: var(--muted); margin: 0; }
.shop-item .del { border: 0; background: transparent; color: #b3bdb5; font-size: 18px; padding: 4px 6px; }
.ck { width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid #cfd8cf; background: #fff; flex: none; }
.ck.on { background: var(--green); border-color: var(--green); position: relative; }
.ck.on::after { content: "✓"; color: #fff; font-size: 14px; position: absolute; left: 4px; top: -1px; }
.addrow { display: flex; gap: 8px; margin-top: 10px; }
.addrow input { flex: 1; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); font-size: 14px; }
.addrow button { padding: 0 16px; border-radius: 12px; border: 0; background: var(--ink); color: #fff; font-size: 14px; }

/* ---------- 我的 ---------- */
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .v { color: var(--muted); text-align: right; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mini { font-size: 12px; color: var(--muted); line-height: 1.55; }
.about { text-align: center; margin-top: 14px; }

/* ---------- 底部导航 / 悬浮按钮 ---------- */
nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  display: flex; max-width: 520px; margin: 0 auto;
}
nav button { flex: 1; border: 0; background: transparent; padding: 8px 0 7px; color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
nav button .ico { font-size: 20px; line-height: 1; }
nav button.on { color: var(--green); font-weight: 600; }
.fab {
  position: fixed; right: calc(50% - 260px + 18px); bottom: calc(88px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--green); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 8px 20px rgba(31, 157, 97, .35); z-index: 20;
}
@media (max-width: 520px) { .fab { right: 18px; } }

/* ---------- 弹层 ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 25, 20, .42); z-index: 50; display: none; align-items: flex-end; justify-content: center; }
.overlay.show { display: flex; }
.sheet {
  width: 100%; max-width: 520px; background: #fff; border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.close { border: 0; background: transparent; font-size: 26px; color: var(--muted); line-height: 1; padding: 0 4px; }
.sub { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.field { margin-bottom: 11px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  font-size: 15px; background: #fbfcfb; color: var(--ink); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--green); }
.field.two, .field.three { display: flex; gap: 10px; }
.field.two > div, .field.three > div { flex: 1; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.quick button { padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fbfcfb; font-size: 13.5px; color: var(--ink); }
.quick button:active { background: var(--green-soft); border-color: var(--green); }
.quick-search { margin-bottom: 8px; }
.quick-search input { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); font-size: 14px; outline: none; }
.cat-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tabs button { flex: none; padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-size: 12.5px; color: var(--muted); }
.cat-tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.divider { text-align: center; color: #a9b4ac; font-size: 12px; margin: 16px 0 10px; position: relative; }
.divider::before, .divider::after { content: ""; position: absolute; top: 50%; width: 36%; height: 1px; background: var(--line); }
.divider::before { left: 0; } .divider::after { right: 0; }
.act-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.act-list .btn { width: 100%; }
.dish-steps { padding-left: 18px; margin: 8px 0 14px; }
.dish-steps li { margin-bottom: 9px; font-size: 14px; line-height: 1.55; }
.dish-season { font-size: 12.5px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
  background: rgba(20, 35, 28, .92); color: #fff; font-size: 13.5px; padding: 10px 16px; border-radius: 12px;
  opacity: 0; transition: .22s; z-index: 99; pointer-events: none; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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