:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --line: #e6e9f0;
  --text: #1f2430;
  --muted: #7a8194;
  --brand: #2f5496;
  --brand-2: #3a6bb5;
  --brand-soft: #eaf0fb;
  --ok: #1f9d57;
  --ok-soft: #e6f6ec;
  --warn: #b9750f;
  --warn-soft: #fdf3e2;
  --danger: #c43c3c;
  --danger-soft: #fbecec;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 6px 24px rgba(20, 30, 60, .05);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}

a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 0%, #eaf0fb 0%, #f4f6fb 55%), var(--bg);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow); padding: 36px 32px;
}
.login-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 8px; }
.login-logo .mark {
  width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; display: grid; place-items: center; font-size: 22px; font-weight: 700;
}
.login-card h1 { font-size: 20px; text-align: center; }
.login-sub { text-align: center; color: var(--muted); margin: 6px 0 24px; font-size: 13px; }

/* ---------- 布局 ---------- */
.app { display: none; min-height: 100vh; }
.app.on { display: block; }
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: #1f2740; color: #cdd4e6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 18px; color: #fff; font-weight: 700; font-size: 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 18px; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow: auto; }
.nav a {
  color: #c2c9dd; padding: 11px 14px; border-radius: 9px; display: flex; align-items: center; gap: 11px;
  font-size: 14px; transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a .ico { width: 20px; text-align: center; font-size: 16px; }
.nav a.sub { padding-left: 44px; font-size: 13px; color: #9aa3bd; }
.nav a.sub:hover { color: #fff; }
.nav a.sub.active { color: #fff; }
.sidebar .foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #8b93ad; }
.sidebar .foot .who { color: #e7ebf5; font-weight: 600; font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 22px; gap: 14px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .userchip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.topbar .userchip .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; }
.content { padding: 22px; overflow: auto; flex: 1; }

/* ---------- 卡片 / 面板 ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card .head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.card .head h3 { font-size: 15px; }
.card .head .spacer { flex: 1; }
.card .body { padding: 18px; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .field { position: relative; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field label .req { color: var(--danger); margin-left: 2px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; background: #fff; color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=checkbox] { width: auto; }
.rowline { display: flex; gap: 12px; align-items: center; }
.rowline .field { flex: 1; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 9px;
  padding: 9px 16px; font-size: 13.5px; cursor: pointer; font-weight: 500; transition: all .15s;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { border-color: #c9cfdd; background: #fafbfd; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: #f0c9c9; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--brand-soft); color: var(--brand); }
.btn.ghost.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost.active:hover { background: var(--brand-2); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 工具栏 / 筛选 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.toolbar .field { min-width: 150px; }
.toolbar .field label { margin-bottom: 5px; }
.toolbar .grow { flex: 1; }
.toolbar .actions { display: flex; gap: 8px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 720px; }
table.tbl thead th {
  background: #f7f8fc; text-align: left; padding: 11px 14px; color: var(--muted);
  font-weight: 600; border-bottom: 1px solid var(--line); position: sticky; top: 0; white-space: nowrap;
}
table.tbl tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl tbody tr:hover { background: #fafbff; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .muted { color: var(--muted); font-size: 12.5px; }
.empty { padding: 44px; text-align: center; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; opacity: .5; }

/* ---------- 徽章 ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.role-admin { background: var(--brand-soft); color: var(--brand); }
.badge.role-operator { background: #eef1f6; color: #5a6377; }
.badge.off { background: var(--danger-soft); color: var(--danger); }
.badge.inv { background: #eef2fb; color: #4a5bb0; font-weight: 500; margin: 2px 3px 2px 0; white-space: nowrap; }

/* ---------- 分页 ---------- */
.pager { display: flex; align-items: center; gap: 10px; padding: 14px 18px; justify-content: flex-end; color: var(--muted); font-size: 13px; }

/* ---------- 模态框 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 28, 48, .45); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-mask.on { display: flex; }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(10, 20, 50, .25);
}
.modal .head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .head h3 { font-size: 16px; }
.modal .head .spacer { flex: 1; }
.modal .body { padding: 20px; overflow: auto; }
.modal .foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.x-btn { border: none; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px; }

/* 二维码模态 */
.qr-box { text-align: center; padding: 10px 0; }
.qr-box img { width: 260px; height: 260px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 10px; }
.qr-box .code { font-size: 16px; font-weight: 700; margin-top: 12px; letter-spacing: .5px; }
.qr-box .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #1f2430; color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: 360px; animation: slidein .2s ease;
  display: flex; gap: 10px; align-items: flex-start;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast .t { flex: 1; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 扫码页 ---------- */
.scan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.scan-cam { position: relative; background: #0c1018; border-radius: 12px; overflow: hidden; aspect-ratio: 4/3; display: grid; place-items: center; }
.scan-cam video { width: 100%; height: 100%; object-fit: cover; }
.scan-cam canvas { display: none; }
.scan-cam .overlay {
  position: absolute; inset: 0; margin: auto; width: 62%; height: 42%;
  border: 2px solid rgba(255,255,255,.7); border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0,0,0,.25);
}
.scan-cam .tip { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.scan-result { border: 1px dashed var(--line); border-radius: 12px; padding: 20px; }
.scan-result .kv { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; font-size: 14px; }
.scan-result .kv dt { color: var(--muted); }
.scan-result .kv dd { margin: 0; font-weight: 500; }
.scan-result .actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.manual-box { margin-top: 16px; }

/* 响应式 */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .scan-grid { grid-template-columns: 1fr; }
}

/* 打印 */
@media print {
  body * { visibility: hidden; }
  #qrPrintArea, #qrPrintArea * { visibility: visible; }
  #qrPrintArea { position: absolute; left: 0; top: 0; width: 100%; text-align: center; }
  #qrPrintArea img { width: 280px; height: 280px; }
}

/* 出库表单 · 当前库存提示 */
.stock-info { margin-top: 12px; font-size: 13.5px; min-height: 20px; }
.stock-info:empty { display: none; }
.stock-info .stock-ok { color: var(--ok); font-weight: 600; }
.stock-info .stock-zero { color: var(--danger); font-weight: 600; background: var(--danger-soft); padding: 6px 10px; border-radius: 8px; display: inline-block; }
.stock-info .stock-hint { color: var(--muted); }

/* 出库表单 · 入库匹配下拉 */
.outb-suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 5px); z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 252px; overflow: auto; display: none;
}
.outb-suggest.on { display: block; }
.outb-suggest .sb { display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; border: 0; background: transparent; text-align: left;
  font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--line); }
.outb-suggest .sb:last-child { border-bottom: 0; }
.outb-suggest .sb:hover { background: var(--brand-soft); }
.outb-suggest .sb b { font-weight: 600; }
.outb-suggest .sb .st { margin-left: auto; white-space: nowrap; font-size: 12.5px; }
.outb-suggest .sb .st.ok { color: var(--ok); font-weight: 600; }
.outb-suggest .sb .st.zero { color: var(--danger); font-weight: 600; }
.outb-suggest .sb .muted { color: var(--muted); }
.outb-suggest .sb-tip { padding: 8px 12px; font-size: 12px; color: var(--muted); }

/* ---------- 侧边栏：后台管理分组 ---------- */
.nav .nav-group { margin-top: 6px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 6px; }
.nav .nav-group-title {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: #7d88a6; padding: 6px 18px 4px; font-weight: 600;
}

/* ---------- 功能 / 客户范围 复选 ---------- */
.chk-row { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.chk input { width: 15px; height: 15px; accent-color: var(--brand); }
.feat-group { font-size: 12px; font-weight: 600; color: var(--muted); width: 56px; }
.chk-list {
  max-height: 168px; overflow: auto; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; background: var(--bg);
}
.chk-list .chk { font-size: 12.5px; }

/* ---------- 账号表：功能徽章 ---------- */
.badge.feat {
  display: inline-block; padding: 1px 8px; margin: 1px 2px; border-radius: 6px;
  background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 600;
}

/* ---------- 扫码：类型不匹配提示 ---------- */
.scan-mismatch { text-align: center; color: var(--warn); font-size: 14px; line-height: 1.7; padding: 8px; }
.scan-mismatch .big { font-size: 34px; margin-bottom: 6px; }
