:root {
  --sidebar: #101828;
  --sidebar-2: #1a2436;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e6ebf3;
  --text: #0f172a;
  --muted: #6b7a90;
  --ok: #0f9d58;
  --warn: #b7791f;
  --danger: #d63a3a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }

.layout { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: linear-gradient(180deg, #101828, #16233a);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px;
}
.brand .t1 { color: #fff; font-size: 14px; font-weight: 600; letter-spacing: .5px; }
.brand .t2 { font-size: 10px; color: #7f8ea8; letter-spacing: 1.6px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  font-size: 13px; color: #cbd5e1; user-select: none;
  position: relative;
}
.nav-item:hover { background: #16213a; color: #fff; }
.nav-item.active { background: #1b2a4a; color: #fff; }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 2px; background: linear-gradient(#3b82f6, #06b6d4);
}
.nav-item .ico { width: 16px; text-align: center; opacity: .9; }
.nav-item .count {
  margin-left: auto; font-size: 11px; color: #94a3b8;
  background: #1f2f4a; border-radius: 8px; padding: 0 7px; line-height: 17px;
}
.nav-badge {
  margin-left: auto; font-size: 11px; line-height: 17px; padding: 0 7px;
  border-radius: 9px; background: #2563eb; color: #fff; font-weight: 600;
}
.nav-badge.warn { background: #d97706; }
.nav-badge.danger { background: #dc2626; }

.sidebar .spacer { flex: 1; }
.me { border-top: 1px solid #1f2c44; padding-top: 12px; font-size: 12px; }
.me .name { color: #fff; font-weight: 600; }
.me .role { color: #7f8ea8; margin-top: 2px; }
.me .logout { color: #93a4bd; font-size: 11px; cursor: pointer; margin-top: 8px; display: inline-block; }
.me .logout:hover { color: #fff; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.topbar { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; }
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: .3px; }
.topbar .sub { color: var(--muted); font-size: 12px; padding-bottom: 2px; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.card + .card { margin-top: 14px; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-h h3 { font-size: 14px; margin: 0; }
.card-h .sub { font-size: 12px; color: var(--muted); }
.card-b { padding: 14px 16px; }

.muted { color: var(--muted); }
.mono { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- buttons / inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer;
  transition: .15s; font-family: inherit;
}
.btn:hover { border-color: #c9d5e6; background: #f8fafc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #f3c9c9; }
.btn.danger:hover { background: #fdf1f1; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; font-family: inherit; color: var(--text);
  background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #9dbbf5; box-shadow: 0 0 0 3px #eef4ff; }
label.fld { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 6px; }
.tab {
  border: 1px solid var(--line); background: #fff; color: #475569;
  border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.tab.on { background: #2563eb; border-color: #2563eb; color: #fff; }
.filters input[type=search] { width: 220px; }
.filters select { width: auto; min-width: 120px; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 9px 12px; background: #fafbfd; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid #f1f4f9; vertical-align: middle; }
tbody tr:hover { background: #fafcff; }
tbody tr.clickable { cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }
.empty { text-align: center; color: var(--muted); padding: 36px 0 !important; }

.pager { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.pager .spacer { flex: 1; }

.chip {
  display: inline-block; padding: 1px 9px; border-radius: 20px;
  font-size: 11px; line-height: 18px; white-space: nowrap;
}
.chip.in_stock { background: #eef4ff; color: #2563eb; }
.chip.in_use { background: #e9f8ef; color: #0f7a45; }
.chip.repairing { background: #fff6e5; color: #a5640a; }
.chip.scrapped { background: #f2f3f5; color: #6b7280; }
.chip.void { background: #fdecec; color: #c0392b; }
.chip.tag { background: #f1f5f9; color: #52627a; margin-right: 4px; }

.tag-fixed { background: #eef4ff; color: #2563eb; }
.tag-consumable { background: #e9f8ef; color: #0f7a45; }
.tag-low_value { background: #fff6e5; color: #a5640a; }
.tag-qr { background: #f3edff; color: #6d28d9; }

/* ---------- modal / drawer ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .42);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 16px 30px; z-index: 40; overflow: auto;
}
.modal {
  background: #fff; border-radius: 14px; width: 620px; max-width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .22);
}
.modal.wide { width: 860px; }
.modal-h { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-h h3 { margin: 0; font-size: 15px; }
.modal-h .x { margin-left: auto; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; }
.modal-b { padding: 16px 18px; max-height: 68vh; overflow: auto; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

.drawer-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 92vw;
  background: #fff; z-index: 41; box-shadow: -12px 0 40px rgba(0, 0, 0, .16);
  display: flex; flex-direction: column;
}
.drawer-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-h h3 { margin: 0; font-size: 15px; }
.drawer-h .x { margin-left: auto; cursor: pointer; color: var(--muted); font-size: 18px; }
.drawer-b { padding: 16px 18px; overflow: auto; flex: 1; }
.drawer-f { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 9px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-all; }

.sect { font-size: 12px; color: var(--muted); margin: 18px 0 8px; letter-spacing: .5px; }
.timeline { border-left: 2px solid #e8eef8; margin-left: 5px; padding-left: 14px; }
.timeline .item { position: relative; padding-bottom: 12px; font-size: 12.5px; }
.timeline .item::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: #93b4f7;
  position: absolute; left: -19px; top: 4px;
}
.timeline .t { color: var(--muted); font-size: 11px; }

.qr-box { text-align: center; padding: 8px 0 2px; }
.qr-box img { width: 132px; height: 132px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- toast ---------- */
.toast-wrap { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #101828; color: #fff; border-radius: 8px; padding: 9px 16px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2); animation: fade .18s ease-out;
}
.toast.err { background: #b42318; }
@keyframes fade { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- import ---------- */
.drop {
  border: 1.5px dashed #c9d5e6; border-radius: 12px; padding: 26px;
  text-align: center; color: var(--muted); font-size: 13px; background: #fbfcfe; cursor: pointer;
}
.drop:hover { border-color: #9dbbf5; background: #f7faff; }
.drop b { color: var(--text); }
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.stat { background: #fafbfd; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; min-width: 120px; }
.stat .n { font-size: 20px; font-weight: 600; }
.stat .l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.err-table td { font-size: 12px; }
.code-inline { background: #f4f6fb; border-radius: 4px; padding: 1px 5px; font-family: Consolas, monospace; font-size: 11.5px; }

/* ---------- 标签打印 ---------- */
#print-area { display: none; }
#print-area .label-grid { display: flex; flex-wrap: wrap; gap: 3mm; }
#print-area .label {
  width: 50mm; height: 30mm; box-sizing: border-box;
  border: 1px dashed #c8d2e2; border-radius: 2mm;
  padding: 2mm 2.5mm; display: flex; flex-direction: column; justify-content: space-between;
  page-break-inside: avoid; break-inside: avoid; overflow: hidden;
}
#print-area .l-name { font-size: 9pt; font-weight: 700; line-height: 1.2; max-height: 2.4em; overflow: hidden; }
#print-area .l-code { font-family: Consolas, monospace; font-size: 7.5pt; color: #334155; letter-spacing: .2px; }
#print-area .l-bottom { display: flex; gap: 2.5mm; align-items: flex-end; }
#print-area .l-bottom img { width: 17mm; height: 17mm; image-rendering: pixelated; }
#print-area .l-meta { font-size: 6.5pt; color: #475569; line-height: 1.5; overflow: hidden; }
#print-area .l-tip { color: #94a3b8; }

@media print {
  body { background: #fff; }
  .layout, .toast-wrap, .mask, .drawer, .drawer-mask { display: none !important; }
  #print-area { display: block; }
  @page { size: A4; margin: 8mm; }
}

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; }
  .brand { padding: 0 12px 0 0; }
  .brand .t2 { display: none; }
  .nav { flex-direction: row; }
  .nav-item { white-space: nowrap; padding: 7px 10px; }
  .nav-item.active::before { display: none; }
  .sidebar .spacer, .me { display: none; }
  .main { padding: 16px 14px 30px; }
  .topbar { flex-wrap: wrap; }
  .topbar .actions { margin-left: 0; width: 100%; }
  .filters input[type=search] { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 78px 1fr; }
  .drawer { width: 100%; max-width: 100%; }
}
