:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --ok: #16a34a;
  --warn: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { 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: 15px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* 顶栏 */
.topbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-d));
  color: #fff; padding: 12px 16px; display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 700; font-size: 17px; flex: 1; }
.topbar .who { font-size: 13px; opacity: .9; text-align: right; }
.topbar .menu-btn { background: rgba(255,255,255,.18); border: 0; color: #fff; font-size: 20px; width: 38px; height: 38px; border-radius: 8px; cursor: pointer; }

/* 抽屉导航 */
.drawer-mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; display: none; }
.drawer-mask.show { display: block; }
.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 240px; background: #fff; z-index: 31; transform: translateX(-100%); transition: transform .2s; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
.drawer.show { transform: translateX(0); }
.drawer .nav-item { display: flex; align-items: center; gap: 10px; padding: 14px 18px; color: var(--text); border-bottom: 1px solid var(--border); cursor: pointer; font-size: 15px; }
.drawer .nav-item:hover { background: #f0f4ff; }
.drawer .nav-item .ic { width: 22px; text-align: center; }
.drawer .hd { padding: 18px; font-weight: 700; background: var(--primary); color: #fff; }

/* 内容 */
.content { padding: 16px; max-width: 980px; margin: 0 auto; padding-bottom: 40px; }
.page-title { font-size: 19px; font-weight: 700; margin: 4px 0 14px; }
.sub { color: var(--muted); font-size: 13px; margin: -8px 0 14px; }

/* 卡片 */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media(max-width: 640px){ .grid.cols-4 { grid-template-columns: repeat(2,1fr); } .grid.cols-2 { grid-template-columns: 1fr; } }
.stat { text-align: center; padding: 14px 8px; }
.stat .n { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat .l { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* 表单 */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 15px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row.between { justify-content: space-between; align-items: center; }
.row.between > * { flex: 0 1 auto; }
.mb { margin-bottom: 10px; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border: 0; border-radius: 9px; background: var(--primary); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; transition: .15s; }
.btn:hover { background: var(--primary-d); }
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 11px; font-size: 13px; }
.btn.ghost { background: #eef2ff; color: var(--primary); }
.btn.gray { background: #e5e7eb; color: var(--text); }
.btn.danger { background: #fee2e2; color: var(--warn); }
.btn.ok { background: #dcfce7; color: var(--ok); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; background: #fafafa; position: sticky; top: 0; }
td.wrap { white-space: normal; }
.bc-prod, .bc-rc, .bc-pp, .bc-src, .bc-wh, .bc-qty, .bc-pd { width: 100%; box-sizing: border-box; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eef2ff; color: var(--primary); }
.tag.low { background: #fee2e2; color: var(--warn); }
.tag.off { background: #f3f4f6; color: var(--muted); }
.tag.ok { background: #dcfce7; color: #15803d; }

/* 扫码提示卡 */
.scan-card { text-align: center; padding: 22px; }
.scan-card .big { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.scan-steps { text-align: left; font-size: 14px; color: var(--muted); margin: 10px auto; max-width: 340px; }
.scan-steps li { margin: 6px 0; }

/* 二维码标签 */
.label-sheet { display: flex; flex-wrap: wrap; gap: 14px; }
.label-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; width: 240px; text-align: center; background: #fff; }
.label-card canvas { width: 160px; height: 160px; image-rendering: pixelated; }
.label-card .pname { font-weight: 700; margin-top: 6px; }
.label-card .pmeta { font-size: 12px; color: var(--muted); }
.label-card .psku { font-family: monospace; font-size: 12px; color: var(--primary); }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 14px; }

/* Toast */
.toast-wrap { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.2); animation: tin .2s; }
.toast.err { background: #b91c1c; }
.toast.ok { background: #15803d; }
@keyframes tin { from { opacity: 0; transform: translateY(8px);} to {opacity:1;} }

/* 底部操作条（手机） */
.fixed-bar { position: sticky; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border); padding: 10px 16px; display: flex; gap: 10px; z-index: 10; }

/* 打印 */
@media print {
  .topbar, .drawer, .drawer-mask, .toast-wrap, .no-print, .content .page-title, .content > .sub { display: none !important; }
  body { background: #fff; }
  .label-sheet { gap: 0; }
  .label-card { width: 100%; border: 0; page-break-inside: avoid; }
}
.scan-input-row { display: flex; gap: 8px; }
.scan-input-row input { flex: 1; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px; }

/* 商品搜索下拉 */
.ps-wrap { position: relative; }
.ps-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--border); border-radius: 9px; max-height: 260px; overflow: auto; z-index: 50; box-shadow: var(--shadow); }
.ps-results.hidden { display: none; }
.ps-item { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 14px; }
.ps-item:last-child { border-bottom: 0; }
.ps-item:hover { background: #f0f4ff; }

/* 警告框（标签访问地址未配置） */
.warn-box { background: #fff7ed; border: 1px solid #fdba74; color: #9a3412; padding: 10px 12px; border-radius: 9px; font-size: 13px; line-height: 1.6; }

/* 局域网自动切换胶囊 */
#lanPill { position: fixed; top: 0; left: 0; right: 0; z-index: 80; background: #15803d; color: #fff; text-align: center; font-size: 14px; padding: 9px 12px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.18); animation: tin .25s; }
#lanPill:active { background: #166534; }
