:root {
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --ink: #1f2430;
  --ink-soft: #6b7280;
  --line: #e6e9f0;
  --brand: #4361ee;
  --brand-soft: #eaeffa;
  --danger: #e5484d;
  --ok: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* touch-action: manipulation 关掉移动端双击缩放，连点 +/- 时不再忽大忽小 */
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-left { flex: 0 0 auto; }
.topbar-center { flex: 1 1 auto; display: flex; justify-content: center; }
.topbar-right { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }

.brand {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: .5px;
}

.search-box {
  position: relative;
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  font-size: 14px;
  opacity: .6;
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, .12);
}
.search-clear {
  position: absolute;
  right: 10px;
  border: none;
  background: #e8ebf3;
  color: #555;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.ghost-btn:hover { background: #f6f8fc; border-color: #d3d9e6; }

.primary-btn {
  border: none;
  background: var(--brand);
  color: #fff;
  height: 36px;
  padding: 0 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  transition: filter .15s;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:disabled { opacity: .5; cursor: not-allowed; }

.cart-btn {
  position: relative;
  border: 1px solid var(--line);
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 18px;
}
.cart-btn:hover { background: #f6f8fc; }
.cart-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 700;
}

/* ---------- 分类栏 ---------- */
.category-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
  background: rgba(244, 246, 251, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px 0;
}
.chip-row {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 10px;
}
.chip-row-sub { padding-top: 0; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .12s;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.chip .count {
  font-size: 11px;
  background: rgba(0, 0, 0, .06);
  border-radius: 999px;
  padding: 0 6px;
  line-height: 16px;
  color: inherit;
  opacity: .85;
}
.chip.active .count { background: rgba(255, 255, 255, .25); }
.chip-sub {
  height: 28px;
  font-size: 12px;
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand);
}
.chip-sub.active { background: var(--brand); color: #fff; }

/* ---------- 结果统计 ---------- */
.result-bar {
  max-width: 1320px;
  margin: 16px auto 0;
  padding: 0 20px;
  color: var(--ink-soft);
  font-size: 13px;
}

/* ---------- 商品网格 ---------- */
.grid {
  max-width: 1320px;
  margin: 12px auto 60px;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);   /* 所有屏幕固定每行 3 个，卡片宽度自适应 */
  gap: 14px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 14px rgba(16, 24, 40, .10), 0 14px 36px rgba(16, 24, 40, .10);
}

/* 无图片：用名称首字 + 渐变色块当封面 */
.card-cover {
  position: relative;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 800;
  color: rgba(255, 255, 255, .92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .12);
  user-select: none;
}

.new-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #fff;
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  text-shadow: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.card-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  min-height: 38px;
  /* 名称完整显示：不再截断，长名换行、卡片自适应增高；超长无空格串也强制换行不溢出 */
  overflow-wrap: anywhere;
  word-break: break-word;
}
.card-barcode {
  font-size: 11px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  letter-spacing: .3px;
}

.card-stepper {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  height: 34px;
}
.card-stepper.active { border-color: var(--brand); }
.card-step {
  border: none;
  background: var(--brand-soft);
  color: var(--brand);
  width: 40px;
  height: 100%;
  font-size: 20px;
  line-height: 1;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.card-step:hover:not(:disabled) { background: var(--brand); color: #fff; }
.card-step:disabled { color: var(--line); cursor: default; background: #fafafa; }
.card-qty {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 16px;            /* ≥16px 防 iOS 聚焦时自动放大 */
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  border: none;
  background: transparent;
  outline: none;
  padding: 0;
  touch-action: manipulation;
  -moz-appearance: textfield;
}

.empty-state {
  max-width: 1320px;
  margin: 40px auto;
  padding: 40px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 15px;
}

/* ---------- 购物车面板 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 40;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.cart-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  max-width: 90vw;
  background: #fff;
  z-index: 50;
  box-shadow: -8px 0 30px rgba(16, 24, 40, .14);
  transform: translateX(100%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
}
.cart-panel.open { transform: translateX(0); }

.cart-header {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.cart-title { font-weight: 700; font-size: 15px; }
#cartTitleCount { color: var(--danger); }

.cart-list { flex: 1; overflow-y: auto; padding: 8px 12px; }
.cart-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

.cart-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--line);
}
.ci-info { flex: 1; min-width: 0; }
.ci-name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.ci-meta { font-size: 11px; color: var(--ink-soft); margin-top: 3px; }
.ci-del {
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--ink-soft);
  padding: 4px;
}
.ci-del:hover { color: var(--danger); }

.qty {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.qty button {
  border: none;
  background: var(--brand-soft);
  color: var(--brand);
  width: 28px;
  height: 28px;
  font-size: 16px;
  line-height: 1;
}
.qty button:hover { background: var(--brand); color: #fff; }
.qty input {
  width: 44px;
  min-width: 44px;
  text-align: center;
  font-size: 16px;            /* ≥16px 防 iOS 聚焦时自动放大 */
  font-variant-numeric: tabular-nums;
  border: none;
  outline: none;
  background: transparent;
  padding: 0;
  touch-action: manipulation;
  -moz-appearance: textfield;
}

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade .15s ease;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25);
}
.modal-wide { max-width: 640px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-title { margin: 0 0 6px; font-size: 18px; }
.modal-sub { margin: 0 0 16px; font-size: 13px; color: var(--ink-soft); }
.modal-head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head-row .modal-title { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field span { color: var(--ink-soft); }
.field input {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 12px;
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(67, 97, 238, .12); }

.submit-summary {
  margin: 16px 0;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink);
}
.submit-summary .row { display: flex; justify-content: space-between; padding: 3px 0; }
.submit-summary .row span:last-child { color: var(--ink-soft); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- 记录 ---------- */
.records-list { overflow-y: auto; flex: 1; }
.record {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.record-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.record-person { font-weight: 700; font-size: 14px; }
.record-time { font-size: 12px; color: var(--ink-soft); }
.record-items { font-size: 13px; color: var(--ink); line-height: 1.7; }
.record-items .tag {
  display: inline-block;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: 6px;
  padding: 1px 8px;
  margin: 2px 4px 2px 0;
  font-size: 12px;
}
.records-empty { padding: 40px; text-align: center; color: var(--ink-soft); }

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 36, 48, .94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  box-shadow: var(--shadow);
  animation: toastin .2s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- AI 分类结果 ---------- */
.ai-cat-result {
  margin: 14px 0 0;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  border: 1px solid var(--line);
}
.ai-result-ok { color: var(--ok); font-weight: 700; margin-bottom: 6px; }
.ai-result-err { color: var(--danger); font-weight: 700; }
.ai-result-stats { color: var(--ink); line-height: 1.8; }
.ai-result-uncat { color: var(--ink-soft); margin-top: 6px; font-size: 12px; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .topbar-center { order: 3; flex-basis: 100%; }
  .brand { font-size: 16px; }
  /* 手机竖屏：每行 3 个，整体缩小但名称仍完整显示 */
  .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 10px; }
  .card-cover { height: 68px; font-size: 24px; }
  .card-body { padding: 8px 7px 9px; gap: 4px; }
  .card-name { font-size: 12px; line-height: 1.3; min-height: 31px; }
  .card-barcode { font-size: 10px; }
  .card-stepper { height: 30px; }
  .card-step { width: 28px; font-size: 17px; }
  .card-qty { font-size: 16px; }   /* 仍保持 16px 防聚焦缩放 */
}
