:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1c2420;
  --text-2: #5f6b63;
  --text-3: #93a099;
  --line: #e6eae6;
  --accent: #2f7a58;
  --accent-soft: #e8f3ec;
  --warn: #b4711c;
  --warn-soft: #fdf2e0;
  --danger: #bb3f3f;
  --danger-soft: #fceceb;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { 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", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.locked { overflow: hidden; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(110px + var(--safe-b));
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: 19px; font-weight: 500;
  letter-spacing: 0;
}
.brand h1 { font-size: 18px; font-weight: 500; margin: 0; letter-spacing: .5px; }
.brand .sub { margin: 1px 0 0; font-size: 12px; color: var(--text-3); }
.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 11px;
  color: var(--text-2);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:active { background: #eef1ee; }

/* 提醒条 */
.alert-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--warn-soft);
  border: 1px solid #f0dcbb;
  color: #7d4f10;
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 13.5px;
  margin-bottom: 12px;
}
.alert-banner.show { display: flex; }
.alert-banner b { font-weight: 500; }
.alert-banner button {
  flex: none;
  border: none;
  background: #7d4f10;
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

/* 统计 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
}
.stat b { display: block; font-size: 24px; font-weight: 500; line-height: 1.15; }
.stat span { font-size: 12px; color: var(--text-3); }
.stat.warn { background: var(--warn-soft); border-color: #f3e2c6; }
.stat.warn b { color: var(--warn); }
.stat.danger { background: var(--danger-soft); border-color: #f5d5d2; }
.stat.danger b { color: var(--danger); }

/* 搜索 */
.searchbar {
  display: flex; align-items: center; gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  height: 42px;
  color: var(--text-3);
  margin-bottom: 10px;
}
.searchbar input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14.5px; color: var(--text); height: 100%;
}
.searchbar input::placeholder { color: var(--text-3); }
.searchbar input::-webkit-search-cancel-button { display: none; }

/* 筛选 chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding-bottom: 0; }
.chips button {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text-2);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}
.chips button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* 列表 */
.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
}
.card-photo {
  width: 52px; height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex: none;
  background: #eef1ee;
}
.card-photo.ph {
  display: grid; place-items: center;
  font-size: 12.5px;
  color: var(--text-3);
  letter-spacing: .5px;
}
.card-photo.ico {
  font-size: 23px;
  font-weight: 600;
  letter-spacing: 0;
  text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.detail-photo .ph.big.ico-big {
  font-size: 44px;
  font-weight: 600;
  text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.card-main { flex: 1; min-width: 0; cursor: pointer; }
.card-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.card-name {
  font-size: 15px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-sub {
  display: flex; align-items: center; gap: 8px;
  margin-top: 5px; font-size: 12.5px;
  overflow: hidden; white-space: nowrap;
}
.card-sub .dim { color: var(--text-3); }
.card-note {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.pill {
  flex: none;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 12px;
}

.tag {
  flex: none;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
}
.lvl-ok { background: #f0f2f0; color: var(--text-2); }
.lvl-near { background: #f0f2f0; color: var(--text-2); }
.lvl-soon { background: var(--warn-soft); color: var(--warn); }
.lvl-expired { background: var(--danger-soft); color: var(--danger); }
.lvl-disposed { background: #eef0ee; color: var(--text-3); }

.mini {
  flex: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-2);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.mini:active { background: #f0f2f0; }

/* 空态 */
.empty { text-align: center; padding: 56px 20px; color: var(--text-2); }
.empty p { margin: 6px 0; }
.empty .dim { color: var(--text-3); font-size: 13px; }
.empty-ico {
  width: 54px; height: 54px; margin: 0 auto 12px;
  border-radius: 50%;
  border: 1px dashed #cfd7d1;
  color: var(--text-3);
  font-size: 26px;
  display: grid; place-items: center;
}

.footnote {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
  margin: 22px 0 0;
  line-height: 1.7;
}

/* 悬浮按钮 */
.fab {
  position: fixed;
  right: 50%;
  transform: translateX(50%);
  bottom: calc(24px + var(--safe-b));
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(47, 122, 88, .28);
  cursor: pointer;
  z-index: 20;
}
@media (min-width: 600px) {
  .fab { right: calc(50% - 250px); transform: none; }
}
.fab:active { transform: translateX(50%) scale(.95); }
@media (min-width: 600px) { .fab:active { transform: scale(.95); } }

/* 遮罩与抽屉 */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 26, 22, .38);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
  z-index: 30;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  transform: translateY(102%);
  transition: transform .28s cubic-bezier(.32, .72, 0, 1);
  z-index: 40;
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}
.sheet.show { transform: translateY(0); }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  flex: none;
}
.sheet-head h2 { font-size: 16px; font-weight: 500; margin: 0; }
.sheet-head .spacer { width: 40px; }
.text-btn {
  border: none; background: transparent;
  color: var(--text-2); font-size: 14.5px;
  padding: 4px; cursor: pointer;
}
.text-btn.primary { color: var(--accent); font-weight: 500; }
.text-btn:disabled { opacity: .5; }

.sheet-body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(20px + var(--safe-b));
}
.sheet-foot {
  flex: none;
  display: flex; gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.btn-ghost {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text-2);
  border-radius: 11px;
  padding: 11px 8px;
  font-size: 14.5px;
  cursor: pointer;
}
.btn-ghost.danger { color: var(--danger); }
.btn-solid {
  flex: 1.4;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 11px;
  padding: 11px 8px;
  font-size: 14.5px;
  cursor: pointer;
}

/* 表单 */
.photo-box { margin-bottom: 10px; }
.photo-box:empty { display: none; }
.photo-box {
  position: relative;
  cursor: pointer;
}
.photo-box img {
  width: 100%;
  max-height: 190px;
  object-fit: contain;
  background: #eef1ee;
  border-radius: 12px;
  display: block;
}
.ph-hint {
  position: absolute;
  right: 8px; bottom: 8px;
  background: rgba(20, 26, 22, .62);
  color: #fff;
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 999px;
}

.scan-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px dashed #c3d3c8;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 12px;
  padding: 12px;
  font-size: 14.5px;
  cursor: pointer;
  margin-bottom: 14px;
}
.scan-btn:active { background: #dcefe4; }

.scan-row { display: flex; gap: 10px; margin-bottom: 14px; }
.scan-row .scan-btn { margin-bottom: 0; flex: 1; }
.scan-btn.alt { background: #fff; border-style: solid; border-color: var(--line); color: var(--text-2); }
.scan-btn.alt:active { background: #f0f2f0; }

.barcode-strip { margin-bottom: 14px; }
.barcode-strip:empty { display: none; }
.barcode-strip {
  display: flex; align-items: center; gap: 8px;
  background: #eef1ee;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}
.barcode-strip .bc-label { font-family: inherit; color: var(--text-3); flex: none; }
.barcode-strip .bc-x {
  margin-left: auto; flex: none;
  border: none; background: transparent;
  color: var(--text-3); font-size: 18px; line-height: 1;
  cursor: pointer; padding: 0 2px;
}

/* 扫码 */
.scan-body { text-align: center; }
.cam-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 46vh;
  background: #1c2420;
  border-radius: 12px;
  overflow: hidden;
}
#scanVideo { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-frame {
  position: absolute;
  left: 12%; right: 12%;
  top: 50%;
  transform: translateY(-50%);
  height: 62px;
  border: 2px solid rgba(255, 255, 255, .9);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .28);
}
.scan-tip { font-size: 13.5px; color: var(--text-2); margin: 14px 0 6px; }
.scan-tip.err { color: var(--danger); }
.scan-body .hint { text-align: left; margin-bottom: 14px; }
.scan-body .btn-ghost { width: 100%; }

.ai-panel { margin-bottom: 14px; }
.ai-panel:empty { display: none; }
.ai-loading, .ai-ok, .ai-fail {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
}
.ai-loading { background: #eef1ee; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.ai-ok { background: var(--accent-soft); color: #235c42; }
.ai-warn { background: var(--warn-soft); color: #7d4f10; }
.ai-fail { background: var(--warn-soft); color: #7d4f10; }
.spinner {
  width: 13px; height: 13px;
  border: 2px solid #cfd7d1;
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.suggest {
  display: none;
  margin-top: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 11px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
.suggest.show { display: block; }
.sg-item { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.sg-item:last-child { border-bottom: none; }
.sg-item:active { background: var(--accent-soft); }
.sg-name { font-size: 14.5px; color: var(--text-1); display: flex; align-items: center; gap: 6px; }
.sg-bc {
  font-size: 11px; color: #235c42; background: var(--accent-soft);
  border-radius: 5px; padding: 1px 5px; flex: none;
}
.sg-sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

.dict-info { display: none; margin-bottom: 14px; }
.dict-info.show { display: block; }
.dict-info .di-in {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--accent-soft); color: #235c42;
  border-radius: 10px; padding: 9px 12px; font-size: 13px; line-height: 1.5;
}
.dict-info .di-tag { flex: none; font-size: 11px; opacity: 0.75; padding-top: 1px; }

/* 身份选择 */
.id-lead { font-size: 13.5px; color: var(--text-2); margin: 0 0 10px; line-height: 1.6; }
.chips.wrap { margin-bottom: 6px; }
.chips button i {
  font-style: normal; font-size: 11px; opacity: 0.6; margin-left: 4px;
}
.chip-empty { font-size: 13px; color: var(--text-3); padding: 4px 0 8px; display: block; }
.family-info { border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; }
.fi-row { font-size: 14px; color: var(--text-1); margin: 2px 0; }
.fi-row.dim { font-size: 13px; color: var(--text-3); }
.fi-row b { color: var(--text-1); }

.field { display: block; margin-bottom: 14px; position: relative; }
.field > span {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field > span i { color: var(--danger); font-style: normal; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 11px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
  -webkit-appearance: none;
  appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235f6b63' stroke-width='2.4' stroke-linecap='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.field textarea { resize: none; line-height: 1.55; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #a8cbb8; }
.field input.invalid, .field textarea.invalid { border-color: #e5a3a0; background: #fdf7f7; }
.field em {
  display: block;
  font-style: normal;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 6px;
  line-height: 1.55;
}
.field textarea[readonly] { background: #f0f2f0; color: var(--text-2); font-size: 13px; }

.row2 { display: flex; gap: 10px; }
.row2 .field { flex: 1; }
.row2 .field.narrow { flex: 0 0 96px; }

.hint {
  font-size: 12px;
  color: var(--text-3);
  margin: 4px 0 0;
  line-height: 1.6;
}

.digest-actions { margin-top: 8px; }
.digest-actions .btn-ghost { padding: 8px; font-size: 13px; }

/* 详情 */
.detail-photo { margin-bottom: 14px; }
.detail-photo img {
  width: 100%;
  max-height: 210px;
  object-fit: contain;
  border-radius: 12px;
  background: #eef1ee;
  display: block;
}
.detail-photo .ph.big {
  height: 110px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: #eef1ee;
  color: var(--text-3);
  font-size: 13px;
}
.kv {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.kv:last-of-type { border-bottom: none; }
.kv span { color: var(--text-2); flex: none; }
.kv b { font-weight: 400; text-align: right; word-break: break-all; }
.disclaim {
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.7;
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translate(-50%, 12px);
  background: rgba(28, 36, 32, .92);
  color: #fff;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  max-width: 82vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
