/* ============================================================
   库存管理系统 · 样式
   设计原则：浅色、紧凑、数字对齐、表格好扫读；不引外部字体和图标库
   ============================================================ */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e5e7eb;
  --line-soft: #f0f1f3;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --green: #15803d;
  --green-soft: #ecfdf3;
  --red: #b91c1c;
  --red-soft: #fef2f2;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, Consolas, "Courier New", monospace; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 登录 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #eef2ff 0%, #f5f6f8 45%, #f8fafc 100%);
  padding: 20px;
}
.login-card {
  width: 340px;
  background: var(--panel);
  padding: 28px 26px 22px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .10);
  border: 1px solid var(--line);
}
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card p { margin: 0 0 20px; font-size: 13px; }
.login-logo {
  display: block;
  width: 56px; height: 56px;
  border-radius: 12px;
  object-fit: cover;
  margin: 0 auto 14px;
  box-shadow: 0 4px 12px rgba(16, 24, 40, .12);
}
.login-msg { color: var(--red); font-size: 13px; min-height: 20px; margin-top: 10px; }
.login-foot { margin-top: 6px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ---------------- 布局 ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  flex: 0 0 210px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.brand-icon { font-size: 22px; }
.brand-logo {
  width: 34px; height: 34px;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 34px;
}
.brand-title { font-weight: 600; font-size: 14px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { padding: 10px 8px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  color: #374151;
  font-size: 13.5px;
  cursor: pointer;
  margin-bottom: 1px;
}
.nav a:hover { background: #f3f4f6; text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-group {
  font-size: 11px; color: #9ca3af; padding: 14px 10px 6px; letter-spacing: .04em;
}
.nav .badge {
  background: var(--red); color: #fff; border-radius: 9px;
  font-size: 11px; padding: 0 6px; line-height: 17px; min-width: 18px; text-align: center;
}
.nav .badge:empty { display: none; }
.sidebar-foot {
  border-top: 1px solid var(--line-soft);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.linkbtn {
  background: none; border: 0; padding: 6px 4px; text-align: left;
  color: var(--muted); font-size: 13px; cursor: pointer; border-radius: 4px;
}
.linkbtn:hover { color: var(--primary); background: #f3f4f6; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 52px; flex: 0 0 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  position: sticky; top: 0; z-index: 20;
}
.crumb { font-weight: 600; font-size: 15px; }
.who { font-size: 13px; color: var(--muted); }
.main { padding: 16px 18px 40px; }

/* ---------------- 卡片 / 区块 ---------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.card-head h2 { font-size: 14px; margin: 0; font-weight: 600; }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }
.card-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 6px; font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f9fafb; border-color: #d1d5db; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { background: var(--panel); border-color: #fecaca; color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { height: 27px; padding: 0 9px; font-size: 12.5px; }
.btn.block { width: 100%; height: 38px; font-size: 14px; margin-top: 6px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); padding: 0 6px; }
.btn.ghost:hover { background: var(--primary-soft); }

/* ---------------- 表单 ---------------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; height: 32px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13.5px; color: var(--text); background: #fff;
  outline: none;
}
textarea { height: auto; min-height: 60px; padding: 6px 9px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
input[readonly] { background: #f9fafb; color: var(--muted); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #6b7280 50%), linear-gradient(135deg, #6b7280 50%, transparent 50%); background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 26px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > .field { flex: 1 1 180px; margin-bottom: 10px; }

/* ---------------- 表格 ---------------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: #fafbfc; color: var(--muted); font-weight: 600;
  text-align: left; padding: 9px 10px; white-space: nowrap;
  border-bottom: 1px solid var(--line); font-size: 12.5px;
}
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:hover { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); }
.table-wrap.short { max-height: 360px; }

.empty {
  padding: 30px 12px; text-align: center; color: var(--muted); font-size: 13px;
}

/* ---------------- 标签 / 状态 ---------------- */
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  font-size: 12px; line-height: 18px; white-space: nowrap;
  background: #f3f4f6; color: #4b5563;
}
.tag.blue { background: var(--primary-soft); color: var(--primary-dark); }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.gray { background: #f3f4f6; color: #6b7280; }

.plus { color: var(--green); font-weight: 600; }
.minus { color: var(--red); font-weight: 600; }
.warn-text { color: var(--red); font-weight: 600; }

/* ---------------- 工具条 ---------------- */
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft); background: #fff;
}
.toolbar input, .toolbar select { width: auto; min-width: 120px; height: 30px; font-size: 13px; }
.toolbar .spacer { flex: 1; }

/* ---------------- 统计卡 ---------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .value small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.stat.alert .value { color: var(--red); }

/* 迷你柱状图（不引图表库） */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 130px; padding: 8px 2px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.chart .bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .bar { width: 11px; border-radius: 2px 2px 0 0; min-height: 2px; transition: height .3s; }
.chart .bar.in { background: #93c5fd; }
.chart .bar.out { background: #2563eb; }
.chart .x { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

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

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal-box {
  background: var(--panel); border-radius: 10px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, .22);
  padding: 18px 20px 16px;
}
.modal-box.wide { max-width: 900px; }
.modal-box h3 { margin: 0 0 4px; font-size: 16px; }
.modal-box .modal-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-close { position: absolute; }

/* 点击弹窗外部：闪烁提示（不关闭，防误触） */
@keyframes modalShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.modal-box.shake { animation: modalShake .45s ease; }

/* ---------------- 提示 ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13.5px; z-index: 200; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  max-width: 80vw;
}
.toast.error { background: #991b1b; }
.toast.ok { background: #166534; }

/* ---------------- 单据编辑 ---------------- */
.doc-head { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.doc-head .field { flex: 1 1 170px; margin-bottom: 8px; }

.items-editor { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 6px 0 10px; }
.items-editor table { font-size: 13px; }
.items-editor thead th { background: #f9fafc; padding: 7px 8px; }
.items-editor tbody td { padding: 5px 6px; }
.items-editor input { height: 29px; font-size: 13px; padding: 0 7px; }
.items-editor .prod-cell { position: relative; min-width: 220px; }
.items-editor .qty-cell { width: 92px; }
.items-editor .price-cell { width: 100px; }
.items-editor .del-cell { width: 40px; text-align: center; }

.suggest {
  position: absolute; left: 0; right: 0; top: 32px; z-index: 30;
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 8px 22px rgba(16, 24, 40, .16); max-height: 240px; overflow-y: auto;
}
.suggest div { padding: 7px 10px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.suggest div:hover, .suggest div.active { background: var(--primary-soft); }
.suggest .s-code { color: var(--muted); font-size: 12px; }
.suggest .s-stock { color: var(--muted); font-size: 12px; white-space: nowrap; }

.doc-total {
  display: flex; justify-content: flex-end; gap: 22px;
  padding: 8px 10px; background: #fafbfc; border-radius: 6px; font-size: 13px;
}
.doc-total b { font-variant-numeric: tabular-nums; }

/* ---------------- 盘点作业 ---------------- */
.count-table input { width: 90px; text-align: right; }
.diff-plus { color: var(--green); }
.diff-minus { color: var(--red); }

/* ---------------- 提示条 ---------------- */
.notice {
  border-radius: 6px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px;
  background: var(--primary-soft); color: var(--primary-dark); border: 1px solid #dbeafe;
}
.notice.warn { background: var(--amber-soft); color: var(--amber); border-color: #fde68a; }
.notice.danger { background: var(--red-soft); color: var(--red); border-color: #fecaca; }

/* ---------------- 打印 ---------------- */
@media print {
  .sidebar, .topbar, .toolbar, .pager, .btn, .card-tools { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}

/* ---------------- 小屏 ---------------- */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: column; }
  .nav { display: flex; overflow-x: auto; gap: 4px; padding: 8px; }
  .nav a { white-space: nowrap; margin: 0; }
  .nav-group { display: none; }
  .sidebar-foot { flex-direction: row; gap: 12px; justify-content: flex-end; }
  .brand { padding: 10px 12px; }
  .main { padding: 12px; }
  .table-wrap { max-height: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 12px; }
  .modal-box { padding: 14px; }
}

/* ============================================================
   商城协同 · 扫码台
   ============================================================ */
.scanbar {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfcff, #f7f9ff);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.scan-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px;
}
.scan-head b { color: var(--text); font-size: 15px; }
.scan-target { color: var(--primary); }
.scan-target b { font-size: 13px; }
.scan-row { display: flex; gap: 8px; align-items: center; }
.scan-row select { flex: 0 0 148px; }
.scan-input {
  flex: 1; height: 44px; padding: 0 14px; font-size: 16px; letter-spacing: .5px;
  border: 2px solid var(--primary); border-radius: 8px; background: #fff;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.scan-input:focus { outline: none; box-shadow: 0 0 0 4px var(--primary-soft); }
.scan-tip { margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 18px; }
.progress { margin-top: 8px; height: 6px; background: #e8edf7; border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 99px; transition: width .2s; }

tr.row-target td { background: var(--primary-soft); }
tr.group-row td { background: #f8fafc; font-size: 12.5px; border-top: 2px solid var(--line); }

.cell-input {
  width: 100%; border: 1px solid transparent; background: transparent;
  padding: 3px 5px; border-radius: 5px; font: inherit; color: inherit;
}
.cell-input:hover { border-color: var(--line); background: #fff; }
.cell-input:focus { border-color: var(--primary); background: #fff; outline: none; }
.cell-input.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.cell-sel {
  width: 100%; border: 1px solid transparent; background: transparent;
  padding: 3px 4px; border-radius: 5px; font: inherit; color: inherit;
}
.cell-sel:hover { border-color: var(--line); background: #fff; }
td .cell-input[type="number"] { text-align: right; }

/* hidden 属性优先于组件自身的 display（按钮在 hidden 时必须真隐藏） */
[hidden] { display: none !important; }
