:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e6e9f0;
  --text: #1c2333;
  --muted: #7a8398;
  --brand: #2f6fed;
  --brand-dark: #1f4fbf;
  --nav: #101a2f;
  --nav-2: #16233d;
  --ok: #0f9f6e;
  --warn: #e8890c;
  --danger: #e04646;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--brand); text-decoration: none; }

/* ---------- 登录 ---------- */
#login {
  height: 100%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 15% 10%, #21386b 0%, #0e1729 55%, #0b1220 100%);
}
#login.hide { display: none; }
.login-card {
  width: 380px; background: #fff; border-radius: 16px; padding: 34px 32px 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-logo .mark { width: 38px; height: 38px; border-radius: 10px; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; }
.login-logo h1 { font-size: 20px; margin: 0; letter-spacing: .5px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 4px 0 22px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.login-card input {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  outline: none; transition: .15s;
}
.login-card input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,111,237,.12); }
.login-btn {
  width: 100%; height: 44px; margin-top: 22px; background: var(--brand); color: #fff;
  border: 0; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.login-btn:hover { background: var(--brand-dark); }
.login-err { color: var(--danger); font-size: 12.5px; height: 18px; margin-top: 10px; }
.login-foot { text-align: center; color: #9aa3b5; font-size: 12px; margin-top: 18px; }

/* ---------- 主框架 ---------- */
#app { display: none; height: 100%; }
#app.show { display: flex; }
.sidebar {
  width: 216px; background: var(--nav); color: #c9d2e4; display: flex; flex-direction: column;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 9px; padding: 18px 18px 14px; color: #fff;
}
.brand .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.brand h2 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: .3px; }
.brand > div { min-width: 0; }
.brand small { display: block; font-size: 11px; color: #7f8cab; font-weight: 400; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 148px; }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px 20px; }
.nav-group { color: #6d7c99; font-size: 11.5px; padding: 14px 10px 6px; letter-spacing: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; color: #c3cddf; font-size: 13.5px; margin-bottom: 2px;
}
.nav-item:hover { background: var(--nav-2); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; opacity: .9; }
.nav-foot { padding: 10px 14px 14px; font-size: 11.5px; color: #64718c; border-top: 1px solid #1b2740; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 20px; gap: 14px; flex-shrink: 0;
}
.topbar .title { font-size: 15.5px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: 9px; cursor: pointer; padding: 5px 8px; border-radius: 8px; }
.userbox:hover { background: #f2f4f9; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.userbox .uname { font-size: 13.5px; }
.role-tag { font-size: 11px; color: var(--brand); background: #eaf0ff; padding: 2px 7px; border-radius: 20px; }

.content { flex: 1; overflow-y: auto; padding: 18px 20px 28px; }

/* ---------- 通用组件 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px; }
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title h3 { margin: 0; font-size: 15px; font-weight: 600; }
.hint { color: var(--muted); font-size: 12.5px; }

.btn {
  height: 34px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--line);
  background: #fff; color: var(--text); cursor: pointer; font-size: 13.5px; transition: .12s;
}
.btn:hover { border-color: #c9d2e4; background: #f7f9fd; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f2c8c8; }
.btn.danger:hover { background: #fff5f5; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.input, .select {
  height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff;
  outline: none; min-width: 120px;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,111,237,.1); }
.input.search { width: 240px; }
.input.date { width: 145px; }
.input.scan { border-color: #b9c9ff; background: #f6f9ff; }

.table-wrap { overflow: auto; border-radius: 8px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid #f0f2f7; font-size: 13px;
  white-space: nowrap; }
th { background: #f8f9fc; color: #5d6679; font-weight: 600; font-size: 12.5px; position: sticky; top: 0; z-index: 1; }
tr:hover td { background: #fafbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: "Consolas", "Cascadia Mono", monospace; font-size: 12.5px; }
.empty { text-align: center; color: var(--muted); padding: 36px 0; font-size: 13px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; line-height: 17px; }
.tag.ok { background: #e8f7ef; color: #0b7f57; }
.tag.draft { background: #fff4e3; color: #b9700a; }
.tag.void { background: #f2f3f6; color: #8a90a2; }
.tag.low { background: #ffecec; color: #c93434; }
.tag.blue { background: #eaf0ff; color: #2f6fed; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
/* 工作台 7 个指标卡，列宽收窄一点保证一行排开 */
.kpis-dash { grid-template-columns: repeat(auto-fit, minmax(146px, 1fr)); }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 23px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi.alert .value { color: var(--danger); }
.kpi.good .value { color: var(--ok); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(12,18,32,.5); display: flex; align-items: center;
  justify-content: center; z-index: 30; padding: 24px;
}
.modal {
  background: #fff; border-radius: 14px; width: 560px; max-width: 100%; max-height: 92vh;
  display: flex; flex-direction: column; box-shadow: 0 30px 70px rgba(0,0,0,.28);
}
.modal.wide { width: 880px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 15.5px; }
.modal-head .x { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 7px; padding: 0 9px; outline: none;
}
.field textarea { height: 70px; padding: 8px 9px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,111,237,.1);
}
.check-row { display: flex; gap: 18px; align-items: center; height: 34px; }
.check-row label { display: flex; align-items: center; gap: 5px; color: var(--text); font-size: 13px; }

/* ---------- 单据编辑 ---------- */
.doc-head { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; }
.doc-lines { margin-top: 14px; }
.line-table td { padding: 6px 8px; }
.line-table .cell-input { width: 100%; height: 30px; border: 1px solid #e6e9f0; border-radius: 6px;
  padding: 0 8px; outline: none; font-size: 13px; }
.line-table .cell-input:focus { border-color: var(--brand); }
.line-table .cell-input.num { text-align: right; }
.line-table .sn-cell { display: flex; gap: 4px; align-items: center; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 5px; }
.icon-btn:hover { color: var(--brand); }
.doc-total { display: flex; justify-content: flex-end; gap: 26px; padding: 14px 6px 0; font-size: 13.5px; }
.doc-total b { font-size: 17px; color: var(--danger); }
.doc-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ---------- 单据打印视图 ---------- */
.doc-print { background: #fff; padding: 26px 30px; border-radius: 10px; border: 1px solid var(--line); }
.doc-print h2 { text-align: center; font-size: 20px; margin: 0 0 4px; letter-spacing: 2px; }
.doc-print .sub { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.print-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; font-size: 13px; margin-bottom: 12px; }
.print-meta span { color: var(--muted); }
.doc-print table { border: 1px solid #dfe3ec; }
.doc-print th, .doc-print td { border: 1px solid #dfe3ec; }
.sign-row { display: flex; justify-content: space-between; margin-top: 34px; font-size: 13px; color: #333; }

/* ---------- Toast ---------- */
#toast { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast-item { background: #16233d; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: tin .2s ease; }
.toast-item.err { background: #c93434; }
.toast-item.ok { background: #0b7f57; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- 其他 ---------- */
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 12.5px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab { padding: 7px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 13px; }
.tab.active { background: #fff; color: var(--brand); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; }
.perm-grid label { display: flex; align-items: center; gap: 7px; font-size: 13px; padding: 5px 0; }
.stock-batches { color: var(--muted); font-size: 12px; }
.mini-bar { height: 6px; background: #eef1f7; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.mini-bar i { display: block; height: 100%; background: var(--brand); }
.mini-bar.low i { background: var(--danger); }
@media print {
  .sidebar, .topbar, .toolbar, .doc-foot, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
}


/* 打印模板中心 */
.tpl-wrap { display: grid; grid-template-columns: 190px 1fr 420px; gap: 14px; align-items: start; }
.tpl-side { padding: 12px; }
.tpl-tab { padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: #334; }
.tpl-tab:hover { background: #f2f5fb; }
.tpl-tab.active { background: #e8efff; color: #1b4dd8; font-weight: 600; }
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tpl-checks { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 14px; font-size: 13px; }
.tpl-preview { padding: 14px; }
.tpl-paper { background: #fff; border: 1px solid #e3e6ee; border-radius: 6px; padding: 20px 22px; font-size: 12px; color: #222; }
.tpl-paper.compact { padding: 12px 14px; font-size: 11px; }
.tpl-company { font-size: 15px; font-weight: 700; text-align: center; }
.tpl-title { font-size: 17px; font-weight: 700; text-align: center; margin: 6px 0 8px; letter-spacing: 3px; }
.tpl-note { color: #666; margin: 4px 0; line-height: 1.6; }
.tpl-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.tpl-table th, .tpl-table td { border: 1px solid #999; padding: 5px 6px; }
.tpl-table th { background: #f4f5f8; }
.tpl-table .num { text-align: right; }
.tpl-total { text-align: right; font-weight: 600; margin: 8px 0; }
.tpl-foot { border-top: 1px dashed #bbb; margin-top: 10px; padding-top: 8px; color: #555; line-height: 1.7; }
.tpl-sign { display: flex; justify-content: space-between; margin-top: 16px; color: #333; }


/* 打印页模板元素 */
.print-note { text-align: center; color: #555; font-size: 12px; margin-top: -2px; }
.print-foot { border-top: 1px dashed #bbb; margin-top: 12px; padding-top: 8px; color: #555; font-size: 12px; line-height: 1.7; }
.doc-print.compact { font-size: 12px; }
.doc-print.compact h2 { font-size: 18px; }
.doc-print.compact .sub { margin-bottom: 8px; }
.doc-print.compact table td, .doc-print.compact table th { padding: 4px 6px; }
@media print {
  .doc-print.compact table td, .doc-print.compact table th { padding: 3px 5px; }
}
