/* ============================================================
   MEDICORE PMS — Complete Stylesheet
   Design: Clinical Precision + Modern SaaS
   ============================================================ */

:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --primary-dark: #1d4ed8;
  --primary-fade: #dbeafe;
  --secondary: #0ea5e9;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #6366f1;

  /* Light Mode */
  --bg: #f1f5f9;
  --bg2: #ffffff;
  --bg3: #f8fafc;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active-bg: #2563eb;
  --sidebar-active-text: #ffffff;
  --text: #0f172a;
  --text2: #475569;
  --text3: #94a3b8;
  --border: #e2e8f0;
  --border2: #cbd5e1;
  --card-shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --card-shadow-hover: 0 10px 25px rgba(0,0,0,.1);
  --input-bg: #f8fafc;
  --input-border: #e2e8f0;
  --input-focus: #2563eb;
  --table-stripe: #f8fafc;
  --modal-overlay: rgba(15,23,42,.5);
  --topbar-bg: #ffffff;
  --topbar-border: #e2e8f0;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --font: 'Inter', sans-serif;
}

.dark-mode {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #0f172a;
  --sidebar-bg: #020617;
  --sidebar-hover: #0f172a;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #475569;
  --border: #1e293b;
  --border2: #334155;
  --card-shadow: 0 1px 3px rgba(0,0,0,.4);
  --card-shadow-hover: 0 10px 25px rgba(0,0,0,.5);
  --input-bg: #0f172a;
  --input-border: #334155;
  --table-stripe: #1e293b;
  --modal-overlay: rgba(0,0,0,.7);
  --topbar-bg: #1e293b;
  --topbar-border: #334155;
  --primary-fade: #1e3a8a30;
}

/* ============================================================ RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); transition: background var(--transition), color var(--transition); line-height: 1.6; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; outline: none; font-family: var(--font); }
input, select, textarea { font-family: var(--font); outline: none; }
table { border-collapse: collapse; width: 100%; }
img { max-width: 100%; }

/* ============================================================ SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ============================================================ LOGIN */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #0f172a 100%);
  position: relative;
  overflow: hidden;
}
.login-bg { position: absolute; inset: 0; pointer-events: none; }
.login-bg-shape {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(37,99,235,.3), transparent);
}
.login-bg-shape.s1 { width: 600px; height: 600px; top: -200px; left: -100px; }
.login-bg-shape.s2 { width: 400px; height: 400px; bottom: -100px; right: 100px; background: radial-gradient(circle, rgba(6,182,212,.2), transparent); }
.login-bg-shape.s3 { width: 300px; height: 300px; top: 50%; left: 60%; background: radial-gradient(circle, rgba(99,102,241,.2), transparent); }

.login-card {
  background: rgba(255,255,255,.05);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 24px;
  padding: 48px 40px;
  width: 420px;
  max-width: calc(100vw - 32px);
  position: relative;
  z-index: 1;
  box-shadow: 0 25px 50px rgba(0,0,0,.5);
}
.login-brand { text-align: center; margin-bottom: 36px; }
.login-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  font-size: 28px; color: white;
  box-shadow: 0 8px 24px rgba(37,99,235,.4);
}
.login-brand h1 { color: white; font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.login-brand p { color: rgba(255,255,255,.5); font-size: 14px; margin-top: 4px; }

.login-form .form-group { margin-bottom: 20px; }
.login-form label { display: block; color: rgba(255,255,255,.7); font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.input-icon { position: relative; }
.input-icon > i:first-child {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: rgba(255,255,255,.3); font-size: 15px; pointer-events: none;
}
.input-icon input {
  width: 100%; padding: 12px 16px 12px 44px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  color: white; font-size: 15px;
  transition: all var(--transition);
}
.input-icon input::placeholder { color: rgba(255,255,255,.3); }
.input-icon input:focus { background: rgba(255,255,255,.12); border-color: rgba(37,99,235,.7); box-shadow: 0 0 0 3px rgba(37,99,235,.2); }
.pw-toggle {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  background: none; color: rgba(255,255,255,.3);
  transition: color var(--transition);
}
.pw-toggle:hover { color: rgba(255,255,255,.7); }

.login-error {
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.btn-login {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: white; font-size: 15px; font-weight: 600;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all var(--transition);
  box-shadow: 0 4px 15px rgba(37,99,235,.4);
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 8px 25px rgba(37,99,235,.5); }
.btn-login:active { transform: translateY(0); }
.login-note { text-align: center; color: rgba(255,255,255,.3); font-size: 12px; margin-top: 20px; }

/* ============================================================ APP LAYOUT */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 260px; min-width: 260px;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  transition: transform var(--transition), width var(--transition);
  position: relative; z-index: 100;
  border-right: 1px solid rgba(255,255,255,.05);
}
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* SIDEBAR HEADER */
.sidebar-header {
  padding: 20px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 16px;
}
.brand-name { color: white; font-weight: 700; font-size: 17px; display: block; line-height: 1; }
.brand-sub { color: rgba(255,255,255,.3); font-size: 10px; display: block; margin-top: 2px; }
.sidebar-close { display: none; background: none; color: rgba(255,255,255,.4); font-size: 16px; }

/* SIDEBAR USER */
.sidebar-user {
  padding: 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.user-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.user-avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.user-info { min-width: 0; }
.user-name { color: white; font-size: 13px; font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-role {
  font-size: 10px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px;
  background: rgba(37,99,235,.3); color: #93c5fd;
  display: inline-block; margin-top: 2px;
}

/* SIDEBAR NAV */
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-section { padding: 8px 0; }
.nav-section-title {
  padding: 6px 16px 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  color: rgba(255,255,255,.2); text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  font-size: 14px; font-weight: 500;
  border-radius: 8px;
  margin: 1px 8px;
  transition: all var(--transition);
  position: relative;
}
.nav-item:hover { background: var(--sidebar-hover); color: white; }
.nav-item.active { background: var(--sidebar-active-bg); color: white; }
.nav-item i { width: 18px; text-align: center; font-size: 15px; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 10px;
  min-width: 18px; text-align: center;
  display: none;
}
.nav-badge.today { background: var(--success); }
.nav-badge:not(:empty) { display: block; }

/* SIDEBAR FOOTER */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex; flex-direction: column; gap: 6px;
}
.theme-toggle, .btn-logout {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  transition: all var(--transition);
  width: 100%;
}
.theme-toggle { background: rgba(255,255,255,.05); color: rgba(255,255,255,.6); }
.theme-toggle:hover { background: rgba(255,255,255,.1); color: white; }
.btn-logout { background: rgba(239,68,68,.1); color: #f87171; }
.btn-logout:hover { background: rgba(239,68,68,.2); }

/* ============================================================ TOPBAR */
.topbar {
  height: 60px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  transition: background var(--transition);
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.menu-toggle {
  background: none; color: var(--text2); font-size: 18px;
  padding: 6px; border-radius: 6px;
  transition: all var(--transition);
  display: none;
}
.menu-toggle:hover { background: var(--bg); color: var(--text); }
.breadcrumb { font-size: 18px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.topbar-date { display: flex; align-items: center; gap: 6px; color: var(--text2); font-size: 13px; }
.topbar-user { display: flex; align-items: center; gap: 8px; color: var(--text2); font-size: 13px; font-weight: 500; }

/* ============================================================ PAGE CONTENT */
.page-content {
  flex: 1; overflow-y: auto;
  padding: 24px;
  background: var(--bg);
  transition: background var(--transition);
}

/* ============================================================ CARDS */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  transition: box-shadow var(--transition), background var(--transition);
  overflow: hidden;
}
.card:hover { box-shadow: var(--card-shadow-hover); }
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.card-body { padding: 20px; }

/* STAT CARDS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  display: flex; align-items: center; gap: 16px;
  transition: all var(--transition);
  cursor: pointer;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--card-shadow-hover); }
.stat-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.green { background: #d1fae5; color: #10b981; }
.stat-icon.orange { background: #fef3c7; color: #f59e0b; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.red { background: #fee2e2; color: #ef4444; }
.stat-icon.teal { background: #cffafe; color: #06b6d4; }
.dark-mode .stat-icon.blue { background: #1e3a8a30; color: #60a5fa; }
.dark-mode .stat-icon.green { background: #06402430; color: #34d399; }
.dark-mode .stat-icon.orange { background: #78350f30; color: #fbbf24; }
.dark-mode .stat-icon.purple { background: #4c1d9530; color: #a78bfa; }
.dark-mode .stat-icon.red { background: #7f1d1d30; color: #f87171; }
.dark-mode .stat-icon.teal { background: #16434630; color: #22d3ee; }
.stat-info { min-width: 0; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* ============================================================ CHARTS */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.chart-card { background: var(--bg2); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.chart-header { padding: 16px 20px 0; }
.chart-title { font-size: 14px; font-weight: 600; color: var(--text); }
.chart-body { padding: 16px; }
canvas { max-height: 220px !important; }

/* ============================================================ FORMS */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text2); }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-control {
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  transition: all var(--transition);
  width: 100%;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); background: var(--bg2); }
.form-control::placeholder { color: var(--text3); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ============================================================ BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(37,99,235,.3); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; box-shadow: 0 4px 12px rgba(16,185,129,.3); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; }
.btn-secondary { background: var(--bg); color: var(--text2); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-fade); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }

/* ============================================================ TABLE */
.table-wrapper { overflow-x: auto; }
.table-actions { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  flex: 1; max-width: 320px;
}
.search-box i { color: var(--text3); font-size: 13px; }
.search-box input { background: none; border: none; color: var(--text); font-size: 14px; flex: 1; min-width: 0; }
.search-box input::placeholder { color: var(--text3); }
.data-table { width: 100%; }
.data-table thead th {
  padding: 12px 16px;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text2);
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
}
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--table-stripe); }
.data-table tbody td { padding: 12px 16px; font-size: 13px; color: var(--text); vertical-align: middle; }

/* ============================================================ BADGES */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0e7ff; color: #3730a3; }
.badge-gray { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }
.badge-primary { background: #dbeafe; color: #1e40af; }
.dark-mode .badge-success { background: #06402430; color: #6ee7b7; }
.dark-mode .badge-warning { background: #78350f30; color: #fcd34d; }
.dark-mode .badge-danger { background: #7f1d1d30; color: #fca5a5; }
.dark-mode .badge-info { background: #3730a330; color: #a5b4fc; }
.dark-mode .badge-primary { background: #1e3a8a30; color: #93c5fd; }

/* ============================================================ MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--bg2);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px rgba(0,0,0,.3);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn .2s ease;
}
.modal-box.lg { max-width: 860px; }
.modal-box.sm { max-width: 440px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-20px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close { background: var(--bg3); color: var(--text2); width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; transition: all var(--transition); }
.modal-close:hover { background: var(--danger); color: white; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: flex-end; gap: 10px; }

/* ============================================================ TOAST */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  min-width: 280px; max-width: 360px;
  animation: toastIn .3s ease;
  font-size: 13px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info { border-left: 3px solid var(--info); }
.toast i { font-size: 16px; flex-shrink: 0; }
.toast-success i { color: var(--success); }
.toast-error i { color: var(--danger); }
.toast-warning i { color: var(--warning); }
.toast-info i { color: var(--info); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ============================================================ LOADING */
.loading-overlay {
  position: fixed; inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(6px);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.3s ease;
}

.loading-card {
  background: var(--bg2);
  padding: 32px 48px;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px rgba(0,0,0,.2);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  animation: modalIn 0.3s ease;
}

.loading-logo {
  width: 80px; /* Made slightly wider to give the line room to travel */
  height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(37,99,235,.3);
  overflow: hidden; /* Keeps the drawing line neatly inside the box */
  padding: 0 5px;
}

/* Base styling for the EKG SVG */
.ekg-svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: #ffffff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The magic drawing animation */
.ekg-svg polyline {
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: drawEkg 1.8s infinite linear;
}

@keyframes drawEkg {
  0% { stroke-dashoffset: 200; }
  50% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -200; }
}


.loading-text {
  font-size: 15px; font-weight: 600; color: var(--text);
  letter-spacing: 0.5px;
}

.loading-progress {
  width: 160px; height: 6px;
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.loading-bar {
  position: absolute; top: 0; left: 0; height: 100%;
  width: 40%;
  background: var(--primary);
  border-radius: 10px;
  animation: loadingSlide 1.2s infinite ease-in-out;
}

@keyframes loadingSlide {
  0% { left: -40%; }
  100% { left: 100%; }
}



/* ============================================================ PAGE HEADER */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 20px; font-weight: 700; color: var(--text); }
.page-header p { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ============================================================ PATIENT PROFILE */
.profile-header {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  color: white;
  display: flex; align-items: center; gap: 20px;
}
.profile-avatar {
  width: 72px; height: 72px;
  background: rgba(255,255,255,.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700;
  border: 3px solid rgba(255,255,255,.3);
  flex-shrink: 0;
}
.profile-info h2 { font-size: 22px; font-weight: 700; }
.profile-info p { opacity: .8; font-size: 14px; margin-top: 4px; }
.profile-tags { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.profile-tag {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px; font-weight: 500;
}

/* ============================================================ TABS */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab-btn {
  padding: 10px 20px;
  background: none; color: var(--text2);
  font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all var(--transition);
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover:not(.active) { color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================================ PRESCRIPTION PRINT */
.rx-print {
  font-family: var(--font);
  max-width: 720px; margin: 0 auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.rx-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--primary); padding-bottom: 16px; margin-bottom: 16px; }
.rx-clinic h2 { color: var(--primary); font-size: 22px; }
.rx-table { width: 100%; margin-top: 16px; }
.rx-table th { background: var(--primary); color: white; padding: 8px 12px; text-align: left; font-size: 13px; }
.rx-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }

/* ============================================================ UTILITIES */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text2); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.info-row { display: flex; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 12px; color: var(--text3); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; min-width: 140px; flex-shrink: 0; }
.info-value { font-size: 13px; color: var(--text); font-weight: 500; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text2); }
.empty-state i { font-size: 48px; color: var(--text3); margin-bottom: 16px; display: block; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text2); }
.empty-state p { font-size: 13px; color: var(--text3); margin-top: 4px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

/* Medicine row in prescription form */
.medicine-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.add-medicine-btn { color: var(--primary); font-size: 13px; font-weight: 600; background: var(--primary-fade); border: 1.5px dashed var(--primary); border-radius: 8px; padding: 8px; text-align: center; cursor: pointer; transition: all var(--transition); }
.add-medicine-btn:hover { background: #dbeafe; }

/* ============================================================ REPORTS */
.report-filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.report-stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin: 16px 0; }
.report-stat { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.report-stat .rs-val { font-size: 24px; font-weight: 700; color: var(--primary); }
.report-stat .rs-lbl { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ============================================================ RESPONSIVE */
@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    transform: translateX(-100%);
    z-index: 200;
    width: 260px;
    height: 100vh;
    top: 0; left: 0;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex !important; }
  .menu-toggle { display: flex !important; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-2, .form-grid-2 { grid-template-columns: 1fr; }
  .medicine-row { grid-template-columns: 1fr 1fr; }
  .table-actions { flex-direction: column; align-items: stretch; }
  .search-box { max-width: 100%; }
  .topbar-date { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .modal-box { max-width: 100%; margin: 8px; }
}

/* Print styles */
@media print {
  .sidebar, .topbar, .btn, .page-header button, .modal-close { display: none !important; }
  .main-content { margin-left: 0 !important; }
  body { background: white; color: black; }
}

/* Smooth Transitions */
.sidebar {
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden; /* Prevents text from spilling out while animating */
}
.main-content {
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================
   COLLAPSED SIDEBAR STATE (ULTRA-THIN)
   ========================================= */
body.sidebar-collapsed .sidebar {
  width: 60px !important;
  min-width: 60px !important;
}

/* Expand the main content area */
body.sidebar-collapsed .main-content {
  margin-left: 60px !important;
  width: calc(100% - 60px) !important;
}

/* Hide all text and labels completely */
body.sidebar-collapsed .sidebar span,
body.sidebar-collapsed .nav-section-title,
body.sidebar-collapsed .user-info {
  display: none !important;
}

/* 1. Perfectly Center Header (Logo & Menu Button) */
body.sidebar-collapsed .sidebar-header {
  flex-direction: column;
  padding: 16px 0;
  gap: 16px;
  justify-content: center;
}
body.sidebar-collapsed .logo i {
  font-size: 22px;
  margin: 0;
  color: var(--primary); /* Makes the heartbeat icon pop! */
}

/* 2. Perfectly Center User Avatar */
body.sidebar-collapsed .sidebar-user {
  justify-content: center;
  padding: 16px 0;
}
body.sidebar-collapsed .user-avatar {
  margin: 0; /* Removes default spacing */
}

/* 3. Perfectly Center Navigation Icons */
body.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 12px 0;
  margin: 4px 8px; /* Tighter margins for the 60px width */
}
body.sidebar-collapsed .nav-item i {
  margin: 0 !important;
  font-size: 18px;
  text-align: center;
}

/* 4. Perfectly Center Footer Icons (Theme & Logout) */
body.sidebar-collapsed .sidebar-footer {
  padding: 12px 8px;
}
body.sidebar-collapsed .theme-toggle,
body.sidebar-collapsed .btn-logout {
  justify-content: center;
  padding: 12px 0;
}
body.sidebar-collapsed .theme-toggle i,
body.sidebar-collapsed .btn-logout i {
  margin: 0 !important;
  font-size: 18px;
}

/* ============================================================
   CALENDAR MODULE (Practo-Style)
   ============================================================ */
.cal-container {
  display: flex;
  height: calc(100vh - 120px);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Left Sidebar (Doctors) */
.cal-sidebar-left {
  width: 240px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg3);
}
.cal-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cal-doc-list { flex: 1; overflow-y: auto; }
.cal-doc-item {
  display: flex; align-items: center;
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.cal-doc-item:hover { background: var(--bg); }
.cal-doc-item.active { background: #e0e7ff; border-left-color: var(--primary); font-weight: 600; }
.cal-doc-dot { width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; display: inline-block; }
.cal-doc-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0; margin-right: 10px;
}
.cal-doc-item span { flex: 1; }

/* Center Main Calendar */
.cal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.cal-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-wrap: wrap;
  gap: 10px;
}
.cal-title-area { display: flex; align-items: center; gap: 16px; }
.cal-title { font-size: 18px; font-weight: 600; color: var(--text); }
.cal-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cal-nav-group { display: flex; align-items: center; gap: 6px; }
.cal-date-range { font-weight: 600; font-size: 14px; min-width: 140px; text-align: center; color: var(--text); }
.cal-nav-btn { background: none; border: 1px solid var(--border); padding: 6px 12px; border-radius: 4px; font-size: 13px; cursor: pointer; }
.cal-nav-btn:hover { background: var(--bg); }
.cal-view-toggles { display: flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.cal-view-btn { background: var(--bg2); border: none; border-right: 1px solid var(--border); padding: 6px 16px; font-size: 13px; cursor: pointer; }
.cal-view-btn:last-child { border-right: none; }
.cal-view-btn.active { background: #64748b; color: white; }

.cal-grid-wrapper { flex: 1; overflow-y: auto; position: relative; }
.cal-grid { display: flex; min-width: 800px; }

.cal-time-col { width: 70px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--bg2); text-align: left; }
.cal-time-allday-header {
  height: 37px;
  padding: 10px 6px;
  font-size: 11px;
  color: var(--text2);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}
.cal-allday-row {
  height: 33px;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}
.cal-time-slot {
  position: relative;
  padding: 2px 6px 0;
  font-size: 11px;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}
.cal-time-slot.off-hours { background: #e9e9e9; }
.cal-time-label {
  position: relative;
  top: -7px;
  display: inline-block;
  white-space: nowrap;
}

.cal-day-col { flex: 1; border-right: 1px solid var(--border); position: relative; }
.cal-day-col.is-today { background: #fff2df; }
.cal-day-col.is-today .cal-slot.off-hours { background: rgba(233,233,233,0.75); }

.cal-day-header { padding: 10px; text-align: center; font-size: 12px; font-weight: 600; color: var(--text2); border-bottom: 1px solid var(--border); text-transform: uppercase; }
.cal-day-header.active { background: #64748b; color: white; }

.cal-slot { border-bottom: 1px solid #f1f5f9; box-sizing: border-box; }
.cal-slot.hour-line { border-bottom: 1px solid var(--border); }
.cal-slot.off-hours { background: #e9e9e9; }

/* Event Blocks */
.cal-event {
  position: absolute;
  left: 2px; right: 2px;
  background: #c2d5b6; /* Greenish Practo color */
  border-left: 4px solid #5a6e2a;
  padding: 4px 6px;
  font-size: 11px;
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.cal-event.completed { background: #e2e8f0; border-left-color: #94a3b8; text-decoration: line-through; opacity: 0.7; }
.cal-event-title { font-weight: 600; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Right Sidebar (Agenda) */
.cal-sidebar-right {
  width: 320px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg2);
}
.cal-agenda-header { padding: 16px; border-bottom: 1px solid var(--border); }
.cal-stats { display: flex; justify-content: space-between; margin: 16px 0; text-align: center; }
.cal-stat-box { font-size: 10px; font-weight: 600; color: var(--text2); }
.cal-stat-num { display: inline-block; padding: 2px 10px; border-radius: 4px; color: white; font-size: 12px; margin-top: 4px; }
.cal-agenda-list { flex: 1; overflow-y: auto; }
.cal-agenda-item { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; }
.cal-agenda-time { font-size: 12px; font-weight: 600; color: var(--text2); min-width: 45px; }
.cal-agenda-details h4 { font-size: 13px; font-weight: 600; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; }
.cal-agenda-details p { font-size: 11px; color: var(--text3); margin: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.Scheduled { background: var(--primary); }
.status-dot.Completed { background: var(--success); }
.status-dot.Cancelled { background: var(--danger); }



/* ============================================================
   CALENDAR POPOVER MODULE
   ============================================================ */
.cal-popover {
  position: absolute; /* Changed from fixed for better scrolling support */
  width: 320px;
  background: var(--bg2);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  z-index: 9999;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.cal-popover-actions { text-align: right; padding: 12px 16px 4px; color: var(--text3); font-size: 14px; }
.cal-popover-actions i { margin-left: 12px; cursor: pointer; transition: color 0.2s; }
.cal-popover-actions i:hover { color: var(--primary); }
.cal-popover-actions .fa-times-circle:hover { color: var(--danger); }
.cal-popover-header { display: flex; gap: 14px; padding: 0 16px 16px; border-bottom: 1px solid var(--border); }
.cal-popover-avatar {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 50%; border: 1.5px solid var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-weight: 600; font-size: 16px;
}
.cal-popover-info h4 { margin: 0 0 4px 0; font-size: 15px; font-weight: 700; color: var(--text); }
.cal-popover-info p { margin: 0 0 2px 0; font-size: 12px; color: var(--text2); }
.cal-popover-body { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cal-popover-row { display: flex; gap: 12px; margin-bottom: 8px; align-items: center; font-size: 12px; color: var(--text2); }
.cal-popover-row i { color: var(--text3); width: 14px; text-align: center; }
.cal-popover-appt {
  background: var(--bg); padding: 12px; border-radius: 6px; margin-top: 16px;
  display: flex; justify-content: space-between; align-items: flex-start;
  border: 1px solid var(--border);
}
.cal-popover-appt-details { font-size: 11px; color: var(--text2); line-height: 1.5; padding-left: 26px; }
.cal-popover-appt-details strong { color: var(--text); font-size: 12px; }
.cal-popover-med-history { padding: 12px 16px; }
.cal-popover-med-history h5 { margin: 0 0 6px 0; font-size: 12px; font-weight: 700; color: var(--text); }
.cal-popover-med-history p { margin: 0; font-size: 12px; color: var(--text2); }
.cal-popover-footer { 
  background: #0ea5e9; color: white; padding: 12px 16px; 
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.cal-popover-footer button { 
  background: #f59e0b; color: white; border: none; padding: 6px 12px; 
  border-radius: 4px; font-size: 12px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.cal-popover-footer button:hover { background: #d97706; }




/* ============================================================
   ADVANCED PATIENT REGISTRATION & WEBCAM
   ============================================================ */
.modal-box.xl { max-width: 1100px; }

.reg-layout { display: grid; grid-template-columns: 180px 1fr 320px; gap: 24px; }

/* Photo Box */
.reg-photo-col { display: flex; flex-direction: column; gap: 12px; }
.photo-preview-box {
  width: 180px; height: 180px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.photo-preview-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview-box i { font-size: 64px; color: var(--border2); }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Form Sections */
.reg-section-title { font-size: 14px; font-weight: 700; color: var(--text); padding-bottom: 8px; border-bottom: 1px solid var(--border); margin: 20px 0 12px 0; }
.reg-section-title:first-child { margin-top: 0; }
.form-row { display: grid; grid-template-columns: 140px 1fr; align-items: center; margin-bottom: 10px; gap: 12px; }
.form-row label { text-align: right; font-size: 12px; color: var(--text2); font-weight: 500; }
.form-row .multi-input { display: flex; gap: 8px; align-items: center; }

/* Checkbox Lists */
.checkbox-list { border: 1px solid var(--border); height: 200px; overflow-y: auto; padding: 8px; border-radius: 4px; background: var(--bg2); }
.checkbox-item { display: flex; align-items: center; gap: 8px; padding: 6px; font-size: 13px; color: var(--text); border-bottom: 1px solid var(--bg); }
.checkbox-item:last-child { border-bottom: none; }
.checkbox-item input { margin: 0; cursor: pointer; }

/* Webcam Overlay */
.webcam-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 10000; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px; }
.webcam-container { width: 400px; height: 300px; background: #000; border-radius: 8px; overflow: hidden; border: 2px solid white; }
.webcam-container video { width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 900px) {
  .reg-layout { grid-template-columns: 1fr; }
  .reg-photo-col { align-items: center; }
  .form-row { grid-template-columns: 1fr; }
  .form-row label { text-align: left; }
}




/* ============================================================
   PATIENT GRID VIEW
   ============================================================ */
.patient-grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding: 20px;
  background: var(--bg2);
}
.patient-grid-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  position: relative;
  transition: box-shadow 0.2s;
}
.patient-grid-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.pg-photo {
  width: 90px;
  height: 110px;
  flex-shrink: 0;
  background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.pg-photo img {
  width: 100%; height: 100%; object-fit: cover;
}
.pg-photo i {
  font-size: 32px; color: var(--border2);
}
.pg-info {
  padding: 12px 16px;
  display: flex; flex-direction: column; justify-content: center;
  flex: 1; min-width: 0; cursor: pointer;
}
.pg-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pg-detail {
  font-size: 12px; color: var(--text2); margin-top: 2px;
}
.pg-id {
  font-size: 12px; color: var(--text2); margin-top: 4px; font-weight: 500;
}
.pg-actions {
  position: absolute;
  top: 8px; right: 8px;
  display: flex; gap: 4px;
  opacity: 0; transition: opacity 0.2s;
}
.patient-grid-card:hover .pg-actions {
  opacity: 1;
}
.btn-icon-sm {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text2); width: 26px; height: 26px;
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; cursor: pointer; transition: 0.2s;
}
.btn-icon-sm:hover {
  background: var(--primary); color: white; border-color: var(--primary);
}



/* ============================================================
   FULL SCREEN PHOTO VIEWER & AVATAR HOVER
   ============================================================ */
.profile-avatar {
  position: relative; /* Required for the overlay to sit correctly */
}
.profile-avatar-overlay {
  position: absolute; inset: 0; 
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 20px; 
  opacity: 0; transition: opacity 0.2s; 
  cursor: pointer; border-radius: 50%;
}
.profile-avatar:hover .profile-avatar-overlay { opacity: 1; }

.photo-viewer-overlay {
  position: fixed; inset: 0; 
  background: rgba(15, 23, 42, 0.95); /* Deep slate background */
  backdrop-filter: blur(5px);
  z-index: 10000; 
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.3s ease;
}
.photo-viewer-overlay.show { opacity: 1; }
.photo-viewer-img { 
  max-width: 90vw; max-height: 85vh; 
  border-radius: 8px; 
  box-shadow: 0 25px 50px rgba(0,0,0,0.5); 
  object-fit: contain; 
  transform: scale(0.95); transition: transform 0.3s ease;
}
.photo-viewer-overlay.show .photo-viewer-img { transform: scale(1); }
.photo-viewer-close { 
  position: absolute; top: 24px; right: 32px; 
  color: rgba(255,255,255,0.7); font-size: 32px; 
  cursor: pointer; transition: 0.2s; 
}
.photo-viewer-close:hover { color: white; transform: scale(1.1); }








/* ============================================================
   PATIENTS SIDEBAR & LAYOUT
   ============================================================ */
.patients-layout { 
  display: flex; gap: 24px; align-items: flex-start; 
}
.patients-sidebar {
  width: 250px; flex-shrink: 0;
  /* Transparent background to match the image, no borders */
}
.patients-main { 
  flex: 1; min-width: 0; 
}
.ps-section { 
  margin-bottom: 30px; 
}
.ps-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
/* The thin green text from the screenshot */
.ps-header h4 { 
  font-size: 22px; font-weight: 300; color: #65a30d; margin: 0; 
} 
.ps-header a { 
  font-size: 11px; color: var(--secondary); text-decoration: none; font-weight: 500; 
}
.ps-header a:hover { text-decoration: underline; }

.ps-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; cursor: pointer; border-radius: 6px;
  font-size: 13px; color: var(--text); margin-bottom: 2px;
  transition: all 0.2s;
}
.ps-item:hover { 
  background: rgba(14, 165, 233, 0.1); 
}
.ps-item.active { 
  background: #0ea5e9; color: white; font-weight: 500; 
}
.ps-badge {
  background: #94a3b8; color: white; font-size: 11px;
  padding: 2px 10px; border-radius: 12px; font-weight: 600;
}
.ps-item.active .ps-badge { 
  background: rgba(255,255,255,0.3); color: white; 
}

@media (max-width: 900px) {
  .patients-layout { flex-direction: column; }
  .patients-sidebar { width: 100%; }
}


/* Update this in style.css */
.patients-layout { 
  display: flex; gap: 24px; align-items: stretch; /* 'stretch' ensures equal height columns */
  width: 100%;
}
.patients-sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--bg2); /* Added background to match the card look */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.patients-main { flex: 1; min-width: 0; }




/* ============================================================
   PATIENT PROFILE - VITALS, NOTES, AND FILES
   ============================================================ */

/* --- Vital Signs Grid --- */
.vitals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.vital-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--card-shadow);
}
.vital-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.vital-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
/* Specific Icon Colors */
.vital-icon.temp { background: rgba(234, 88, 12, 0.1); color: #ea580c; }
.vital-icon.hr { background: rgba(225, 29, 72, 0.1); color: #e11d48; }
.vital-icon.bp { background: rgba(37, 99, 235, 0.1); color: #2563eb; }
.vital-icon.resp { background: rgba(22, 163, 74, 0.1); color: #16a34a; }
/* NEW VITAL ICONS */
.vital-icon.spo2 { background: rgba(14, 165, 233, 0.1); color: #0ea5e9; } 
.vital-icon.weight { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; } 
.vital-icon.height { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }

.vital-title {
  font-size: 13px;
  color: var(--text2);
  font-weight: 500;
}
.vital-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}
.vital-value span {
  font-size: 14px;
  font-weight: 500;
  color: var(--text3);
  margin-left: 4px;
}
.vital-time {
  font-size: 11px;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- Clinical Notes --- */
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.section-header-row h4 {
  font-size: 16px;
  color: var(--text);
  margin: 0;
}
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}
.note-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 16px;
}
.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text3);
}
.note-author {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.note-author i {
  color: var(--primary);
}
.note-content {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.6;
  margin: 0;
}

/* --- Files Area --- */
.file-upload-zone {
  border: 2px dashed var(--border2);
  border-radius: 12px;
  padding: 32px 16px;
  text-align: center;
  background: var(--bg3);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 16px;
}
.file-upload-zone:hover {
  border-color: var(--primary);
  background: var(--primary-fade);
}
.file-upload-icon {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 12px;
}
.file-upload-text {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.file-upload-subtext {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
}
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.file-info {
  display: flex;
  align-items: center;
  gap: 16px;
}
.file-icon {
  font-size: 24px;
}
.file-icon.pdf { color: #ef4444; }
.file-icon.img { color: #0ea5e9; }
.file-details h5 {
  font-size: 14px;
  color: var(--text);
  margin: 0 0 4px 0;
  font-weight: 500;
}
.file-details p {
  font-size: 11px;
  color: var(--text3);
  margin: 0;
}
.file-actions button {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: all 0.2s;
}
.file-actions button:hover {
  color: var(--primary);
  background: var(--primary-fade);
}


/* ============================================================
   APPOINTMENTS TABLE & STATUS BADGES
   ============================================================ */

/* --- Status Badges --- */
.status-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: capitalize;
}
.status-badge.consulted {
  background: rgba(16, 185, 129, 0.1); /* Light green */
  color: var(--success); /* #10b981 */
}
.status-badge.cancelled {
  background: rgba(239, 68, 68, 0.1); /* Light red */
  color: var(--danger); /* #ef4444 */
}
.status-badge.upcoming {
  background: rgba(37, 99, 235, 0.1); /* Light blue */
  color: var(--primary); /* #2563eb */
}

/* --- Table Specifics --- */
.table-subtext {
  font-size: 12px;
  color: var(--text3);
  display: block;
  margin-top: 2px;
}
.patient-name-bold {
  font-weight: 600;
  color: var(--text);
}

/* --- Action Buttons --- */
.action-group {
  display: flex;
  gap: 8px;
}
.action-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: all 0.2s ease;
  font-size: 15px;
}
.action-btn:hover:not(:disabled) {
  background: var(--bg3);
}
.action-btn.edit:hover:not(:disabled) { color: var(--primary); }
.action-btn.check:hover:not(:disabled) { color: var(--success); }
.action-btn.delete:hover:not(:disabled) { color: var(--danger); }

.action-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* --- Pill Tabs (if not already styled) --- */
.pill-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.pill-tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.pill-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.pill-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}


/* =========================================
   SIDEBAR TOGGLE BUTTON FIX
   ========================================= */
/* 1. Force the icon to be a light color so it's visible on the dark sidebar */
.sidebar-header button {
  color: rgba(255, 255, 255, 0.6) !important;
  transition: color 0.2s ease;
}

.sidebar-header button:hover {
  color: #ffffff !important;
}

/* 2. Ensure perfect centering when the sidebar collapses */
body.sidebar-collapsed .sidebar-header button {
  margin: 0;
  padding: 8px 0;
  display: flex;
  justify-content: center;
  width: 100%;
}
/* ── Month View ───────────────────────────────────────────── */
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: auto;
  grid-auto-rows: minmax(105px, 1fr);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.cal-month-headcell {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.cal-month-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0 4px 4px;
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  min-height: 105px;
}
.cal-month-cell.other-month { background: var(--bg3); }
.cal-month-cell.other-month .cal-month-datenum { color: var(--text3); }
.cal-month-cell.is-today { background: #fff2df; }
.cal-month-cell.is-today .cal-month-datenum { color: #b45309; font-weight: 700; }

.cal-month-datenum {
  text-align: right;
  font-size: 12px;
  color: var(--text2);
  padding: 4px 4px 4px;
}

.cal-month-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.cal-month-event {
  background: #c2d5b6;
  border-left: 4px solid #5a6e2a;
  border-radius: 2px;
  padding: 2px 6px;
  font-size: 12px;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.cal-month-event.inactive {
  background: #e0e0e0;
  border-left-color: #9ca3af;
  color: #6b7280;
  text-decoration: line-through;
}
.cal-month-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  background: #16a34a;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 2px;
  margin-right: 4px;
  text-decoration: none;
  vertical-align: middle;
}
.cal-month-more {
  font-size: 11px;
  color: #7598ab;
  text-align: right;
  padding: 2px 6px;
  cursor: pointer;
}
.cal-month-more:hover { text-decoration: underline; }

/* ============================================================
   MOBILE RESPONSIVENESS (≤768px) — Calendar, Charts, Profile, Tabs
   ============================================================ */
@media (max-width: 768px) {
  /* Charts: allow narrower cards and shorter canvases */
  .charts-grid { grid-template-columns: 1fr; gap: 16px; }
  .chart-body { padding: 12px; }
  .chart-body canvas, canvas { max-height: 200px !important; }

  /* Generic grids collapse to single column */
  .grid-2, .grid-3, .form-grid-2 { grid-template-columns: 1fr; }
  .vitals-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  /* Calendar: stack the three panels vertically */
  .cal-container {
    flex-direction: column;
    height: auto;
    max-height: none;
  }
  .cal-sidebar-left {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 160px;
  }
  .cal-doc-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    flex: none;
  }
  .cal-doc-item {
    flex-shrink: 0;
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }
  .cal-doc-item.active { border-left-color: transparent; border-bottom-color: var(--primary); }
  .cal-sidebar-header { padding: 12px; }

  .cal-main { min-width: 0; }
  .cal-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 12px;
  }
  .cal-controls { justify-content: space-between; }
  .cal-nav-group { flex: 1; justify-content: center; }
  .cal-date-range { min-width: 100px; font-size: 13px; }
  .cal-view-toggles { flex: 1; }
  .cal-view-btn { flex: 1; padding: 7px 4px; font-size: 12px; }

  /* Day/Week grid: allow horizontal scroll, keep readable column widths */
  .cal-grid-wrapper { overflow-x: auto; }
  .cal-grid { min-width: 640px; }
  .cal-time-col { width: 56px; }
  .cal-day-col { min-width: 90px; }

  /* Month view: shrink cell heights & font sizes for small screens */
  .cal-month-grid { grid-auto-rows: minmax(80px, auto); }
  .cal-month-cell { min-height: 80px; }
  .cal-month-event { font-size: 11px; padding: 1px 4px; }
  .cal-month-headcell { padding: 4px 4px; font-size: 10px; }
  .cal-month-datenum { font-size: 11px; }

  .cal-sidebar-right {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 360px;
  }
  .cal-stats { flex-wrap: wrap; gap: 8px; }
  .cal-stat-box { flex: 1 1 40%; }

  /* Patient profile modal */
  .profile-header { flex-direction: column; text-align: center; padding: 16px; gap: 12px; }
  .profile-tags { justify-content: center; }
  .profile-info h2 { font-size: 18px; }

  .tabs { gap: 4px; }
  .tab-btn { padding: 8px 12px; font-size: 13px; }

  .section-header-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .section-header-row .btn { width: 100%; justify-content: center; }

  /* Patient grid cards */
  .patient-grid-container { grid-template-columns: 1fr; padding: 12px; gap: 12px; }

  /* Resources tab */
  .resources-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}

@media (max-width: 480px) {
  .vitals-grid { grid-template-columns: 1fr; }
  .cal-stat-box { flex: 1 1 100%; }
  .resources-grid { grid-template-columns: 1fr; }
  .modal-box.lg { max-width: 100%; }
  .cal-time-col { width: 48px; }
  .cal-time-label { font-size: 10px; }
}

/* ============================================================
   RESOURCES TAB
   ============================================================ */
.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.res-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  transition: box-shadow 0.2s, transform 0.2s;
  display: flex;
  flex-direction: column;
}
.res-card:hover { box-shadow: var(--card-shadow-hover); transform: translateY(-2px); }

/* Preview area */
.res-preview {
  height: 180px;
  overflow: hidden;
  background: #f1f5f9;
  position: relative;
}
.dark-mode .res-preview { background: #1e293b; }
.res-preview img {
  width: 100%; height: 100%; object-fit: cover;
  display: block; cursor: pointer;
  transition: transform 0.2s;
}
.res-preview img:hover { transform: scale(1.04); }
.res-preview-icon-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; cursor: pointer; gap: 8px;
}
.res-preview-icon { font-size: 48px; opacity: 0.5; }
.res-preview-label { font-size: 12px; color: var(--text2); font-weight: 500; }

/* Card body */
.res-card-body { padding: 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.res-type-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
  width: fit-content;
}
.res-title { font-size: 14px; font-weight: 700; color: var(--text); margin: 2px 0; line-height: 1.4; }
.res-desc { font-size: 12px; color: var(--text2); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.res-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: auto; padding-top: 8px;
  border-top: 1px solid var(--border);
}
.res-date { font-size: 11px; color: var(--text3); }
.res-actions { display: flex; gap: 6px; }
.res-actions button {
  width: 30px; height: 30px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); cursor: pointer; color: var(--text2); font-size: 13px;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.res-actions button:hover { background: var(--bg3); color: var(--primary); }
.res-actions button.danger:hover { background: #fee2e2; color: var(--danger); border-color: var(--danger); }

/* ============================================================
   COMPREHENSIVE MOBILE RESPONSIVE FIX v2
   Covers: charts, tables, tabs, page-header, resources,
           appointments, billing, patients, calendar
   ============================================================ */

/* ── Global: prevent any element creating horizontal scroll ── */
.page-content { overflow-x: hidden; }

/* ── Page header: wrap on mobile so button stays accessible ── */
.page-header {
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}
.page-header > div { min-width: 0; }

/* ── Charts: fix minmax overflow on narrow viewports ── */
.charts-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr));
}
.chart-body { position: relative; min-height: 0; }
.chart-body canvas { display: block; width: 100% !important; }

/* ── Tables: always allow horizontal scroll on any viewport ── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0 0 var(--radius) var(--radius);
}
.data-table { min-width: 480px; }
.data-table thead th { white-space: nowrap; }

/* ── Tabs: scroll horizontally instead of overflowing ── */
.tabs {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap !important;
  padding-bottom: 0;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { flex-shrink: 0; }

/* ── Resources: video play-overlay card design ── */
.res-preview { position: relative; }
.res-video-thumb {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 10px;
  cursor: pointer;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}
.res-video-play {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #ef4444;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}
.res-video-thumb:hover .res-video-play { transform: scale(1.1); box-shadow: 0 6px 28px rgba(0,0,0,0.5); }
.res-video-label { color: rgba(255,255,255,0.8); font-size: 12px; font-weight: 500; }

/* Video modal responsive */
.res-video-modal { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: 8px; background: #000; }
.res-video-modal iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; }

/* Photo preview with a soft gradient overlay */
.res-preview-img { overflow: hidden; }
.res-preview-img img { transition: transform 0.3s ease; }
.res-preview-img:hover img { transform: scale(1.05); }

/* 3D model preview */
.res-3d-thumb {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; cursor: pointer;
  background: linear-gradient(135deg, #0f0c29, #302b63);
}
.res-3d-icon { font-size: 44px; color: rgba(167, 139, 250, 0.8); }
.res-3d-label { color: rgba(255,255,255,0.7); font-size: 12px; font-weight: 500; }

/* Doc preview */
.res-doc-thumb {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; cursor: pointer;
  background: linear-gradient(135deg, #fff8ee, #ffecd2);
}
.dark-mode .res-doc-thumb { background: linear-gradient(135deg, #2d2008, #3d2e0a); }
.res-doc-icon { font-size: 44px; color: #f59e0b; }
.res-doc-label { color: #92400e; font-size: 12px; font-weight: 500; }
.dark-mode .res-doc-label { color: #fcd34d; }

@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  /* Hide less-critical columns in appointment table on mobile */
  .appt-col-type, .appt-col-actions-header { display: none; }
  .appt-col-type-cell { display: none; }

  /* Stat cards: 2 across */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 12px; gap: 12px; }
  .stat-icon { width: 42px; height: 42px; font-size: 18px; border-radius: 10px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 11px; }

  /* Charts */
  .charts-grid { grid-template-columns: 1fr; gap: 14px; }
  .chart-body { padding: 10px; }
  canvas { max-height: 180px !important; }

  /* Tables */
  .data-table { font-size: 12px; }
  .data-table thead th { padding: 8px 10px; font-size: 11px; }
  .data-table tbody td { padding: 10px; }

  /* Resources */
  .resources-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .res-preview { height: 140px; }
  .res-card-body { padding: 10px; gap: 4px; }
  .res-title { font-size: 13px; }
  .res-video-play { width: 44px; height: 44px; font-size: 18px; }

  /* Page header */
  .page-header { gap: 8px; }
  .page-header h2 { font-size: 18px; }
  .page-header .btn { white-space: nowrap; }

  /* Form actions */
  .table-actions { flex-direction: column; gap: 8px; }
  .table-actions > * { width: 100%; }
  .search-box { max-width: 100%; }
  .filter-row { flex-direction: column; gap: 8px; }
  .filter-row > * { width: 100%; }

  /* Grid adjustments */
  .grid-2, .grid-3, .form-grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  /* Cards on mobile */
  .card { border-radius: 8px; }

  /* Dashboard bottom grid */
  #dashBottom { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px 10px; gap: 10px; }
  .stat-icon { width: 36px; height: 36px; font-size: 16px; }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 10px; }

  canvas { max-height: 160px !important; }

  .resources-grid { grid-template-columns: 1fr; }
  .res-preview { height: 160px; }

  .modal-box, .modal-box.lg, .modal-box.sm { max-width: calc(100vw - 16px); margin: 8px; border-radius: 12px; }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }

  .page-content { padding: 12px; }
  .topbar { padding: 0 12px; }
  .topbar-date { display: none; }

  .tab-btn { padding: 8px 10px; font-size: 12px; }

  .vitals-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Responsive column hiders ── */
@media (max-width: 600px) {
  .hide-xs { display: none !important; }
  .hide-xs.th, th.hide-xs { display: none !important; }
  .data-table { min-width: 260px; }
}
@media (max-width: 480px) {
  .hide-sm { display: none !important; }
}

/* ── Dashboard bottom 2-up grid ── */
.dash-bottom { gap: 20px; }
@media (max-width: 900px) {
  .dash-bottom { grid-template-columns: 1fr !important; }
}

/* ── Fix canvas in chart-body ── */
.chart-body { position: relative; }
.chart-body canvas { position: absolute; top: 0; left: 0; width: 100% !important; height: 100% !important; }

/* ── Mobile sidebar backdrop ───────────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199; /* below sidebar (200) but above everything else */
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
@media (max-width: 768px) {
  .sidebar-backdrop { display: block; }
  .sidebar-backdrop.active { opacity: 1; pointer-events: auto; }

  /* Sidebar slide transition */
  .sidebar {
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  /* Ensure sidebar-header shows brand + close button on mobile */
  .sidebar-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
  }
  .sidebar-close {
    display: flex !important;
    align-items: center; justify-content: center;
    background: none; border: none;
    color: rgba(255,255,255,0.6);
    font-size: 18px; cursor: pointer;
    width: 32px; height: 32px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
  }
  .sidebar-close:hover { background: rgba(255,255,255,0.1); color: #fff; }

  /* On mobile: disable desktop-collapse styles entirely */
  body.sidebar-collapsed .sidebar { width: 260px !important; min-width: 260px !important; transform: translateX(-100%); }
  body.sidebar-collapsed .sidebar.open { transform: translateX(0); }
  body.sidebar-collapsed .main-content { margin-left: 0 !important; width: 100% !important; }
  body.sidebar-collapsed .sidebar span,
  body.sidebar-collapsed .nav-section-title,
  body.sidebar-collapsed .user-info { display: revert !important; }
  body.sidebar-collapsed .sidebar-header { flex-direction: row !important; padding: 16px !important; }
  body.sidebar-collapsed .nav-item { justify-content: flex-start !important; padding: 10px 20px !important; }
  body.sidebar-collapsed .nav-badge { display: flex !important; }
}



/* =========================================
   RESOURCE GRID THUMBNAIL FIX
   ========================================= */
.res-preview {
  width: 100%;
  height: 180px !important; /* Forces perfect uniformity */
  background-size: cover !important;
  background-position: center !important;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}

.res-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}