:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e8eaee;
  --text: #14161a;
  --muted: #8b919c;
  --accent: #2f6fed;
  --accent-soft: #e8f0ff;
  --ok: #12a06b;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

/* 连点两下不要放大页面（Safari 会忽略 user-scalable=no，得靠这个） */
html, body { touch-action: manipulation; }
button, input, .step, .btn, .row, .chip, .scan-btn, .export-btn, .mgr-op, .bind-item {
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: contain; }

.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  background: rgba(245, 246, 248, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.titles { min-width: 0; flex: 1; }

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.export-btn {
  flex: none;
  height: 34px;
  padding: 0 16px;
  border: none;
  border-radius: 17px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.export-btn:active { opacity: 0.8; }

.export-btn.ghost {
  background: #eef1f6;
  color: #455;
}

/* ---------- 品类管理 ---------- */
.mgr-bar {
  display: flex;
  gap: 8px;
  padding: 4px 18px 8px;
}
.mgr-bar .btn { flex: 1; }

.mgr-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 18px 10px;
}
.mgr-form input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  outline: none;
}
.mgr-form input:focus { border-color: #c6d6f5; }
.mgr-form-actions { display: flex; gap: 8px; }
.mgr-form-actions .btn { flex: 1; }

.mgr-list {
  max-height: 46vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 8px;
}

.mgr-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}
.mgr-row:last-child { border-bottom: none; }

.mgr-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.3;
  word-break: break-all;
}
.mgr-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.mgr-op {
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #556;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}
.mgr-op:active { background: #f2f4f8; }
.mgr-op[disabled] { opacity: 0.3; }
.mgr-op.del { color: #c0392b; border-color: #f0d5d2; }

/* ---------- 搜索 ---------- */
.searchbar { padding: 10px 16px 4px; }

#search {
  width: 100%;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
}
#search:focus { border-color: #c6d6f5; }

/* ---------- 手动输条码 ---------- */
.codebar {
  display: flex;
  gap: 8px;
  padding: 6px 16px 2px;
}

#codeInput {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
}
#codeInput:focus { border-color: #c6d6f5; }

.code-go {
  flex: none;
  height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: #2f6bff;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.code-go:active { opacity: 0.85; }

/* ---------- 商品自己的条码 ---------- */
.codes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 18px 0;
}
.codes:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 6px 0 10px;
  border-radius: 15px;
  background: #eef3ff;
  color: #2f5fbf;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.chip button {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(47, 95, 191, 0.14);
  color: #2f5fbf;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}
.chip.add {
  background: #f1f2f5;
  color: #666;
  padding: 0 12px;
}
.chip.add:active { opacity: 0.8; }

.code-add { padding: 8px 18px 0; }
.code-add input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  outline: none;
}
.code-add input:focus { border-color: #c6d6f5; }

/* ---------- 列表 ---------- */
.list {
  padding: 8px 12px 120px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  margin-bottom: 8px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid transparent;
  transition: background 0.15s;
}
.row:active { background: #f9fafc; }
.row.done { border-color: #d7e6ff; background: #fbfdff; }

.row-main { flex: 1; min-width: 0; }

.row-name {
  font-size: 14.5px;
  line-height: 1.35;
  font-weight: 500;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-meta {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.row-qty {
  flex: none;
  min-width: 46px;
  text-align: right;
  font-size: 17px;
  font-weight: 700;
  color: #c8ccd4;
  font-variant-numeric: tabular-nums;
}
.row.done .row-qty { color: var(--accent); }
.row-qty small { font-size: 11px; font-weight: 500; color: var(--muted); }

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

/* ---------- 底部扫码按钮 ---------- */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 62%, rgba(245, 246, 248, 0));
}

.scan-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 54px;
  border: none;
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(47, 111, 237, 0.3);
}
.scan-btn:active { transform: scale(0.985); opacity: 0.92; }

/* ---------- 扫码全屏 ---------- */
.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
  overflow: hidden;
}

.reader { position: absolute; inset: 0; }
.reader video { object-fit: cover !important; width: 100% !important; height: 100% !important; }
.reader__scan_region { background: transparent; }
.reader__dashboard { display: none !important; }

.scan-top {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 12px;
  right: 12px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.scan-top > * { pointer-events: auto; }

.scan-title {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.round-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.scan-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 34px);
  z-index: 3;
  text-align: center;
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}

.scan-hint.tappable {
  color: #fff;
  font-weight: 600;
  text-decoration: underline;
  pointer-events: auto;
  cursor: pointer;
}

/* ---------- 遮罩 + 底部弹层 ---------- */
.mask {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(12, 14, 18, 0.42);
  animation: fade 0.16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  padding: 8px 18px calc(18px + var(--safe-b));
  background: #fff;
  border-radius: 18px 18px 0 0;
  animation: up 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
  max-height: 82vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-grab {
  width: 36px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: 2px;
  background: #dfe2e8;
}

.sheet-name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  word-break: break-all;
}

.sheet-meta {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--muted);
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 0;
}
.qty-row:first-of-type { margin-top: 16px; }

.qty-label {
  flex: none;
  width: 34px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.qty-row .step {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  font-size: 22px;
}

.qty-row .qty-input {
  height: 46px;
  font-size: 22px;
}

.exp-note {
  margin: 2px 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 16px;
}

.step {
  flex: none;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 14px;
  background: #f0f2f6;
  color: #3a3f47;
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
}
.step:active { background: #e4e7ee; }

.qty-input {
  flex: 1;
  min-width: 0;
  height: 52px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  outline: none;
}
.qty-input:focus { border-color: var(--accent); }

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  flex: 1;
  height: 50px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { opacity: 0.88; }
.btn.ghost { background: #f0f2f6; color: #50565f; }
.btn.ghost:active { background: #e4e7ee; }

/* ---------- 绑定商品 ---------- */
.bind-search {
  width: 100%;
  height: 40px;
  margin: 14px 0 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
.bind-search:focus { border-color: #c6d6f5; }

.bind-list {
  max-height: 46vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
}

.bind-item {
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.35;
  word-break: break-all;
}
.bind-item small { display: block; margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.bind-item:active { background: #f7f8fa; }

/* ---------- 导出弹层 ---------- */
.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.45;
  color: #33383f;
}
.opt input { flex: none; margin: 2px 0 0; width: 18px; height: 18px; accent-color: var(--accent); }

#expSheet .sheet-actions { margin-top: 16px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  z-index: 80;
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(20, 22, 26, 0.9);
  color: #fff;
  font-size: 13.5px;
  text-align: center;
  animation: fade 0.15s ease;
  pointer-events: none;
}
