:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #e6eaee;
  --text: #1d2733;
  --sub: #7b8794;
  --brand: #2f80ed;
  --brand-soft: #e8f1fe;
  --ok: #27ae60;
  --warn: #f5a623;
  --bad: #eb5757;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 42, 67, .06), 0 4px 14px rgba(16, 42, 67, .05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 760px; margin: 0 auto; min-height: 100vh; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { padding: 10px 16px 8px; }
.logo { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.logo-ico { font-style: normal; }
.searchbox { position: relative; margin-top: 8px; }
.searchbox input {
  width: 100%; border: 1px solid var(--line); background: #f7f9fb;
  border-radius: 10px; padding: 8px 34px 8px 12px; font-size: 15px;
  color: var(--text); outline: none;
}
.searchbox input:focus { border-color: var(--brand); background: #fff; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: none; background: #d7dde4; color: #fff; width: 22px; height: 22px;
  border-radius: 50%; font-size: 12px; line-height: 1; cursor: pointer;
}

/* ---------- 主区 ---------- */
.view { padding: 14px 14px 84px; }
.section { margin-bottom: 18px; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--sub);
  margin: 4px 2px 10px; letter-spacing: .5px;
}
.section-title .cnt {
  background: var(--card); border: 1px solid var(--line);
  color: var(--sub); border-radius: 20px; padding: 0 8px; font-size: 12px;
}

/* ---------- 通用按钮 ---------- */
.btn {
  border: none; border-radius: 10px; padding: 9px 14px; font-size: 14px;
  font-weight: 600; cursor: pointer; color: #fff; background: var(--brand);
  font-family: inherit; transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.gray { background: #e9edf2; color: var(--text); }
.btn.danger { background: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.warn { background: var(--warn); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

/* 空状态 */
.empty {
  text-align: center; color: var(--sub); padding: 34px 16px; font-size: 14px;
}
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------- 首页：临期/过期横幅 ---------- */
.alert-band { margin-bottom: 14px; border-radius: var(--radius); overflow: hidden; }
.alert-card {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; color: #fff; text-decoration: none;
}
.alert-card .a-ico { font-size: 20px; }
.alert-card .a-main { flex: 1; min-width: 0; }
.alert-card .a-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-card .a-sub { font-size: 12px; opacity: .9; }
.alert-card .a-go { font-size: 18px; opacity: .85; }
.alert-card.bad { background: linear-gradient(135deg, #ee5a5a, #d94343); }
.alert-card.warn { background: linear-gradient(135deg, #f0a331, #e08c16); }

/* ---------- 容器卡片 ---------- */
.container-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
}
.cc-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; cursor: pointer; user-select: none;
}
.cc-ico {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.cc-ico.cold { background: #e3f2fd; }
.cc-ico.freezer { background: #e8f4f8; }
.cc-ico.normal { background: #f0f1f3; }
.cc-info { flex: 1; min-width: 0; }
.cc-name { font-weight: 700; font-size: 16px; }
.cc-tags { font-size: 12px; color: var(--sub); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 1px; }
.cc-tags .tag {
  background: var(--bg); padding: 1px 7px; border-radius: 20px; color: var(--sub);
}
.cc-tags .tag.red { background: #fdeaea; color: var(--bad); }
.cc-tags .tag.yellow { background: #fef3e0; color: #b8791a; }
.cc-arrow { color: #c2cbd5; font-size: 18px; transition: transform .2s; }
.cc-arrow.open { transform: rotate(180deg); }
.cc-body { display: none; border-top: 1px solid var(--line); padding: 4px 0 6px; }
.cc-body.open { display: block; }

/* 批次行 */
.batch-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px 9px 18px; border-left: 3px solid transparent;
}
.batch-row.expired { border-left-color: var(--bad); background: #fef6f6; }
.batch-row.expiring { border-left-color: var(--warn); background: #fffbf2; }
.batch-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.none { background: #cdd5dd; }
.b-info { flex: 1; min-width: 0; }
.b-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-sub { font-size: 12px; color: var(--sub); margin-top: 1px; }
.b-sub .danger { color: var(--bad); font-weight: 600; }
.b-sub .warn-t { color: #c47c13; font-weight: 600; }
.b-actions { display: flex; gap: 6px; flex: none; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar { max-width: 760px; margin: 0 auto; }
.tab-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); color: #9aa5b1;
  font-size: 11px; font-weight: 600; font-family: inherit;
}
.tab-btn .tab-ico { font-size: 21px; line-height: 1.2; filter: grayscale(1) opacity(.55); }
.tab-btn.active { color: var(--brand); }
.tab-btn.active .tab-ico { filter: none; }
.badge {
  position: absolute; background: var(--bad); color: #fff; font-size: 10px;
  min-width: 16px; height: 16px; border-radius: 10px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  transform: translate(2px, -6px); font-weight: 700;
}
.badge[hidden] { display: none; }

/* ---------- 放入页 ---------- */
.add-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 16px 18px; margin-bottom: 14px;
}
.frm-label { font-size: 13px; font-weight: 700; color: var(--sub); margin: 14px 2px 8px; }
.frm-label:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: #f8fafb; border-radius: 22px;
  padding: 7px 14px; font-size: 14px; cursor: pointer; color: var(--text);
  font-family: inherit; transition: all .12s;
}
.chip:active { transform: scale(.96); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.frm-input, select.frm-input, textarea.frm-input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; color: var(--text); background: #fff;
  outline: none; font-family: inherit;
}
.frm-input:focus { border-color: var(--brand); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-2-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.unit-line { display: flex; align-items: baseline; gap: 4px; }
.unit-suffix { color: var(--sub); font-size: 13px; white-space: nowrap; }
.shelf-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shelf-opt {
  border: 1.5px solid var(--line); background: #f8fafb; border-radius: 10px;
  padding: 9px 10px; text-align: left; cursor: pointer; font-family: inherit;
}
.shelf-opt .so-t { font-weight: 700; font-size: 14px; color: var(--text); }
.shelf-opt .so-d { font-size: 11px; color: var(--sub); margin-top: 1px; }
.shelf-opt.on { border-color: var(--brand); background: var(--brand-soft); }
.shelf-opt.on .so-t { color: var(--brand); }
.shelf-extra { margin-top: 10px; }
.hint { font-size: 12px; color: var(--sub); margin-top: 8px; }
.add-bar { display: flex; gap: 10px; margin-top: 18px; }
.add-bar .btn { flex: 1; padding: 12px; font-size: 16px; }

/* ---------- 购物页 ---------- */
.shop-group { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.shop-title { padding: 13px 16px 6px; font-size: 14px; font-weight: 700; }
.shop-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px;
  border-bottom: 1px solid #f1f4f7; cursor: pointer;
}
.shop-item:last-child { border-bottom: none; }
.shop-check {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  border: 2px solid #c9d2db; display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: transparent;
}
.shop-item.done .shop-check { background: var(--ok); border-color: var(--ok); color: #fff; }
.shop-item.done .shop-name { text-decoration: line-through; color: var(--sub); }
.shop-name { flex: 1; font-size: 15px; font-weight: 600; }
.shop-qty { color: var(--sub); font-size: 13px; }
.shop-del { border: none; background: none; color: #c9d2db; font-size: 18px; cursor: pointer; padding: 4px; }
.shop-del:hover { color: var(--bad); }
.shop-add-form { display: flex; gap: 8px; padding: 12px 16px; }
.shop-add-form input { flex: 1; }

/* 建议补货 */
.suggest-item { display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-bottom: 1px solid #f1f4f7; }
.suggest-item:last-child { border-bottom: none; }
.suggest-item .s-ico { font-size: 18px; }
.sg-main { flex: 1; }
.sg-name { font-weight: 600; font-size: 14px; }
.sg-sub { font-size: 12px; color: var(--sub); }
.sg-sub b.ok-n { color: var(--ok); }

/* ---------- 管理页 ---------- */
.mg-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; padding: 6px 0; }
.mg-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; }
.mg-head h3 { margin: 0; font-size: 15px; }
.mg-row { display: flex; align-items: center; gap: 8px; padding: 9px 16px; border-top: 1px solid #f1f4f7; }
.mg-name { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-sub { font-size: 12px; color: var(--sub); display: block; }
.mg-btn { border: none; background: #eef2f6; color: var(--text); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.mg-btn:hover { background: #e0e6ec; }
.mg-btn.del { color: var(--bad); }
.mg-btn.plus { background: var(--brand); color: #fff; width: auto; padding: 0 12px; font-size: 13px; font-weight: 700; }
.setting-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid #f1f4f7; }
.setting-row input { width: 70px; }
.mg-note { color: var(--sub); font-size: 12px; padding: 0 16px 10px; }

/* ---------- 历史 ---------- */
.his-row { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-top: 1px solid #f1f4f7; font-size: 13px; }
.his-row .h-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.his-row .h-sub { color: var(--sub); font-size: 12px; }
.his-tag { font-size: 11px; padding: 1px 6px; border-radius: 10px; }
.his-tag.eat { background: #e8f6ee; color: var(--ok); }
.his-tag.dispose { background: #fdeaea; color: var(--bad); }

/* ---------- 底部抽屉 sheet ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(10, 20, 30, .45); z-index: 50;
  animation: fadein .15s;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: #fff; border-radius: 18px 18px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
  animation: slideup .18s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(40px); opacity: .4; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: #dfe5ea; margin: 4px auto 14px; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.sheet-title { font-size: 17px; font-weight: 700; flex: 1; }
.sheet-sub { color: var(--sub); font-size: 13px; margin-top: 2px; }
.sheet-close { border: none; background: #eef2f6; width: 30px; height: 30px; border-radius: 50%; font-size: 14px; cursor: pointer; color: var(--sub); }
.sheet-actions { display: grid; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { padding: 13px; font-size: 16px; }
.sheet-mini { display: flex; gap: 8px; margin-top: 10px; }
.sheet-note { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--sub); font-size: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%); z-index: 60;
  background: #23303d; color: #fff; border-radius: 12px; padding: 11px 16px;
  display: flex; align-items: center; gap: 12px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: fadein .15s;
}
.toast[hidden] { display: none; }
.toast-undo { background: #ffd479; color: #4a3600; border: none; border-radius: 8px; padding: 5px 12px; font-weight: 700; font-size: 13px; cursor: pointer; }
.toast-close { background: none; border: none; color: #9fb0c0; font-size: 14px; cursor: pointer; }

/* 空容器占位 */
.container-empty { color: #aab4bf; font-size: 13px; text-align: center; padding: 14px; }

/* 桌面适配 */
@media (min-width: 620px) {
  .view { padding-left: 18px; padding-right: 18px; }
  .container-card:hover { box-shadow: 0 2px 6px rgba(16,42,67,.1); }
}

/* ---------- AI 聊天页 ---------- */
.ai-banner {
  background: #fef3e0; border: 1px solid #f5d9a8; color: #8a5a10;
  font-size: 13px; border-radius: 12px; padding: 10px 12px; margin-bottom: 12px;
  line-height: 1.55;
}
.ai-msgs { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 140px; }
.ai-page { min-height: 40dvh; }
.ai-msg { display: flex; max-width: 88%; }
.ai-msg.user { align-self: flex-end; }
.ai-msg.bot { align-self: flex-start; }
.ai-bubble {
  padding: 10px 13px; border-radius: 16px; font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.ai-msg.user .ai-bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 5px; }
.ai-msg.bot .ai-bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.ai-msg.bot .ai-bubble.ai-err { background: #fdeaea; border-color: #f3c1c1; color: #a32d2d; }
.ai-msg .ai-bubble.ai-wait { color: var(--sub); font-size: 14px; }
.ai-inputbar {
  position: fixed; left: 0; right: 0; bottom: 58px; z-index: 45;
  max-width: 760px; margin: 0 auto;
  display: flex; gap: 8px; padding: 8px 12px 8px;
  background: linear-gradient(180deg, rgba(244,246,248,0), #f4f6f8 32%);
}
.ai-inputbar input { flex: 1; font-size: 16px; }
.ai-cam, .ai-send {
  border: none; border-radius: 12px; flex: none; cursor: pointer;
  font-family: inherit;
}
.ai-cam { width: 46px; font-size: 20px; background: #eef2f6; }
.ai-send { padding: 0 18px; font-size: 15px; font-weight: 700; background: var(--brand); color: #fff; }
.ai-send:disabled { opacity: .5; }
.ai-cam-btn-row { margin-bottom: 14px; }
.ai-tip { color: var(--sub); font-size: 13px; margin: 4px 2px 0; }

/* ---------- 拍照识别确认层 ---------- */
.photo-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 71;
  background: #fff; border-radius: 18px 18px 0 0;
  max-width: 760px; margin: 0 auto;
  display: flex; flex-direction: column;
  max-height: 86dvh;
  animation: slideup .18s ease-out;
}
.photo-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px 4px; }
.photo-title { font-size: 16px; font-weight: 700; flex: 1; }
.photo-sub { color: var(--sub); font-size: 13px; padding: 0 18px 6px; }
.photo-body { overflow-y: auto; padding: 4px 14px 10px; flex: 1; }
.pi-row {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  margin-bottom: 8px; background: #fbfcfd;
}
.pi-line1 { display: flex; gap: 6px; align-items: center; }
.pi-name { flex: 1; font-weight: 700; font-size: 15px; padding: 7px 9px; min-width: 0; }
.pi-line2 { display: flex; gap: 6px; margin-top: 7px; align-items: center; }
.pi-line2 .frm-input { font-size: 14px; padding: 6px 8px; }
.pi-qty { width: 62px; text-align: center; }
.pi-unit { width: 74px; }
.pi-cid { flex: 1; min-width: 0; }
.pi-shelf { font-size: 12px; color: var(--ok); margin-top: 6px; }
.photo-actions {
  display: flex; gap: 10px; padding: 8px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.photo-actions .btn { flex: 1; padding: 12px; font-size: 15px; }
.photo-loading { text-align: center; color: var(--sub); padding: 26px 14px; font-size: 14px; }

/* ---------- 管理页表单（sheet 内） ---------- */
.form-body { padding: 4px 2px; }
.fm-label { display: block; font-size: 13px; font-weight: 600; color: var(--sub); margin: 12px 2px 5px; }
.fm-label:first-child { margin-top: 2px; }
.fm-req { color: var(--bad); }
.fm-row { display: flex; gap: 10px; }
.fm-row > div { min-width: 0; }
#fdChips .chip { padding: 8px 12px; border-radius: 12px; text-align: center; line-height: 1.25; flex: 1; min-width: 96px; }
#fdChips .chip small { font-weight: 400; font-size: 11px; display: block; margin-top: 2px; color: var(--sub); }
#fdChips .chip.on small { color: var(--brand); }

/* ---------- 库存行：数量徽标 ---------- */
.b-qty {
  display: inline-block; background: var(--brand-soft); color: var(--brand);
  font-size: 11px; font-weight: 700; border-radius: 8px; padding: 1px 7px;
  margin-right: 6px; vertical-align: 1px; white-space: nowrap;
}
.tag.strong { background: var(--brand-soft); color: var(--brand); font-weight: 700; }

/* ---------- 购物页：建议补货放底部时的观感 ---------- */
.suggest-group { margin-top: 18px; border: 1.5px dashed var(--line); box-shadow: none; }
.suggest-group .shop-title { color: var(--sub); font-weight: 600; }
