/* ─── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --primary:       #1a4f8a;
  --primary-dark:  #0f3460;
  --primary-light: #e8f0fb;
  --accent:        #0e9f8e;
  --accent-dark:   #0a7a6c;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --success:       #059669;
  --success-light: #d1fae5;
  --bg:            #f0f4f8;
  --surface:       #ffffff;
  --border:        #d1d9e6;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --radius:        10px;
  --shadow:        0 2px 12px rgba(0,0,0,.08);
  --shadow-md:     0 4px 24px rgba(0,0,0,.12);
}

/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
.page-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}
.card-sm  { max-width: 420px; width: 100%; }
.card-md  { max-width: 640px; width: 100%; }
.card-lg  { max-width: 900px; width: 100%; }

/* ─── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.navbar-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}
.navbar-brand svg { width: 26px; height: 26px; }
.navbar-right { display: flex; align-items: center; gap: 16px; }
.navbar-user { font-size: .875rem; opacity: .9; }
.navbar-hospital {
  font-size: .75rem;
  background: rgba(255,255,255,.15);
  padding: 2px 10px;
  border-radius: 20px;
}

/* ─── Typography ─────────────────────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1.1rem;  font-weight: 600; }
.text-muted { color: var(--text-muted); font-size: .875rem; }
.text-sm    { font-size: .875rem; }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group label .required { color: var(--danger); margin-left: 2px; }
input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9375rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,79,138,.12);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .9375rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent  { background: var(--accent);  color: #fff; }
.btn-accent:hover  { background: var(--accent-dark); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 14px; font-size: .8125rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: .875rem;
  margin-bottom: 16px;
  border-left: 4px solid;
  display: none;
}
.alert.show { display: block; }
.alert-error   { background: var(--danger-light);  color: #991b1b; border-color: var(--danger); }
.alert-success { background: var(--success-light); color: #065f46; border-color: var(--success); }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: var(--warning); }

/* ─── Auth Pages ─────────────────────────────────────────────────────────────── */
.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo .logo-icon {
  width: 52px; height: 52px;
  background: var(--primary);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.auth-logo .logo-icon svg { color: #fff; }
.auth-logo h1 { font-size: 1.4rem; color: var(--primary); }
.auth-logo p  { color: var(--text-muted); font-size: .875rem; margin-top: 4px; }
.auth-footer  { text-align: center; margin-top: 20px; font-size: .875rem; color: var(--text-muted); }
.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 24px 0; color: var(--text-muted); font-size: .8125rem;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ─── Register Tabs ──────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Main Layout ────────────────────────────────────────────────────────────── */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

/* ─── Stats Grid ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}
.stat-card .stat-label { font-size: .8125rem; color: var(--text-muted); font-weight: 500; }
.stat-card.low    .stat-value { color: var(--danger); }
.stat-card.normal .stat-value { color: var(--success); }
.stat-card.high   .stat-value { color: var(--warning); }

/* ─── Chart Panel ────────────────────────────────────────────────────────────── */
.chart-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.controls-row .form-group { margin-bottom: 0; min-width: 150px; }
.chart-wrap { position: relative; }

/* ─── Metrics Table ──────────────────────────────────────────────────────────── */
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.metrics-table th, .metrics-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.metrics-table th { background: var(--bg); font-weight: 600; font-size: .8125rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.metrics-table tbody tr:hover { background: var(--primary-light); }

/* ─── Patients Table ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.data-table th, .data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th { background: var(--bg); font-weight: 600; font-size: .8125rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.data-table tbody tr:hover { background: #f8fafc; cursor: pointer; }

/* ─── Badge ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-role-hospital_admin { background: #ede9fe; color: #5b21b6; }
.badge-role-doctor         { background: #dbeafe; color: #1d4ed8; }
.badge-role-nurse          { background: #e0f2fe; color: #0369a1; }
.badge-role-patient        { background: #d1fae5; color: #065f46; }
.badge-active   { background: var(--success-light); color: #065f46; }
.badge-inactive { background: #f1f5f9; color: var(--text-muted); }

/* ─── Glucose Range Badges ───────────────────────────────────────────────────── */
.glucose-value { font-weight: 700; }
.glucose-low    { color: var(--danger); }
.glucose-normal { color: var(--success); }
.glucose-high   { color: var(--warning); }

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 24px;
  display: none;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.25rem; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-footer { margin-top: 24px; display: flex; gap: 10px; justify-content: flex-end; }

/* ─── Simulate Panel ─────────────────────────────────────────────────────────── */
.simulate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.toggle-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .875rem;
  cursor: pointer;
}
.toggle-item input[type="checkbox"] { width: auto; cursor: pointer; accent-color: var(--primary); }

/* ─── Spinner ────────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Empty State ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; opacity: .3; margin-bottom: 12px; }

/* ─── Code Block (hospital code display) ────────────────────────────────────── */
.code-display {
  background: var(--primary-light);
  border: 2px dashed var(--primary);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  margin: 16px 0;
}
.code-display .code-value {
  font-family: 'Courier New', monospace;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--primary);
}
.code-display .code-label { font-size: .8125rem; color: var(--text-muted); margin-top: 4px; }
