:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e3e8ef;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #e8f7ee;
  --red: #dc2626;
  --red-bg: #fdeaea;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

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

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
}
.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--primary);
}
.nav { display: flex; gap: 6px; }
.nav-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
}
.nav-btn:hover { background: #eef2f7; color: var(--text); }
.nav-btn.active { background: #e7eefe; color: var(--primary-dark); font-weight: 600; }

/* ---------- 用户区 ---------- */
.user-area { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 14px; font-weight: 600; color: var(--text); }
.role-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--text-muted);
}
.role-tag.admin { background: #e7eefe; color: var(--primary-dark); }

/* ---------- 认证页 ---------- */
.auth-wrap {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
}
.auth-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: #eef1f5; padding: 4px; border-radius: 10px; }
.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
}
.auth-tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- 容器 ---------- */
.container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.page-title { font-size: 20px; font-weight: 700; margin: 0; }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #f3f6fb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--red); border-color: #f3c1c1; }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---------- 统计卡片 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--text-muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-value.normal { color: var(--green); }
.stat-value.abnormal { color: var(--red); }

/* ---------- 表格 ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: #f8fafc;
  font-weight: 600;
  color: #374151;
  font-size: 13px;
  position: sticky;
  top: 0;
}
tbody tr:hover { background: #f9fbfe; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 6px; }
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

/* ---------- 状态徽标 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.normal { background: var(--green-bg); color: var(--green); }
.badge.abnormal { background: var(--red-bg); color: var(--red); }
.badge.neutral { background: #eef1f5; color: var(--text-muted); }
.badge.warn { background: #fef3c7; color: var(--amber); }

/* 测试值单元格状态 */
.cell-val { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.normal { background: var(--green); }
.dot.abnormal { background: var(--red); }
.val-abnormal { color: var(--red); font-weight: 600; }

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-label .req { color: var(--red); }
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* 测试项分组 */
.group-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid #e7eefe;
}
.group-title.record { color: #475569; border-bottom-color: var(--border); }
.item-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 16px;
}
.item-field {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfcfe;
}
.item-field.judged-ok { border-color: #b9e6c7; background: #f4fcf7; }
.item-field.judged-bad { border-color: #f3b9b9; background: #fdf5f5; }
.item-field .item-name { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.item-field .item-range { font-size: 12px; color: var(--text-muted); }
.item-input-row { display: flex; align-items: center; gap: 8px; }
.item-input-row .input { width: 160px; }
.item-unit { color: var(--text-muted); font-size: 13px; }
.item-status { margin-left: auto; font-size: 12px; font-weight: 600; }
.item-status.ok { color: var(--green); }
.item-status.bad { color: var(--red); }
.item-status.pending { color: var(--text-muted); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 880px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.modal.small { max-width: 480px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close {
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.modal-body { padding: 20px 22px; max-height: 70vh; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  padding: 10px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: slidein 0.2s ease;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slidein {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .item-grid { grid-template-columns: 1fr; }
}
