/*
 * assets/css/medai.css — Base Stylesheet (Light Theme Default)
 *
 * Purpose: Core UI for MedAI — layout, components, typography.
 * Theme variables live here; overrides in themes.css via [data-theme].
 * Dependencies: Inter (Google Fonts)
 * Last Updated: 2026-06-10
 */

/* ─── Root (Light/Default) ────────────────────────────────────── */
:root {
  --bg:          #f0f4f8;
  --surface:     #ffffff;
  --surface2:    #f1f5f9;
  --border:      #e2e8f0;
  --ink:         #1e293b;
  --muted:       #64748b;
  --accent:      #3b82f6;
  --accent2:     #16a34a;
  --danger:      #dc2626;
  --warning:     #d97706;
  --info:        #0284c7;
  --sidebar-w:   64px;
  --sidebar-bg:  #1e293b;
  --topbar-h:    0px;
  --radius:      12px;
  --shadow:      0 1px 3px rgba(0,0,0,.08);
  --font:        'Inter', system-ui, sans-serif;
  --font-mono:   'IBM Plex Mono', ui-monospace, monospace;
  --transition:  0.15s ease;
}

[data-theme="dark"] {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface2:    #21262d;
  --border:      #30363d;
  --ink:         #e6edf3;
  --muted:       #8b949e;
  --accent:      #58a6ff;
  --accent2:     #3fb950;
  --danger:      #f85149;
  --warning:     #e3b341;
  --info:        #79c0ff;
  --sidebar-bg:  #0d1117;
  --shadow:      0 1px 4px rgba(0,0,0,.5);
}

/* ─── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App Shell ───────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  grid-template-areas:
    "sidebar main";
  min-height: 100vh;
}

/* ─── Sidebar (64px Icon-Only) ────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: visible;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  z-index: 100;
  padding: 16px 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}

.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 14px; color: #fff;
}

.sidebar-brand .brand-text { display: none; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 0;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

.nav-section-label { display: none; }

.nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  color: #64748b;
  border-radius: 10px;
  transition: all var(--transition);
  position: relative;
  cursor: pointer;
  text-decoration: none;
}

.nav-link svg { flex-shrink: 0; width: 20px; height: 20px; }

.nav-link .nav-label { display: none; }

.nav-link:hover {
  background: rgba(255,255,255,.08);
  color: #94a3b8;
  text-decoration: none;
}

.nav-link.active {
  background: rgba(59,130,246,.15);
  color: #60a5fa;
}

.nav-link.active::before { display: none; }

/* Tooltip on hover */
.nav-link[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px); top: 50%;
  transform: translateY(-50%);
  background: #1e293b;
  color: #f1f5f9;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
}
.nav-link[data-tooltip]:hover::after { opacity: 1; }

.nav-badge { display: none; }

.sidebar-spacer { flex: 1; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.sidebar-footer .footer-text { display: none; }

/* Allow <button> elements to be styled as nav-links */
button.nav-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
}

.sidebar-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  position: relative;
  z-index: 1100;
}

.sidebar-avatar-wrap[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px); top: 50%;
  transform: translateY(-50%);
  background: #1e293b;
  color: #f1f5f9;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
}
.sidebar-avatar-wrap[data-tooltip]:hover::after { opacity: 1; }

.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: #334155;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}

/* Role-based avatar colours */
.sidebar-avatar.role-doctor       { background: #1d4ed8; color: #fff; }
.sidebar-avatar.role-nurse        { background: #059669; color: #fff; }
.sidebar-avatar.role-admin        { background: #7c3aed; color: #fff; }
.sidebar-avatar.role-receptionist { background: #0891b2; color: #fff; }
.sidebar-avatar.role-billing      { background: #d97706; color: #fff; }
.sidebar-avatar.role-lab          { background: #dc2626; color: #fff; }
.sidebar-avatar.role-default      { background: #334155; color: #94a3b8; }

.sidebar-role-badge { display: none; }

/* ─── Avatar Popup Menu ──────────────────────────────────────── */
.avatar-menu {
  display: none;
  position: absolute;
  left: calc(100% + 8px);
  bottom: 0;
  width: 200px;
  background: var(--surface, #1e293b);
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.28);
  z-index: 1200;
  overflow: hidden;
  padding: 4px 0;
}
.avatar-menu.open { display: block; }

/* When menu is open, suppress the CSS tooltip */
.sidebar-avatar-wrap.menu-open[data-tooltip]::after { display: none; }

.avatar-menu-header {
  padding: 12px 14px 8px;
}
.avatar-menu-name {
  font-size: 13px; font-weight: 600; color: var(--ink, #1e293b);
  line-height: 1.2;
}
.avatar-menu-role {
  font-size: 11px; color: var(--muted, #64748b); margin-top: 2px;
}
.avatar-menu-divider {
  height: 1px; background: var(--border, rgba(255,255,255,0.06));
  margin: 4px 0;
}
.avatar-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 14px;
  background: none; border: none;
  font-size: 13px; font-weight: 500; font-family: inherit;
  color: var(--ink, #1e293b);
  cursor: pointer;
  transition: background 0.12s;
  text-align: left;
}
.avatar-menu-item:hover {
  background: rgba(255,255,255,0.06);
}
.avatar-menu-item svg { flex-shrink: 0; opacity: 0.7; }
.avatar-menu-item--danger { color: #f87171; }
.avatar-menu-item--danger:hover { background: rgba(239,68,68,0.1); }

/* ─── Lock Screen Overlay ────────────────────────────────────── */
.lock-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.lock-screen-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.lock-screen-card {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 340px;
  background: var(--surface, #1e293b);
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 20px;
  padding: 40px 32px 32px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.35);
  text-align: center;
}
.lock-screen-avatar {
  width: 56px; height: 56px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: #fff;
  margin-bottom: 14px;
}
.lock-screen-name {
  font-size: 18px; font-weight: 700; color: var(--ink, #1e293b);
  margin-bottom: 4px;
}
.lock-screen-hint {
  font-size: 13px; color: var(--muted, #64748b); margin-bottom: 20px;
}
.lock-screen-error {
  background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.25);
  border-radius: 8px; color: #fca5a5; padding: 8px 12px;
  font-size: 12px; margin-bottom: 12px; width: 100%;
}
.lock-screen-form {
  width: 100%; display: flex; flex-direction: column; gap: 12px;
}
.lock-screen-input {
  width: 100%; padding: 12px 14px;
  background: var(--bg, #0f172a);
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 10px;
  font-size: 14px; font-family: inherit; color: var(--ink, #1e293b);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lock-screen-input:focus {
  outline: none;
  border-color: var(--accent, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.lock-screen-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px;
  background: var(--accent, #3b82f6); color: #fff;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: opacity 0.15s;
}
.lock-screen-btn:hover { opacity: 0.9; }
.lock-screen-btn:disabled { opacity: 0.5; cursor: default; }
.lock-screen-signout {
  margin-top: 16px; background: none; border: none;
  font-size: 12px; color: var(--muted, #64748b);
  cursor: pointer; font-family: inherit;
  transition: color 0.15s;
}
.lock-screen-signout:hover { color: #f87171; }

/* ─── Lock Screen: Disable Background Interaction ─────────────── */
/* When lock screen is visible, prevent interaction with main app content */
/* This class is managed by JavaScript in showLockScreen() and unlock handler */
.app-shell.locked-ui {
  pointer-events: none;
  opacity: 0.6;
}


.nav-link-signout { /* no longer red — inherits default nav-link colour */ }

/* ─── Nav badge (waiting room counter) ───────────────────────── */
.nav-badge-wrap { position: absolute; top: 4px; right: 4px; }
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e53e3e;
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 1;
  padding: 0 4px;
  pointer-events: none;
}

/* ─── Doctor name watermark (lower-right corner) ─────────────── */
.main-content::after {
  content: attr(data-doctor);
  position: fixed;
  bottom: 18px;
  right: 24px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: rgba(0,0,0,0.09);
  pointer-events: none;
  z-index: 1;
  text-transform: uppercase;
}
[data-theme="dark"] .main-content::after {
  color: rgba(255,255,255,0.10);
}

/* ─── Online/offline status below watermark ──────────────────── */
.watermark-presence {
  position: fixed;
  bottom: 4px;
  right: 24px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: rgba(0,0,0,0.18);
  text-transform: uppercase;
}
[data-theme="dark"] .watermark-presence {
  color: rgba(255,255,255,0.18);
}
.watermark-presence .presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.watermark-presence .presence-dot.online  { background: #22c55e; }
.watermark-presence .presence-dot.away    { background: #f59e0b; }
.watermark-presence .presence-dot.offline { background: #94a3b8; }

/* ─── Topbar (hidden — topbar removed from layout) ────────────── */
.topbar {
  display: none;
}

.patient-search-wrap {
  flex: 1;
  max-width: 400px;
  position: relative;
}

.patient-search-wrap input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  padding: 7px 12px 7px 34px;
  font-size: 13px;
  font-family: var(--font);
  transition: border-color var(--transition);
}

.patient-search-wrap input:focus {
  outline: none;
  border-color: var(--accent);
}

.patient-search-wrap .search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  width: 14px; height: 14px;
  pointer-events: none;
}

.search-results-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  max-height: 280px;
  overflow-y: auto;
  display: none;
}

.search-results-dropdown.open { display: block; }

/* ── Combo-dropdown: text input with clickable option list ─────────────── */
.combo-wrap { position: relative; }
.combo-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 210;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.combo-dropdown.open { display: block; }
.combo-option {
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.combo-option:last-child { border-bottom: none; }
.combo-option:hover, .combo-option.highlighted { background: var(--surface); }
.combo-toggle {
  position: absolute;
  right: 1px; top: 1px; bottom: 1px;
  width: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted);
  border-left: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface2);
  font-size: 10px;
  user-select: none;
}
.combo-toggle:hover { color: var(--text); }
.combo-wrap .form-control { padding-right: 34px; }

/* Allow combo-dropdowns inside cards to overflow visibly */
#waiting-room-card { overflow: visible; }
#waiting-room-card .card-header { border-radius: var(--radius) var(--radius) 0 0; }

/* Allow native <select> popups to escape card overflow clipping (Chromium) */
#cal-card { overflow: visible; }
#cal-card .cal-header { border-radius: var(--radius) var(--radius) 0 0; }

/* ── Custom-list editor (clinic settings → lists tab) ──────────────────── */
.custom-list-items { display: flex; flex-wrap: wrap; gap: 8px; }
.custom-list-item {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; font-size: 13px;
}
.custom-list-item .list-item-remove {
  cursor: pointer; color: var(--text-muted); font-size: 15px; line-height: 1;
  border: none; background: none; padding: 0 2px;
}
.custom-list-item .list-item-remove:hover { color: var(--danger, #e74c3c); }

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface); }
.search-result-item .patient-name { font-weight: 600; font-size: 13px; }
.search-result-item .patient-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.topbar-spacer { flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ─── Main Content ────────────────────────────────────────────── */
.main-content {
  grid-area: main;
  padding: 0;
  overflow-y: auto;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.3px;
}

.page-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

/* ─── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

.card-body { padding: 18px; }

/* ─── Stat Tiles ──────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform .15s ease, box-shadow .15s ease;
}
/* Clickable stat tile (wrapped in <a>) */
a.stat-tile-link {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  gap: 6px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
a.stat-tile-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  border-color: var(--accent);
  text-decoration: none;
}
a.stat-tile-link[data-accent="blue"]   { border-left: 3px solid var(--accent); }
a.stat-tile-link[data-accent="green"]  { border-left: 3px solid var(--accent2); }
a.stat-tile-link[data-accent="yellow"] { border-left: 3px solid var(--warning); }
a.stat-tile-link[data-accent="red"]    { border-left: 3px solid var(--danger); }

/* ─── Dashboard Waiting Panel ─────────────────────────────────── */
.dash-wait-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  transition: background .12s ease;
}
.dash-wait-row:hover { background: var(--surface2); }
.dash-wait-row:last-child { border-bottom: none; }

.dash-wait-status { flex-shrink: 0; }
.dash-wait-status select {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-width: 120px;
}
.dash-wait-time {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--muted);
  white-space: nowrap;
}
.dash-wait-time.urgent { color: var(--danger); font-weight: 600; }

/* ─── Dashboard appointments table row actions ────────────────── */
.dash-appt-actions { display: flex; gap: 4px; flex-wrap: nowrap; }

.stat-tile .stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

.stat-tile .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.stat-tile .stat-delta {
  font-size: 11px;
  color: var(--muted);
}

.stat-tile .stat-icon {
  align-self: flex-end;
  margin-top: -2px;
  color: var(--accent);
}

/* ─── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: var(--surface2); }
tbody tr:last-child td { border-bottom: none; }

/* ─── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: rgba(63,185,80,.18);  color: var(--accent2); }
.badge-blue   { background: rgba(88,166,255,.18); color: var(--accent); }
.badge-yellow { background: rgba(227,179,65,.18); color: var(--warning); }
.badge-red    { background: rgba(248,81,73,.18);  color: var(--danger); }
.badge-gray   { background: var(--surface2);      color: var(--muted); }

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #2563eb; border-color: #2563eb; text-decoration: none; color: #fff; }

.btn-secondary {
  background: var(--surface2);
  color: var(--ink);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #ff6b6b; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--ink); background: var(--surface2); text-decoration: none; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }
.btn-icon.btn-sm { padding: 4px; }

/* ─── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-control {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
  transition: border-color var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
}
.form-control::placeholder { color: var(--muted); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }
.form-hint  { font-size: 11px; color: var(--muted); margin-top: 4px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ─── Tabs ────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  margin-bottom: 0;
}

.tab-btn {
  padding: 14px 20px;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  gap: 7px;
}

.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-btn .tab-count {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--muted);
}
.tab-btn.active .tab-count {
  background: rgba(59,130,246,.12);
  color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Tab content area with padding */
.tab-content-area { padding: 24px 32px; }

/* ─── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  width: min(560px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 15px; font-weight: 700; }
.modal-body  { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ─── Toast Notifications ─────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  min-width: 220px;
  max-width: 340px;
  box-shadow: var(--shadow);
  animation: slideUp .2s ease;
  pointer-events: all;
}

.toast.toast-success { border-left-color: var(--accent2); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ─── Vitals Chart ────────────────────────────────────────────── */
.chart-container { position: relative; height: 220px; }

/* ─── Alert / Care Gap ────────────────────────────────────────── */
.alert {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-warning { background: rgba(227,179,65,.12); border: 1px solid rgba(227,179,65,.3); color: var(--warning); }
.alert-danger  { background: rgba(248,81,73,.12);  border: 1px solid rgba(248,81,73,.3);  color: var(--danger); }
.alert-info    { background: rgba(88,166,255,.10); border: 1px solid rgba(88,166,255,.3); color: var(--info); }
.alert-success { background: rgba(63,185,80,.10);  border: 1px solid rgba(63,185,80,.3);  color: var(--accent2); }

/* ─── Patient Header Strip (Full-Width) ───────────────────────── */
.patient-strip {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 0;
  border-radius: 0;
}

.patient-avatar {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.patient-info { flex: 1; }
.patient-info .pname {
  font-size: 20px; font-weight: 700; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.patient-info .pmeta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.patient-strip-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Inline edit icon next to patient name */
.btn-inline-edit {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  background: none; border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.btn-inline-edit:hover { background: var(--surface2); color: var(--ink); }

/* Patient search inside the chart header strip */
.patient-search-chart { flex-shrink: 0; }
.patient-search-chart input {
  padding: 6px 10px 6px 30px;
  font-size: 12px;
  height: 32px;
}

/* ─── Calendar (Scheduling) ───────────────────────────────────── */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}

.cal-grid {
  display: grid;
  grid-template-columns: 60px 1fr;
  overflow: hidden;
}

.cal-time-col { border-right: 1px solid var(--border); }

.cal-slot {
  height: 48px;
  display: flex;
  align-items: flex-start;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.appt-block {
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.appt-scheduled { background: rgba(88,166,255,.2);  color: var(--accent); }
.appt-confirmed { background: rgba(63,185,80,.2);   color: var(--accent2); }
.appt-completed { background: rgba(139,148,158,.2); color: var(--muted); }
.appt-cancelled { background: rgba(248,81,73,.1);   color: var(--danger); text-decoration: line-through; }
.appt-no-show,
.appt-no_show   { background: rgba(227,179,65,.1);  color: var(--warning); }

/* ─── Theme switcher ──────────────────────────────────────────── */
.theme-switcher { display: flex; gap: 6px; }

.theme-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition), transform var(--transition);
}

.theme-dot:hover, .theme-dot.active { border-color: var(--ink); transform: scale(1.2); }

/* ─── Loading Spinner ─────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  gap: 12px;
  color: var(--muted);
}

/* ─── Utility ─────────────────────────────────────────────────── */
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.mb-3 { margin-bottom: 14px; }
.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--accent2); }
.text-accent { color: var(--accent); }
.text-sm { font-size: 12px; }
.text-mono { font-family: var(--font-mono); font-size: 12px; }
.fw-bold { font-weight: 700; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.p-4 { padding: 16px; }
.w-100 { width: 100%; }
.ml-auto { margin-left: auto; }
.hidden { display: none !important; }

/* ─── Chart Overview Grid ─────────────────────────────────────────────────── */
.overview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* ─── Recent Patients List (Dashboard) ───────────────────────────────────── */
.recent-patient-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  text-decoration: none;
  color: var(--text);
  transition: background var(--transition);
}
.recent-patient-item:hover { background: var(--surface2); text-decoration: none; }

/* ─── Calendar View Toggle ───────────────────────────────────────────────── */
.cal-view-toggle {
  display: flex;
  gap: 2px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}
.cal-view-btn {
  padding: 5px 14px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}
.cal-view-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.cal-view-btn:hover:not(.active) { color: var(--ink); }

/* ─── Week view day headers ──────────────────────────────────────────────── */
.cal-week-day-header {
  text-align: center;
  padding: 8px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  transition: color var(--transition);
}
.cal-week-day-header:hover { color: var(--accent); }
.cal-week-day-header.today { color: var(--accent); }

/* ─── Clickable empty slots ──────────────────────────────────────────────── */
.cal-empty-slot { cursor: pointer; transition: background var(--transition); }
.cal-empty-slot:hover { background: rgba(88,166,255,.07); }

/* ─── Slot hover + button ────────────────────────────────────────────────── */
.cal-slot-content { position: relative; }
.cal-slot-add-btn {
  display: none;
  width: 100%;
  background: rgba(88,166,255,.10);
  color: var(--accent);
  border: 1.5px dashed var(--accent);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 3px 0;
  text-align: center;
  margin-top: 3px;
  opacity: .8;
}
.cal-slot-content:hover .cal-slot-add-btn { display: block; }
.cal-slot-add-btn:hover { opacity: 1; background: rgba(88,166,255,.18); }

/* Past time-slot background */
.cal-slot-past {
  background: var(--surface2) !important;
  opacity: .55;
}

/* ─── Month grid ─────────────────────────────────────────────────────────── */
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.cal-month-day-header {
  text-align: center;
  padding: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.cal-month-cell {
  min-height: 90px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  cursor: pointer;
  transition: background var(--transition);
}
.cal-month-cell:hover { background: rgba(88,166,255,.04); }
.cal-month-cell.other-month { opacity: .45; }
.cal-day-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.cal-month-cell.today .cal-day-num { background: var(--accent); color: var(--bg); }
.cal-month-appt {
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.cal-more { font-size: 10px; color: var(--muted); padding: 0 2px; cursor: pointer; }
.cal-more:hover { color: var(--accent); text-decoration: underline; }

/* ─── Provider colour legend ─────────────────────────────────────────────── */
#cal-provider-legend {
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.provider-legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 7px;
  border-radius: 100px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.provider-legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Provider initials badge on appointment blocks ─────────────────────── */
.appt-provider-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  margin-right: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}
/* Smaller version used in week view (compact cells) */
.appt-provider-dot-sm {
  float: right;
  margin-right: 0;
  margin-left: 3px;
  width: 14px; height: 14px;
  font-size: 8px;
}

/* ─── Current-time indicator line ────────────────────────────────────────── */
.cal-now-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: var(--danger);
  z-index: 10;
  pointer-events: none;
}
.cal-now-line::before {
  content: '';
  position: absolute;
  left: -4px; top: -4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

/* ─── Mobile menu button ─────────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
}
.mobile-menu-btn:hover { background: var(--surface2); color: var(--ink); }

/* ─── Sidebar overlay ────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
}
.sidebar-overlay.open { display: block; }

/* ─── flex-wrap helper ───────────────────────────────────────────────────── */
.flex-wrap { flex-wrap: wrap; }

/* ─── Responsive: Tablet ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  .sidebar {
    left: -70px;
    transition: left var(--transition);
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
  }
  .sidebar.mobile-open { left: 0; }
  .mobile-menu-btn { display: flex; }
  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .overview-grid { grid-template-columns: 1fr; }
  .patient-strip { flex-wrap: wrap; gap: 12px; padding: 16px; }
  .patient-strip-actions { width: 100%; justify-content: flex-end; }
  .page-header { flex-wrap: wrap; gap: 10px; }
  .page-header .d-flex { flex-wrap: wrap; }
  .tabs { overflow-x: auto; white-space: nowrap; padding: 0 16px; }
  .tab-btn { white-space: nowrap; }
  .main-content { padding: 0; }
  .tab-content-area { padding: 16px; }
  .topbar { padding: 0 16px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .modal { width: 94vw; max-width: 94vw; }
}

/* ─── Responsive: Phone ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-header .d-flex { gap: 6px; }
  .patient-search-wrap { max-width: none; }
  .cal-month-cell { min-height: 60px; }
  .cal-month-appt { display: none; }
  .main-content { padding: 10px; }
  .topbar { padding: 0 12px; }
}

/* ─── Modal Overlay (inline display toggle) ──────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay .modal-close {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

/* ─── Roles & Permissions Page ───────────────────────────────────────────── */
.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}
.role-card { transition: border-color .15s; }
.role-card:hover { border-color: var(--accent); }
.role-perm-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.role-perm-tags .badge { font-size: 0.7rem; }

.badge-info      { background: rgba(88,166,255,.18); color: var(--accent); }
.badge-secondary { background: var(--surface2); color: var(--muted); }
.badge-danger, .btn-danger {
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
}
.btn-danger:hover { opacity: .85; }

.perm-module {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: var(--surface2);
  border-radius: var(--radius);
}
.perm-module-header { margin-bottom: 0.5rem; }
.perm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  padding-left: 1.5rem;
}
.perm-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.perm-item input[type="checkbox"] { accent-color: var(--accent); }

/* ── AI Consult Chat ──────────────────────────────────────────────────────── */
.ai-msg {
  padding: 10px 14px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  max-width: 85%;
}
.ai-msg-user {
  background: rgba(88,166,255,.12);
  color: var(--fg);
  margin-left: auto;
  text-align: right;
  border-bottom-right-radius: 2px;
}
.ai-msg-assistant {
  background: var(--surface2);
  color: var(--fg);
  border-bottom-left-radius: 2px;
}
.ai-msg-assistant h2, .ai-msg-assistant h3, .ai-msg-assistant h4, .ai-msg-assistant h5 {
  margin: 8px 0 4px;
  font-size: 14px;
}
.ai-msg-assistant h2 { font-size: 15px; }
.ai-msg-assistant p { margin: 0 0 6px; }
.ai-msg-assistant p:last-child { margin-bottom: 0; }
.ai-msg-assistant ul, .ai-msg-assistant ol { margin: 4px 0; padding-left: 20px; }
.ai-msg-assistant li { margin-bottom: 2px; }
.ai-msg-assistant code {
  background: rgba(255,255,255,.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}
.ai-msg-error {
  background: rgba(248,81,73,.15);
  color: var(--danger);
  border-left: 3px solid var(--danger);
}
.ai-typing {
  color: var(--muted);
  font-style: italic;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }
.ai-meta {
  text-align: right;
  padding: 0 4px 6px;
  font-size: 11px;
}

/* ── AI History Attachment ─────────────────────────────────────────────── */
.ai-history-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  max-height: 350px;
  overflow-y: auto;
}
.ai-hist-collection {
  border-bottom: 1px solid var(--border);
  padding: 6px 0;
}
.ai-hist-collection:last-child { border-bottom: none; }
.ai-hist-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ai-hist-col-header label { font-size: 13px; font-weight: 500; }
.ai-hist-col-header input[type="checkbox"] { accent-color: var(--accent); }
.ai-hist-col-items {
  padding: 6px 0 6px 24px;
  font-size: 12px;
  border-left: 2px solid var(--border);
  margin-left: 10px;
  margin-top: 4px;
}
.hist-item {
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  line-height: 1.5;
}
.hist-item:last-child { border-bottom: none; }
.hist-date {
  display: inline-block;
  min-width: 80px;
  color: var(--muted);
  font-size: 11px;
  margin-right: 4px;
}
.hist-toggle-btn {
  font-size: 11px;
  white-space: nowrap;
}

/* Attached bar */
.ai-attached-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(88,166,255,.08);
  border: 1px solid rgba(88,166,255,.2);
  border-radius: var(--radius);
  font-size: 12px;
}
.ai-attached-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(88,166,255,.15);
  color: var(--fg);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.ai-badge-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}
.ai-badge-remove:hover { color: var(--danger); }

/* ─── Procedures Table ────────────────────────────────────────── */
.procedures-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

/* ─── All Events Timeline ─────────────────────────────────────── */
.timeline-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}
.timeline-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  transition: all 0.15s;
}
.timeline-chip:hover { border-color: var(--accent); color: var(--ink); }
.timeline-chip.active { border-color: var(--accent); background: rgba(59,130,246,.1); color: var(--accent); }
.timeline-chip .chip-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.timeline-list { position: relative; padding-left: 24px; }
.timeline-list::before {
  content: '';
  position: absolute;
  left: 7px; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-event {
  position: relative;
  margin-bottom: 16px;
  padding-left: 20px;
}
.timeline-event::before {
  content: '';
  position: absolute;
  left: -20px; top: 6px;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface);
}
.timeline-event[data-type="note"]::before { background: #3b82f6; }
.timeline-event[data-type="vital"]::before { background: #ef4444; }
.timeline-event[data-type="lab"]::before { background: #8b5cf6; }
.timeline-event[data-type="medication"]::before { background: #16a34a; }
.timeline-event[data-type="appointment"]::before { background: #f59e0b; }
.timeline-event[data-type="procedure"]::before { background: #ec4899; }
.timeline-event[data-type="allergy"]::before { background: #f97316; }
.timeline-event[data-type="problem"]::before { background: #dc2626; }

.timeline-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: border-color 0.15s;
}
.timeline-card:hover { border-color: var(--accent); }
.timeline-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.timeline-card-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
}
.timeline-card-type.note { background: rgba(59,130,246,.1); color: #3b82f6; }
.timeline-card-type.vital { background: rgba(239,68,68,.1); color: #ef4444; }
.timeline-card-type.lab { background: rgba(139,92,246,.1); color: #8b5cf6; }
.timeline-card-type.medication { background: rgba(22,163,106,.1); color: #16a34a; }
.timeline-card-type.appointment { background: rgba(245,158,11,.1); color: #f59e0b; }
.timeline-card-type.procedure { background: rgba(236,72,153,.1); color: #ec4899; }
.timeline-card-type.allergy { background: rgba(249,115,22,.1); color: #f97316; }
.timeline-card-type.problem { background: rgba(220,38,38,.1); color: #dc2626; }
.timeline-card-date { font-size: 12px; color: var(--muted); }
.timeline-card-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.timeline-card-detail { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ─── Page content wrapper (adds padding for non-chart pages) ─── */
.page-content-padded { padding: 24px 32px; }

/* ─── Settings Page ───────────────────────────────────────────── */
.settings-sections {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 900px;
}

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.settings-section-header { margin-bottom: 18px; }

.settings-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}

.settings-section-desc { font-size: 13px; }

/* Theme card grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 14px;
}

.theme-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.theme-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
}

.theme-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.theme-preview {
  height: 90px;
  display: flex;
  overflow: hidden;
}

.theme-preview-sidebar { width: 16px; flex-shrink: 0; }

.theme-preview-bar {
  height: 7px;
  border-radius: 4px;
}

.theme-card-footer {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.theme-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.theme-card-desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

.theme-card-check { opacity: 0; transition: opacity 0.15s; }
.theme-card-check.visible { opacity: 1; }

/* Density buttons */
.density-grid {
  display: flex;
  gap: 14px;
}

.density-btn {
  flex: 1;
  max-width: 200px;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface2);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.density-btn:hover { border-color: var(--accent); background: var(--surface); }
.density-btn.active { border-color: var(--accent); background: var(--surface); }

.density-icon { color: var(--accent); display: block; }
.density-label { font-size: 13px; font-weight: 600; display: block; }
.density-desc  { font-size: 11px; color: var(--muted); display: block; }

/* ── Compact density layout ────────────────────────────────────── */
[data-density="compact"] .page-content-padded { padding: 14px 20px; }
[data-density="compact"] .tab-content-area    { padding: 10px 16px !important; }
[data-density="compact"] .page-header         { margin-bottom: 10px; }
[data-density="compact"] .card-header         { padding: 8px 12px; }
[data-density="compact"] .card-body           { padding: 10px 12px; }
[data-density="compact"] .stat-tile           { padding: 10px 12px; gap: 4px; }
[data-density="compact"] .stat-tile .stat-value { font-size: 22px; }
[data-density="compact"] .stat-grid           { gap: 8px; margin-bottom: 12px; }
[data-density="compact"] thead th             { padding: 6px 10px; }
[data-density="compact"] tbody td             { padding: 6px 10px; }
[data-density="compact"] .btn                 { padding: 4px 10px; font-size: 12px; }
[data-density="compact"] .mb-3                { margin-bottom: 8px !important; }
[data-density="compact"] .mb-4                { margin-bottom: 12px !important; }
[data-density="compact"] .gap-2               { gap: 6px !important; }
[data-density="compact"] .form-group          { margin-bottom: 8px; }

/* Profile info card */
.profile-info-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.profile-info-details { display: flex; flex-direction: column; gap: 3px; }
.profile-info-name  { font-size: 16px; font-weight: 700; color: var(--ink); }
.profile-info-role  { font-size: 12px; text-transform: capitalize; }
.profile-info-email { font-size: 12px; font-family: var(--font-mono); }

/* Change-password form */
.settings-pw-form { max-width: 560px; }
.form-row-inline {
  display: flex;
  gap: 16px;
}
.form-row-inline .form-group { flex: 1; }

.settings-pw-msg {
  font-size: 13px;
  min-height: 20px;
  margin-bottom: 12px;
  border-radius: 6px;
  padding: 0;
  transition: all 0.2s;
}
.settings-pw-msg.success {
  color: var(--success, #22c55e);
  padding: 8px 12px;
  background: rgba(34,197,94,.1);
  border: 1px solid rgba(34,197,94,.3);
}
.settings-pw-msg.error {
  color: var(--danger, #f87171);
  padding: 8px 12px;
  background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.3);
}

/* ─── Support Ticket System ───────────────────────────────────── */

/* Two-panel layout */
.support-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.25rem;
  height: calc(100vh - 140px);
  min-height: 400px;
}
@media (max-width: 860px) {
  .support-shell { grid-template-columns: 1fr; height: auto; }
  .support-shell .support-thread-panel { display: none; }
  .support-shell.thread-open .support-list-panel { display: none; }
  .support-shell.thread-open .support-thread-panel { display: flex !important; }
}

/* List panel */
.support-list-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius, 12px);
  border: 1px solid var(--border);
  background: var(--bg);
}
.support-list-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.support-list-header select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}
.support-list-body {
  flex: 1;
  overflow-y: auto;
}

/* Ticket row in list */
.support-ticket-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.support-ticket-row:hover { background: var(--surface-hover, #f3f4f6); }
.support-ticket-row.active { background: var(--surface-hover, #f3f4f6); }
.support-ticket-row.has-unread::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.support-ticket-row.has-unread { padding-left: 22px; }

.support-ticket-info { flex: 1; min-width: 0; }
.support-ticket-subject {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.support-ticket-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.support-ticket-ref {
  font-family: var(--mono, monospace);
  font-size: 10px;
  color: var(--muted);
  opacity: 0.7;
}
.support-ticket-time {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Priority pill in list */
.priority-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.priority-dot.low    { background: var(--muted); }
.priority-dot.normal { background: var(--accent); }
.priority-dot.high   { background: #f59e0b; }
.priority-dot.urgent { background: var(--danger); }

/* Category badge */
.cat-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.cat-badge.general { background: rgba(88,166,255,.12); color: var(--accent); }
.cat-badge.billing { background: rgba(34,197,94,.12);  color: var(--accent2); }
.cat-badge.bug     { background: rgba(248,81,73,.12);  color: var(--danger); }
.cat-badge.feature { background: rgba(163,113,247,.12); color: #a371f7; }
.cat-badge.account { background: rgba(227,179,65,.12);  color: #c4960a; }

/* Thread panel */
.support-thread-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius, 12px);
  border: 1px solid var(--border);
  background: var(--bg);
}
.support-thread-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.support-thread-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.support-thread-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

/* Messages area */
.support-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.support-day-sep {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin: 12px 0 6px;
  position: relative;
}
.support-day-sep::before,
.support-day-sep::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 50px);
  height: 1px;
  background: var(--border);
}
.support-day-sep::before { left: 0; }
.support-day-sep::after  { right: 0; }

.support-msg {
  max-width: 78%;
  animation: supportMsgIn 0.2s ease;
}
@keyframes supportMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.support-msg.admin  { align-self: flex-start; }
.support-msg.tenant { align-self: flex-end; }
.support-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.support-msg.admin .support-msg-bubble {
  background: #e8ecf1;
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.support-msg.tenant .support-msg-bubble {
  background: #dbeafe;
  color: #1e3a5f;
  border-bottom-right-radius: 4px;
}
.support-msg-meta {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
  padding: 0 4px;
}
.support-msg.admin .support-msg-meta  { text-align: left; }
.support-msg.tenant .support-msg-meta { text-align: right; }

/* Reply box */
.support-reply-box {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.support-reply-box textarea {
  resize: vertical;
  min-height: 60px;
}
.support-reply-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.support-reply-hint {
  font-size: 11px;
  color: var(--muted);
}

/* Placeholder / empty state */
.support-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  gap: 12px;
  padding: 40px;
  text-align: center;
}
.support-placeholder svg {
  opacity: 0.35;
}
.support-placeholder-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.support-placeholder-desc {
  font-size: 13px;
  max-width: 320px;
  line-height: 1.5;
}

/* Empty state for list */
.support-empty-list {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}
.support-empty-list svg { opacity: 0.3; margin-bottom: 10px; }
.support-empty-list p { font-size: 13px; margin: 4px 0 0; }

/* Create ticket modal extras */
.support-category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.support-cat-option {
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 12px;
  font-weight: 500;
}
.support-cat-option:hover { border-color: var(--accent); background: rgba(59,130,246,.04); }
.support-cat-option.selected { border-color: var(--accent); background: rgba(59,130,246,.08); }
.support-cat-option .cat-icon { font-size: 20px; display: block; margin-bottom: 4px; }

.support-priority-row {
  display: flex;
  gap: 8px;
}
.support-pri-option {
  flex: 1;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}
.support-pri-option:hover { border-color: var(--accent); }
.support-pri-option.selected { font-weight: 700; }
.support-pri-option.selected.low    { border-color: var(--muted); background: rgba(148,163,184,.1); }
.support-pri-option.selected.normal { border-color: var(--accent); background: rgba(59,130,246,.08); }
.support-pri-option.selected.high   { border-color: #f59e0b; background: rgba(245,158,11,.08); }
.support-pri-option.selected.urgent { border-color: var(--danger); background: rgba(248,81,73,.08); }

/* Mobile back button */
.support-back-btn {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  margin-bottom: 4px;
}
@media (max-width: 860px) {
  .support-back-btn { display: inline-flex; }
}

/* Reopen bar */
.support-reopen-bar {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
}

/* ─── Clinical Reminder Rule Cards ───────────────────────────────────── */
.reminder-rule-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: box-shadow var(--transition);
}
.reminder-rule-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.reminder-rule-card.disabled {
  opacity: .55;
}
