:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #e8efff;
  --success: #16a34a;
  --success-soft: #e7f7ed;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0891b2;
  --info-soft: #e0f2fe;
  --border: #e3e8f0;
  --sidebar: #0f172a;
  --sidebar-2: #1c2740;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: none; }

a { color: var(--primary); text-decoration: none; }

.boot {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; color: var(--muted);
}
.boot-spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #dbe3f0; border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, #26385f 0%, transparent 60%), linear-gradient(160deg, #101a2e 0%, #16233c 45%, #1e3a8a 100%);
}
.login-card {
  width: 100%; max-width: 400px;
  background: rgba(255, 255, 255, .97);
  border-radius: 18px; padding: 30px 28px 26px;
  box-shadow: 0 20px 60px rgba(2, 8, 23, .35);
}
.login-logo {
  width: 52px; height: 52px; border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: flex; align-items: center; justify-content: center;
  color: #fff; margin-bottom: 14px;
}
.login-logo svg { width: 28px; height: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 21px; letter-spacing: .5px; }
.login-sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login-tip {
  margin-top: 16px; padding: 10px 12px; border-radius: 10px;
  background: var(--primary-soft); color: #1e3a8a; font-size: 12px; line-height: 1.6;
}

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex: none;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px; font-size: 15px; font-weight: 600; color: #fff;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand small { display: block; font-size: 11px; color: #64748b; font-weight: 400; }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: #cbd5e1; font-size: 14px; border: none; background: none; width: 100%;
  text-align: left; transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, #2563eb, #3b82f6); color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, .35); }
.nav-footer { padding: 12px; border-top: 1px solid #1e293b; font-size: 12px; color: #64748b; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; flex: none;
  background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { margin: 0; font-size: 17px; }
.topbar .crumb { color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.content { padding: 20px; flex: 1; min-width: 0; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--primary-soft); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px;
}
.user-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 10px; }
.user-chip:hover { background: var(--bg); }
.user-chip .un { font-size: 13px; font-weight: 500; line-height: 1.2; }
.user-chip .ur { font-size: 11px; color: var(--muted); }

/* ---------- 通用组件 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.card-title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }

.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: none; }
.stat-icon svg { width: 19px; height: 19px; }
.stat-num { font-size: 22px; font-weight: 700; line-height: 1.15; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; cursor: pointer;
  transition: all .14s; white-space: nowrap; font-family: inherit;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.94); background: var(--success); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); background: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-outline-danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn-outline-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 5px 9px; font-size: 12px; border-radius: 8px; }
.btn-lg { padding: 12px 18px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500;
}
.badge-in_stock { background: var(--success-soft); color: #15803d; }
.badge-lent { background: var(--warn-soft); color: #b45309; }
.badge-repairing { background: #ede9fe; color: #6d28d9; }
.badge-scrapped { background: #f1f5f9; color: #64748b; }
.badge-out { background: var(--warn-soft); color: #b45309; }
.badge-returned { background: var(--success-soft); color: #15803d; }
.badge-overdue { background: var(--danger-soft); color: #b91c1c; }
.badge-admin { background: var(--primary-soft); color: var(--primary-dark); }
.badge-clerk { background: #f1f5f9; color: #475569; }

input[type=text], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
  outline: none; transition: border-color .14s, box-shadow .14s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; min-height: 68px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-help { font-size: 11px; color: var(--muted); margin-top: 4px; }

table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
table.tbl th { background: #f8fafc; color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; position: sticky; top: 0; z-index: 2; }
table.tbl tbody tr:hover { background: #f9fbff; }
table.tbl td .sub { color: var(--muted); font-size: 11px; }
.tbl-wrap { overflow: auto; }
.nowrap { white-space: nowrap; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 160px; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--muted); }
.search-box input { padding-left: 32px; }

/* 输入联想下拉 */
.suggest {
  position: absolute; z-index: 80; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); max-height: min(46vh, 320px); overflow: auto;
}
.suggest-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item.active { background: var(--primary-soft); }
.suggest-main { flex: 1; min-width: 0; }
.suggest-title { font-weight: 600; font-size: 13px; }
.suggest-sub { color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-all; }
.suggest-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }
.suggest-loading { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; flex-wrap: wrap; }
.pager-info { color: var(--muted); font-size: 12px; }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .35; margin-bottom: 10px; }

.hint-box {
  background: var(--info-soft); border: 1px solid #bae6fd; color: #075985;
  padding: 10px 12px; border-radius: 10px; font-size: 12.5px; line-height: 1.6;
}
.warn-box { background: var(--warn-soft); border: 1px solid #fde68a; color: #92400e; padding: 10px 12px; border-radius: 10px; font-size: 12.5px; }

/* ---------- 列表卡片（移动端） ---------- */
.list-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.list-card .lc-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list-card .lc-name { font-weight: 600; font-size: 14px; }
.list-card .lc-meta { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.7; word-break: break-all; }
.list-card .lc-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 1000;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 70px rgba(2, 8, 23, .3);
}
.modal-lg { max-width: 880px; }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 8px; }
.modal-close:hover { background: var(--bg); }

/* ---------- Toast ---------- */
.toast-root { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow); animation: drop .2s ease; max-width: 90vw;
}
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.warn { background: #b45309; }
@keyframes drop { from { opacity: 0; transform: translateY(-12px) } to { opacity: 1; transform: none } }

/* ---------- 扫码 ---------- */
.scan-tabs { display: flex; background: #eef2f8; padding: 4px; border-radius: 12px; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.scan-tab {
  flex: 1; min-width: 84px; padding: 9px 6px; border-radius: 9px; border: none; background: none;
  cursor: pointer; font-size: 13px; color: var(--muted); font-family: inherit; font-weight: 500;
}
.scan-tab.active { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow-sm); }

.scanner { position: relative; background: #0f172a; border-radius: var(--radius); overflow: hidden; }
.scanner video { width: 100%; display: block; max-height: 46vh; object-fit: cover; background: #0f172a; }
.scanner-frame {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 62%; aspect-ratio: 1 / 1; max-width: 300px; border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, .85); box-shadow: 0 0 0 100vmax rgba(2, 8, 23, .35);
}
.scanner-frame::after {
  content: ''; position: absolute; left: 0; right: 0; height: 2px; top: 0;
  background: linear-gradient(90deg, transparent, #38bdf8, transparent);
  animation: scanline 2.2s linear infinite;
}
@keyframes scanline { 0% { top: 4% } 50% { top: 96% } 100% { top: 4% } }
.scanner-off {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 36px 16px; color: #94a3b8; background: #0f172a; border-radius: var(--radius); text-align: center;
}
.scanner-off svg { width: 40px; height: 40px; opacity: .5; }

.result-card { border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border); background: #fff; }
.result-card.ok { border-color: #86efac; background: var(--success-soft); }
.result-card.err { border-color: #fca5a5; background: var(--danger-soft); }
.kv { display: grid; grid-template-columns: 82px 1fr; gap: 6px 10px; font-size: 13px; line-height: 1.6; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- 设备详情/借还信息 ---------- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.info-item { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.info-item .k { font-size: 11px; color: var(--muted); }
.info-item .v { font-size: 13px; font-weight: 500; word-break: break-all; }

/* ---------- 导入 ---------- */
.drop-zone {
  border: 2px dashed #cbd5e1; border-radius: var(--radius); padding: 26px;
  text-align: center; color: var(--muted); cursor: pointer; transition: all .15s; background: #fbfcfe;
}
.drop-zone:hover, .drop-zone.drag { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.drop-zone svg { width: 34px; height: 34px; opacity: .6; margin-bottom: 8px; }
.import-summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.import-summary .pill { background: #f1f5f9; border-radius: 999px; padding: 4px 12px; font-size: 12px; }
.import-summary .pill.g { background: var(--success-soft); color: #15803d; }
.import-summary .pill.y { background: var(--warn-soft); color: #b45309; }
.import-summary .pill.r { background: var(--danger-soft); color: #b91c1c; }

/* ---------- 设备标签（40mm×30mm，参考样张版式） ---------- */
.label-cfg-title { margin: 12px 0 6px; font-weight: 700; font-size: 13px; color: var(--muted); }
.label-cfg { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.label-cfg .chk { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.label-cfg .chk input { width: 15px; height: 15px; cursor: pointer; }
#lb-preview { margin-top: 4px; padding: 10px; background: #f1f5f9; border-radius: 8px; }
.label-sheet { display: flex; flex-wrap: wrap; gap: 5px; }
.blabel {
  position: relative; width: 40mm; min-width: 40mm; max-width: 40mm; height: 30mm; box-sizing: border-box;
  flex: none;
  border: none; padding: 1.2mm 1.6mm;
  background: #fff; overflow: hidden; break-inside: avoid; page-break-inside: avoid;
  display: flex; flex-direction: column;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif; color: #000;
}
.blabel-title { text-align: center; font-weight: 700; font-size: 2.2mm; line-height: 1.25; letter-spacing: .2mm; }
.blabel-mid { display: flex; align-items: flex-start; gap: 1.2mm; margin-top: .4mm; flex: 1; min-height: 0; overflow: hidden; }
.blabel-info { flex: 1; min-width: 0; font-size: 2mm; font-weight: 700; line-height: 1.55; word-break: break-all; }
.blabel-info b { font-weight: 700; }
.blabel-qr { width: 12mm; height: 12mm; flex: none; background: #fff; }
.blabel-qr svg { width: 100%; height: 100%; display: block; }
.blabel-code { margin-top: .4mm; text-align: center; padding: 0; }
.blabel-code svg { width: 100%; height: 8mm; display: block; margin: 0 auto; }
.blabel-code-num { font-size: 2.2mm; letter-spacing: .2mm; line-height: 1.2; }
.blabel-stock { position: absolute; right: 1.6mm; bottom: 1mm; font-size: 2.2mm; font-weight: 700; }

/* ---------- 响应式：手机 ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; height: auto;
    flex-direction: row; z-index: 60; padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid #1e293b; background: rgba(15, 23, 42, .98); backdrop-filter: blur(8px);
  }
  .brand, .nav-footer { display: none; }
  .nav { flex-direction: row; padding: 4px 2px; gap: 0; }
  .nav-item {
    flex-direction: column; gap: 3px; font-size: 11px; padding: 7px 2px;
    justify-content: center; align-items: center; background: none; border-radius: 10px;
  }
  .nav-item.active { background: transparent; box-shadow: none; color: #60a5fa; }
  .nav-item:hover { background: transparent; color: #fff; }
  .topbar { padding: 0 12px; height: 54px; }
  .topbar h2 { font-size: 15px; }
  .content { padding: 12px 12px 84px; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px; }
  .stat-num { font-size: 20px; }
  .field-row { grid-template-columns: 1fr; }
  .modal { max-height: 92vh; }
  .modal-foot .btn { flex: 1; }
  .card-head { padding: 12px; }
  .card-body { padding: 12px; }
  .scan-tabs .scan-tab { flex: 1 1 22%; min-width: 0; padding: 9px 2px; font-size: 12px; }
  .tbl-wrap { display: none; }
  .pager { padding: 10px 12px; }
  .btn-lg { padding: 13px 16px; }
}

@media (min-width: 901px) {
  .mobile-only { display: none !important; }
}

/* ---------- 打印 ---------- */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .toast-root, .no-print, .modal-mask { display: none !important; }
  .content { padding: 0; }
}

/* ---------- 快捷操作 ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 900px) { .quick-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; } }

/* ---------- 工作台分区标题 ---------- */
.section-label {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 0 10px; font-size: 14px; font-weight: 600; color: var(--text);
}
.section-label svg { width: 17px; height: 17px; color: #2563eb; }
.section-action { display: flex; justify-content: flex-end; padding: 8px 12px 0; }

/* 工作台手机端动态列表：限制高度，避免把页面撑得过长 */
@media (max-width: 900px) {
  .recent-scroll { max-height: 420px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .recent-scroll .list-card:last-child { margin-bottom: 0; }
}

/* ---------- 打印专用容器（二维码标签） ---------- */
#print-area { display: none; }
@media print {
  html, body { height: auto !important; background: #fff; }
  body > * { display: none !important; }
  body > #print-area { display: block !important; padding: 0 !important; margin: 0 !important; }
  #print-area .label-sheet { gap: 0; }
  .blabel, .blabel * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
