:root {
  --primary: #8c3b2e;
  --primary-dark: #6e2c22;
  --accent: #e8a33d;
  --bg: #f7f2ec;
  --card: #ffffff;
  --text: #33261f;
  --text-sub: #8a7a6e;
  --border: #e7ddd2;
  --danger: #c0392b;
  --ok: #2e7d4f;
  --warn: #b8860b;
  --radius: 14px;
  --tabbar-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--primary); color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.top-count { font-size: 13px; opacity: .85; }

main { padding: 12px 14px 20px; max-width: 640px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ---------- 搜索 & 分类筛选 ---------- */
.searchbar input {
  width: 100%; padding: 10px 14px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); outline: none;
}
.searchbar input:focus { border-color: var(--primary); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 6px 14px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--card); color: var(--text-sub); cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- 网格卡片 ---------- */
.grid {
  margin-top: 10px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.card-item {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 4px rgba(60,40,20,.08); cursor: pointer;
  transition: transform .12s ease;
}
.card-item:active { transform: scale(.97); }
.card-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #eee; }
.card-item .ci-body { padding: 8px 10px 10px; }
.card-item .ci-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-item .ci-cat { font-size: 12px; color: var(--accent); margin-top: 2px; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-sub); font-size: 14px; }
.empty-icon { font-size: 44px; margin-bottom: 12px; }

/* ---------- 识别页 ---------- */
.rec-intro { text-align: center; color: var(--text-sub); font-size: 14px; line-height: 1.7; margin: 24px 0 20px; }
.big-capture {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  width: 180px; height: 180px; margin: 0 auto;
  border-radius: 50%; background: linear-gradient(145deg, var(--primary), var(--primary-dark));
  color: #fff; font-size: 17px; font-weight: 600; cursor: pointer;
  box-shadow: 0 8px 24px rgba(140,59,46,.35);
}
.big-capture:active { transform: scale(.96); }
.big-capture-icon { font-size: 44px; }

#recResult { margin-top: 24px; }
.verdict {
  border-radius: var(--radius); padding: 14px 16px; font-size: 15px; font-weight: 600;
  margin-bottom: 14px; text-align: center;
}
.verdict.dup { background: #fdecea; color: var(--danger); }
.verdict.maybe { background: #fdf6e3; color: var(--warn); }
.verdict.new { background: #e8f5ee; color: var(--ok); }

.rec-query { display: flex; justify-content: center; margin-bottom: 14px; }
.rec-query img { width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius); border: 2px solid var(--border); }

.match-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); padding: 10px;
  margin-bottom: 10px; cursor: pointer; box-shadow: 0 1px 4px rgba(60,40,20,.08);
}
.match-row img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: #eee; }
.match-info { flex: 1; min-width: 0; }
.match-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.match-score { font-size: 15px; font-weight: 700; }
.score-hi { color: var(--danger); }
.score-mid { color: var(--warn); }
.score-lo { color: var(--text-sub); }

/* ---------- 分类管理 ---------- */
.hint { font-size: 13px; color: var(--text-sub); line-height: 1.7; margin-bottom: 12px; }
.cat-list { margin-bottom: 14px; }
.cat-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; box-shadow: 0 1px 4px rgba(60,40,20,.08);
}
.cat-name { flex: 1; font-size: 15px; font-weight: 500; }
.cat-count { font-size: 12px; color: var(--text-sub); }
.icon-btn {
  border: none; background: var(--bg); border-radius: 8px;
  width: 34px; height: 34px; font-size: 15px; cursor: pointer;
}

/* ---------- 设置页 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(60,40,20,.08);
}
.card h3 { font-size: 15px; margin-bottom: 10px; }
.stat-text { font-size: 14px; line-height: 1.8; color: var(--text-sub); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 20px; font-size: 15px; font-weight: 600;
  border-radius: 999px; border: none; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-outline { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-danger { background: #fdecea; color: var(--danger); }
.btn-block { width: 100%; margin-top: 10px; }

/* ---------- 悬浮按钮 ---------- */
#fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(145deg, var(--accent), #d18b26);
  color: #fff; font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 18px rgba(232,163,61,.45); z-index: 25;
}
#fab:active { transform: scale(.94); }

/* ---------- 底部标签栏 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: none; background: none; font-size: 11px; color: var(--text-sub); cursor: pointer;
}
.tab.active { color: var(--primary); font-weight: 600; }
.tab-icon { font-size: 20px; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(30,20,15,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh;
  background: var(--bg); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px;
}
.sheet-head h2 { font-size: 17px; }
.close-btn { border: none; background: var(--border); border-radius: 50%; width: 30px; height: 30px; font-size: 14px; cursor: pointer; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 18px 10px; }
.sheet-foot {
  display: flex; gap: 10px; padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.sheet-foot .btn { flex: 1; }

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); outline: none; font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }

/* ---------- 照片行 ---------- */
.photo-row { display: flex; gap: 10px; overflow-x: auto; padding: 6px 0 12px; }
.photo-thumb { position: relative; flex: 0 0 auto; }
.photo-thumb img { width: 86px; height: 86px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); display: block; }
.photo-del {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%; border: none;
  background: var(--danger); color: #fff; font-size: 12px; line-height: 1; cursor: pointer;
}
.photo-add {
  flex: 0 0 auto; width: 86px; height: 86px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1.5px dashed var(--primary); border-radius: 12px;
  color: var(--primary); cursor: pointer; background: rgba(140,59,46,.04);
}
.photo-add span { font-size: 22px; }
.photo-add small { font-size: 11px; }

.dup-warn {
  display: flex; align-items: center; gap: 10px;
  background: #fdf6e3; border: 1px solid #f0dfae; border-radius: 12px;
  padding: 10px 12px; margin-bottom: 14px; font-size: 13px; color: var(--warn);
}
.dup-warn img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; }

/* ---------- 详情 ---------- */
.detail-photos { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; }
.detail-photos img { height: 220px; border-radius: var(--radius); flex: 0 0 auto; max-width: 100%; object-fit: contain; background: #fff; }
.detail-info p { font-size: 14px; line-height: 2; border-bottom: 1px dashed var(--border); padding: 4px 0; }
.detail-info p b { color: var(--text-sub); font-weight: 500; margin-right: 10px; }

.loading { text-align: center; color: var(--text-sub); padding: 20px; font-size: 14px; }

/* ---------- 居中对话框 & 轻提示 ---------- */
.modal.dlg { align-items: center; padding: 0 30px; }
.dlg-box { width: 100%; max-width: 340px; background: var(--card); border-radius: 16px; padding: 20px 18px 16px; animation: fadein .15s ease; }
.dlg-box h3 { font-size: 16px; margin-bottom: 12px; }
.dlg-box p { font-size: 13px; color: var(--text-sub); line-height: 1.6; margin-bottom: 10px; }
.dlg-box input { width: 100%; padding: 10px 12px; font-size: 15px; border: 1px solid var(--border); border-radius: 10px; outline: none; font-family: inherit; }
.dlg-box input:focus { border-color: var(--primary); }
.dlg-btns { display: flex; gap: 10px; margin-top: 16px; }
.dlg-btns .btn { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 30px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 99;
  background: rgba(40,30,25,.88); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; white-space: nowrap;
}

/* ---------- 访问密码锁（纯空白，不暴露项目信息） ---------- */
.lock-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
}
.lock-screen[hidden] { display: none; }
.lock-screen input {
  width: 150px; padding: 8px 4px; font-size: 16px;
  text-align: center; letter-spacing: 4px;
  border: none; border-bottom: 1px solid #e5e5e5; border-radius: 0;
  background: transparent; outline: none; color: #999;
}
.lock-screen input:focus { border-bottom-color: #ccc; }
