/* ============================================
   AgendaFarma — Modern SaaS Design System v2
   Healthcare-focused, mobile-first, premium feel
   ============================================ */

/* --- CSS Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-primary, #0f172a);
  background: var(--bg-body, #f1f5f9);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary, #2563eb); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: var(--primary-dark, #1d4ed8); }

img { max-width: 100%; height: auto; display: block; }

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
  /* Primary — Medical Blue */
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-200: #bfdbfe;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  --primary-900: #1e3a8a;

  /* Accent — Teal/Medical */
  --accent: #0891b2;
  --accent-light: #cffafe;
  --accent-dark: #0e7490;

  /* Semantic Colors */
  --success: #059669;
  --success-light: #d1fae5;
  --success-dark: #047857;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --warning-dark: #b45309;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --danger-dark: #b91c1c;
  --info: #0891b2;
  --info-light: #cffafe;
  --info-dark: #0e7490;

  /* Neutrals — Slate Scale */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --border-focus: #93c5fd;

  /* Backgrounds */
  --bg-body: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: rgba(37, 99, 235, 0.15);
  --bg-header: rgba(255, 255, 255, 0.8);
  --bg-input: #f8fafc;
  --bg-hover: #f8fafc;
  --bg-stripe: #f8fafc;
  --bg-elevated: #ffffff;

  /* Shadows — Layered */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.18);
  --shadow-glow: 0 0 20px rgba(37, 99, 235, 0.15);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-card-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);

  /* Radius — Modern Rounded */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Spacing Scale */
  --space-2xs: 2px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Typography Scale */
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.9375rem;
  --font-size-lg: 1.0625rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;

  /* Line Heights */
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-sidebar: 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  --transition-label: 0.3s cubic-bezier(0.22, 1, 0.36, 1);

  /* Layout */
  --sidebar-width: 260px;
  --sidebar-mini-width: 70px;
  --sidebar-collapsed: 0px;
  --header-height: 64px;
  --content-max: 1440px;

  /* Z-index Scale */
  --z-sidebar: 100;
  --z-header: 90;
  --z-dropdown: 110;
  --z-modal: 200;
  --z-toast: 300;
  --z-tooltip: 400;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0f172a;
  --border: #334155;
  --border-light: #1e293b;
  --border-focus: #3b82f6;
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #020617;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: rgba(59, 130, 246, 0.15);
  --bg-header: rgba(15, 23, 42, 0.95);
  --bg-input: #1e293b;
  --bg-hover: #1e293b;
  --bg-stripe: #1e293b;
  --bg-elevated: #1e293b;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-card-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .top-header {
  background: rgba(15, 23, 42, 0.95);
}

[data-theme="dark"] .card,
[data-theme="dark"] .stat-card {
  border-color: #334155;
}

[data-theme="dark"] .sidebar-footer {
  background: rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-textarea {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-select:focus,
[data-theme="dark"] .form-textarea:focus {
  background: #1e293b;
}

[data-theme="dark"] .table tbody tr:hover {
  background: #1e293b;
}

[data-theme="dark"] .badge-neutral {
  background: #334155;
  color: #94a3b8;
}

[data-theme="dark"] .modal {
  border-color: #334155;
}

[data-theme="dark"] .alert-success { background: rgba(5, 150, 105, 0.15); color: #6ee7b7; }
[data-theme="dark"] .alert-warning { background: rgba(217, 119, 6, 0.15); color: #fcd34d; }
[data-theme="dark"] .alert-danger { background: rgba(220, 38, 38, 0.15); color: #fca5a5; }
[data-theme="dark"] .alert-info { background: rgba(8, 145, 178, 0.15); color: #67e8f9; }

[data-theme="dark"] .btn-secondary {
  background: #334155;
  border-color: #475569;
  color: #f1f5f9;
}

[data-theme="dark"] .btn-secondary:hover {
  background: #475569;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }

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

/* ============================================
   SIDEBAR — Modern Dark with Glow
   ============================================ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-inverse);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-sidebar), box-shadow var(--transition-sidebar);
  overflow: hidden;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  will-change: transform;
  touch-action: pan-y;
}

.sidebar.dragging {
  transition: none !important;
}

.sidebar-brand {
  padding: var(--space-lg) var(--space-lg) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.sidebar-brand-text {
  font-size: var(--font-size-lg);
  font-weight: var(--font-bold);
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}



.sidebar-nav {
  flex: 1 1 0;
  padding: var(--space-sm) var(--space-sm);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 4px; }

.sidebar-section-label {
  padding: var(--space-md) var(--space-md) var(--space-xs);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.35);
  font-weight: var(--font-semibold);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 10px var(--space-md);
  color: rgba(255, 255, 255, 0.6);
  font-size: var(--font-size-sm);
  font-weight: var(--font-medium);
  transition: all var(--transition-fast);
  border-radius: var(--radius);
  text-decoration: none;
  margin-bottom: 2px;
  position: relative;
  border-left: none;
}

.sidebar-link:hover {
  background: var(--bg-sidebar-hover);
  color: rgba(255, 255, 255, 0.95);
  transform: translateX(2px);
}

.sidebar-link.active {
  background: var(--bg-sidebar-active);
  color: #ffffff;
  font-weight: var(--font-semibold);
  border-left-color: transparent;
  box-shadow: inset 3px 0 0 var(--primary);
}

.sidebar-link.active::before {
  content: none;
}

.sidebar-link .icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-link.active .icon {
  opacity: 1;
}

.sidebar-footer {
  padding: var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.15);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm);
  border-radius: var(--radius);
  transition: background var(--transition-fast);
}

.sidebar-user:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-bold);
  flex-shrink: 0;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

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

.sidebar-user-name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #ffffff;
}

.sidebar-user-role {
  font-size: var(--font-size-xs);
  color: rgba(255, 255, 255, 0.45);
  font-weight: var(--font-medium);
}

/* --- Mobile Sidebar Overlay --- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: calc(var(--z-sidebar) - 1);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--transition-sidebar), visibility 0s var(--transition-sidebar);
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--transition-sidebar), visibility 0s 0s;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  min-width: 0;
  overflow-x: hidden;
  transition: margin-left var(--transition-slow);
  will-change: margin-left;
}

/* Body-class breakpoint overrides for smooth margin-left transition on resize */
body.tablet .main-content {
  margin-left: var(--sidebar-mini-width);
}

body.mobile .main-content {
  margin-left: 0;
}

/* Tablet: when sidebar is expanded, use full width */
body.tablet .sidebar.open ~ .main-content {
  margin-left: var(--sidebar-width);
}

/* --- Top Header — Glassmorphism with Solid Fallback --- */
.top-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-xl);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-sm);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 1.25rem;
  transition: all var(--transition-fast);
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hamburger:hover {
  background: var(--bg-hover);
}

.page-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* --- Theme Toggle Button --- */
.theme-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 1.1rem;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}  

/* Theme toggle mobile tap feedback */
.theme-toggle:active .theme-toggle-icon {
  transform: scale(0.85);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle-icon {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  line-height: 1;
}

.theme-toggle:hover .theme-toggle-icon {
  transform: rotate(20deg);
}

/* ============================================
   AUTH THEME TOGGLE — positioned inside auth-card
   ============================================ */
.theme-toggle-auth {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle-auth:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: scale(1.05);
}

/* ============================================
   IMPERSONATION BADGE (Sidebar)
   ============================================ */
.impersonation-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin-bottom: 8px;
}

.impersonation-badge-icon {
  font-size: 0.75rem;
}

.impersonation-badge-body {
  flex: 1;
  min-width: 0;
}

.impersonation-badge-title {
  font-size: 0.7rem;
  color: #f59e0b;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.impersonation-badge-name {
  font-size: 0.8rem;
  color: #fff;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   IMPERSONATION ALERT (top of content area)
   ============================================ */
.impersonation-alert {
  background: #f59e0b;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-md);
}

.impersonation-alert-btn {
  background: #000;
  color: #fff;
  border: none;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.impersonation-alert-btn:hover {
  background: #1a1a1a;
}

/* ============================================
   SIDEBAR LOGOUT
   ============================================ */
.sidebar-logout-form {
  margin: 0;
  padding: 0;
}

.sidebar-logout-btn {
  padding-left: 0;
  color: #f87171;
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font: inherit;
}

.sidebar-logout-btn { padding-left: 0; color: #f87171; background: none; border: none; cursor: pointer; width: 100%; text-align: left; font: inherit; }
.sidebar-logout-btn .icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 0.8;
}

/* --- Content Area --- */
.content-area {
  flex: 1;
  padding: var(--space-xl);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

/* ============================================
   CARDS — Modern with Subtle Elevation
   ============================================ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  overflow: visible;
  transition: box-shadow var(--transition), transform var(--transition);
}

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

.card-header {
  padding: var(--space-lg) var(--space-lg);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.card-title {
  font-size: var(--font-size-base);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.card-title-danger { color: var(--danger); }
.card-title-warning { color: var(--warning); }
.card-title-success { color: var(--success); }

.card-body {
  padding: var(--space-lg);
}

.card-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-light);
  background: var(--bg-stripe);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============================================
   STAT CARDS — Gradient Accent Borders
   ============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--space-lg) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  transition: all var(--transition);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  min-height: 90px;
}

.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  opacity: 0;
  transition: opacity var(--transition);
}

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

.stat-card:hover::before {
  opacity: 1;
}

.stat-card:nth-child(1)::before { background: linear-gradient(180deg, var(--primary), var(--primary-light)); }
.stat-card:nth-child(2)::before { background: linear-gradient(180deg, var(--success), var(--success-light)); }
.stat-card:nth-child(3)::before { background: linear-gradient(180deg, var(--danger), var(--danger-light)); }
.stat-card:nth-child(4)::before { background: linear-gradient(180deg, var(--warning), var(--warning-light)); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.danger { background: var(--danger-light); color: var(--danger); }
.stat-icon.info { background: var(--info-light); color: var(--info); }
.stat-icon.accent { background: var(--accent-light); color: var(--accent); }

.stat-content { flex: 1; min-width: 0; }

.stat-value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-extrabold);
  color: var(--text-primary);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: var(--font-medium);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ============================================
   BUTTONS — Modern with Micro-interactions
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-semibold);
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
  font-family: inherit;
  letter-spacing: -0.01em;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-700));
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-500), var(--primary));
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
  color: #ffffff;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), var(--success-dark));
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
}
.btn-success:hover {
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.35);
  color: #ffffff;
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), var(--danger-dark));
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.2);
}
.btn-danger:hover {
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
  color: #ffffff;
}

.btn-warning {
  background: linear-gradient(135deg, var(--warning), var(--warning-dark));
  color: #ffffff;
}
.btn-warning:hover { color: #ffffff; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #ffffff; }

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

.btn-info {
  background: linear-gradient(135deg, var(--info), var(--info-dark));
  color: #ffffff;
}
.btn-info:hover { color: #ffffff; }

.btn-sm {
  padding: 6px 14px;
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 14px 28px;
  font-size: var(--font-size-base);
  border-radius: var(--radius-lg);
}

.btn-block { width: 100%; }

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
}

.btn-group {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

/* ============================================
   FORMS — Modern Inputs with Focus States
   ============================================ */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: var(--font-size-sm);
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all var(--transition);
  line-height: 1.5;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  background: #ffffff;
}

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

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-help {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 6px;
  line-height: var(--leading-normal);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--danger);
  margin-top: 6px;
}

.form-input.error,
.form-select.error,
.form-textarea.error {
  border-color: var(--danger);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}

.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ============================================
   TABLES — Modern with Rounded Wrappers
   ============================================ */
.table-wrapper,
.table-responsive-mobile {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.table thead {
  background: var(--bg-stripe);
  position: sticky;
  top: 0;
}

.table th {
  padding: 12px var(--space-lg);
  text-align: left;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px var(--space-lg);
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.table tbody tr:hover {
  background: var(--bg-hover);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* --- Mobile Stack Table --- */
@media (max-width: 768px) {
  /* Remove unnecessary overflow-x from wrapper when using stacked cards */
  .table-mobile-stack.table-wrapper,
  .table-mobile-stack.table-responsive-mobile {
    overflow-x: visible;
  }

  .table-mobile-stack thead {
    display: none;
  }

  .table-mobile-stack tbody tr {
    display: block;
    padding: 10px 10px;
    border-bottom: none;
    margin-bottom: 6px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: none;
  }

  .table-mobile-stack tbody tr:last-child {
    margin-bottom: 0;
  }

  .table-mobile-stack tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: var(--font-size-sm);
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
    gap: var(--space-sm);
  }

  .table-mobile-stack tbody td:last-child {
    border-bottom: none;
  }

  .table-mobile-stack tbody td::before {
    content: attr(data-label);
    font-weight: var(--font-semibold);
    color: var(--text-muted);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    min-width: 60px;
    padding-top: 1px;
  }

  /* Actions column: inline buttons, no label spread */
  .table-mobile-stack tbody td[data-label="Ações"] {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    margin-top: 3px;
    border-bottom: none;
    padding-bottom: 0;
  }

  .table-mobile-stack tbody td[data-label="Ações"]::before {
    display: none;
  }

  .table-mobile-stack tbody td[data-label="Ações"] .btn-sm {
    padding: 4px 8px;
    min-height: 30px;
    font-size: 0.7rem;
  }

  /* Compact ID row */
  .table-mobile-stack tbody td[data-label="ID"] {
    padding-bottom: 2px;
  }
  .table-mobile-stack tbody td[data-label="ID"]::before {
    color: var(--text-muted);
    font-size: 0.6rem;
  }

  /* Badges inside stacked cards stay compact */
  .table-mobile-stack tbody .badge {
    font-size: 0.6rem;
    padding: 2px 7px;
  }
}

/* ============================================
   BADGES — Modern Pill Design
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-full);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.badge-primary { background: var(--primary-light); color: var(--primary-700); }
.badge-success { background: var(--success-light); color: var(--success-dark); }
.badge-warning { background: var(--warning-light); color: var(--warning-dark); }
.badge-danger { background: var(--danger-light); color: var(--danger-dark); }
.badge-info { background: var(--info-light); color: var(--info-dark); }
.badge-neutral { background: var(--border-light); color: var(--text-secondary); }

/* ============================================
   ALERTS — Modern with Icon
   ============================================ */
.alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius);
  border-left: 4px solid;
  font-size: var(--font-size-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  line-height: var(--leading-normal);
}

.alert-success { background: var(--success-light); border-color: var(--success); color: #065f46; }
.alert-warning { background: var(--warning-light); border-color: var(--warning); color: #92400e; }
.alert-danger { background: var(--danger-light); border-color: var(--danger); color: #991b1b; }
.alert-info { background: var(--info-light); border-color: var(--info); color: #155e75; }

/* ============================================
   MODALS — Modern with Slide-up Animation
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-overlay.active {
  display: flex;
  animation: overlayIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  animation: modalSlideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid var(--border);
}

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

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

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-lg);
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* ============================================
   TOASTS — Modern Slide-in
   ============================================ */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-width: 420px;
  width: calc(100% - 32px);
}

.toast {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  animation: toastSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: var(--bg-card);
  border-left: 4px solid;
  font-weight: var(--font-medium);
}

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

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3.5rem;
  margin-bottom: var(--space-md);
  opacity: 0.6;
}

.empty-state-text {
  font-size: var(--font-size-lg);
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-sm);
  color: var(--text-secondary);
}

.empty-state-sub {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* ============================================
   AVATARS
   ============================================ */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-bold);
  font-size: var(--font-size-sm);
  flex-shrink: 0;
  background: var(--primary-light);
  color: var(--primary);
}

.avatar-sm { width: 32px; height: 32px; font-size: var(--font-size-xs); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--font-size-lg); }

/* ============================================
   PHOTO PREVIEW (medications)
   ============================================ */
.photo-preview { max-height: 80px; border-radius: var(--radius); }

/* ============================================
   LOADING SPINNER
   ============================================ */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

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

.spinner-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
}

/* ============================================
   DROPDOWN
   ============================================ */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: var(--space-xs);
  z-index: var(--z-dropdown);
  display: none;
  animation: dropdownIn 0.15s ease;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-menu.active { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
}

.dropdown-item:hover {
  background: var(--bg-hover);
}

.dropdown-divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-xs) 0;
}

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

.alerts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}

.alerts-grid > :only-child {
  grid-column: 1 / -1;
}

.alerts-card {
  border-left: 4px solid transparent !important;
}

.card.alerts-card-danger {
  border-left-color: var(--danger);
}

.card.alerts-card-warning {
  border-left-color: var(--warning);
}

.card.alerts-card-success {
  border-left-color: var(--success);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-lg);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-bold { font-weight: var(--font-bold); }
.font-semibold { font-weight: var(--font-semibold); }
.font-mono { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-sm); }
.mt-2 { margin-top: var(--space-md); }
.mt-3 { margin-top: var(--space-lg); }
.mt-4 { margin-top: var(--space-xl); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-sm); }
.mb-2 { margin-bottom: var(--space-md); }
.mb-3 { margin-bottom: var(--space-lg); }
.mb-4 { margin-bottom: var(--space-xl); }
.mr-1 { margin-right: var(--space-sm); }
.mr-2 { margin-right: var(--space-md); }
.ml-1 { margin-left: var(--space-sm); }
.ml-2 { margin-left: var(--space-md); }
.p-0 { padding: 0; }
.p-1 { padding: var(--space-sm); }
.p-2 { padding: var(--space-md); }
.p-3 { padding: var(--space-lg); }
.p-4 { padding: var(--space-xl); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-sm); }
.gap-2 { gap: var(--space-md); }
.gap-3 { gap: var(--space-lg); }
.flex-1 { flex: 1; }

.hidden { display: none !important; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Extra utility classes for style="" migration --- */
.d-block { display: block; }
.d-inline-block { display: inline-block; }
.d-inline-flex { display: inline-flex; }
.pos-relative { position: relative; }
.pos-absolute { position: absolute; }
.top-16 { top: 16px; }
.right-16 { right: 16px; }
.w-full { width: 100%; }
.w-auto { width: auto; }
.min-w-0 { min-width: 0; }
.min-w-150 { min-width: 150px; }
.min-w-180 { min-width: 180px; }
.min-w-200 { min-width: 200px; }
.max-w-200 { max-width: 200px; }
.max-w-400 { max-width: 400px; }
.max-w-560 { max-width: 560px; }
.max-w-600 { max-width: 600px; }
.max-w-640 { max-width: 640px; }
.self-center { align-self: center; }
.text-nowrap { white-space: nowrap; }
.text-uppercase { text-transform: uppercase; }
.overflow-hidden { overflow: hidden; }
.cursor-pointer { cursor: pointer; }
.pl-0 { padding-left: 0; }
.pr-0 { padding-right: 0; }
.pt-0 { padding-top: 0; }
.pb-0 { padding-bottom: 0; }

/* Color utility classes */
.text-danger-light { color: #f87171; }
.text-success-light { color: #4ade80; }
.text-warning-light { color: #fbbf24; }
.text-red-500 { color: #ef4444; }
.text-red-600 { color: #dc2626; }
.text-amber-600 { color: #d97706; }
.text-amber-700 { color: #b45309; }

/* ============================================
   EMPTY STATE — padding and icon
   ============================================ */
.empty-state-padding { padding: var(--space-2xl); }
.empty-state-icon-big { font-size: 3rem; margin-bottom: var(--space-md); line-height: 1; }

/* ============================================
   DOSE LIST ITEM
   ============================================ */
.dose-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition-fast);
  animation: listItemSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--item-i, 0) * 40ms);
}

.dose-list-item:nth-child(1) { --item-i: 0; }
.dose-list-item:nth-child(2) { --item-i: 1; }
.dose-list-item:nth-child(3) { --item-i: 2; }
.dose-list-item:nth-child(4) { --item-i: 3; }
.dose-list-item:nth-child(5) { --item-i: 4; }
.dose-list-item:nth-child(6) { --item-i: 5; }
.dose-list-item:nth-child(7) { --item-i: 6; }
.dose-list-item:nth-child(8) { --item-i: 7; }
.dose-list-item:nth-child(9) { --item-i: 8; }
.dose-list-item:nth-child(10) { --item-i: 9; }
.dose-list-item:nth-child(11) { --item-i: 10; }
.dose-list-item:nth-child(12) { --item-i: 11; }
.dose-list-item:nth-child(13) { --item-i: 12; }
.dose-list-item:nth-child(14) { --item-i: 13; }
.dose-list-item:nth-child(15) { --item-i: 14; }
.dose-list-item:nth-child(16) { --item-i: 15; }
.dose-list-item:nth-child(17) { --item-i: 16; }
.dose-list-item:nth-child(18) { --item-i: 17; }
.dose-list-item:nth-child(19) { --item-i: 18; }
.dose-list-item:nth-child(20) { --item-i: 19; }

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

.dose-list-info {
  flex: 1;
  min-width: 0;
}

.dose-list-meta {
  text-align: right;
  flex-shrink: 0;
}

/* ============================================
   ADMIN HEADER — action toolbar pattern
   ============================================ */
.admin-header {
  flex-wrap: wrap;
  gap: var(--space-md);
}

/* ============================================
   SECTION TITLE — uppercase label
   ============================================ */
.section-label {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* ============================================
   POPULAR LINKS GRID (404 page)
   ============================================ */
.popular-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-sm);
  text-align: left;
}

.popular-link-card {
  padding: var(--space-md);
  text-decoration: none;
  color: var(--text-primary);
}

.popular-link-card:hover {
  transform: translateY(-2px);
}

/* ============================================
   NOT FOUND PAGE
   ============================================ */
.not-found-page {
  max-width: 640px;
  margin: 0 auto;
  text-align: center;
  padding: var(--space-xl) 0;
}

.not-found-icon {
  font-size: 4rem;
  margin-bottom: var(--space-md);
}

.path-display {
  display: inline-block;
  background: var(--bg-stripe);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 1rem;
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

/* ============================================
   NFC ACTIVE INDICATOR
   ============================================ */
.nfc-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(34, 197, 94, 0.1);
  border-radius: 20px;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.nfc-indicator-text {
  color: #22c55e;
  font-weight: 600;
}

/* ============================================
   SCAN PAGES
   ============================================ */
.scan-step-card {
  padding: 40px 20px;
}

.scan-icon-big {
  font-size: 64px;
  margin: 0 0 12px;
}

.scan-title {
  margin: 0 0 8px;
}

.scan-subtitle {
  margin: 0 0 24px;
}

.scan-btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.scan-btn-minwidth {
  min-width: 180px;
}

.scan-manual-btn {
  font-size: 14px;
}

/* ============================================
   QR CAMERA VIEW
   ============================================ */
.qr-camera-loading {
  padding: 40px 20px;
}

.qr-camera-error {
  padding: 20px;
}

.qr-video {
  width: 100%;
  max-width: 400px;
  border-radius: var(--radius);
  background: #000;
}

/* ============================================
   CONFIRM INFO CARD (scan)
   ============================================ */
.confirm-info-card {
  background: var(--bg-stripe, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  padding: 16px;
}

.confirm-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light, #f1f5f9);
}

.confirm-info-row:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.confirm-info-row .confirm-label {
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-semibold, 600);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary, #475569);
}

.confirm-info-row strong {
  font-size: var(--font-size-base, 0.9375rem);
  color: var(--text-primary, #0f172a);
  text-align: right;
  max-width: 65%;
  word-break: break-word;
}

/* ============================================
   BLOCKER CARD
   ============================================ */
.blocker-card {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 12px;
  padding: 16px;
}

.blocker-card-title {
  font-weight: 600;
  color: #ef4444;
  margin: 0 0 8px;
}

.blocker-list {
  margin: 0;
  padding-left: 20px;
}

.blocker-item {
  color: #dc2626;
  margin-bottom: 4px;
}

.blocker-warning-title {
  font-weight: 600;
  color: #d97706;
  margin: 12px 0 4px;
}

.blocker-warning-item {
  color: #b45309;
  margin-bottom: 4px;
}

/* ============================================
   TEXT SUCCESS CONTENT (2FA setup)
   ============================================ */
.text-success-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.text-success-padding {
  padding: 3rem;
}

/* ============================================
   2FA SECRET DISPLAY
   ============================================ */
.tfa-secret {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  background: var(--bg-stripe);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  display: inline-block;
  user-select: all;
  word-break: break-all;
}

/* ============================================
   TOTP CODE INPUT
   ============================================ */
.totp-input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.3em;
  font-weight: 700;
}

/* ============================================
   MANUAL CODE INPUT
   ============================================ */
.manual-code-input {
  flex: 1;
}

.mx-auto {
  margin-left: auto;
  margin-right: auto;
}

/* ============================================
   SCAN ICON — smaller for loading states
   ============================================ */
.scan-icon-sm {
  font-size: 48px;
  margin: 0;
}

.min-w-300 {
  min-width: 300px;
}

/* ============================================
   MANUAL FORM
   ============================================ */
.manual-form {
  display: flex;
  gap: 12px;
}

/* ============================================
   NFC TAG INPUT
   ============================================ */
.nfc-tag-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
}

.nfc-tag-code-input {
  flex: 1;
  min-width: 150px;
}

.nfc-btn {
  white-space: nowrap;
}

/* ============================================
   AUTH MUTED TEXT (reset-password)
   ============================================ */
.auth-muted-text { color: rgba(255, 255, 255, 0.8); margin-bottom: 1.5rem; }

/* ============================================
   SEARCH INPUT — real-time filter bar
   ============================================ */
.search-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-icon {
  font-size: 0.95rem;
  flex-shrink: 0;
  opacity: 0.5;
  line-height: 1;
}

.search-input {
  border: none !important;
  background: transparent !important;
  padding: 10px 0 !important;
  font-size: var(--font-size-sm);
  box-shadow: none !important;
  flex: 1;
  min-width: 0;
}

.search-input:focus {
  box-shadow: none !important;
  background: transparent !important;
}

.search-clear {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.search-clear:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.search-count {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ============================================
   ENTRANCE ANIMATIONS — card reveal with spring
   ============================================ */
@keyframes cardReveal {
  0% {
    opacity: 0;
    transform: translateY(28px) scale(0.96);
  }
  50% {
    opacity: 1;
    transform: translateY(-1px) scale(1.005);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

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

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

@keyframes shimmer {
  0% { opacity: 0.5; }
  50% { opacity: 1; }
  100% { opacity: 0.5; }
}

/* ============================================
   CRUD CARDS — modern card grid for all admin lists
   ============================================ */
.crud-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-lg);
}

.crud-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  transition: box-shadow var(--transition), transform var(--transition);
  animation: cardReveal 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--card-i, 0) * 60ms);
}

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

/* Fallback stagger for cards without inline --card-i */
.crud-card:nth-child(1) { --card-i: 0; }
.crud-card:nth-child(2) { --card-i: 1; }
.crud-card:nth-child(3) { --card-i: 2; }
.crud-card:nth-child(4) { --card-i: 3; }
.crud-card:nth-child(5) { --card-i: 4; }
.crud-card:nth-child(6) { --card-i: 5; }
.crud-card:nth-child(7) { --card-i: 6; }
.crud-card:nth-child(8) { --card-i: 7; }
.crud-card:nth-child(9) { --card-i: 8; }
.crud-card:nth-child(10) { --card-i: 9; }
.crud-card:nth-child(11) { --card-i: 10; }
.crud-card:nth-child(12) { --card-i: 11; }
.crud-card:nth-child(13) { --card-i: 12; }
.crud-card:nth-child(14) { --card-i: 13; }
.crud-card:nth-child(15) { --card-i: 14; }
.crud-card:nth-child(16) { --card-i: 15; }
.crud-card:nth-child(17) { --card-i: 16; }
.crud-card:nth-child(18) { --card-i: 17; }
.crud-card:nth-child(19) { --card-i: 18; }
.crud-card:nth-child(20) { --card-i: 19; }
.crud-card:nth-child(21) { --card-i: 20; }
.crud-card:nth-child(22) { --card-i: 21; }
.crud-card:nth-child(23) { --card-i: 22; }
.crud-card:nth-child(24) { --card-i: 23; }
.crud-card:nth-child(25) { --card-i: 24; }
.crud-card:nth-child(26) { --card-i: 25; }
.crud-card:nth-child(27) { --card-i: 26; }
.crud-card:nth-child(28) { --card-i: 27; }
.crud-card:nth-child(29) { --card-i: 28; }
.crud-card:nth-child(30) { --card-i: 29; }

.crud-card-accent {
  width: 5px;
  flex-shrink: 0;
}

.crud-card-body {
  flex: 1;
  padding: var(--space-lg);
  min-width: 0;
}

.crud-card-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.crud-card-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: var(--font-bold);
  flex-shrink: 0;
}

.crud-card-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  line-height: var(--leading-tight);
  word-break: break-word;
}

.crud-card-sub {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 1px;
}

.crud-card-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-sm);
}

.crud-card-info-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.crud-card-info-item strong {
  color: var(--text-primary);
}

.crud-card-info-item-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  font-size: 0.9rem;
}

.crud-card-footer {
  display: flex;
  gap: var(--space-sm);
  padding-top: var(--space-md);
  margin-top: var(--space-sm);
  border-top: 1px solid var(--border-light);
}

.crud-card-footer .btn {
  flex: 1;
  justify-content: center;
}

.crud-empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
}

.crud-error {
  text-align: center;
  padding: var(--space-xl);
  color: var(--danger);
  font-weight: var(--font-semibold);
}

.crud-skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-lg); }

@media (max-width: 768px) {
  .crud-grid, .crud-skeleton-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  .crud-card-body { padding: var(--space-md); }
  .crud-card-avatar { width: 38px; height: 38px; font-size: 1rem; }
  .crud-card-title { font-size: var(--font-size-base); }
}

@media (max-width: 480px) {
  .crud-card-footer .btn {
    min-height: 38px;
    font-size: var(--font-size-xs);
  }
}

/* Skeleton */
.crud-skeleton-line {
  height: 14px;
  background: var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  animation: shimmer 1.5s ease-in-out infinite;
}

/* Disable entrance animation during skeleton state */
.crud-skeleton .crud-card,
.crud-card.crud-skeleton {
  animation: none;
}

/* Keep .family-card-* as aliases for backwards compat with families.php */
.family-cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-lg); }
.family-card { background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border); box-shadow: var(--shadow-card); overflow: hidden; display: flex; transition: box-shadow var(--transition), transform var(--transition); animation: cardReveal 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; animation-delay: calc(var(--card-i, 0) * 60ms); }
.family-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.family-card:nth-child(1) { --card-i: 0; }
.family-card:nth-child(2) { --card-i: 1; }
.family-card:nth-child(3) { --card-i: 2; }
.family-card:nth-child(4) { --card-i: 3; }
.family-card:nth-child(5) { --card-i: 4; }
.family-card:nth-child(6) { --card-i: 5; }
.family-card:nth-child(7) { --card-i: 6; }
.family-card:nth-child(8) { --card-i: 7; }
.family-card:nth-child(9) { --card-i: 8; }
.family-card:nth-child(10) { --card-i: 9; }
.family-card:nth-child(11) { --card-i: 10; }
.family-card:nth-child(12) { --card-i: 11; }
.family-card:nth-child(13) { --card-i: 12; }
.family-card:nth-child(14) { --card-i: 13; }
.family-card:nth-child(15) { --card-i: 14; }
.family-card:nth-child(16) { --card-i: 15; }
.family-card:nth-child(17) { --card-i: 16; }
.family-card:nth-child(18) { --card-i: 17; }
.family-card:nth-child(19) { --card-i: 18; }
.family-card:nth-child(20) { --card-i: 19; }
.family-card:nth-child(21) { --card-i: 20; }
.family-card:nth-child(22) { --card-i: 21; }
.family-card:nth-child(23) { --card-i: 22; }
.family-card:nth-child(24) { --card-i: 23; }
.family-card:nth-child(25) { --card-i: 24; }
.family-card:nth-child(26) { --card-i: 25; }
.family-card:nth-child(27) { --card-i: 26; }
.family-card:nth-child(28) { --card-i: 27; }
.family-card:nth-child(29) { --card-i: 28; }
.family-card:nth-child(30) { --card-i: 29; }
.family-card-accent { width: 5px; flex-shrink: 0; }
.family-card-body { flex: 1; padding: var(--space-lg); min-width: 0; }
.family-card-top { display: flex; align-items: flex-start; gap: var(--space-md); margin-bottom: var(--space-md); }
.family-card-avatar { width: 44px; height: 44px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; font-weight: var(--font-bold); flex-shrink: 0; }
.family-card-header { flex: 1; min-width: 0; }
.family-card-name { font-size: var(--font-size-lg); font-weight: var(--font-bold); color: var(--text-primary); line-height: var(--leading-tight); word-break: break-word; }
.family-card-desc { font-size: var(--font-size-sm); color: var(--text-secondary); margin-top: 2px; line-height: var(--leading-normal); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.family-card-stats { display: flex; gap: var(--space-lg); margin-bottom: var(--space-sm); flex-wrap: wrap; }
.family-card-stat { display: inline-flex; align-items: center; gap: 6px; font-size: var(--font-size-sm); color: var(--text-secondary); }
.family-card-stat strong { color: var(--text-primary); }
.family-card-stat-icon { font-size: 1rem; flex-shrink: 0; }
.family-card-date { font-size: var(--font-size-xs); color: var(--text-muted); margin-bottom: var(--space-md); }
.family-card-actions { display: flex; gap: var(--space-sm); padding-top: var(--space-md); border-top: 1px solid var(--border-light); }
.family-card-actions .btn { flex: 1; justify-content: center; }
.family-cards-empty { text-align: center; padding: var(--space-3xl) var(--space-xl); }
.family-cards-error { text-align: center; padding: var(--space-xl); color: var(--danger); font-weight: var(--font-semibold); }
.family-card-skeleton { pointer-events: none; }
.family-card-skeleton-line { height: 14px; background: var(--border-light); border-radius: var(--radius-sm); margin-bottom: 12px; animation: shimmer 1.5s ease-in-out infinite; }
.family-card-skeleton .family-card-skeleton-line:last-child { margin-bottom: 0; }
@media (max-width: 768px) { .family-cards-grid { grid-template-columns: 1fr; gap: var(--space-md); } .family-card-body { padding: var(--space-md); } .family-card-avatar { width: 38px; height: 38px; font-size: 1rem; } .family-card-name { font-size: var(--font-size-base); } }
@media (max-width: 480px) { .family-card-actions .btn { min-height: 38px; font-size: var(--font-size-xs); } }

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

/* ============================================
   PASSWORD STRENGTH BAR
   ============================================ */
.pw-strength-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 4px;
  transition: background var(--transition);
}

.pw-strength-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease, background 0.3s ease;
}

.pw-strength-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-semibold);
  transition: color 0.3s ease;
}

/* ============================================
   CONFIRM / ALERT DIALOG
   ============================================ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-toast) + 10);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.confirm-dialog {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 420px;
  text-align: center;
  padding: var(--space-xl) var(--space-xl) var(--space-lg);
  animation: confirmSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid var(--border);
}

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

.confirm-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-md);
  line-height: 1;
}

.confirm-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.confirm-message {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
  line-height: var(--leading-relaxed);
}

.confirm-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
}

.confirm-actions .btn {
  min-width: 120px;
  padding: 10px 24px;
  font-weight: var(--font-semibold);
  border-radius: var(--radius-full);
}

/* ============================================
   FOCUS VISIBLE
   ============================================ */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================
   STAGGERED FADE-IN ANIMATIONS
   ============================================ */
/* Stat cards staggered entry */
.stats-grid .stat-card {
  animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.stats-grid .stat-card:nth-child(1) { animation-delay: 40ms; }
.stats-grid .stat-card:nth-child(2) { animation-delay: 100ms; }
.stats-grid .stat-card:nth-child(3) { animation-delay: 160ms; }
.stats-grid .stat-card:nth-child(4) { animation-delay: 220ms; }
.stats-grid .stat-card:nth-child(5) { animation-delay: 280ms; }
.stats-grid .stat-card:nth-child(6) { animation-delay: 340ms; }

/* Content cards staggered entry */
.content-area .card {
  animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.content-area .card:nth-child(1) { animation-delay: 0ms; }
.content-area .card:nth-child(2) { animation-delay: 80ms; }
.content-area .card:nth-child(3) { animation-delay: 160ms; }
.content-area .card:nth-child(4) { animation-delay: 240ms; }
.content-area .card:nth-child(5) { animation-delay: 320ms; }
.content-area .card:nth-child(6) { animation-delay: 400ms; }
.content-area .card:nth-child(7) { animation-delay: 480ms; }
.content-area .card:nth-child(8) { animation-delay: 560ms; }

/* Grid cards staggered entry */
.grid-2 .card,
.grid-3 .card,
.grid-4 .card {
  animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.grid-2 .card:nth-child(1),
.grid-3 .card:nth-child(1),
.grid-4 .card:nth-child(1) { animation-delay: 0ms; }
.grid-2 .card:nth-child(2),
.grid-3 .card:nth-child(2),
.grid-4 .card:nth-child(2) { animation-delay: 100ms; }
.grid-3 .card:nth-child(3),
.grid-4 .card:nth-child(3) { animation-delay: 200ms; }
.grid-4 .card:nth-child(4) { animation-delay: 300ms; }

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .card:hover, .stat-card:hover, .btn:hover {
    transform: none;
  }
  .stats-grid .stat-card,
  .content-area .card,
  .grid-2 .card, .grid-3 .card, .grid-4 .card,
  .crud-card, .family-card, .dose-list-item {
    animation: none !important;
    opacity: 1;
  }
  .top-header {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--bg-card);
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  [data-theme="dark"] { --bg-body: #fff; --bg-card: #fff; --text-primary: #000; --text-secondary: #333; --border: #ddd; }
  .sidebar, .top-header, .hamburger, .sidebar-overlay { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
  .content-area .card,
  .stats-grid .stat-card,
  .grid-2 .card, .grid-3 .card, .grid-4 .card,
  .crud-card, .family-card, .dose-list-item { animation: none !important; opacity: 1; }
}

/* ============================================
   RESPONSIVE — TABLET (<=1024px)
   ============================================ */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }

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

  .content-area {
    padding: var(--space-lg);
  }

  .form-row {
    grid-template-columns: 1fr;
  }

    /* Mini-sidebar on tablet (icon-only when collapsed) */
  .sidebar-overlay {
    display: none !important;
  }

  .sidebar {
    width: var(--sidebar-mini-width);
    transform: none;
    height: 100vh;
    overflow: visible;
    transition: width var(--transition-sidebar), box-shadow var(--transition-sidebar);
  }

  .sidebar.open {
    width: var(--sidebar-width);
    box-shadow: var(--shadow-xl);
  }

  /* Stagger indices for sidebar nav children */
  .sidebar-nav > :nth-child(1) { --stagger-i: 1; }
  .sidebar-nav > :nth-child(2) { --stagger-i: 2; }
  .sidebar-nav > :nth-child(3) { --stagger-i: 3; }
  .sidebar-nav > :nth-child(4) { --stagger-i: 4; }
  .sidebar-nav > :nth-child(5) { --stagger-i: 5; }
  .sidebar-nav > :nth-child(6) { --stagger-i: 6; }
  .sidebar-nav > :nth-child(7) { --stagger-i: 7; }
  .sidebar-nav > :nth-child(8) { --stagger-i: 8; }
  .sidebar-nav > :nth-child(9) { --stagger-i: 9; }
  .sidebar-nav > :nth-child(10) { --stagger-i: 10; }
  .sidebar-nav > :nth-child(11) { --stagger-i: 11; }
  .sidebar-nav > :nth-child(12) { --stagger-i: 12; }
  .sidebar-nav > :nth-child(13) { --stagger-i: 13; }
  .sidebar-nav > :nth-child(14) { --stagger-i: 14; }
  .sidebar-nav > :nth-child(15) { --stagger-i: 15; }
  .sidebar-nav > :nth-child(16) { --stagger-i: 16; }
  .sidebar-nav > :nth-child(17) { --stagger-i: 17; }
  .sidebar-nav > :nth-child(18) { --stagger-i: 18; }
  .sidebar-nav > :nth-child(19) { --stagger-i: 19; }
  .sidebar-nav > :nth-child(20) { --stagger-i: 20; }

  /* Stagger indices for footer children */
  .sidebar-footer > :nth-child(1) { --stagger-i: 1; }
  .sidebar-footer > :nth-child(2) { --stagger-i: 2; }
  .sidebar-footer > :nth-child(3) { --stagger-i: 3; }
  .sidebar-footer > :nth-child(4) { --stagger-i: 4; }
  .sidebar-footer > :nth-child(5) { --stagger-i: 5; }

  /* Hide text labels when sidebar is collapsed (snappy collapse — no delay) */
  .sidebar-brand-text,
  .sidebar-section-label,
  .sidebar-user-info {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity var(--transition-label), max-width var(--transition-label);
    transition-delay: 0s;
  }

  .sidebar.open .sidebar-brand-text,
  .sidebar.open .sidebar-section-label,
  .sidebar.open .sidebar-user-info {
    opacity: 1;
    max-width: 200px;
    transition-delay: calc(var(--stagger-i, 0) * 25ms);
  }

  .sidebar-link span:last-child {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity var(--transition-label), max-width var(--transition-label);
    transition-delay: 0s;
  }

  .sidebar.open .sidebar-link span:last-child {
    opacity: 1;
    max-width: 200px;
    transition-delay: calc(var(--stagger-i, 0) * 25ms);
  }

  .sidebar-brand {
    gap: 0;
    padding: var(--space-md) 0;
    justify-content: center;
  }

  .sidebar.open .sidebar-brand {
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-lg) var(--space-md);
    justify-content: flex-start;
  }

  .sidebar-nav {
    padding: var(--space-sm) var(--space-xs);
  }

  .sidebar.open .sidebar-nav {
    padding: var(--space-sm) var(--space-sm);
  }

  .sidebar-link {
    padding: 10px;
    justify-content: center;
    gap: 0;
    border-radius: 0;
    transition-delay: 0s;
  }

  /* In collapsed state (70px), hide close button and brand text wrapper to prevent overflow */
    .sidebar:not(.open) .sidebar-brand > .flex-1 {
    display: none;
  }

  /* Tooltip on hover for mini-sidebar icons */
  .sidebar:not(.open) .sidebar-link:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #f1f5f9;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: var(--font-medium);
    white-space: nowrap;
    z-index: var(--z-tooltip);
    pointer-events: none;
    box-shadow: var(--shadow-md);
    line-height: 1.4;
    animation: tooltipIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .sidebar:not(.open) .sidebar-link:hover::before {
    content: '';
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: #1e293b;
    z-index: var(--z-tooltip);
    pointer-events: none;
  }

  @keyframes tooltipIn {
    from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
    to { opacity: 1; transform: translateY(-50%) translateX(0); }
  }

  .sidebar.open .sidebar-link {
    padding: 10px var(--space-md);
    justify-content: flex-start;
    gap: var(--space-md);
    border-radius: var(--radius);
    transition-delay: calc(var(--stagger-i, 0) * 25ms);
  }

  .sidebar-link .icon {
    width: auto;
    font-size: 1.15rem;
  }

  .sidebar-footer {
    padding: var(--space-sm) 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .sidebar.open .sidebar-footer {
    padding: var(--space-md);
    display: block;
  }

  .sidebar-user {
    padding: 4px;
    justify-content: center;
  }

  .sidebar.open .sidebar-user {
    padding: var(--space-sm);
    justify-content: flex-start;
  }

  .sidebar-footer .sidebar-link {
    padding: 6px 0;
    justify-content: center;
    width: auto;
  }

  .sidebar.open .sidebar-footer .sidebar-link {
    padding: 8px var(--space-md);
    justify-content: flex-start;
    width: 100%;
  }

  .sidebar-logout-form {
    display: flex;
    justify-content: center;
    width: 100%;
  }

  .sidebar.open .sidebar-logout-form {
    display: block;
  }

  .hamburger {
    display: flex;
  }
}

/* ============================================
   RESPONSIVE — MOBILE (<=768px)
   ============================================ */
@media (max-width: 768px) {
  /* Sidebar overlay on mobile (override mini-sidebar from tablet) */
  .sidebar {
    width: var(--sidebar-width);
    transform: translateX(-100%);
    height: 100dvh;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  .sidebar-link {
    padding: 12px var(--space-md);
    justify-content: flex-start;
    gap: var(--space-md);
    border-radius: var(--radius);
    min-height: 44px;
    touch-action: manipulation;
  }

  .sidebar-nav {
    padding: var(--space-sm) var(--space-sm);
  }

  .sidebar-footer {
    padding: var(--space-md);
    display: block;
  }

  .sidebar-user {
    padding: var(--space-sm);
    justify-content: flex-start;
  }

  .sidebar-footer .sidebar-link {
    padding: 12px var(--space-md);
    justify-content: flex-start;
    width: 100%;
  }

  .sidebar-logout-form {
    display: block;
  }

  /* Remove backdrop-filter from overlay to prevent scroll jank on Android */
  .sidebar-overlay {
    display: block !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .top-header {
    height: 56px;
    padding: 0 var(--space-sm);
  }

  .content-area {
    padding: 12px;
  }

  .card {
    border-radius: var(--radius);
  }

  .card:not([class*="mb-"]) {
    margin-bottom: 12px;
  }

  .card-body {
    padding: 12px;
  }

  .card-header {
    padding: 12px;
  }

  .card > .table-wrapper,
  .card > .table-responsive-mobile {
    border: none;
    border-radius: 0;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-bottom: 12px;
  }

  .stat-card {
    padding: 12px 8px;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
    min-height: auto;
  }

  .stat-card::before {
    width: 100%;
    height: 3px;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .stat-icon {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  .stat-value {
    font-size: var(--font-size-base);
    line-height: 1.2;
  }

  .stat-label {
    font-size: 0.6rem;
  }

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

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

  .page-title {
    font-size: var(--font-size-base);
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .btn-group {
    width: 100%;
  }

  .btn-group .btn {
    flex: 1;
    min-height: 44px;
  }

  .btn-block {
    width: 100%;
  }

  .btn {
    min-height: 44px;
    padding: 10px 16px;
    touch-action: manipulation;
  }

  .btn-sm {
    min-height: 36px;
    padding: 6px 12px;
  }

  .table-wrapper {
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table.table-mobile-stack {
    min-width: 100%;
  }

  .table:not(.table-mobile-stack) {
    min-width: 500px;
  }

  .table th,
  .table td {
    padding: 10px 12px;
    font-size: var(--font-size-xs);
  }

  .dose-list-item {
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: 10px 0;
  }

  .dose-list-meta {
    width: 100%;
    text-align: left;
    display: flex;
    gap: var(--space-sm);
    align-items: center;
    flex-wrap: wrap;
  }

  .modal {
    margin: 8px;
    max-height: calc(100dvh - 16px);
    border-radius: var(--radius-lg);
  }

  .modal-body {
    padding: 12px;
  }

  .modal-header {
    padding: 12px;
  }

  .toast-container {
    top: 8px;
    right: 8px;
    left: 8px;
    max-width: none;
    width: auto;
  }

  h1 { font-size: var(--font-size-xl); }
  h2 { font-size: var(--font-size-lg); }
  h3 { font-size: var(--font-size-base); }

  /* Improves touch experience for hamburger and theme toggle */
  .hamburger {
    min-width: 44px;
    min-height: 44px;
  }

  .theme-toggle {
    width: 44px;
    height: 44px;
  }

  /* Fix scrolling on iOS */
  .content-area {
    -webkit-overflow-scrolling: touch;
  }

  .app-layout {
    overflow-x: hidden;
  }

  .main-content {
    overflow-x: hidden;
  }
}

/* ============================================
   RESPONSIVE — SMALL MOBILE (<=480px)
   ============================================ */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .stat-card {
    padding: 8px 6px;
    min-height: 60px;
  }

  .stat-icon {
    width: 26px;
    height: 26px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
  }

  .stat-value {
    font-size: var(--font-size-sm);
  }

  .stat-label {
    font-size: 0.55rem;
    letter-spacing: 0.02em;
  }

  .content-area {
    padding: 8px;
  }

  .card {
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
  }

  .card-header,
  .card-body {
    padding: 8px;
  }

  .btn {
    padding: 10px 12px;
    font-size: var(--font-size-xs);
    min-height: 40px;
  }

  .btn-sm {
    padding: 6px 10px;
    min-height: 32px;
    font-size: 0.7rem;
  }

  .form-input,
  .form-select,
  .form-textarea {
    padding: 10px 10px;
    font-size: 16px; /* Prevent iOS zoom on focus */
  }

  .sidebar-brand {
    padding: var(--space-md);
  }

  .sidebar-link {
    padding: 10px var(--space-md);
    min-height: 40px;
  }

  .badge {
    padding: 2px 6px;
    font-size: 0.6rem;
  }

  .top-header {
    height: 50px;
    padding: 0 6px;
  }

  .page-title {
    font-size: var(--font-size-sm);
  }

  .hamburger {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
  }

  .table td,
  .table th {
    padding: 8px 8px;
    font-size: 0.7rem;
  }

  .modal {
    margin: 4px;
    border-radius: var(--radius);
  }

  /* Settings page: form buttons full-width */
  .card-body .btn-primary[type="submit"],
  .card-body .btn-secondary {
    width: 100%;
    justify-content: center;
  }

  /* Push notification section: stack buttons */
  #pushStatus + .btn-primary,
  #pushStatus ~ .btn-danger {
    width: 100%;
    justify-content: center;
    margin-top: 8px;
  }

  /* Smaller form row gap on very small screens */
  .form-row {
    gap: var(--space-sm);
  }

}
