:root {
  --primary: #2f6fed;
  --primary-dark: #1f56c4;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e3e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- 顶部 ---------- */
header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-size: 18px; font-weight: 700; white-space: nowrap; }
.logout-btn { margin-left: auto; padding: 7px 14px; font-size: 13px; }
#tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1 1 auto; }
.tab {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.tab:hover { background: #eef2fb; color: var(--primary); }
.tab.active { background: var(--primary); color: #fff; font-weight: 600; }

/* 移动端 header：标题与按钮一行，菜单 tab 单独一行可横滚，避免被挤成竖排 */
@media (max-width: 720px) {
  header { flex-wrap: wrap; padding: 8px 12px; gap: 6px 10px; }
  .brand { font-size: 15px; order: 0; }
  .logout-btn { padding: 5px 10px; font-size: 12px; margin-left: auto; }
  #tabs { order: 9; flex: 1 1 100%; padding-bottom: 2px; }
  .tab { padding: 6px 12px; font-size: 13px; }
}

/* ---------- 布局 ---------- */
main { padding: 20px; max-width: 1280px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
h2 { font-size: 16px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0 0 12px; }

.entry-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .entry-layout { grid-template-columns: 1fr; } }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field-row.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .field-row.two-col { grid-template-columns: 1fr; } }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.req { color: var(--danger); }
.tip { font-weight: 400; color: #9aa3b2; font-size: 12px; }
input[type="text"], input[type="password"], input[type="datetime-local"], input[type="date"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  min-height: 40px;
  box-sizing: border-box;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 111, 237, .15); }
select:disabled {
  background: #f3f5f9;
  color: var(--muted);
  cursor: not-allowed;
}
textarea { resize: vertical; min-height: 0; }

/* 扫码输入框：限宽（不要拉满），与右边几个控件等高 */
.scan-input { display: flex; gap: 8px; max-width: 420px; }
.scan-input input { flex: 1; }
.cam-btn {
  border: 1px solid var(--border);
  background: #eef2fb;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 18px;
  min-height: 40px;
}
.cam-btn:hover { background: #dfe8fb; }

.seg { display: inline-flex; background: #eef1f7; border-radius: 8px; padding: 3px; gap: 3px; }
.seg-btn {
  border: none;
  background: transparent;
  padding: 7px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}
.seg-btn.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 2px rgba(16,24,40,.1); }

.form-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.hint { color: #9aa3b2; font-size: 12px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--border);
  background: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
.btn:hover { border-color: #c6cfe0; background: #f8fafd; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #e5484d; border-color: #e5484d; color: #fff; }
.btn.danger:hover { background: #cf3f44; }

/* 删除按钮（列表/表格） */
.ri-del {
  position: absolute;
  top: 4px;
  right: 4px;
  border: 1px solid #f0c9ca;
  background: #fff;
  color: #e5484d;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  z-index: 2;
}
.ri-del:hover { color: #fff; background: #e5484d; border-color: #e5484d; }
.row-del {
  border: 1px solid #f0c9ca;
  background: #fff5f5;
  color: #e5484d;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.row-del:hover { background: #e5484d; color: #fff; border-color: #e5484d; }

.del-msg { color: var(--text); line-height: 1.7; white-space: pre-line; margin: 8px 0 4px; }

/* ---------- 最近扫描 ---------- */
.recent-card { max-height: calc(100vh - 96px); display: flex; flex-direction: column; }
.recent-tip { font-size: 12px; color: #9aa3b2; margin-bottom: 10px; }
.recent-badge { background: var(--primary); color: #fff; border-radius: 10px; padding: 1px 9px; font-size: 12px; vertical-align: middle; }
.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.recent-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  background: #fff;
}
.recent-item:hover { border-color: var(--primary); }
.recent-item.active { border-color: var(--primary); background: #f0f5ff; }
.ri-top { position: relative; padding-right: 64px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.ri-model { font-weight: 600; }
.ri-model small { color: var(--primary); font-weight: 500; }
.ri-dir { font-size: 12px; border-radius: 5px; padding: 1px 8px; }
.ri-dir.out { background: #fff1e6; color: var(--warn); }
.ri-dir.in { background: #e8f7ef; color: var(--ok); }
.ri-line { font-size: 13px; color: var(--text); }
.ri-time { font-size: 12px; color: #9aa3b2; margin-top: 4px; }

/* ---------- 查询 ---------- */
/* 查询筛选：5 个控件严格等宽等高（用 flex 避免 datetime 内部 min-content 撑开列） */
.filter-grid {
  display: flex;
  gap: 12px;
  align-items: end;
}
.filter-grid > .field {
  flex: 1 1 0;
  min-width: 0;
  margin-bottom: 0;
}
.filter-grid .field input,
.filter-grid .field select {
  min-width: 0;
  width: 100%;
  height: 40px;           /* 固定高度，保证 5 个控件绝对等高 */
  padding: 0 12px;        /* 竖向由 height 控制 */
  line-height: 1.2;
  box-sizing: border-box;
}
@media (max-width: 900px) {
  .filter-grid { flex-wrap: wrap; }
  .filter-grid > .field { flex: 1 1 calc(50% - 6px); min-width: 180px; }
}
.filter-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.kw-wrap { position: relative; }
.kw-popup {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(16,24,40,.12);
  z-index: 30;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 4px;
}
.kw-popup.hidden { display: none; }
.kw-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f0f2f7; }
.kw-item:last-child { border-bottom: none; }
.kw-item:hover { background: #f0f5ff; }
.kw-main { font-weight: 600; }
.kw-sub { font-size: 12px; color: var(--muted); }
.kw-empty { padding: 12px; color: var(--muted); text-align: center; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 20px; }
.detail-grid label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 2px; }

.table-wrap { overflow-x: auto; }
.scroll-y { max-height: 420px; overflow-y: auto; }
.load-tip { text-align: center; color: #9aa3b2; font-size: 12px; padding: 8px 0 2px; }
.detail-actions { margin-top: 12px; }
.detail-actions .btn { margin-right: 8px; }
.seq-tag {
  display: inline-block;
  background: #eef2fb;
  color: var(--primary);
  border-radius: 5px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 600;
}
.recent-item.editing { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(47,111,237,.2); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #eef1f6; white-space: nowrap; }
th { background: #f7f9fd; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
tbody tr:hover { background: #f8faff; cursor: pointer; }
td.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.badge { background: #eef2fb; color: var(--primary); border-radius: 10px; padding: 1px 9px; font-size: 12px; }
.dir { font-size: 12px; border-radius: 5px; padding: 1px 8px; }
.dir.out { background: #fff1e6; color: var(--warn); }
.dir.in { background: #e8f7ef; color: var(--ok); }

/* ---------- 导入导出 ---------- */
.io-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .io-grid { grid-template-columns: 1fr; } }
.io-box { border: 1px dashed #c9d3e4; border-radius: 8px; padding: 14px 16px; }
.io-box h3 { margin-top: 0; }
.io-box p { color: var(--muted); font-size: 13px; }
.io-box code { background: #f0f2f7; padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.io-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#importResult { margin-top: 10px; font-size: 13px; }
.ok { color: var(--ok); }
.err { color: var(--danger); }
#importResult li { color: var(--muted); }

/* ---------- 报表 ---------- */
.report-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.report-tools select { width: auto; }
.cmp-tools { align-items: flex-end; }
.range-box { display: flex; flex-direction: column; gap: 4px; }
.range-box label { font-size: 12px; color: var(--muted); }
.range-box .inputs-row { display: flex; align-items: center; gap: 4px; }
.range-box .sep { color: var(--muted); }
.range-box input[type="date"] { width: 150px; }
.summary-text {
  background: linear-gradient(135deg, #ffffff 0%, #f8faff 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 22px;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(47, 111, 237, .06);
}

/* 汇总文字：大数字 + 型号 chips（高端版） */
.summary-layout { display: flex; flex-direction: column; gap: 14px; }
.stat-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.stat-num {
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #2f6fed 0%, #5b8def 60%, #7aa6ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat-unit { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat-meta { font-size: 13px; color: var(--muted); }
.stat-empty { color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: #fff;
  border: 1px solid #e3e8f0;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .05);
  transition: transform .15s, box-shadow .15s;
}
.chip:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(47, 111, 237, .12); }
.chip b { color: var(--primary); font-weight: 600; }
.chip .cnt { color: var(--muted); font-weight: 500; }

/* 对比文字：区间A VS 区间B 双栏（高端版） */
.cmp-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: stretch; }
.cmp-col {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 4px 14px rgba(47, 111, 237, .06);
  position: relative;
}
.cmp-col::before {
  content: '';
  position: absolute;
  top: 0; left: 18px; right: 18px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, #2f6fed, #5b8def);
  opacity: .8;
}
.cmp-title {
  font-size: 11px;
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-top: 4px;
}
.cmp-range { font-size: 12px; color: #9aa3b2; }
.cmp-num {
  font-size: 34px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #2f6fed 0%, #5b8def 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.cmp-num small {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  margin-left: 4px;
  letter-spacing: 0;
}
.cmp-vs {
  align-self: center;
  font-weight: 800;
  color: #c6cfe0;
  font-size: 22px;
  padding: 0 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cmp-diff {
  margin-top: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 10px 16px;
  background: linear-gradient(135deg, #f0f5ff 0%, #e8efff 100%);
  border: 1px solid #d9e2f5;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.cmp-diff .arrow { font-size: 16px; font-weight: 800; }
.cmp-diff.up .arrow { color: #ef4444; }
.cmp-diff.down .arrow { color: #16a34a; }
.cmp-diff.flat .arrow { color: var(--muted); }
.cmp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cmp-chips .chip { padding: 2px 10px; font-size: 12px; box-shadow: none; }

/* 录入错误条 */
.form-error {
  margin-top: 10px;
  padding: 9px 14px;
  background: linear-gradient(135deg, #fef2f2 0%, #fff1f1 100%);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.form-error::before { content: '⚠'; font-size: 14px; }
.form-error.success {
  background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf9 100%);
  color: var(--ok);
  border-color: #bbf7d0;
}
.form-error.success::before { content: '✓'; }

/* 图表压缩，给汇总文字留空间 */
.chart { width: 100%; height: 420px; }
#summaryChart { height: 260px; }
#compareChart { height: 300px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  width: min(92vw, 420px);
}
.modal-box h3 { margin-top: 0; }
#camReader { width: 100%; border-radius: 8px; overflow: hidden; position: relative; }
.modal-actions { margin-top: 12px; text-align: right; }
#camReader video { border-radius: 8px; display: block; }

/* 扫码取景框（模仿微信/支付宝：四周压暗 + 红色框 + 扫描线） */
.cam-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.cam-frame {
  position: absolute;
  top: 27.5%;
  left: 15%;
  width: 70%;
  height: 45%;
  border: 2px solid rgba(229, 72, 77, .95);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35);
}
.cam-frame::before, .cam-frame::after {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  border: 3px solid #e5484d;
}
.cam-frame::before { top: -3px; left: -3px; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.cam-frame::after { bottom: -3px; right: -3px; border-left: none; border-top: none; border-radius: 0 0 8px 0; }
.cam-line {
  position: absolute;
  left: 16%;
  width: 68%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #e5484d, transparent);
  animation: camScan 2.2s ease-in-out infinite;
}
@keyframes camScan {
  0%, 100% { top: 29%; }
  50% { top: 70%; }
}
/* 取景框提示文字 */
.cam-tip {
  position: absolute;
  left: 0; right: 0; top: 18%;
  text-align: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
  letter-spacing: 0.5px;
}
.cam-tip small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 400;
  opacity: 0.85;
}

/* ========== 移动端 / 小屏适配 ========== */
@media (max-width: 900px) {
  main { padding: 12px; }
  .entry-layout { grid-template-columns: 1fr; }
  .recent-card { max-height: 50vh; }
  .cmp-grid { grid-template-columns: 1fr; gap: 10px; }
  .cmp-vs { transform: rotate(90deg); width: 30px; height: 30px; font-size: 15px; margin: 0 auto; }
  .report-tools select { width: 100%; }
  .range-box { width: 100%; }
  .range-box input[type="date"] { width: 100%; min-width: 0; }
  .cmp-tools { flex-direction: column; align-items: stretch; }
  .table-wrap { max-width: 100%; }
}

@media (max-width: 640px) {
  header { padding: 10px 12px; gap: 10px; }
  .brand { font-size: 15px; }
  .tab { padding: 7px 10px; font-size: 13px; }
  .stat-num { font-size: 30px; }
  .detail-grid { grid-template-columns: 1fr; }
  .filter-actions { flex-direction: column; }
  .filter-actions .btn { width: 100%; }
  .io-actions { flex-direction: column; align-items: stretch; }
  .io-actions input[type="file"] { width: 100%; }
  #summaryChart { height: 220px; }
  #compareChart { height: 260px; }
  .cam-btn { min-height: 40px; }
}
