/* ===========================
   BioGuard - Main Stylesheet
   Premium Health Management System
   =========================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800;900&family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Primary Palette */
  --primary: #0a84ff;
  --primary-dark: #0066cc;
  --primary-light: #4da6ff;
  --primary-glow: rgba(10, 132, 255, 0.3);

  /* Accent Colors */
  --accent-cyan: #00d4ff;
  --accent-purple: #7b5ea7;
  --accent-teal: #00b4a0;

  /* Status Colors */
  --success: #30d158;
  --success-dark: #25a244;
  --success-bg: rgba(48, 209, 88, 0.1);
  --warning: #ff9f0a;
  --warning-dark: #cc7a00;
  --warning-bg: rgba(255, 159, 10, 0.1);
  --danger: #ff3b30;
  --danger-dark: #cc2c22;
  --danger-bg: rgba(255, 59, 48, 0.1);
  --info: #64d2ff;
  --info-bg: rgba(100, 210, 255, 0.1);

  /* Dark Theme (Default) */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-card: #1c2128;
  --bg-card-hover: #22272e;
  --bg-sidebar: #0d1117;
  --bg-nav: rgba(13, 17, 23, 0.95);
  --bg-modal: #1c2128;
  --bg-input: #1c2128;
  --bg-glass: rgba(255, 255, 255, 0.05);
  --bg-glass-hover: rgba(255, 255, 255, 0.08);

  /* Text Colors */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --text-link: #58a6ff;

  /* Border Colors */
  --border-primary: #30363d;
  --border-secondary: #21262d;
  --border-accent: rgba(10, 132, 255, 0.4);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(10, 132, 255, 0.3);
  --shadow-danger: 0 0 20px rgba(255, 59, 48, 0.3);
  --shadow-success: 0 0 20px rgba(48, 209, 88, 0.3);

  /* Layout */
  --sidebar-width: 260px;
  --topnav-height: 64px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;
  --border-radius-xl: 24px;

  /* Transitions */
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s ease;
  --transition-slow: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme */
[data-theme="light"] {
  --bg-primary: #f0f4f8;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-sidebar: #1e293b;
  --bg-nav: rgba(255, 255, 255, 0.95);
  --bg-modal: #ffffff;
  --bg-input: #f0f4f8;
  --bg-glass: rgba(255, 255, 255, 0.8);
  --bg-glass-hover: rgba(255, 255, 255, 0.95);
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-link: #0a84ff;
  --border-primary: #e2e8f0;
  --border-secondary: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.15);
}

/* ===========================
   RESET & BASE
   =========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  direction: rtl;
  scroll-behavior: smooth;
}

body {
  font-family: 'Cairo', 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
}

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

/* ===========================
   LAYOUT - APP SHELL
   =========================== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ===========================
   SIDEBAR
   =========================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-secondary);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  z-index: 100;
  transition: var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.sidebar-logo img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.sidebar-logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
}

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 12px 12px 6px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--border-radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
  position: relative;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: right;
}

.sidebar-item:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: rgba(10, 132, 255, 0.15);
  color: var(--primary-light);
  border: 1px solid rgba(10, 132, 255, 0.2);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--primary);
  border-radius: 2px;
}

.sidebar-item .icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  background: var(--bg-glass);
  flex-shrink: 0;
  transition: var(--transition);
}

.sidebar-item.active .icon,
.sidebar-item:hover .icon {
  background: rgba(10, 132, 255, 0.2);
  color: var(--primary-light);
}

.sidebar-item .badge-count {
  margin-right: auto;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border-secondary);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-user:hover { background: var(--bg-glass); }

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; }
.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
}
.sidebar-user-role {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ===========================
   MAIN CONTENT
   =========================== */
.main-content {
  flex: 1;
  margin-right: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===========================
   TOP NAVIGATION
   =========================== */
.top-nav {
  height: var(--topnav-height);
  background: var(--bg-nav);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-secondary);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 16px;
}

.top-nav-title {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.top-nav-breadcrumb {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.top-nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-primary);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
  position: relative;
  text-decoration: none;
}

.nav-btn:hover {
  background: var(--bg-glass-hover);
  color: var(--primary);
  border-color: var(--primary);
}

.nav-btn .badge {
  position: absolute;
  top: -4px;
  left: -4px;
  width: 16px;
  height: 16px;
  background: var(--danger);
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-divider {
  width: 1px;
  height: 24px;
  background: var(--border-primary);
}

.nav-patient-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.nav-patient-info .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
}

/* ===========================
   PAGE CONTENT
   =========================== */
.page-content {
  flex: 1;
  padding: 24px;
  animation: fadeInUp 0.4s ease;
}

/* ===========================
   CARDS
   =========================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  transition: var(--transition);
  overflow: hidden;
}

.card:hover {
  border-color: var(--border-accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.card-body {
  padding: 20px;
}

.card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

/* Stat Cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  padding: 20px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.stat-card.primary::before { background: var(--primary); }
.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.purple::before { background: var(--accent-purple); }
.stat-card.cyan::before { background: var(--accent-cyan); }

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-accent);
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-unit {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 400;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-change {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  display: inline-block;
  margin-top: 6px;
}

.stat-change.up { background: var(--success-bg); color: var(--success); }
.stat-change.down { background: var(--danger-bg); color: var(--danger); }
.stat-change.neutral { background: var(--info-bg); color: var(--info); }

/* ===========================
   STATUS BADGES
   =========================== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.critical {
  background: var(--danger-bg);
  color: var(--danger);
}
.status-badge.critical::before { background: var(--danger); animation: pulse-dot 1s infinite; }

.status-badge.warning {
  background: var(--warning-bg);
  color: var(--warning);
}
.status-badge.warning::before { background: var(--warning); }

.status-badge.stable {
  background: var(--success-bg);
  color: var(--success);
}
.status-badge.stable::before { background: var(--success); }

.status-badge.info {
  background: var(--info-bg);
  color: var(--info);
}
.status-badge.info::before { background: var(--info); }

/* ===========================
   BUTTONS
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--border-radius-sm);
  border: none;
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(10, 132, 255, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), var(--success-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(48, 209, 88, 0.3);
}
.btn-success:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(48, 209, 88, 0.4); }

.btn-danger {
  background: linear-gradient(135deg, var(--danger), var(--danger-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(255, 59, 48, 0.3);
}
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255, 59, 48, 0.4); }

.btn-warning {
  background: linear-gradient(135deg, var(--warning), var(--warning-dark));
  color: white;
}
.btn-warning:hover { transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}
.btn-outline:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
  border-color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
}
.btn-ghost:hover { background: var(--bg-glass); color: var(--primary); }

.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-lg { padding: 12px 24px; font-size: 0.95rem; }
.btn-icon { padding: 8px; min-width: 36px; height: 36px; }
.btn-icon-sm { padding: 5px; min-width: 28px; height: 28px; font-size: 0.78rem; }

/* ===========================
   FORM CONTROLS
   =========================== */
.form-control, .form-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-family: 'Cairo', sans-serif;
  font-size: 0.875rem;
  transition: var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
  background: var(--bg-secondary);
}

.form-control::placeholder { color: var(--text-muted); }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group { margin-bottom: 16px; }

/* ===========================
   MODALS
   =========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-box {
  background: var(--bg-modal);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9) translateY(20px);
  transition: var(--transition);
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal-box {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-primary);
  background: var(--bg-glass);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
}
.modal-close:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-secondary);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===========================
   ALERT TOASTS
   =========================== */
.toast-container {
  position: fixed;
  top: 80px;
  left: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  animation: slideInLeft 0.3s ease;
  transition: var(--transition);
}

.toast.removing { animation: slideOutLeft 0.3s ease forwards; }

.toast-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.9rem;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.success .toast-icon { background: var(--success-bg); color: var(--success); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.warning .toast-icon { background: var(--warning-bg); color: var(--warning); }
.toast.danger { border-left: 3px solid var(--danger); }
.toast.danger .toast-icon { background: var(--danger-bg); color: var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
.toast.info .toast-icon { background: var(--info-bg); color: var(--info); }

.toast-content { flex: 1; }
.toast-title { font-size: 0.85rem; font-weight: 700; color: var(--text-primary); margin-bottom: 2px; }
.toast-message { font-size: 0.78rem; color: var(--text-secondary); }

/* ===========================
   PROGRESS BARS
   =========================== */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border-secondary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-fill.primary { background: linear-gradient(90deg, var(--primary), var(--accent-cyan)); }
.progress-fill.success { background: linear-gradient(90deg, var(--success), var(--accent-teal)); }
.progress-fill.warning { background: linear-gradient(90deg, var(--warning), #ffcc00); }
.progress-fill.danger { background: linear-gradient(90deg, var(--danger), #ff6b6b); }

/* ===========================
   TABLES
   =========================== */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table th {
  padding: 10px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-secondary);
  text-align: right;
}

.data-table td {
  padding: 12px 14px;
  font-size: 0.85rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-secondary);
  transition: var(--transition);
}

.data-table tr:hover td { background: var(--bg-glass); }
.data-table tr:last-child td { border-bottom: none; }

/* ===========================
   VITAL SIGN WIDGET
   =========================== */
.vital-widget {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.vital-widget:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-md);
}

.vital-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.vital-value {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text-primary);
}

.vital-unit {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 2px;
}

.vital-trend {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  opacity: 0.3;
}

/* ===========================
   LIVE INDICATOR
   =========================== */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  background: rgba(48, 209, 88, 0.1);
  border: 1px solid rgba(48, 209, 88, 0.3);
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--success);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-dot 1s infinite;
}

/* ===========================
   GRID LAYOUTS
   =========================== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }

.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

/* ===========================
   CHART AREA (Canvas)
   =========================== */
.chart-container {
  position: relative;
  width: 100%;
}

/* ===========================
   MINI SPARKLINE SVG
   =========================== */
.sparkline {
  width: 100%;
  height: 40px;
}

/* ===========================
   PULSE RING
   =========================== */
.pulse-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pulse-ring::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  animation: ring-pulse 2s infinite;
}

/* ===========================
   FAMILY MEMBER CARD
   =========================== */
.family-card {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  padding: 20px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.family-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.family-card.stable::after { background: var(--success); }
.family-card.warning::after { background: var(--warning); }
.family-card.critical::after { background: var(--danger); }

.family-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-accent);
}

.family-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: white;
  margin: 0 auto 12px;
  position: relative;
}

.family-avatar.male { background: linear-gradient(135deg, var(--primary), var(--accent-cyan)); }
.family-avatar.female { background: linear-gradient(135deg, #ff6eb4, #ff8e53); }
.family-avatar.child { background: linear-gradient(135deg, var(--accent-purple), #9f7aea); }

.family-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 4px;
}

.family-relation {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 12px;
}

.family-vitals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.family-vital-item {
  background: var(--bg-glass);
  border-radius: var(--border-radius-sm);
  padding: 8px;
  text-align: center;
}

.family-vital-val {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.family-vital-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===========================
   MEDICINE CARD
   =========================== */
.medicine-card {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  position: relative;
}

.medicine-card:hover {
  border-color: var(--border-accent);
  transform: translateX(-2px);
  box-shadow: var(--shadow-md);
}

.medicine-card .med-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(10, 132, 255, 0.1);
  border: 1px solid rgba(10, 132, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--primary);
  flex-shrink: 0;
}

.medicine-info { flex: 1; }
.medicine-name { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); }
.medicine-dose { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.medicine-times { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

.medicine-stock {
  text-align: center;
  min-width: 60px;
}
.medicine-stock-val {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
}
.medicine-stock-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ===========================
   SCHEDULE ITEM
   =========================== */
.schedule-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-glass);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius-sm);
  margin-bottom: 8px;
  transition: var(--transition);
}

.schedule-item:hover { border-color: var(--border-accent); }

.schedule-item.taken {
  opacity: 0.5;
  text-decoration: line-through;
}

.schedule-time {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 55px;
}

.schedule-name { flex: 1; font-size: 0.85rem; color: var(--text-primary); }
.schedule-dose { font-size: 0.75rem; color: var(--text-muted); }

/* ===========================
   ALERT ITEM
   =========================== */
.alert-item {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.alert-item::before {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.alert-item.critical::before { background: var(--danger); }
.alert-item.warning::before { background: var(--warning); }
.alert-item.info::before { background: var(--info); }
.alert-item.success::before { background: var(--success); }

.alert-item.critical { background: rgba(255, 59, 48, 0.05); }
.alert-item.warning { background: rgba(255, 159, 10, 0.05); }

.alert-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.alert-item.critical .alert-icon { background: var(--danger-bg); color: var(--danger); }
.alert-item.warning .alert-icon { background: var(--warning-bg); color: var(--warning); }
.alert-item.info .alert-icon { background: var(--info-bg); color: var(--info); }
.alert-item.success .alert-icon { background: var(--success-bg); color: var(--success); }

.alert-content { flex: 1; }
.alert-title { font-size: 0.85rem; font-weight: 700; color: var(--text-primary); }
.alert-message { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.alert-time { font-size: 0.68rem; color: var(--text-muted); margin-top: 4px; }

/* ===========================
   EMERGENCY STYLES
   =========================== */
.emergency-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.emergency-header {
  background: linear-gradient(135deg, #ff3b30, #cc2c22);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
}

.patient-critical {
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.3);
  border-radius: var(--border-radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}

.patient-warning {
  background: rgba(255, 159, 10, 0.08);
  border: 1px solid rgba(255, 159, 10, 0.3);
  border-radius: var(--border-radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}

.patient-stable {
  background: rgba(48, 209, 88, 0.05);
  border: 1px solid rgba(48, 209, 88, 0.2);
  border-radius: var(--border-radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}

/* ===========================
   MAP PLACEHOLDER
   =========================== */
.map-placeholder {
  background: linear-gradient(135deg, #1a2744, #0d1a3a);
  border-radius: var(--border-radius);
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.map-placeholder::before {
  content: '';
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(circle at 30% 60%, rgba(10, 132, 255, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 70% 30%, rgba(0, 212, 255, 0.1) 0%, transparent 50%);
}

.map-pin {
  width: 40px;
  height: 40px;
  border-radius: 50% 50% 50% 0;
  background: var(--primary);
  transform: rotate(-45deg);
  box-shadow: 0 0 20px rgba(10, 132, 255, 0.5);
  animation: bounce 2s infinite;
}

/* ===========================
   SEARCH BAR
   =========================== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  padding: 8px 14px;
  transition: var(--transition);
  flex: 1;
  max-width: 300px;
}

.search-bar:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
}

.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Cairo', sans-serif;
  font-size: 0.875rem;
}

.search-bar input::placeholder { color: var(--text-muted); }
.search-bar .search-icon { color: var(--text-muted); font-size: 0.85rem; }

/* ===========================
   SECTION HEADER
   =========================== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(10, 132, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 0.85rem;
}

/* ===========================
   TABS
   =========================== */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius-sm);
  padding: 4px;
  border: 1px solid var(--border-secondary);
}

.tab-btn {
  flex: 1;
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Cairo', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.tab-btn:hover:not(.active) { color: var(--text-primary); }

/* ===========================
   ANIMATIONS
   =========================== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutLeft {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(-20px); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

@keyframes pulse-ring {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
}

@keyframes ring-pulse {
  0% { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(10, 132, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0); }
}

@keyframes bounce {
  0%, 100% { transform: rotate(-45deg) translateY(0); }
  50% { transform: rotate(-45deg) translateY(-6px); }
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14% { transform: scale(1.1); }
  28% { transform: scale(1); }
  42% { transform: scale(1.08); }
  56% { transform: scale(1); }
}

@keyframes scan {
  0% { top: 0; }
  100% { top: 100%; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(10, 132, 255, 0.3); }
  50% { box-shadow: 0 0 30px rgba(10, 132, 255, 0.7); }
}

@keyframes danger-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255, 59, 48, 0.3); }
  50% { box-shadow: 0 0 30px rgba(255, 59, 48, 0.7); }
}

.animate-fade-up { animation: fadeInUp 0.5s ease forwards; }
.animate-fade-up-delay-1 { animation: fadeInUp 0.5s ease 0.1s forwards; opacity: 0; }
.animate-fade-up-delay-2 { animation: fadeInUp 0.5s ease 0.2s forwards; opacity: 0; }
.animate-fade-up-delay-3 { animation: fadeInUp 0.5s ease 0.3s forwards; opacity: 0; }
.animate-fade-up-delay-4 { animation: fadeInUp 0.5s ease 0.4s forwards; opacity: 0; }

.heartbeat { animation: heartbeat 1.5s ease infinite; }
.float-anim { animation: float 3s ease-in-out infinite; }
.glow-pulse { animation: glow-pulse 2s ease infinite; }
.danger-pulse { animation: danger-pulse 1.5s ease infinite; }

/* ===========================
   UTILITY CLASSES
   =========================== */
.text-primary-color { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

.bg-primary-subtle { background: rgba(10, 132, 255, 0.1); border: 1px solid rgba(10, 132, 255, 0.2); }
.bg-success-subtle { background: var(--success-bg); border: 1px solid rgba(48, 209, 88, 0.2); }
.bg-warning-subtle { background: var(--warning-bg); border: 1px solid rgba(255, 159, 10, 0.2); }
.bg-danger-subtle { background: var(--danger-bg); border: 1px solid rgba(255, 59, 48, 0.2); }

.fw-700 { font-weight: 700; }
.fw-600 { font-weight: 600; }
.fw-500 { font-weight: 500; }
.fs-sm { font-size: 0.8rem; }
.fs-xs { font-size: 0.72rem; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-1 { flex: 1; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }

.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

.rounded { border-radius: var(--border-radius); }
.rounded-sm { border-radius: var(--border-radius-sm); }
.rounded-lg { border-radius: var(--border-radius-lg); }
.rounded-full { border-radius: 50%; }

.text-center { text-align: center; }
.w-full { width: 100%; }

.divider {
  height: 1px;
  background: var(--border-secondary);
  margin: 16px 0;
}

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 992px) {
  :root { --sidebar-width: 220px; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-right: 0; }
  :root { --topnav-height: 56px; }
  .page-content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .col-span-2, .col-span-3 { grid-column: span 1; }
  .top-nav-title { font-size: 0.9rem; }
}

/* ===========================
   LOADING SKELETON
   =========================== */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-glass) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--border-radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===========================
   CHART LEGEND
   =========================== */
.chart-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.chart-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===========================
   SCROLL REVEAL
   =========================== */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* ===========================
   MOBILE SIDEBAR TOGGLE
   =========================== */
.sidebar-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-primary);
  background: var(--bg-card);
  color: var(--text-secondary);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }
  .sidebar-overlay { display: block; opacity: 0; pointer-events: none; }
  .sidebar-overlay.active { opacity: 1; pointer-events: all; }
}
