:root {
  --primary: #0ead6a;
  --primary-dark: #0b8f57;
  --primary-soft: #e6f8f0;
  --primary-grad: linear-gradient(110deg, #13c577, #0ead6a);
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea580c;
  --text: #1f2937;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e5e7eb;
  --radius: 12px;
  --nav-h: 58px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }

/* ---------- 布局 ---------- */
#app { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }
.page { max-width: 720px; margin: 0 auto; }
.has-nav #app .page { padding-bottom: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--primary-grad); color: #fff;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; flex: 1; }
.topbar .back { width: 32px; height: 32px; display: grid; place-items: center; background: rgba(255,255,255,.16); border-radius: 50%; cursor: pointer; border: 0; color: #fff; font-size: 19px; }
.topbar .right { font-size: 14px; opacity: .9; }

.content { padding: 12px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.card-title { font-size: 16px; font-weight: 600; margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; }
.card-title small { font-weight: 400; color: var(--text-2); font-size: 13px; }

/* ---------- 工作台 ---------- */
/* 首页顶部：头区与 hero 合一，直接贴顶（含安全区），避免「绿条+灰缝+绿块」 */
.hero {
  background: var(--primary-grad); color: #fff;
  border-radius: 0 0 14px 14px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 16px;
}
.hero-row { display: flex; align-items: center; gap: 10px; }
.hero .shop { font-size: 19px; font-weight: 700; flex: 1; min-width: 0; }
.hero-me { font-size: 14px; opacity: .92; cursor: pointer; white-space: nowrap; }
.hero .meta { font-size: 13.5px; opacity: .88; margin-top: 4px; }
.hero .stats { display: flex; gap: 10px; margin-top: 16px; }
.stat-cell {
  flex: 1; min-width: 0; text-align: left; cursor: pointer; color: #fff;
  background: rgba(255,255,255,.14); border: 0; border-radius: 10px; padding: 9px 11px;
}
.stat-cell:active { background: rgba(255,255,255,.26); }
.stat-cell b { display: block; font-size: 21px; font-weight: 700; line-height: 1.15; }
.stat-cell span { font-size: 12.5px; opacity: .85; }

/* 待收提醒 */
.notice {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--radius); padding: 12px 14px;
}
.notice:active { background: #ffedd5; }
.notice-ico { font-size: 20px; }
.notice-main { flex: 1; min-width: 0; }
.notice-title { display: block; font-weight: 600; font-size: 15px; color: #9a3412; }
.notice-sub { display: block; font-size: 13px; color: #b45309; margin-top: 2px; }
.notice-arrow { color: #d97706; font-size: 22px; line-height: 1; }

/* 主操作 */
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: var(--radius); padding: 18px 8px; cursor: pointer;
  font-size: 16px; font-weight: 600; color: #fff;
}
.quick-btn:active { opacity: .9; }
.quick-btn.in { background: linear-gradient(135deg, #16a34a, #059669); }
.quick-btn.out { background: linear-gradient(135deg, #f97316, #ea580c); }
.quick-btn .ico { font-size: 27px; }
.quick-btn small { font-size: 12.5px; font-weight: 400; opacity: .9; }

/* 次级功能入口：统一磁贴，列数随数量自适应（不再固定 4 列留空） */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 6px; color: var(--text); box-shadow: 0 1px 2px rgba(16,24,40,.05);
}
.tile:active { background: #f9fafb; }
.tile .ico { font-size: 24px; line-height: 1.2; }
.tile-label { font-size: 14px; font-weight: 600; }
.tile-sub { max-width: 100%; font-size: 11.5px; line-height: 1.3; color: var(--text-3); text-align: center; }

/* ---------- 列表 ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--card); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.item-row { display: flex; align-items: flex-start; gap: 10px; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 16px; word-break: break-all; }
.item-sub { color: var(--text-2); font-size: 13.5px; margin-top: 3px; word-break: break-all; }
/* 「结存」问号说明 */
.help-q { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; margin-left: 4px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); font-size: 11px; font-weight: 700; line-height: 1; font-style: normal; cursor: pointer; vertical-align: 1px; user-select: none; }
.help-q:active { background: var(--primary); color: #fff; }
/* 置于顶部绿色导航栏上的浅色变体 */
.help-q-light { width: 20px; height: 20px; margin-left: 0; font-size: 13px; background: rgba(255,255,255,.22); color: #fff; }
.help-q-light:active { background: rgba(255,255,255,.4); color: #fff; }
.item-right { text-align: right; flex-shrink: 0; }
.price { font-weight: 700; color: var(--primary); }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark); margin-left: 6px; vertical-align: 1px; }
.tag.warn { background: #fef3c7; color: #b45309; }
.tag.danger { background: #fee2e2; color: #b91c1c; }
.tag.ok { background: #dcfce7; color: #15803d; }
/* 到货明细里的「本单待收 X」：醒目高亮，字号比副标题大一号 */
.pending-badge { display: inline-block; font-size: 15px; font-weight: 700; color: #b45309; background: #fef3c7; padding: 2px 11px; border-radius: 999px; margin-left: 6px; vertical-align: -1px; }
/* 订货 / 提货列表：字号整体加大一号 */
.list.lg .item-name { font-size: 18px; }
.list.lg .item-sub { font-size: 15px; }
.list.lg .price { font-size: 20px; }
.list.lg .tag { font-size: 13px; }
/* 首页「今日概况」卡片：字号加大一号 */
.card.lg .card-title { font-size: 18px; }
.card.lg .card-title small { font-size: 14px; }
.card.lg .item-sub { font-size: 15px; }
.empty { text-align: center; color: var(--text-3); padding: 40px 12px; font-size: 15px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 14px; color: var(--text-2); margin-bottom: 5px; }
.field label .req { color: var(--red); }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(19,197,119,.15); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border: 0; border-radius: 10px; background: var(--primary-grad); color: #fff;
  font-weight: 600; cursor: pointer; width: 100%;
}
.btn:active { opacity: .88; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.gray { background: #eef0f3; color: var(--text); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 7px 12px; font-size: 14.5px; width: auto; border-radius: 8px; }
.btn-bar { display: flex; gap: 10px; }

/* ---------- 底部固定操作条 ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 12px;
  max-width: 720px; margin: 0 auto;
}
.actionbar .sum { flex: 1; font-size: 14px; color: var(--text-2); }
.actionbar .sum b { color: var(--red); font-size: 18px; }

/* ---------- 底部导航 ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #fff; border-top: 1px solid var(--border);
  display: flex; max-width: 720px; margin: 0 auto;
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-3); font-size: 12px;
}
.nav a .ico { font-size: 20px; line-height: 1; }
.nav a.active { color: var(--primary); }

/* ---------- 扫码 ---------- */
.scanner-mask { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; }
.scanner-head { color: #fff; padding: calc(14px + env(safe-area-inset-top,0px)) 16px 10px; display: flex; align-items: center; gap: 10px; }
.scanner-head h2 { font-size: 17px; margin: 0; flex: 1; font-weight: 600; }
.scanner-head button { background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 8px; padding: 7px 12px; }
.hd-btn {
  background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 13px; font-size: 15px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.hd-btn:active { opacity: .8; }
.hd-btn.solid { background: #16a34a; font-weight: 600; }

.scan-live { padding: 0 16px 10px; text-align: center; }
.scan-live-total { color: #fff; font-size: 17px; font-weight: 600; }
.scan-live-total b { font-size: 27px; color: #4ade80; margin: 0 2px; vertical-align: -1px; }
.scan-live-last { color: #9ca3af; font-size: 14px; margin-top: 6px; min-height: 20px; word-break: break-all; }
.scan-live-last .ok { color: #4ade80; }
.scan-live-last .err { color: #f87171; }
.scan-live-last .warn { color: #fbbf24; }

#reader { width: 100%; flex: 1; overflow: hidden; }
#reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scanner-tip { color: #d1d5db; font-size: 14px; text-align: center; padding: 12px 16px calc(16px + env(safe-area-inset-bottom,0px)); }
.scanner-manual { display: flex; gap: 8px; padding: 0 16px 12px; }
.scanner-manual input { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid #374151; background: #111827; color: #fff; }

/* ---------- Toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom,0px)); transform: translateX(-50%); z-index: 200; pointer-events: none; }
.toast-item {
  background: rgba(17,24,39,.92); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 15px; margin-top: 8px; max-width: 80vw; text-align: center;
  animation: toastIn .2s ease;
}
.toast-item.err { background: rgba(220,38,38,.95); }
.toast-item.ok { background: rgba(22,163,74,.95); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 弹层 ---------- */
.mask { position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; }
.sheet { background: #fff; width: 100%; max-width: 720px; margin: 0 auto; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom,0px)); max-height: 85vh; overflow: auto; animation: sheetUp .22s ease; }
.sheet h3 { margin: 0 0 12px; font-size: 17px; }
@keyframes sheetUp { from { transform: translateY(20px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--primary-grad); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 18px; padding: 26px 22px; box-shadow: 0 20px 40px rgba(0,0,0,.18); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card p.sub { margin: 0 0 20px; text-align: center; color: var(--text-2); font-size: 14px; }
.login-tip { margin-top: 14px; font-size: 13px; color: var(--text-3); text-align: center; line-height: 1.7; }

/* ---------- 数量步进器 ---------- */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stepper button { width: 32px; height: 32px; border: 0; background: #f3f4f6; font-size: 19px; line-height: 1; cursor: pointer; }
.stepper input { width: 52px; height: 32px; border: 0; text-align: center; outline: none; }

/* ---------- 报表 ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 13px 14px; }
.stat .k { font-size: 13.5px; color: var(--text-2); }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 3px; }
.stat .v.green { color: var(--green); }
.stat .v.orange { color: var(--orange); }
.stat .v.red { color: var(--red); }

/* ---------- 到货：正在收的商品（点选） ---------- */
.recv-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.recv-chip {
  flex: 0 0 auto; border: 1.5px solid var(--border); border-radius: 999px;
  padding: 7px 13px; font-size: 14.5px; background: #fff; white-space: nowrap; cursor: pointer;
}
.recv-chip.active { border-color: var(--green); background: #f0fdf4; color: #166534; font-weight: 600; }
.recv-chip b { color: var(--primary); }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; justify-content: flex-end; height: 100%; }
.bars .bar { width: 60%; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .bar.in { background: #16a34a; }
.bars .bar.out { background: #f97316; }
.bars .lbl { font-size: 10px; color: var(--text-3); white-space: nowrap; transform: scale(.9); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }

.searchbar { display: flex; gap: 8px; }
.searchbar .input { flex: 1; }
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { flex-shrink: 0; padding: 6px 13px; border-radius: 999px; background: #fff; border: 1px solid var(--border); font-size: 14px; cursor: pointer; color: var(--text-2); }
.chip.active { background: var(--primary-grad); border-color: var(--primary); color: #fff; }

.load-more { text-align: center; color: var(--text-3); font-size: 14px; padding: 10px; }
