:root {
  --bg: #0f1419;
  --bg-card: rgba(22, 30, 39, 0.8);
  --bg-glass: rgba(30, 41, 55, 0.6);
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --text: #e8edf3;
  --text-soft: #8b99ab;
  --text-muted: #5b6b7e;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --accent-soft: #60a5fa;
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.12);
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a78bfa;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.2);
  --sidebar-w: 240px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* --- Utility -------------------------------------------------------------- */
.glass {
  background: var(--bg-glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.glass:hover { border-color: var(--border-hover); }

.unit { font-size: 0.7em; color: var(--text-soft); font-weight: 400; }
.disclaimer { color: var(--text-muted); font-size: 0.82rem; margin-bottom: 1.2rem; }
.error-text { color: var(--red); font-size: 0.85rem; margin-top: 0.8rem; }

/* --- Screens -------------------------------------------------------------- */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  background: var(--bg);
}
.screen[hidden] { display: none !important; }

.boot-screen {
  flex-direction: column; gap: 1.2rem;
}
.loader-ring {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot-text { color: var(--text-soft); font-size: 0.9rem; }

.signin-screen { background: linear-gradient(135deg, #0f1419 0%, #1a2332 50%, #0f1419 100%); }
.signin-container { text-align: center; max-width: 380px; padding: 2rem; }
.signin-hero { margin-bottom: 2rem; }
.logo-mark { color: var(--accent); margin-bottom: 1rem; }
.signin-hero h1 { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; }
.signin-subtitle { color: var(--text-soft); margin-top: 0.3rem; }
.signin-card {
  padding: 2rem; border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.signin-card p { color: var(--text-soft); margin-bottom: 1.5rem; font-size: 0.9rem; line-height: 1.6; }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: none; border-radius: var(--radius-sm);
  font: inherit; font-weight: 500; cursor: pointer;
  transition: all var(--transition);
}
.btn-primary {
  background: var(--accent); color: #fff;
  padding: 0.65rem 1.4rem;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-primary:hover { background: #2563eb; transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-lg { padding: 0.8rem 2rem; font-size: 1rem; }
.btn-ghost {
  background: none; border: none; color: var(--text-muted);
  font: inherit; font-size: 0.8rem; cursor: pointer; padding: 0.3rem 0.5rem;
}
.btn-ghost:hover { color: var(--text); }

.select-styled {
  background: var(--bg-glass); border: 1px solid var(--border);
  color: var(--text); padding: 0.5rem 0.8rem; border-radius: var(--radius-sm);
  font: inherit; font-size: 0.85rem; cursor: pointer;
}

/* --- Layout --------------------------------------------------------------- */
#app { display: flex; min-height: 100vh; }
#app[hidden] { display: none !important; }

.sidebar {
  width: var(--sidebar-w); position: fixed; top: 0; left: 0; bottom: 0;
  background: rgba(15, 20, 25, 0.95); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1.2rem 0.8rem;
  z-index: 20;
  backdrop-filter: blur(8px);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.4rem 0.6rem; margin-bottom: 1.5rem;
  color: var(--text); font-weight: 600; font-size: 0.95rem;
}
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.2rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.6rem 0.8rem; border-radius: var(--radius-sm);
  background: none; border: none; color: var(--text-soft);
  font: inherit; font-size: 0.88rem; cursor: pointer;
  transition: all var(--transition);
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active {
  background: var(--accent-glow); color: var(--accent-soft);
  font-weight: 500;
}
.nav-item.active svg { stroke: var(--accent-soft); }
.sidebar-footer { padding-top: 1rem; border-top: 1px solid var(--border); }
.user-pill { display: flex; flex-direction: column; gap: 0.3rem; padding: 0.4rem; }
.user-email { font-size: 0.75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }

.content {
  margin-left: var(--sidebar-w); flex: 1; padding: 2rem 2.5rem;
  min-height: 100vh;
}

.view[hidden] { display: none !important; }

.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.8rem;
}
.view-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.view-subtitle { color: var(--text-muted); font-size: 0.82rem; }
.view-controls { display: flex; gap: 0.6rem; }

/* --- Hero cards ----------------------------------------------------------- */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.hero-card {
  border-radius: var(--radius); padding: 1.2rem 1.4rem;
  position: relative; overflow: hidden;
  transition: all var(--transition);
}
.hero-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.hero-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 0.8rem;
}
.home-icon { background: var(--green-glow); color: var(--green); }
.hgb-icon { background: rgba(239, 68, 68, 0.12); color: var(--red); }
.plt-icon { background: rgba(167, 139, 250, 0.12); color: var(--purple); }
.wbc-icon { background: rgba(245, 158, 11, 0.12); color: var(--amber); }
.anc-icon { background: var(--accent-glow); color: var(--accent-soft); }

.hero-value {
  font-size: 2rem; font-weight: 700; letter-spacing: -0.03em;
  line-height: 1.1; margin-bottom: 0.2rem;
}
.hero-label { color: var(--text-soft); font-size: 0.82rem; }
.hero-sub { color: var(--text-muted); font-size: 0.75rem; margin-top: 0.3rem; }
.hero-delta { font-size: 0.78rem; margin-top: 0.3rem; }
.hero-delta.up { color: var(--green); }
.hero-delta.down { color: var(--red); }
.hero-delta.neutral { color: var(--text-muted); }
.hero-flag {
  font-size: 0.72rem; color: var(--amber); margin-top: 0.3rem;
  padding: 0.15rem 0.5rem; background: rgba(245, 158, 11, 0.1);
  border-radius: 4px; display: inline-block;
}
.hero-flag:empty { display: none; }
.sparkline { margin-top: 0.6rem; height: 40px; }

/* --- Charts --------------------------------------------------------------- */
.dashboard-charts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem;
}
.dashboard-charts.single { grid-template-columns: 1fr; }
.chart-card {
  border-radius: var(--radius); padding: 1.4rem;
  cursor: pointer; transition: all var(--transition);
}
.chart-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.chart-card h3 {
  font-size: 0.92rem; font-weight: 600; margin-bottom: 1rem; color: var(--text);
  display: flex; align-items: center; justify-content: space-between;
}
.chart-card h3::after {
  content: '⤢'; font-size: 1rem; color: var(--text-muted); opacity: 0;
  transition: opacity var(--transition);
}
.chart-card:hover h3::after { opacity: 1; }

/* --- Chart modal ---------------------------------------------------------- */
.chart-modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem;
}
.chart-modal[hidden] { display: none !important; }
.chart-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.chart-modal-content {
  position: relative; z-index: 1;
  width: 100%; max-width: 900px;
  border-radius: var(--radius); padding: 2rem;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  max-height: 90vh; overflow-y: auto;
}
.chart-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.chart-modal-header h2 { font-size: 1.2rem; font-weight: 600; }
.chart-modal-header .btn-ghost { font-size: 1.3rem; padding: 0.4rem 0.6rem; }

.trends-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
.trend-card {
  border-radius: var(--radius); padding: 1.4rem;
}
.trend-card h4 { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.8rem; color: var(--text-soft); }

/* --- Timeline ------------------------------------------------------------- */
.timeline-container { position: relative; padding-left: 2rem; }
.timeline-container::before {
  content: ''; position: absolute; left: 8px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.tl-item {
  position: relative; margin-bottom: 1.2rem;
  padding: 1rem 1.2rem; border-radius: var(--radius-sm);
  background: var(--bg-glass); border: 1px solid var(--border);
  transition: all var(--transition);
}
.tl-item:hover { border-color: var(--border-hover); transform: translateX(4px); }
.tl-item::before {
  content: ''; position: absolute; left: -1.65rem; top: 1.2rem;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--accent); background: var(--bg);
}
.tl-item.type-admission::before { border-color: var(--amber); }
.tl-item.type-transfusion::before { border-color: var(--purple); }
.tl-item.type-fever::before { border-color: var(--red); }
.tl-date { font-size: 0.78rem; color: var(--text-muted); }
.tl-type {
  display: inline-block; font-size: 0.72rem; font-weight: 500;
  padding: 0.1rem 0.5rem; border-radius: 4px; margin: 0.3rem 0;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.tl-type.admission { background: rgba(245, 158, 11, 0.12); color: var(--amber); }
.tl-type.transfusion { background: rgba(167, 139, 250, 0.12); color: var(--purple); }
.tl-type.fever { background: rgba(239, 68, 68, 0.12); color: var(--red); }
.tl-detail { font-size: 0.85rem; color: var(--text-soft); }

/* --- Reports -------------------------------------------------------------- */
.reports-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.report-card {
  border-radius: var(--radius-sm); padding: 1.2rem;
  background: var(--bg-glass); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  transition: all var(--transition); cursor: pointer;
}
.report-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.report-icon {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--accent-glow); color: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.report-info { flex: 1; min-width: 0; }
.report-kind { font-size: 0.88rem; font-weight: 500; }
.report-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }

/* --- Upload --------------------------------------------------------------- */
.upload-area {
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
}
.upload-dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius-sm);
  padding: 2rem; text-align: center; cursor: pointer;
  transition: all var(--transition);
}
.upload-dropzone.dragover { border-color: var(--accent); background: var(--accent-glow); }
.upload-dropzone p { color: var(--text-soft); margin-top: 0.8rem; font-size: 0.9rem; }
.upload-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.3rem; }
.upload-browse {
  color: var(--accent-soft); cursor: pointer; text-decoration: underline;
}
.upload-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.upload-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.8rem; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.02); font-size: 0.85rem;
}
.upload-item.done { opacity: 0.7; }
.upload-item.error { color: var(--red); }
.upload-item.uploading { color: var(--amber); }
.upload-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-size { color: var(--text-muted); font-size: 0.75rem; }
.upload-badge { font-size: 0.8rem; width: 1.5rem; text-align: center; }
.upload-remove { font-size: 0.9rem; }
.upload-actions { margin-top: 1rem; display: flex; align-items: center; gap: 1rem; }
.upload-status { font-size: 0.82rem; color: var(--text-soft); }

/* --- Check-in ------------------------------------------------------------- */
.checkin-container { border-radius: var(--radius); padding: 2rem; max-width: 640px; }
.checkin-intro { color: var(--text-soft); font-size: 0.88rem; margin-bottom: 1.5rem; }
.checkin-form { display: flex; flex-direction: column; gap: 1rem; }
.checkin-row {
  display: grid; grid-template-columns: 8rem 1fr 2.5rem;
  align-items: center; gap: 1rem;
}
.checkin-label { font-size: 0.85rem; color: var(--text-soft); }
.checkin-row input[type=range] {
  width: 100%; accent-color: var(--accent);
  height: 6px; border-radius: 3px;
}
.checkin-val {
  text-align: right; font-size: 0.9rem; font-weight: 600;
  color: var(--text); font-variant-numeric: tabular-nums;
}
.checkin-actions { margin-top: 1.5rem; display: flex; align-items: center; gap: 1rem; }
.checkin-status { font-size: 0.82rem; color: var(--green); }

/* --- Footer --------------------------------------------------------------- */
.app-footer {
  margin-top: 3rem; padding: 1.5rem 0; border-top: 1px solid var(--border);
}
.app-footer p { font-size: 0.78rem; color: var(--text-muted); line-height: 1.6; }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 1024px) {
  .dashboard-charts { grid-template-columns: 1fr; }
  .trends-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 1.2rem; }
  .hero-grid { grid-template-columns: 1fr 1fr; }
}
