:root {
  --primary: #E60012;
  --primary-dark: #C7000B;
  --gold: #F5C34A;
  --bg: #f1f2f6;
  --card: #ffffff;
  --text: #22262b;
  --muted: #7f8c8d;
  --line: #e3e5eb;
  --green: #27ae60;
  --red: #E60012;
  --blue: #2980b9;
  --nav-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: linear-gradient(135deg, #E60012, #C7000B);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.app-title { font-size: 18px; font-weight: 700; }
.app-sub { font-size: 12px; opacity: .85; margin-top: 2px; }
.app-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 27px; height: 27px; margin-right: 8px;
  background: #fff; color: var(--primary);
  border-radius: 8px; font-weight: 800; font-size: 17px;
  vertical-align: -4px; box-shadow: 0 1px 4px rgba(0,0,0,.25);
}

main {
  max-width: 480px; margin: 0 auto;
  padding: calc(76px + env(safe-area-inset-top)) 12px 24px;
}
.page { display: none; }
.page.active { display: block; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin-top: 6px; }
.small { font-size: 12px; line-height: 1.6; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 10px;
  font-size: 16px; font-weight: 600;
  padding: 12px 18px; cursor: pointer;
  background: #e8e9ee; color: var(--text);
  min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.btn-ghost { background: #fff; color: var(--primary); border: 1px solid var(--line); }
.btn-block { width: 100%; }
.btn-small { font-size: 13px; padding: 7px 12px; min-height: 34px; }

/* ---------- 模式切换 ---------- */
.mode-switch {
  display: flex; gap: 8px; margin-bottom: 10px;
}
.mode-btn {
  flex: 1; padding: 12px 0; border-radius: 10px;
  border: 1px solid var(--line); background: #fff;
  font-size: 16px; font-weight: 700; color: var(--muted);
}
.mode-btn.active {
  background: var(--primary); border-color: var(--primary); color: #fff;
}

/* ---------- 扫码区域 ---------- */
.scanner-wrap {
  position: relative; width: 100%;
  aspect-ratio: 4 / 3;
  background: #16181d; border-radius: 14px; overflow: hidden;
  margin-bottom: 10px;
}
.scanner-region { width: 100%; height: 100%; }
.scanner-region video { object-fit: cover; }
.scan-frame {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 50%; height: 50%;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.20);
  pointer-events: none;
  transition: border-color .2s ease;
}
.scan-frame::before, .scan-frame::after {
  content: ""; position: absolute; width: 22px; height: 22px;
  border-color: #7fff7f; border-style: solid;
}
.scan-frame::before { left: -2px; top: -2px; border-width: 3px 0 0 3px; border-top-left-radius: 8px; }
.scan-frame::after { right: -2px; bottom: -2px; border-width: 0 3px 3px 0; border-bottom-right-radius: 8px; }
.scan-frame.ok { border-color: #2ecc71; box-shadow: 0 0 0 9999px rgba(0,0,0,.20), 0 0 14px #2ecc71; }
.scan-laser {
  position: absolute; left: 3%; right: 3%; height: 2px; top: 0;
  background: linear-gradient(90deg, transparent, #ffffff, transparent);
  box-shadow: 0 0 6px rgba(255,255,255,.9);
  animation: laser-move 1.8s ease-in-out infinite;
}
@keyframes laser-move {
  0% { top: 4%; }
  50% { top: 94%; }
  100% { top: 4%; }
}
.scan-frame-small { width: 62%; height: 62%; box-shadow: 0 0 0 9999px rgba(0,0,0,.16); }
.scanner-status {
  position: absolute; left: 0; right: 0; bottom: 6px;
  text-align: center; font-size: 12px; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
  padding: 0 8px;
}

/* ---------- 手动输入 ---------- */
.manual-box {
  display: flex; gap: 8px; margin-bottom: 10px;
}
.op-action-row { display: flex; gap: 8px; margin-bottom: 10px; }
.op-action-row .btn { flex: 1; }
.query-photo-row { margin-top: 8px; }
input, select {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); }

/* ---------- 出入库面板 ---------- */
.op-panel {
  background: var(--card); border-radius: 14px;
  padding: 14px; margin-top: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.op-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.op-name { font-size: 17px; font-weight: 700; }
.op-stock { font-size: 13px; color: var(--muted); }
.op-qty-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px;
}
.op-qty-row em { font-style: normal; color: var(--primary); font-weight: 700; }
.op-qty-row input { width: 110px; text-align: center; font-size: 20px; font-weight: 700; }

/* ---------- 搜索与列表 ---------- */
.search-box { margin-bottom: 10px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.li-name { font-size: 15px; font-weight: 600; }
.li-meta { display: flex; justify-content: space-between; margin-top: 5px; font-size: 13px; color: var(--muted); }
.li-stock b { color: var(--primary); font-size: 15px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }

/* ---------- 详情卡片 ---------- */
.detail-card {
  background: linear-gradient(135deg, #fff, #fff7f6);
  border: 1px solid #f6c6c9; border-radius: 14px;
  padding: 14px; margin-bottom: 10px;
}
.dc-name { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.dc-grid { display: flex; gap: 8px; }
.dc-grid > div {
  flex: 1; background: #fff; border-radius: 10px;
  padding: 10px 6px; text-align: center;
  border: 1px solid var(--line);
}
.dc-num { display: block; font-size: 18px; font-weight: 700; color: var(--primary); }
.dc-label { font-size: 11px; color: var(--muted); }

/* ---------- 管理 ---------- */
.manage-lock {
  background: var(--card); border-radius: 14px; padding: 30px 20px;
  text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.lock-icon { font-size: 42px; }
.manage-lock p { color: var(--muted); margin: 8px 0 16px; }
.manage-lock input { text-align: center; margin-bottom: 12px; }
.manage-content { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--card); border-radius: 14px; padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card h3 { margin: 0 0 10px; font-size: 16px; }
.card select, .card input { margin-bottom: 8px; }
.row2 { display: flex; gap: 8px; }
.row2 label { flex: 1; font-size: 12px; color: var(--muted); }
.row2 input { margin-top: 4px; }

.import-stats { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.import-stats span { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.import-stats .ok { background: #e8f7ee; color: var(--green); }
.import-stats .warn { background: #fdf3e2; color: #b9770e; }
.import-stats .bad { background: #fdecea; color: var(--red); }
.fail-list { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--red); }

/* ---------- 日志 ---------- */
.log-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }
.log-item {
  border-left: 4px solid var(--blue);
  background: #fbfbfd; border-radius: 8px; padding: 9px 10px;
  font-size: 13px;
}
.log-item.type-入库 { border-left-color: var(--green); }
.log-item.type-出库 { border-left-color: var(--red); }
.log-item.type-纠正 { border-left-color: var(--blue); }
.log-item.type-导入 { border-left-color: #95a5a6; }
.log-item.revoked { opacity: .55; }
.log-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.log-type {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #eef0f3; color: var(--muted); font-weight: 600;
}
.log-item.type-入库 .log-type { background: #e8f7ee; color: var(--green); }
.log-item.type-出库 .log-type { background: #fdecea; color: var(--red); }
.log-item.type-纠正 .log-type { background: #e8f0f8; color: var(--blue); }
.log-item.type-导入 .log-type { background: #eef0f3; color: var(--muted); }
.log-time { font-size: 11px; color: var(--muted); }
.log-main { font-weight: 600; margin-bottom: 3px; }
.log-qty.pos { color: var(--green); }
.log-qty.neg { color: var(--red); }
.log-foot { font-size: 12px; color: var(--muted); }
.btn-undo { margin-top: 6px; background: #fdecea; color: var(--red); }

/* ---------- 香烟直接输入 + 扫码 ---------- */
.cig-input-row { display: flex; gap: 8px; }
.cig-input-row input { flex: 1; }
.scan-btn { white-space: nowrap; }
.suggest-list {
  margin-top: 8px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; overflow: hidden; max-height: 200px; overflow-y: auto;
}
.suggest-item {
  padding: 11px 12px; display: flex; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid #f1f2f6; cursor: pointer;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:active { background: #fff1f0; }
.suggest-item .pi-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.suggest-empty { padding: 14px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.scan-area {
  margin-top: 8px; border-radius: 10px; overflow: hidden;
  background: #16181d; height: 170px; position: relative;
}
.scan-area .scanner-region { width: 100%; height: 100%; }
.widget-photo-row { margin-top: 8px; }
.scan-area-status {
  position: absolute; left: 0; right: 0; bottom: 4px;
  text-align: center; font-size: 11px; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
}
.selected-chip {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; padding: 6px 8px 6px 12px;
  background: #fff1f0; color: var(--primary);
  border: 1px solid #f6c6c9; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.chip-clear {
  border: none; background: transparent; color: var(--primary);
  font-size: 14px; cursor: pointer; padding: 0 2px; line-height: 1;
}

/* ---------- 底部导航 ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1; border: none; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--muted);
}
.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--primary); font-weight: 700; }

/* ---------- Toast / Modal ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 22, 26, .92); color: #fff;
  padding: 11px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .25s ease;
  z-index: 90; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.modal-box {
  background: #fff; border-radius: 16px; padding: 18px;
  max-width: 420px; width: 100%; max-height: 88vh; overflow: auto;
}
.modal-box h3 { margin: 0 0 8px; }
.modal-box label { display: block; font-size: 13px; color: var(--muted); margin-top: 10px; }
.modal-box input { margin-top: 4px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
