/* ============ 设计变量 ============ */
:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --surface-2: #efeae3;
  --ink: #221f1c;
  --text: #2c2926;
  --muted: #8d867e;
  --line: #e6e0d7;
  --accent: #b5653f;
  --accent-soft: #f5e6dd;
  --danger: #c0392b;

  --fit-tight: #c0453c;
  --fit-slightly-tight: #d1812f;
  --fit-body: #c9a227;
  --fit-close: #4a8f8f;
  --fit-perfect: #3f7d52;

  --radius: 18px;
  --tabbar-h: 58px;
  --topbar-h: 96px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

#app { max-width: 620px; margin: 0 auto; }

.subtle { color: var(--muted); font-size: 13px; margin: 0; }

/* ============ 顶栏 ============ */
#topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(var(--safe-t) + 8px) 16px 8px;
  background: rgba(246, 244, 241, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
#topbar.scrolled { border-bottom-color: var(--line); }

.topbar-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}
#topbar-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.6px;
  line-height: 1.15;
}
#topbar-sub { margin-top: 2px; }
#topbar-actions { display: flex; gap: 8px; padding-bottom: 4px; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#search-wrap { margin-top: 10px; }
#search {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
#search::-webkit-search-cancel-button { -webkit-appearance: none; }
#search:focus { outline: 2px solid var(--accent-soft); outline-offset: 0; }

/* ============ 主区 ============ */
#view { padding: 14px 16px 8px; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 16px 2px;
  margin: 0 -16px 14px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text);
  transition: background 0.15s, color 0.15s;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .n { opacity: 0.55; font-size: 12px; margin-left: 4px; }

/* 网格 */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(34, 31, 28, 0.04);
  text-align: left;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease;
}
.card .thumb { flex: 0 0 auto; }
.card .card-body { flex: 1 1 auto; }
.card:active { transform: scale(0.975); }

.thumb {
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 38px;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 9px 11px 12px; }
.card-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.size-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text);
}
.fit-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.fit-text { font-size: 12px; color: var(--muted); }
.price { font-size: 13px; font-weight: 600; color: var(--accent); margin-left: auto; }

/* 空状态 */
.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--muted);
}
.empty .emoji { font-size: 46px; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; font-size: 17px; color: var(--text); font-weight: 600; }
.empty p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; }

/* 统计条 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}
.stat .v { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.stat .k { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-danger { background: transparent; border-color: #e8c8c4; color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 13px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ============ 表单 ============ */
.field { margin-bottom: 18px; }
.label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
  letter-spacing: 0.2px;
}
.label .hint { font-weight: 400; font-size: 12px; opacity: 0.8; }

.input, .textarea, .select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: #b8b1a8; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* 照片位 */
.photo-slot {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  border: 1.5px dashed #d6cfc5;
  background: var(--surface);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
}
.photo-slot.has-img { border-style: solid; border-color: var(--line); }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot .ph-inner { text-align: center; padding: 10px 8px; max-width: 100%; }
.photo-slot .ph-icon { font-size: 25px; display: block; margin-bottom: 3px; }
.photo-slot .ph-text { font-size: 11px; line-height: 1.35; display: block; }
.photo-slot .clear {
  position: absolute;
  top: 8px; right: 8px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 15px;
  display: grid;
  place-items: center;
  -webkit-backdrop-filter: blur(4px);
}

/* 合身度 */
.fit-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.fit-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}
.fit-opt .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.fit-opt.active { border-color: var(--ink); background: #fdfcfa; box-shadow: inset 0 0 0 1px var(--ink); }

/* 尺寸项 */
.meas-list { display: flex; flex-direction: column; gap: 8px; }
.meas-row { display: grid; grid-template-columns: 1fr 88px 34px; gap: 8px; align-items: center; }
.meas-del {
  height: 40px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 18px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
}

/* ============ 详情 ============ */
.hero {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 72px;
  margin-bottom: 16px;
}
.hero img { width: 100%; height: 100%; object-fit: cover; }
.hero.hero-empty {
  aspect-ratio: 4 / 3;
  font-size: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.hero-wrap { position: relative; margin-bottom: 16px; }
.hero-wrap .hero { margin-bottom: 0; }

.tag-wrap { position: relative; margin-bottom: 16px; }

.photo-pill {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 17, 15, 0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.photo-pill:active { opacity: 0.75; }

.detail-title { margin: 0 0 4px; font-size: 24px; font-weight: 700; letter-spacing: -0.4px; }

.badge-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
}

.spec-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 16px;
}
.spec {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.spec:last-child { border-bottom: none; }
.spec .k { color: var(--muted); flex: 0 0 auto; }
.spec .v { text-align: right; font-weight: 500; word-break: break-word; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.4px;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.tag-photo {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  overflow: hidden;
}

.detail-actions { display: flex; gap: 10px; margin-top: 20px; }
.detail-actions .btn { flex: 1; }

/* ============ 设置 ============ */
.set-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 18px;
}
.set-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 14px;
  font-size: 15px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.set-item:last-child { border-bottom: none; }
.set-item .v { color: var(--muted); font-size: 14px; flex: 0 0 auto; }
.set-item .chev { color: #c9c2b9; font-size: 17px; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.on { background: var(--fit-perfect); }
.status-dot.off { background: var(--fit-tight); }
.status-dot.warn { background: var(--fit-slightly-tight); }

/* ============ 底部导航 ============ */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: rgba(250, 248, 246, 0.94);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
#tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: #a49c93;
  font-weight: 500;
}
#tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#tabbar a.active { color: var(--ink); }
#tabbar a.active svg { stroke-width: 2; }

/* ============ 浮层 ============ */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(12, 10, 9, 0.96);
  display: grid;
  place-items: center;
  padding: 16px;
}
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }

#sheet {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: rgba(20, 17, 15, 0.4);
  display: flex;
  align-items: flex-end;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.sheet-card {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(20px + var(--safe-b));
  animation: sheetUp 0.22s ease-out;
}
@keyframes sheetUp { from { transform: translateY(18px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-card h3 { margin: 0 0 6px; font-size: 18px; font-weight: 700; }
.sheet-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 18px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 22px);
  transform: translateX(-50%) translateY(10px);
  z-index: 100;
  max-width: 84vw;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(34, 31, 28, 0.93);
  color: #fff;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 表单底部固定条：要浮在底部导航上方，不能被挡住 */
.form-footer {
  position: sticky;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 6px);
  z-index: 20;
  padding: 14px 0 8px;
  margin-top: 24px;
  background: linear-gradient(to top, var(--bg) 72%, rgba(246, 244, 241, 0));
}

/* 识别进度 */
.ocr-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-top: 10px;
  font-size: 13px;
}
.ocr-box .ocr-raw {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow: auto;
  color: #6b645c;
}
.ocr-cands { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.ocr-cand {
  padding: 6px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.ocr-cand:active { background: var(--accent-soft); }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.no-anim { animation: none !important; }

.cat-emoji { margin-right: 4px; }
