/* ============================================
   GlucoTrack — Design System & Styles
   ============================================ */

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

/* ============ CSS VARIABLES ============ */
:root {
  /* Primary Colors — Teal Health Theme */
  --primary-50: #e6faf9;
  --primary-100: #b3f0ed;
  --primary-200: #80e6e0;
  --primary-300: #4dddd4;
  --primary-400: #26d4c8;
  --primary-500: #14b8a6;
  --primary-600: #0d9488;
  --primary-700: #0d7377;
  --primary-800: #0a5c5f;
  --primary-900: #064e4a;

  /* Accent */
  --accent: #f59e0b;
  --accent-light: #fbbf24;

  /* Neutrals */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Status Colors */
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --info: #3b82f6;
  --info-bg: #dbeafe;

  /* Glucose Level Colors */
  --glucose-low: #3b82f6;
  --glucose-normal: #10b981;
  --glucose-high: #f59e0b;
  --glucose-critical: #ef4444;

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

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.1);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 20px rgba(20, 184, 166, 0.3);

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --glass-blur: 12px;

  /* Background */
  --bg-gradient: linear-gradient(135deg, #0d7377 0%, #14919b 30%, #e8f4f2 100%);
  --bg-body: #f0f7f6;
  --bg-card: #ffffff;
  --bg-sidebar: linear-gradient(180deg, #0a5c5f 0%, #0d7377 50%, #14919b 100%);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;

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

/* ============ DARK MODE ============ */
[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: linear-gradient(180deg, #0a3d3f 0%, #0d5557 50%, #0d7377 100%);
  --glass-bg: rgba(30, 41, 59, 0.8);
  --glass-border: rgba(255, 255, 255, 0.1);
  --gray-50: #1e293b;
  --gray-100: #1e293b;
  --gray-200: #334155;
  --gray-300: #475569;
  --gray-400: #64748b;
  --gray-500: #94a3b8;
  --gray-600: #cbd5e1;
  --gray-700: #e2e8f0;
  --gray-800: #f1f5f9;
  --gray-900: #f8fafc;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============ AUTH PAGE ============ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-gradient);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.auth-page::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 50%, rgba(255,255,255,0.1) 0%, transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(20,184,166,0.15) 0%, transparent 40%);
  animation: floatBg 20s ease-in-out infinite;
}

@keyframes floatBg {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(30px, -30px) rotate(2deg); }
  66% { transform: translate(-20px, 20px) rotate(-2deg); }
}

.auth-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
}

.auth-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-xl);
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.6s ease-out;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo .logo-icon {
  font-size: 48px;
  margin-bottom: 8px;
  display: block;
}

.auth-logo h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  color: var(--primary-800);
  letter-spacing: -0.5px;
}

.auth-logo p {
  color: var(--gray-500);
  font-size: 14px;
  margin-top: 4px;
}

.role-toggle {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--border-radius);
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}

.role-toggle button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--border-radius-sm);
  background: transparent;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  color: var(--gray-500);
  cursor: pointer;
  transition: var(--transition-fast);
}

.role-toggle button.active {
  background: white;
  color: var(--primary-700);
  box-shadow: var(--shadow-sm);
}

.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  gap: 4px;
  background: var(--gray-100);
  border-radius: var(--border-radius);
  padding: 4px;
}

.auth-tabs button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--border-radius-sm);
  background: transparent;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  color: var(--gray-500);
  cursor: pointer;
  transition: var(--transition-fast);
}

.auth-tabs button.active {
  background: white;
  color: var(--primary-700);
  box-shadow: var(--shadow-sm);
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--bg-card);
  transition: var(--transition-fast);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
}

.form-control::placeholder {
  color: var(--gray-400);
}

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 40px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-500));
  color: white;
  box-shadow: 0 4px 12px rgba(13, 116, 119, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(13, 116, 119, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary-500);
  color: var(--primary-600);
}

.btn-outline:hover {
  background: var(--primary-50);
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
}

.btn-emergency {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: white;
  font-size: 16px;
  padding: 16px 32px;
  border-radius: var(--border-radius-lg);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
  animation: pulse-emergency 2s infinite;
}

@keyframes pulse-emergency {
  0% { box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 4px 30px rgba(239, 68, 68, 0.6); }
  100% { box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4); }
}

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

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: white;
}

.sidebar-header .logo-icon {
  font-size: 32px;
}

.sidebar-header .logo-text {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}

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

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  border-radius: var(--border-radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition-fast);
  margin-bottom: 4px;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

.sidebar-nav a.active {
  background: rgba(255,255,255,0.2);
  color: white;
  font-weight: 600;
}

.sidebar-nav a .nav-icon {
  font-size: 20px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

.sidebar-user .user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.sidebar-user .user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user .user-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user .user-role {
  font-size: 12px;
  opacity: 0.7;
}

/* Mobile menu button */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: var(--border-radius-sm);
  background: var(--primary-600);
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

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

/* ============ MAIN CONTENT ============ */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}

.page-header .header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

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

.card:hover {
  box-shadow: var(--shadow);
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-800);
}

.card-body {
  padding: 24px;
}

.card-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}

/* Stat Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.stat-card .stat-icon.glucose { background: var(--primary-100); }
.stat-card .stat-icon.medication { background: var(--info-bg); }
.stat-card .stat-icon.diet { background: var(--success-bg); }
.stat-card .stat-icon.hba1c { background: var(--warning-bg); }

.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 4px;
}

.stat-card .stat-change {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}

.stat-card .stat-change.up { color: var(--danger); }
.stat-card .stat-change.down { color: var(--success); }
.stat-card .stat-change.stable { color: var(--gray-400); }

/* ============ GRID LAYOUTS ============ */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

/* ============ TABLES ============ */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th, table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
  font-size: 14px;
}

table th {
  font-weight: 600;
  color: var(--gray-600);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--gray-50);
}

table tbody tr {
  transition: var(--transition-fast);
}

table tbody tr:hover {
  background: var(--gray-50);
}

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

.badge-success { background: var(--success-bg); color: #065f46; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-info { background: var(--info-bg); color: #1e40af; }
.badge-neutral { background: var(--gray-100); color: var(--gray-600); }

/* Glucose level badges */
.glucose-low { background: #dbeafe; color: #1e40af; }
.glucose-normal { background: #d1fae5; color: #065f46; }
.glucose-high { background: #fef3c7; color: #92400e; }
.glucose-critical { background: #fee2e2; color: #991b1b; }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--gray-100);
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  color: var(--gray-500);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.modal-close:hover {
  background: var(--gray-200);
  color: var(--gray-700);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ============ TOAST ============ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--border-radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 3s forwards;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 380px;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-warning { background: var(--warning); color: white; }
.toast-info { background: var(--info); color: white; }

/* ============ AI CHAT ============ */
.ai-chat-card {
  border: 2px solid var(--primary-200);
  background: linear-gradient(135deg, var(--primary-50), var(--bg-card));
}

.ai-response {
  background: var(--gray-50);
  border-radius: var(--border-radius-sm);
  padding: 16px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.ai-input-group {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.ai-input-group input {
  flex: 1;
}

.ai-disclaimer {
  font-size: 11px;
  color: var(--gray-400);
  text-align: center;
  margin-top: 8px;
}

/* ============ QUICK ACTIONS ============ */
.quick-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.quick-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 24px;
  background: var(--bg-card);
  border: 2px solid var(--gray-200);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-sans);
  color: var(--gray-700);
  min-width: 120px;
}

.quick-action-btn:hover {
  border-color: var(--primary-400);
  background: var(--primary-50);
  transform: translateY(-2px);
}

.quick-action-btn .qa-icon {
  font-size: 28px;
}

.quick-action-btn .qa-label {
  font-size: 13px;
  font-weight: 600;
}

/* ============ SCHEDULE ============ */
.schedule-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}

.schedule-item:last-child {
  border-bottom: none;
}

.schedule-time {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-700);
  min-width: 60px;
}

.schedule-info {
  flex: 1;
}

.schedule-info .schedule-title {
  font-size: 14px;
  font-weight: 500;
}

.schedule-info .schedule-desc {
  font-size: 12px;
  color: var(--gray-500);
}

/* ============ DARK MODE TOGGLE ============ */
.theme-toggle {
  position: relative;
  width: 48px;
  height: 26px;
  cursor: pointer;
}

.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 13px;
  transition: var(--transition);
}

.theme-toggle .slider::before {
  content: '☀️';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.theme-toggle input:checked + .slider {
  background: var(--primary-600);
}

.theme-toggle input:checked + .slider::before {
  transform: translateX(22px);
  content: '🌙';
}

/* ============ LANGUAGE SELECTOR ============ */
.lang-selector {
  position: relative;
}

.lang-selector select {
  appearance: none;
  padding: 6px 28px 6px 10px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--border-radius-sm);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 18px;
  color: var(--gray-600);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 20px;
}

/* ============ LOADING ============ */
.loading-spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  gap: 12px;
  color: var(--gray-500);
}

/* ============ ANIMATIONS ============ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-10px); }
}

.animate-in {
  animation: fadeInUp 0.4s ease-out;
}

/* ============ RISK BADGES (Doctor Panel) ============ */
.risk-normal { border-left: 4px solid var(--success); }
.risk-warning { border-left: 4px solid var(--warning); }
.risk-critical { border-left: 4px solid var(--danger); }

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

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .main-content {
    margin-left: 0;
    padding: 20px;
    padding-top: 72px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .grid-3 { grid-template-columns: 1fr; }

  .page-header h1 {
    font-size: 22px;
  }

  .quick-actions {
    flex-wrap: wrap;
  }

  .quick-action-btn {
    flex: 1;
    min-width: 100px;
  }

  .auth-card {
    padding: 32px 24px;
  }

  /* Mobile bottom navigation */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--gray-200);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
    z-index: 90;
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .mobile-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 4px;
    text-decoration: none;
    color: var(--gray-400);
    font-size: 11px;
    font-weight: 500;
    transition: var(--transition-fast);
  }

  .mobile-bottom-nav a.active {
    color: var(--primary-600);
  }

  .mobile-bottom-nav a .nav-icon {
    font-size: 22px;
  }

  .main-content {
    padding-bottom: 80px;
  }
}

@media (min-width: 769px) {
  .mobile-bottom-nav {
    display: none;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 28px 20px;
    border-radius: var(--border-radius-lg);
  }

  .modal {
    max-width: 100%;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    position: fixed;
    bottom: 0;
    animation: slideUpModal 0.3s ease;
  }

  @keyframes slideUpModal {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

/* ============ PRINT ============ */
@media print {
  .sidebar, .mobile-menu-btn, .mobile-bottom-nav, .quick-actions { display: none !important; }
  .main-content { margin-left: 0; padding: 0; }
}
