:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #1f2a37;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #e8efff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --gray-soft: #eef0f3;
  --violet: #7c3aed;
  --violet-soft: #f1eafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --side: 220px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --surface: #171d25; --surface-2: #1d242e; --border: #2a333f;
    --text: #e6e9ee; --muted: #9aa4b2; --primary: #5b8cff; --primary-soft: #1d2a47;
    --danger: #f87171; --danger-soft: #3a1d1f; --ok: #4ade80; --ok-soft: #16301f;
    --warn: #fbbf24; --warn-soft: #36290f; --gray-soft: #262e39; --violet: #a78bfa; --violet-soft: #2a2140;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.side {
  width: var(--side); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 650; font-size: 16px; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; color: #fff; flex: none; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text);
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav svg { width: 19px; height: 19px; flex: none; }
.side-foot { margin-top: auto; padding: 10px 12px; font-size: 13px; color: var(--muted); }
.main { flex: 1; min-width: 0; padding: 26px 32px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 650; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

@media (max-width: 820px) {
  .layout { display: block; }
  .side {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: auto; height: auto; z-index: 20;
    flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .side-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; text-align: center; }
  .nav a.active { background: none; }
  .nav a.admin-only { display: none; }
  .main { padding: 16px 16px calc(90px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 20px; }
  .mobile-only { display: inline-flex !important; }
}
.mobile-only { display: none !important; }

/* ---------- 卡片 & 网格 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 650; line-height: 1.2; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.hl { background: var(--primary); color: #fff; border-color: transparent; }
.stat.hl .label, .stat.hl .sub { color: rgba(255,255,255,.82); }
@media (max-width: 520px) { .stats { grid-template-columns: 1fr 1fr; } .stat .value { font-size: 24px; } }

/* ---------- 表单 ---------- */
.form { display: grid; gap: 12px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }
.field > span b { color: var(--danger); font-weight: 400; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s; min-height: 40px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input.big { font-size: 26px; font-weight: 650; padding: 8px 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 38px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap;
  font-size: 14px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.icon { padding: 0; width: 32px; min-height: 32px; }
.btn.block { width: 100%; min-height: 44px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 160px; }
.toolbar input[type=date] { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .n { opacity: .65; margin-left: 4px; }

/* ---------- 列表 ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); align-items: flex-start; }
.item:first-child { border-top: 0; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-meta { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; gap: 4px 12px; flex-wrap: wrap; }
.item-note { font-size: 13px; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.qty { font-size: 20px; font-weight: 650; }
.qty small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.day-head { display: flex; justify-content: space-between; padding: 8px 18px; background: var(--surface-2); border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.day-head:first-child { border-top: 0; border-radius: var(--radius) var(--radius) 0 0; }
.day-head b { color: var(--text); }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--gray-soft); color: var(--muted); }
.badge.s-待检测 { background: var(--warn-soft); color: var(--warn); }
.badge.s-待维修 { background: var(--warn-soft); color: var(--warn); }
.badge.s-可再售 { background: var(--ok-soft); color: var(--ok); }
.badge.s-已拆件 { background: var(--violet-soft); color: var(--violet); }
.badge.s-报废 { background: var(--gray-soft); color: var(--muted); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.status-select { width: auto; min-height: 30px; padding: 3px 8px; font-size: 13px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stepper button { border: 0; background: var(--surface); width: 32px; height: 32px; cursor: pointer; font-size: 18px; line-height: 1; }
.stepper button:hover { background: var(--surface-2); }
.stepper span { min-width: 44px; text-align: center; font-weight: 650; font-size: 16px; padding: 0 4px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); line-height: 32px; }
.zero { opacity: .55; }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--primary); opacity: .85; }
.chart .bar.today { opacity: 1; }
.chart .bar:hover { opacity: 1; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--border); }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; padding: 28px; }
.login .brand { padding: 0 0 20px; font-size: 18px; }

/* ---------- 弹窗 & 提示 ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 40px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(15, 20, 26, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 0; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--text); color: var(--surface);
  padding: 10px 18px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }
@media (max-width: 820px) { #toast { bottom: calc(84px + env(safe-area-inset-bottom)); } }
.hint { font-size: 13px; color: var(--muted); }
.err-text { color: var(--danger); font-size: 13px; min-height: 1em; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 10px 18px; border-top: 1px solid var(--border); }
table.simple th { font-weight: 500; color: var(--muted); font-size: 13px; border-top: 0; }
.log-pos { color: var(--ok); font-weight: 600; }
.log-neg { color: var(--danger); font-weight: 600; }
