:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.04);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--text);
  font-size: 16px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #10b981);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.nav-links { display: flex; gap: 4px; margin-left: auto; }

.nav-links a {
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.nav-links a:hover { background: #f1f5f9; }
.nav-links a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 72px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-head h1 { font-size: 24px; letter-spacing: -0.01em; }
.sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat .label { font-size: 12.5px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -0.01em; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.seg {
  display: inline-flex;
  background: #e9eef5;
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  border-radius: 9px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}

.seg button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1); font-weight: 600; }

select, input[type="text"], input[type="date"], input[type="password"], input[type="number"], textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover { background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--red); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.chart-title { font-weight: 650; font-size: 15px; }
.chart-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chart-wrap { position: relative; height: 220px; min-width: 0; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.normal { background: var(--green-soft); color: var(--green); }
.badge.low { background: var(--primary-soft); color: var(--primary); }
.badge.high { background: var(--red-soft); color: var(--red); }
.badge.unknown { background: #f1f5f9; color: var(--muted); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
  font-size: 14px;
}

.empty .big { font-size: 34px; margin-bottom: 8px; opacity: 0.5; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; background: #f8fafc; }
td { vertical-align: middle; }
tr:last-child td { border-bottom: 0; }

.num { font-variant-numeric: tabular-nums; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { resize: vertical; min-height: 72px; }

.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid { display: grid; gap: 14px; }

.result-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.25fr) minmax(90px, 0.9fr) minmax(80px, 0.7fr) minmax(90px, 0.8fr) minmax(90px, 0.8fr) 40px;
  gap: 10px;
  align-items: end;
  padding: 12px 0;
  border-bottom: 1px dashed var(--border);
}

.result-row:last-of-type { border-bottom: 0; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--red-soft); color: var(--red); border-color: #fecaca; }

.mobile-nav { display: none; }

.toast-wrap {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
  animation: toast-in 0.18s ease-out;
}

.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal {
  background: #fff;
  border-radius: 18px;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
}

.modal h2 { font-size: 18px; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 500px at 50% -10%, #dbeafe 0%, transparent 60%), var(--bg);
}

.login-card {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

.login-card .brand { justify-content: center; margin-bottom: 6px; }
.login-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login-card .sub { text-align: center; margin-bottom: 22px; }
.login-card .btn { width: 100%; margin-top: 6px; padding: 11px; }

.login-error {
  background: var(--red-soft);
  color: var(--red);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.section-title { font-size: 15px; font-weight: 650; margin-bottom: 12px; }

.danger-zone { border-color: #fecaca; background: #fffafa; }

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-links { display: none; }
  .charts { grid-template-columns: 1fr; }
  .chart-wrap { height: 210px; }
  .form-row { grid-template-columns: 1fr; }
  .result-row { grid-template-columns: 1fr 1fr; align-items: start; }
  .result-row .field { min-width: 0; }
  .result-row .icon-btn { align-self: end; }

  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    backdrop-filter: blur(10px);
  }

  .mobile-nav a {
    flex: 1;
    text-align: center;
    padding: 7px 4px;
    border-radius: 10px;
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
  }

  .mobile-nav a.active { color: var(--primary); background: var(--primary-soft); }
  .mobile-nav .ico { font-size: 17px; line-height: 1; }

  .container { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .page-head { align-items: flex-start; }
  .topbar-inner { padding: 10px 16px; }
}

@media (max-width: 640px) {
  .container { padding-left: 14px; padding-right: 14px; }
  .card { padding: 16px; border-radius: 14px; }
  .stats { gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat .value { font-size: 19px; }

  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; padding: 6px 4px; }
  table.responsive td { border: 0; padding: 6px 12px; white-space: normal; display: flex; justify-content: space-between; gap: 12px; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; }
  table.responsive td.actions { justify-content: flex-end; }
  table.responsive td.actions::before { content: ""; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
