:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --text: #1c1b19;
  --muted: #6b6862;
  --line: #e2e0da;
  --accent: #1f6f5c;
  --accent-soft: #e3efe9;
  --warn: #a8641a;
  --warn-soft: #fbf0e0;
  --danger: #b03a2e;
  --danger-soft: #fbe9e7;
  --cat-food: #a8641a;       --cat-food-bg: #fbf0e0;
  --cat-medicine: #2f5f9e;   --cat-medicine-bg: #e8f0fb;
  --cat-pet: #7a4a9e;        --cat-pet-bg: #f3eafb;
  --cat-child: #b0476f;      --cat-child-bg: #fbe8ef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28,27,25,.06), 0 4px 14px rgba(28,27,25,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --surface: #1f2225;
    --surface-2: #262a2e;
    --text: #ecebe8;
    --muted: #9b9891;
    --line: #33383d;
    --accent: #58b79c;
    --accent-soft: #1d3330;
    --warn: #dda85c;
    --warn-soft: #33291a;
    --danger: #e08b80;
    --danger-soft: #33211f;
    --cat-food: #dda85c;       --cat-food-bg: #33291a;
    --cat-medicine: #7fb0e8;   --cat-medicine-bg: #1c2a3a;
    --cat-pet: #c09ae8;        --cat-pet-bg: #2b2138;
    --cat-child: #e89ab5;      --cat-child-bg: #38202a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  }
}

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

/* hidden 必须真的隐藏。浏览器默认样式给的是 display:none，但作者样式里任何
   display 声明都会盖掉它——.modal 的 display:flex 就让两个空弹框一直浮在页面上。
   放在最前面、带 !important，谁再加 display 都不会把它顶掉。 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 19px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; color: var(--muted); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- 顶栏 --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  font-size: 20px; padding: 4px 6px; cursor: pointer; border-radius: 8px;
}

.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 600;
}
.badge-off { background: var(--surface-2); color: var(--muted); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

/* --- 布局 --- */
#view { padding: 16px 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 720px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.row { display: flex; gap: 8px; align-items: center; }

input[type=text], input[type=search], input[type=number], select {
  flex: 1; min-width: 0;
  padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 16px; /* iOS 防缩放 */
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  border: none; border-radius: 11px; padding: 11px 15px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { filter: brightness(.92); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:active { filter: brightness(.95); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:active { filter: brightness(.95); }
.btn:disabled { opacity: .5; }

/* --- 录音 --- */
.record-stage { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px 0 8px; }
.rec-btn {
  width: 156px; height: 156px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 34%, transparent);
  transition: transform .12s ease, box-shadow .12s ease;
  touch-action: none; user-select: none;
}
.rec-btn:active, .rec-btn.recording { transform: scale(.94); }
.rec-btn.recording {
  background: var(--danger);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 60%, transparent);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 55%, transparent); }
  70% { box-shadow: 0 0 0 22px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.rec-btn.busy { background: var(--muted); pointer-events: none; }
.rec-icon { font-size: 42px; line-height: 1; }
.rec-label { font-size: 14px; font-weight: 600; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 0; max-width: 320px; }
.rec-status {
  font-size: 14px; padding: 9px 14px; border-radius: 10px;
  background: var(--surface-2); color: var(--text); text-align: center;
}
.text-fallback { margin-top: 20px; }

/* --- 卡片 --- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h3 { margin-bottom: 10px; }

.drafts { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }

.draft {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  animation: fade .2s ease;
}
.draft.need-confirm { border-left-color: var(--warn); background: var(--warn-soft); }
.draft.committed { border-left-color: var(--accent); background: var(--accent-soft); }
.draft-title { font-size: 16px; font-weight: 650; margin-bottom: 4px; }
.draft-meta { font-size: 13px; color: var(--muted); }
.draft-reason { font-size: 13px; color: var(--warn); margin-top: 6px; font-weight: 600; }
.draft-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.draft-actions .btn { padding: 9px 13px; font-size: 14px; }

.transcript {
  font-size: 14px; color: var(--muted); margin-bottom: 4px;
  padding: 8px 12px; background: var(--surface-2); border-radius: 10px;
}

.query-result {
  margin-top: 16px; padding: 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  font-size: 16px; line-height: 1.6;
}

/* --- 清单 --- */
.list-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.shopping-list { display: flex; flex-direction: column; gap: 8px; }

.shop-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; box-shadow: var(--shadow);
}
.shop-item.checked { opacity: .55; }
.shop-item.checked .shop-name { text-decoration: line-through; }
.shop-item.stale { opacity: .45; }

.checkbox {
  width: 26px; height: 26px; min-width: 26px; border-radius: 8px;
  border: 2px solid var(--line); background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 16px; font-weight: 700;
}
.shop-item.checked .checkbox { background: var(--accent); border-color: var(--accent); color: #fff; }

.shop-main { flex: 1; min-width: 0; }
.shop-name { font-weight: 600; font-size: 16px; }
.shop-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tag {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); margin-right: 6px; font-weight: 600;
}
.tag.missing { background: var(--danger-soft); color: var(--danger); }
.tag.estimated { background: var(--warn-soft); color: var(--warn); }
.tag.predicted { background: var(--accent-soft); color: var(--accent); }

/* 分类标签：五个分类各一色，和类型标签（灰底）区分开。
   分类是组织维度，颜色只用于扫视，不承载状态含义。 */
.tag.cat-food { background: var(--cat-food-bg); color: var(--cat-food); }
.tag.cat-daily { background: var(--accent-soft); color: var(--accent); }
.tag.cat-medicine { background: var(--cat-medicine-bg); color: var(--cat-medicine); }
.tag.cat-pet { background: var(--cat-pet-bg); color: var(--cat-pet); }
.tag.cat-child { background: var(--cat-child-bg); color: var(--cat-child); }

/* --- 物品 --- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 2px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.chip:active { background: var(--surface-2); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-icon { font-size: 14px; line-height: 1; }

.items-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px;
}
.item-row:active { background: var(--surface-2); }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 600; }
.item-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; min-width: 9px; background: var(--line); }
.dot.to_buy { background: var(--danger); }
.dot.near_expiry { background: var(--warn); }
.dot.in_use { background: var(--accent); }

/* --- 设置 --- */
.kv { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.kv > div, .kv > span { display: flex; justify-content: space-between; gap: 12px; }
.kv b { font-weight: 600; }

/* --- 底栏 --- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 9px 0 8px; font-size: 11px; font-family: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative;
}
.tabbtn span { font-size: 21px; line-height: 1; }
.tabbtn.active { color: var(--accent); font-weight: 600; }
.pill {
  position: absolute; top: 4px; right: 50%; margin-right: -26px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
}

/* --- 提示 / 弹窗 --- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 90;   /* 压过弹框 */
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); max-width: 88vw; text-align: center;
}

.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.42); padding: 20px;
}
/* 物品详情是 #sheet，它上面还要再弹一层输入框（登记位置、加别名……）。
   两者都是 .modal、z-index 相同，DOM 里 #modal 在前就会被 #sheet 盖住——
   于是输入框藏在详情页背后，得先关掉详情页才看得见。给 #modal 抬高一层。 */
#modal { z-index: 70; }
.modal-box {
  background: var(--surface); border-radius: 18px; padding: 20px;
  width: 100%; max-width: 420px; box-shadow: 0 18px 50px rgba(0,0,0,.3);
  max-height: 82vh; overflow-y: auto;
}
.modal-box h3 { margin-bottom: 14px; color: var(--text); font-size: 17px; }
.modal-box p { margin: 0 0 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn { flex: 0 0 auto; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field select { width: 100%; }

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