/* ============================================================
   血液病智能管理平台 — HematoIQ Platform
   视觉系统：医疗科研专业风
   ============================================================ */

:root {
  /* Brand */
  --brand:        oklch(42% 0.14 240);   /* 临床深蓝 */
  --brand-deep:   oklch(28% 0.10 245);   /* 深海蓝（侧栏）*/
  --brand-ink:    oklch(18% 0.04 250);   /* 近黑墨蓝 */
  --accent:       oklch(62% 0.16 200);   /* AI 科技青 */
  --accent-soft:  oklch(94% 0.04 200);   /* 青底 */

  /* Status */
  --critical:     oklch(55% 0.22 25);    /* 危急红 */
  --critical-bg:  oklch(96% 0.04 25);
  --warning:      oklch(72% 0.16 75);    /* 警示橙 */
  --warning-bg:   oklch(97% 0.04 80);
  --success:      oklch(58% 0.14 155);   /* 通过绿 */
  --success-bg:   oklch(96% 0.04 155);
  --info:         oklch(56% 0.12 250);
  --info-bg:      oklch(97% 0.02 240);

  /* Neutrals */
  --bg:           oklch(99% 0.003 240);
  --surface:      oklch(100% 0 0);
  --surface-2:    oklch(98% 0.004 240);
  --fg:           oklch(20% 0.018 250);
  --fg-soft:      oklch(32% 0.018 250);
  --muted:        oklch(50% 0.018 250);
  --muted-2:      oklch(64% 0.012 250);
  --border:       oklch(92% 0.006 240);
  --border-strong: oklch(86% 0.006 240);

  /* Fonts */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", SFMono-Regular, ui-monospace, Menlo, monospace;

  /* Sizing */
  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "tnum" 1, "cv11" 1;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* tabular numerics everywhere by default */
.num, .kpi-value, .table td, .table th, code, kbd, .mono { font-variant-numeric: tabular-nums; }
.mono, code, kbd { font-family: var(--font-mono); }

/* ===== Layout shell ===== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--brand-ink);
  color: oklch(86% 0.02 240);
  padding: 20px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-right: 1px solid oklch(28% 0.04 250);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid oklch(28% 0.04 250);
  margin-bottom: 12px;
}
.sidebar .logo .mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  display: grid; place-items: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.sidebar .logo .wordmark {
  display: flex; flex-direction: column; line-height: 1.15;
}
.sidebar .logo .wordmark b {
  color: white;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sidebar .logo .wordmark span {
  font-size: 10.5px;
  color: oklch(68% 0.02 240);
  letter-spacing: 0.04em;
}

.sidebar .group {
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: oklch(60% 0.03 240);
  padding: 8px 8px 4px;
}

.sidebar a.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: oklch(82% 0.02 240);
  transition: background .12s, color .12s;
  position: relative;
}
.sidebar a.nav-item:hover {
  background: oklch(30% 0.06 245);
  color: white;
}
.sidebar a.nav-item.active {
  background: oklch(34% 0.10 240);
  color: white;
}
.sidebar a.nav-item.active::before {
  content: '';
  position: absolute;
  left: -14px;
  top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.sidebar a.nav-item .icon {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  opacity: 0.7;
}
.sidebar a.nav-item.active .icon { opacity: 1; }
.sidebar a.nav-item .badge {
  margin-left: auto;
  font-size: 10px;
  background: oklch(38% 0.10 245);
  padding: 1px 6px;
  border-radius: 999px;
  color: white;
  font-variant-numeric: tabular-nums;
}
.sidebar a.nav-item.active .badge { background: var(--accent); }

.sidebar .footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid oklch(28% 0.04 250);
  font-size: 11.5px;
  color: oklch(64% 0.02 240);
}
.sidebar .user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: 6px;
  background: oklch(24% 0.04 250);
  margin-bottom: 8px;
}
.sidebar .user .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--brand));
  color: white; display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
}
.sidebar .user .meta { line-height: 1.2; }
.sidebar .user .meta b { color: white; font-size: 12px; font-weight: 500; display: block; }
.sidebar .user .meta span { color: oklch(64% 0.02 240); font-size: 10.5px; }

/* Main column */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0;
  z-index: 30;
}
.topbar .crumbs {
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar .crumbs b { color: var(--fg); font-weight: 600; }
.topbar .crumbs .sep { color: var(--muted-2); }
.topbar .search {
  margin-left: auto;
  position: relative;
  width: 320px;
}
.topbar .search input {
  width: 100%;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px 0 30px;
  font-size: 13px;
  background: var(--surface-2);
  outline: none;
}
.topbar .search input:focus {
  border-color: var(--accent);
  background: var(--surface);
}
.topbar .search::before {
  content: '';
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 12px; height: 12px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
}
.topbar .search::after {
  content: '';
  position: absolute; left: 18px; top: 50%;
  width: 5px; height: 1.5px;
  background: var(--muted);
  transform: translateY(2px) rotate(45deg);
  transform-origin: left;
}
.topbar .tool-btn {
  height: 32px;
  min-width: 32px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--fg-soft);
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.topbar .tool-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.topbar .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px oklch(96% 0.04 155);
}

.content {
  padding: 24px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
}

/* ===== Section headers ===== */
.page-head {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.page-head .sub {
  font-size: 13px;
  color: var(--muted);
  max-width: 720px;
}
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 12px;
}
.section-head h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 8px;
}
.section-head .hint { font-size: 12px; color: var(--muted); }
.section-head .tabs {
  display: flex; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 6px;
}
.section-head .tabs button {
  border: 0; background: transparent;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  color: var(--muted);
  font-weight: 500;
}
.section-head .tabs button.active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 1px 2px oklch(0% 0 0 / 0.04);
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card .card-head {
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.card .card-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.card .card-head .meta { font-size: 11.5px; color: var(--muted); }
.card .card-body { padding: 16px; }

/* ===== KPI Tiles ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.kpi .label {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
  display: flex; align-items: center; gap: 6px;
}
.kpi .value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.kpi .value .unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
  letter-spacing: 0;
}
.kpi .delta {
  font-size: 11.5px;
  margin-top: 6px;
  display: inline-flex; align-items: center; gap: 4px;
  font-variant-numeric: tabular-nums;
}
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--critical); }
.kpi .delta.flat { color: var(--muted); }
.kpi .spark { margin-top: 8px; }

.kpi.accent {
  border-color: oklch(82% 0.10 200);
  background: linear-gradient(180deg, var(--accent-soft), var(--surface));
}
.kpi.accent .value { color: var(--brand); }

/* ===== Buttons ===== */
.btn {
  height: 32px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 13px;
  color: var(--fg);
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 500;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}
.btn.primary:hover { background: oklch(36% 0.14 240); }
.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn.accent:hover { background: oklch(56% 0.16 200); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn.danger { background: var(--critical); border-color: var(--critical); color: white; }
.btn.sm { height: 26px; font-size: 12px; padding: 0 10px; }
.btn.lg { height: 38px; padding: 0 18px; font-size: 14px; }
.btn.icon-only { width: 32px; padding: 0; justify-content: center; }

/* ===== Tags / pills ===== */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--fg-soft);
  border: 1px solid var(--border);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}
.pill.success { background: var(--success-bg); color: var(--success); border-color: oklch(86% 0.08 155); }
.pill.warn    { background: var(--warning-bg); color: oklch(48% 0.16 75); border-color: oklch(86% 0.10 75); }
.pill.danger  { background: var(--critical-bg); color: var(--critical); border-color: oklch(86% 0.10 25); }
.pill.info    { background: var(--info-bg); color: var(--info); border-color: oklch(86% 0.06 240); }
.pill.accent  { background: var(--accent-soft); color: var(--accent); border-color: oklch(86% 0.08 200); }
.pill.ink     { background: var(--brand-ink); color: white; border-color: var(--brand-ink); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ===== Tables ===== */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 10px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--surface-2); }
.table .id { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }

/* ===== Charts ===== */
.chart {
  width: 100%;
  height: 160px;
}
.chart-axis text { font-size: 10px; fill: var(--muted-2); font-family: var(--font-mono); }
.chart-axis line { stroke: var(--border); }
.chart-grid line { stroke: var(--border); stroke-dasharray: 2 4; }
.chart-area { fill: oklch(62% 0.16 200 / 0.12); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.chart-line.brand { stroke: var(--brand); }
.chart-line.critical { stroke: var(--critical); }

/* Sparkline */
.spark { width: 100%; height: 28px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--fg-soft); font-weight: 500; }
.input, .select, .textarea {
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 13px;
  background: var(--surface);
  outline: none;
  color: var(--fg);
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.4; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px oklch(94% 0.06 200); }

/* ===== Utility ===== */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.between { justify-content: space-between; }
.center { justify-content: center; align-items: center; }
.muted { color: var(--muted); }
.muted-2 { color: var(--muted-2); }
.fg-soft { color: var(--fg-soft); }
.text-xs { font-size: 11.5px; }
.text-sm { font-size: 12.5px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.text-num { font-variant-numeric: tabular-nums; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; } .mt-5 { margin-top: 24px; } .mt-6 { margin-top: 32px; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.gap-4 { gap: 16px; } .gap-5 { gap: 24px; }
.flex-1 { flex: 1; } .flex-grow { flex-grow: 1; }
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-12 { grid-template-columns: repeat(12, 1fr); gap: 16px; }
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: span 4; }
.col-span-5 { grid-column: span 5; }
.col-span-6 { grid-column: span 6; }
.col-span-7 { grid-column: span 7; }
.col-span-8 { grid-column: span 8; }
.col-span-9 { grid-column: span 9; }
.col-span-12 { grid-column: span 12; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.dot-sep::before { content: '·'; margin: 0 6px; color: var(--muted-2); }

/* ===== Progress bar ===== */
.bar {
  width: 100%;
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
}
.bar.brand > span { background: var(--brand); }
.bar.success > span { background: var(--success); }
.bar.warn > span { background: var(--warning); }
.bar.critical > span { background: var(--critical); }

/* ===== Modality badge for MICM ===== */
.modality {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 500;
}
.modality .swatch {
  width: 8px; height: 8px; border-radius: 2px;
}
.modality.morph .swatch     { background: oklch(58% 0.16 25); }
.modality.immuno .swatch    { background: oklch(58% 0.16 145); }
.modality.cyto .swatch      { background: oklch(58% 0.16 280); }
.modality.molecular .swatch { background: oklch(62% 0.16 75); }

.modality.morph     { color: oklch(40% 0.16 25); }
.modality.immuno    { color: oklch(40% 0.16 145); }
.modality.cyto      { color: oklch(40% 0.16 280); }
.modality.molecular { color: oklch(40% 0.16 75); }

/* ===== Responsive ===== */
@media (max-width: 1180px) {
  :root { --sidebar-w: 64px; }
  .sidebar { padding: 14px 8px; }
  .sidebar .logo .wordmark,
  .sidebar .group,
  .sidebar a.nav-item span:not(.icon),
  .sidebar .user .meta,
  .sidebar .footer { display: none; }
  .sidebar a.nav-item { justify-content: center; padding: 8px; }
  .sidebar a.nav-item.active::before { left: -8px; }
  .sidebar .logo { justify-content: center; padding: 4px 0 14px; }
  .sidebar .user { padding: 0; background: transparent; }
}

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    height: 56px;
    flex-direction: row;
    padding: 6px 8px;
    border-top: 1px solid oklch(28% 0.04 250);
    border-right: 0;
    z-index: 50;
    overflow-x: auto;
  }
  .sidebar .logo, .sidebar .group, .sidebar .footer, .sidebar .user { display: none; }
  .sidebar a.nav-item { flex-shrink: 0; padding: 6px 10px; }
  .sidebar a.nav-item.active::before { display: none; }
  .main { padding-bottom: 64px; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .topbar .search { width: 160px; }
  .page-head h1 { font-size: 18px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ===== Page entry animations ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.content > * { animation: fadeUp .22s ease-out both; }
.content > *:nth-child(2) { animation-delay: .04s; }
.content > *:nth-child(3) { animation-delay: .08s; }
.content > *:nth-child(4) { animation-delay: .12s; }
.content > *:nth-child(5) { animation-delay: .16s; }
.content > *:nth-child(6) { animation-delay: .20s; }
