:root {
  --bg: #0e131a;
  --panel: #151d27;
  --panel-2: #1b2531;
  --panel-3: #212d3b;
  --line: #2b3747;
  --line-soft: #222d3a;
  --txt: #e7eef7;
  --muted: #8d9caf;
  --dim: #63728a;
  --amber: #e3a85c;
  --teal: #4fcaab;
  --rose: #e9808a;
  --blue: #70a9e8;
  --violet: #a58be3;
  --radius: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

/* ---------- shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: #121a24;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(145deg, var(--amber), #b97532);
  display: grid; place-items: center;
  color: #1a1207; font-weight: 800; font-size: 15px;
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: var(--dim); letter-spacing: 1.2px; text-transform: uppercase; }

.topbar-spacer { flex: 1; }

.role-switch { display: flex; align-items: center; gap: 9px; }
.role-switch label { font-size: 12px; color: var(--muted); white-space: nowrap; }

select, input[type="text"], input[type="number"], input[type="date"], textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  outline: none;
  min-width: 0;
}
select:focus, input:focus, textarea:focus { border-color: var(--amber); }
input::placeholder, textarea::placeholder { color: var(--dim); }
textarea { resize: vertical; min-height: 68px; width: 100%; }

.body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 208px; flex: 0 0 208px;
  background: #121a24;
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  position: sticky; top: 60px; height: calc(100vh - 60px);
  display: flex; flex-direction: column;
}
.nav-group-title {
  font-size: 11px; color: var(--dim); letter-spacing: 1.5px;
  padding: 0 10px 10px;
}
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: transparent; border: 0; border-radius: 8px;
  padding: 10px 11px; margin-bottom: 3px;
  color: var(--muted); font-size: 13.5px;
}
.nav-item:hover { background: var(--panel-2); color: var(--txt); }
.nav-item.active { background: var(--panel-3); color: var(--txt); font-weight: 600; }
.nav-item.active::before {
  content: ""; width: 3px; height: 16px; border-radius: 2px;
  background: var(--amber); position: absolute; margin-left: -10px;
}
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.nav-item.active .nav-dot { background: var(--amber); }
.nav-badge {
  margin-left: auto; background: var(--rose); color: #25121a;
  border-radius: 10px; padding: 0 6px; font-size: 11px; font-weight: 700;
}
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line-soft); }
.sidebar-foot p { margin: 0; font-size: 11px; color: var(--dim); line-height: 1.7; }

.main { flex: 1; min-width: 0; padding: 24px 26px 60px; }

/* ---------- headings ---------- */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: .3px; }
.page-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.page-head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.section-title { font-size: 14px; font-weight: 650; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title .hint { font-size: 11.5px; color: var(--dim); font-weight: 400; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.card.tight { padding: 0; overflow: hidden; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 7px; padding: 7px 13px; font-size: 13px;
  white-space: nowrap; transition: .15s;
}
.btn:hover { border-color: #41536b; background: var(--panel-3); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1d1307; font-weight: 650; }
.btn.primary:hover { background: #f0b76b; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--rose); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-link { background: none; border: 0; color: var(--blue); padding: 0; font-size: 12.5px; }
.btn-link:hover { text-decoration: underline; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; }
.stat-label { font-size: 11.5px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: .5px; }
.stat-note { font-size: 11px; color: var(--dim); margin-top: 2px; }
.stat.warn .stat-value { color: var(--rose); }
.stat.ok .stat-value { color: var(--teal); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px;
  letter-spacing: .4px; padding: 11px 14px; background: #18222e;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .022); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.cell-low { color: var(--rose); font-weight: 700; }
.cell-low::after { content: " 低"; font-size: 10px; font-weight: 500; }
.cell-zero { color: var(--dim); }

.empty { padding: 34px 14px; text-align: center; color: var(--dim); font-size: 13px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge.gray { background: #26313f; color: #a8b7ca; }
.badge.amber { background: rgba(227, 168, 92, .15); color: var(--amber); border-color: rgba(227, 168, 92, .3); }
.badge.teal { background: rgba(79, 202, 171, .13); color: var(--teal); border-color: rgba(79, 202, 171, .3); }
.badge.rose { background: rgba(233, 128, 138, .13); color: var(--rose); border-color: rgba(233, 128, 138, .3); }
.badge.blue { background: rgba(112, 169, 232, .13); color: var(--blue); border-color: rgba(112, 169, 232, .3); }
.badge.violet { background: rgba(165, 139, 227, .13); color: var(--violet); border-color: rgba(165, 139, 227, .3); }

.delta-plus { color: var(--teal); font-weight: 650; font-variant-numeric: tabular-nums; }
.delta-minus { color: var(--rose); font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- filters / tabs ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar select, .toolbar input { font-size: 12.5px; padding: 6px 9px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab {
  background: none; border: 0; padding: 9px 15px; color: var(--muted);
  font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--txt); }
.tab.active { color: var(--amber); border-bottom-color: var(--amber); font-weight: 650; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea { width: 100%; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hint-text { font-size: 11.5px; color: var(--dim); margin-top: 6px; line-height: 1.6; }

.item-row { display: grid; grid-template-columns: 1fr 100px 130px 34px; gap: 8px; margin-bottom: 8px; align-items: center; }
.item-row select, .item-row input { width: 100%; font-size: 12.5px; padding: 6px 8px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); line-height: 1;
}
.icon-btn:hover { color: var(--rose); border-color: var(--rose); }

/* ---------- modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(5, 9, 14, .72);
  display: grid; place-items: center; z-index: 60; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.modal.wide { max-width: 700px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-close { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- toast ---------- */
#toast-root { position: fixed; top: 72px; right: 22px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 220px; max-width: 380px;
  background: var(--panel-3); border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: 8px; padding: 10px 14px; font-size: 13px;
  box-shadow: var(--shadow); animation: slidein .18s ease-out;
}
.toast.err { border-left-color: var(--rose); }
@keyframes slidein { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

/* ---------- misc ---------- */
.kv { display: flex; gap: 8px; font-size: 12.5px; margin-bottom: 5px; }
.kv span:first-child { color: var(--dim); min-width: 64px; }
.inline-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-3); border: 1px solid var(--line); border-radius: 5px; padding: 2px 8px; font-size: 11.5px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.notice {
  background: rgba(227, 168, 92, .08); border: 1px solid rgba(227, 168, 92, .25);
  border-radius: 8px; padding: 10px 13px; font-size: 12.5px; color: #d9c2a0; margin-bottom: 16px;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

@media (max-width: 820px) {
  .body { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static; flex: none;
    border-right: 0; border-bottom: 1px solid var(--line);
    flex-direction: row; overflow-x: auto; padding: 8px; gap: 4px;
  }
  .nav-group-title, .sidebar-foot { display: none; }
  .nav-item { width: auto; white-space: nowrap; margin: 0; }
  .nav-item.active::before { display: none; }
  .main { padding: 18px 14px 50px; }
  .brand-sub, .role-switch label { display: none; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand { min-width: 0; }
  .two-col, .form-grid, .field-row { grid-template-columns: 1fr; }
}

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 28px 16px;
  background: radial-gradient(900px 520px at 18% -10%, rgba(227, 168, 92, .13), transparent 60%),
              radial-gradient(760px 480px at 92% 110%, rgba(79, 202, 171, .10), transparent 60%),
              var(--bg);
}
.login-wrap { width: 100%; max-width: 900px; display: grid; grid-template-columns: 1fr 380px; gap: 26px; align-items: center; }
.login-intro h1 { font-size: 32px; margin: 0 0 10px; letter-spacing: 1px; }
.login-intro h1 span { color: var(--amber); }
.login-intro p { color: var(--muted); font-size: 14px; line-height: 1.9; margin: 0 0 18px; max-width: 460px; }
.login-feats { display: flex; flex-wrap: wrap; gap: 8px; }
.login-feats span { border: 1px solid var(--line); background: var(--panel); border-radius: 20px; padding: 5px 12px; font-size: 12px; color: var(--muted); }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 20px; }
.login-card h2 { margin: 0 0 4px; font-size: 18px; }
.login-card .login-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 20px; }
.login-card .field input { width: 100%; padding: 10px 12px; }
.login-btn { width: 100%; padding: 11px; font-size: 14px; margin-top: 4px; }
.login-error { background: rgba(233, 128, 138, .12); border: 1px solid rgba(233, 128, 138, .35); color: var(--rose); border-radius: 7px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px; }
.demo-box { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
.demo-title { font-size: 11.5px; color: var(--dim); margin-bottom: 9px; letter-spacing: .5px; }
.demo-list { display: grid; gap: 5px; }
.demo-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 6px; font-size: 12px; font-family: inherit; color: var(--muted); text-align: left; background: none; border: 0; border-radius: 6px; cursor: pointer; }
.demo-item:hover { background: var(--panel-2); color: var(--txt); }
.demo-item code { background: var(--panel-3); border: 1px solid var(--line); border-radius: 5px; padding: 1px 7px; color: var(--txt); font-size: 11.5px; }
.demo-item .demo-pwd { margin-left: auto; color: var(--dim); font-size: 11px; }
.login-foot { margin-top: 14px; font-size: 11px; color: var(--dim); line-height: 1.7; }
@media (max-width: 760px) { .login-wrap { grid-template-columns: 1fr; } .login-intro { display: none; } }

/* ---------- 顶栏用户信息 ---------- */
.user-chip { display: flex; align-items: center; gap: 9px; padding: 4px 10px 4px 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 22px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(145deg, var(--blue), #3f6fa8); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #0b1520; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-meta strong { font-size: 12px; font-weight: 650; }
.user-meta small { font-size: 10.5px; color: var(--dim); }
.link-btn { color: var(--blue); background: none; border: 0; font-size: 12.5px; padding: 6px 4px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- 账号与权限 ---------- */
.perm-tags { display: flex; flex-wrap: wrap; gap: 4px; max-width: 280px; }
.perm-tags .tag { background: var(--panel-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.perm-groups { display: grid; gap: 12px; }
.perm-group { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; background: var(--panel-2); }
.perm-group-head { display: flex; align-items: center; gap: 10px; font-size: 12.5px; font-weight: 650; margin-bottom: 10px; }
.perm-group-head .btn { margin-left: auto; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.perm-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.perm-item input { width: 15px; height: 15px; accent-color: var(--amber); }
.perm-note { font-size: 11.5px; color: var(--dim); line-height: 1.7; margin-top: 10px; }

/* ---------- 清单与打印 ---------- */
.receipt-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.receipt-layout .card { margin-bottom: 0; }
.receipt-panel { display: grid; gap: 14px; position: sticky; top: 78px; }
.receipt-preview { background: #e9edf2; border-radius: 10px; padding: 16px; display: grid; place-items: center; min-height: 260px; overflow: auto; }
.receipt-paper {
  background: #fff; color: #111; box-shadow: 0 8px 26px rgba(0, 0, 0, .35);
  padding: 12px 10px 8px; font-family: ui-monospace, SFMono-Regular, Menlo, "Courier New", monospace;
  font-size: 11px; line-height: 1.5; white-space: pre; width: 220px;
}
.receipt-paper[data-w="80"] { width: 302px; font-size: 12px; }
.receipt-inner { display: block; }
.r-line { white-space: pre; min-height: 1.5em; }
.r-big { font-weight: 800; font-size: 1.35em; text-align: center; }
.r-center { text-align: center; }
.r-sep { color: #555; }
.r-qr { text-align: center; font-size: .9em; color: #555; }
.r-foot { margin-top: 10px; padding-top: 7px; border-top: 1px dashed #bbb; font-size: 9px; color: #888; white-space: normal; text-align: center; }
.print-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.print-result { font-size: 12px; border-radius: 7px; padding: 9px 12px; line-height: 1.6; }
.print-result.ok { background: rgba(79, 202, 171, .1); border: 1px solid rgba(79, 202, 171, .3); color: var(--teal); }
.print-result.err { background: rgba(233, 128, 138, .1); border: 1px solid rgba(233, 128, 138, .3); color: var(--rose); }
.settings-note { font-size: 11.5px; color: var(--dim); line-height: 1.8; }
.settings-note code { background: var(--panel-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--muted); }
#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  .receipt-paper { box-shadow: none; margin: 0 auto; }
  .r-foot { display: none; }
  @page { margin: 4mm; }
}
@media (max-width: 1100px) { .receipt-layout { grid-template-columns: 1fr; } .receipt-panel { position: static; } }

/* ---------- v3：品类分组 / 整件规格 / 清单自定义 / 扫码 ---------- */
.cat-row td { background: var(--panel-3); color: var(--teal); font-weight: 600; letter-spacing: .3px; padding: 8px 14px !important; font-size: 12.5px; }
.cat-row td .cat-count { color: var(--dim); font-weight: 400; margin-left: 8px; }
.pack-spec { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.pack-spec code { color: var(--teal); }
.unit-line { display: flex; gap: 8px; align-items: center; }
.unit-line input { flex: 1; }
.unit-line select { width: 118px; flex: none; }
.unit-hint { margin-top: 6px; font-size: 11.5px; color: var(--dim); }
.unit-hint b { color: var(--teal); font-weight: 600; }
.scan-line { display: flex; gap: 8px; align-items: center; }
.scan-line input[type=text] { flex: 1; min-width: 0; }
.cat-manage { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cat-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px 5px 12px; font-size: 12.5px; }
.cat-chip .icon-btn { padding: 0 3px; }
.sort-btns { display: flex; gap: 4px; }
.sort-btns button { border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); border-radius: 5px; width: 24px; height: 24px; line-height: 1; font-size: 12px; }
.sort-btns button:hover { color: var(--teal); border-color: var(--teal); }

/* 清单自定义编辑行 */
.rc-head, .rc-row { display: grid; grid-template-columns: minmax(130px, 2.2fr) 70px 66px minmax(90px, 1.2fr) minmax(80px, 1fr) 28px; gap: 6px; align-items: center; }
.rc-head { font-size: 11px; color: var(--dim); padding: 4px 2px; }
.rc-row { margin-bottom: 6px; }
.rc-row input { min-width: 0; width: 100%; padding: 6px 8px; font-size: 12.5px; }
.rc-row .icon-btn { padding: 0; }
.tpl-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.tpl-row .chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; }

/* 摄像头扫码浮层 */
.scan-mask { position: fixed; inset: 0; z-index: 200; background: rgba(5, 9, 14, .82); display: flex; align-items: center; justify-content: center; padding: 16px; }
.scan-box { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.scan-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.scan-x { margin-left: auto; border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; }
.scan-video-wrap { position: relative; background: #05080c; aspect-ratio: 4 / 3; }
.scan-video-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18% 12%; border: 2px solid var(--teal); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .28); pointer-events: none; }
.scan-frame::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(79, 202, 171, .6); }
.scan-status { padding: 10px 14px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.scan-status.ok { color: var(--teal); }
.scan-status.warn { color: var(--amber); }
.scan-manual { display: flex; gap: 8px; padding: 0 14px 10px; }
.scan-manual input { flex: 1; min-width: 0; }
.scan-hint { padding: 0 14px 14px; font-size: 11px; color: var(--dim); line-height: 1.6; }

