/* ============================================================================
   Health Dashboard - Mobile-First UX Design System
   Based on UX_GUIDELINES.md v1.0
   Last Updated: 2025-10-27
   ============================================================================ */

/* ============================================================================
   1. CSS VARIABLES - Design Tokens
   ============================================================================ */

:root {
  /* Primary Colors - Dark Theme (App-Wide Default) */
  --primary-green: #81C784;
  --primary-blue: #64B5F6;
  --primary-red: #FF3D00;
  --primary-yellow: #FFB300;

  /* Semantic Health Colors */
  --glucose-critical-low: #D50000;
  --glucose-low: #FF6D00;
  --glucose-target: #00C853;
  --glucose-high: #FFB300;
  --glucose-critical-high: #D50000;

  --activity-run: #FF6B35;
  --activity-ride: #4ECDC4;
  --activity-swim: #2196F3;
  --activity-other: #95A5A6;

  /* Neutral Colors - Dark Theme (App-Wide Default) */
  --gray-900: #E0E0E0;
  --gray-800: #BDBDBD;
  --gray-700: #9E9E9E;
  --gray-600: #757575;
  --gray-500: #616161;
  --gray-400: #424242;
  --gray-300: #424242;
  --gray-200: #303030;
  --gray-100: #212121;
  --white: #121212;

  /* Background Colors - Dark Theme */
  --card-bg: #1E1E1E;
  --body-bg: #121212;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-success: linear-gradient(135deg, #00C853 0%, #00E676 100%);
  --gradient-warning: linear-gradient(135deg, #FFB300 0%, #FFC107 100%);
  --gradient-danger: linear-gradient(135deg, #FF3D00 0%, #FF6E40 100%);

  /* Typography */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  --text-4xl: 36px;
  --text-5xl: 48px;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Spacing (8px base unit) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.15);

  /* Easing Functions */
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Dark Theme is now the App-Wide Default */
/* Future: Add light theme support via theme toggle/switcher */
/* @media (prefers-color-scheme: light) {
  :root {
    --gray-900: #212121;
    --gray-800: #424242;
    --gray-700: #616161;
    --gray-300: #E0E0E0;
    --gray-100: #F5F5F5;
    --white: #FFFFFF;
    --primary-blue: #2196F3;
    --primary-green: #00C853;
    --card-bg: #FFFFFF;
    --body-bg: #F5F5F5;
  }
} */

/* Image opacity for dark theme */
img {
  opacity: 0.9;
}

/* ============================================================================
   2. RESET & BASE STYLES
   ============================================================================ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden; /* Prevent horizontal scroll on entire page */
}

body {
  overflow-x: hidden; /* Prevent horizontal scroll on body */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
               'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans',
               'Helvetica Neue', sans-serif;
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: 1.5;
  color: var(--gray-900);
  background: var(--gray-100);
  margin: 0;
  padding: 0;
  padding-top: 64px; /* Space for fixed header on mobile */
  padding-bottom: calc(72px + env(safe-area-inset-bottom)); /* Bottom nav on mobile */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================================
   3. LAYOUT - Mobile First
   ============================================================================ */

.container {
  width: 100%;
  max-width: 100vw; /* Never exceed viewport width */
  padding: var(--space-4);
  margin: 0 auto;
  box-sizing: border-box;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

@media (min-width: 768px) {
  .container {
    max-width: 720px;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 960px;
  }
}

@media (min-width: 1280px) {
  .container {
    max-width: 1200px;
  }
}

/* Main Content Wrappers (for pages like Logs, CGM) */
.logs-main,
.cgm-main {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

@media (min-width: 768px) {
  .logs-main,
  .cgm-main {
    padding: var(--space-8);
  }
}

@media (min-width: 1600px) {
  .container {
    max-width: 1400px;
  }
}

@media (min-width: 1920px) {
  .container {
    max-width: 1600px;
  }
}

/* ============================================================================
   4. TOP HEADER - Fixed Position
   ============================================================================ */

.top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(56px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-left: var(--space-2);
  padding-right: var(--space-2);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--gray-300);
  display: flex;
  align-items: center;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--gray-900);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.header-logo img {
  width: 32px;
  height: 32px;
}

.header-title {
  flex: 1;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.header-actions {
  display: flex;
  gap: var(--space-1);
}

/* ============================================================================
   5. BOTTOM NAVIGATION - Mobile Primary Nav
   ============================================================================ */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--white);
  border-top: 1px solid var(--gray-300);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  max-width: 100vw;
  padding: 0 var(--space-1);
}

.bottom-nav::-webkit-scrollbar {
  display: none;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 60px;
  max-width: 100px;
  height: 64px;
  text-decoration: none;
  color: var(--gray-700);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: var(--space-1);
  gap: 2px;
}

.nav-item:active {
  transform: scale(0.95);
}

.nav-item.active {
  color: #FC4C02;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: linear-gradient(135deg, #FC4C02 0%, #ff6b35 100%);
  border-radius: 0 0 3px 3px;
}

.nav-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.05));
  transition: all 0.2s ease;
}

.nav-item.active .nav-icon {
  transform: scale(1.1);
  filter: drop-shadow(0 2px 3px rgba(252, 76, 2, 0.3));
}

.nav-label {
  font-size: 11px;
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.2;
}

/* ============================================================================
   BOTTOM NAV RESPONSIVE BREAKPOINTS
   ============================================================================ */

/* Extra Small Mobile (<320px) - Ultra compact */
@media (max-width: 319px) {
  .bottom-nav {
    height: calc(56px + env(safe-area-inset-bottom));
    padding: 0;
    justify-content: flex-start;
  }

  .nav-item {
    min-width: 45px;
    max-width: 60px;
    height: 56px;
    padding: var(--space-1) 2px;
  }

  .nav-icon {
    width: 20px;
    height: 20px;
  }

  .nav-label {
    font-size: 9px;
  }

  .nav-item.active::before {
    width: 24px;
    height: 2px;
  }
}

/* Small Mobile (320px - 359px) - Galaxy Fold, compact phones */
@media (min-width: 320px) and (max-width: 359px) {
  .bottom-nav {
    height: calc(58px + env(safe-area-inset-bottom));
    padding: 0 var(--space-1);
  }

  .nav-item {
    min-width: 46px;
    max-width: 65px;
    height: 58px;
  }

  .nav-icon {
    width: 22px;
    height: 22px;
  }

  .nav-label {
    font-size: 10px;
  }

  .nav-item.active::before {
    width: 28px;
  }
}

/* Standard Mobile (360px - 479px) - iPhone SE, standard phones */
@media (min-width: 360px) and (max-width: 479px) {
  .bottom-nav {
    height: calc(60px + env(safe-area-inset-bottom));
    padding: 0 var(--space-1);
  }

  .nav-item {
    min-width: 50px;
    max-width: 75px;
    height: 60px;
  }

  .nav-icon {
    width: 23px;
    height: 23px;
  }

  .nav-label {
    font-size: 10.5px;
  }
}

/* Large Mobile (480px - 639px) - Large phones */
@media (min-width: 480px) and (max-width: 639px) {
  .bottom-nav {
    height: calc(64px + env(safe-area-inset-bottom));
    padding: 0 var(--space-2);
  }

  .nav-item {
    min-width: 65px;
    max-width: 90px;
    height: 64px;
  }

  .nav-icon {
    width: 25px;
    height: 25px;
  }

  .nav-label {
    font-size: 11.5px;
  }

  .nav-item.active::before {
    width: 36px;
  }
}

/* Extra Large Mobile / Small Tablet (640px - 767px) */
@media (min-width: 640px) and (max-width: 767px) {
  .bottom-nav {
    height: calc(68px + env(safe-area-inset-bottom));
    padding: 0 var(--space-3);
  }

  .nav-item {
    min-width: 75px;
    max-width: 100px;
    height: 68px;
  }

  .nav-icon {
    width: 26px;
    height: 26px;
  }

  .nav-label {
    font-size: 12px;
  }

  .nav-item.active::before {
    width: 40px;
  }
}

/* Desktop - Hide bottom nav, show desktop nav instead */
@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

/* ============================================================================
   6. CARDS - Primary Content Container
   ============================================================================ */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-md);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}

.card-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: 0;
}

.card-action {
  padding: var(--space-2);
  background: transparent;
  border: none;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
}

.card-action:active {
  background: var(--gray-100);
  transform: scale(0.95);
}

.card-body {
  margin-bottom: var(--space-3);
}

.card-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--gray-300);
}

/* ============================================================================
   Statistics Grid - Responsive Layout
   ============================================================================ */

.stats-grid {
  display: grid;
  gap: var(--space-3);
}

/* Mobile: 2 columns (default) - Best for small screens */
.stats-grid {
  grid-template-columns: repeat(2, 1fr);
}

/* Tablet: 2 columns - Maintain readability with larger cards */
@media (min-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Large Tablet/Small Desktop: 4 columns - Optimal use of horizontal space */
@media (min-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Desktop/Large screens: 4 columns with enhanced spacing */
@media (min-width: 1280px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ============================================================================
   Compact Glucose Card - Horizontal Layout
   ============================================================================ */

.card-glucose-compact {
  background: var(--gradient-primary);
  color: white;
  padding: var(--space-4);
}

.glucose-compact-grid {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: var(--space-4);
  align-items: center;
}

/* Mobile: Stack vertically */
@media (max-width: 767px) {
  .glucose-compact-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
}

/* Left: Main Reading */
.glucose-main {
  text-align: center;
}

.glucose-label {
  font-size: var(--text-sm);
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-1);
}

.glucose-reading {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
}

.glucose-value {
  font-size: var(--text-5xl);
  font-weight: var(--weight-bold);
  line-height: 1;
  transition: color 0.3s ease;
}

.glucose-unit {
  font-size: var(--text-base);
  opacity: 0.8;
}

.glucose-time {
  font-size: var(--text-xs);
  opacity: 0.7;
}

/* Middle: Visual Gauge */
.glucose-gauge {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.gauge-container {
  position: relative;
}

.gauge-track {
  height: 40px;
  border-radius: var(--radius-full);
  overflow: hidden;
  display: flex;
  position: relative;
  background: rgba(255, 255, 255, 0.2);
}

.gauge-zone {
  height: 100%;
  transition: opacity 0.3s ease;
}

.gauge-zone-low {
  width: 11.5%;  /* 40-70 out of 40-300 range */
  background: rgba(255, 109, 0, 0.3);
}

.gauge-zone-target {
  width: 42.3%;  /* 70-180 out of 40-300 range */
  background: rgba(0, 200, 83, 0.4);
}

.gauge-zone-high {
  width: 46.2%;  /* 180-300 out of 40-300 range */
  background: rgba(255, 179, 0, 0.3);
}

.gauge-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  background: white;
  border: 3px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: left 0.5s ease;
  z-index: 10;
}

.gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  opacity: 0.7;
  margin-top: var(--space-1);
}

.gauge-label {
  font-size: var(--text-xs);
}

/* Right: Trend & Status */
.glucose-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.trend-display {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.trend-arrow-large {
  font-size: var(--text-4xl);
  line-height: 1;
}

.trend-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.trend-delta {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: 1;
}

.trend-label {
  font-size: var(--text-xs);
  opacity: 0.8;
}

.glucose-range-badge {
  padding: var(--space-1) var(--space-3);
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  transition: background 0.3s ease;
}

.glucose-range-badge.in-range {
  background: rgba(0, 200, 83, 0.3);
}

.glucose-range-badge.high {
  background: rgba(255, 179, 0, 0.3);
}

.glucose-range-badge.low {
  background: rgba(255, 109, 0, 0.3);
}

/* ============================================================================
   Activities List - Responsive Grid Layout
   ============================================================================ */

#activities-list {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(2, 1fr); /* Mobile: 2 columns */
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Tablet: 2 columns */
@media (min-width: 768px) {
  #activities-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Large Tablet: 3 columns */
@media (min-width: 1024px) {
  #activities-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Desktop: 4 columns */
@media (min-width: 1280px) {
  #activities-list {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Large Desktop: 5 columns */
@media (min-width: 1600px) {
  #activities-list {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* Extra Large Desktop: Auto-fit based on card width (dynamic) */
@media (min-width: 1920px) {
  #activities-list {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

/* Activity Card */
.card-activity {
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  aspect-ratio: 1 / 1.2; /* Width to height ratio - creates uniform cards */
  width: 100%;
  box-sizing: border-box;
  overflow: hidden; /* Prevent content overflow */
}

.card-activity:active {
  transform: scale(0.98);
}

.card-activity .card-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-shrink: 0; /* Prevent header from shrinking */
}

.activity-icon {
  font-size: 32px;
  line-height: 1;
  flex-shrink: 0;
}

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

.activity-name {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: 0 0 var(--space-1) 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-time {
  font-size: var(--text-sm);
  color: var(--gray-700);
}

.activity-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-grow: 0; /* Don't stretch stats section */
  flex-shrink: 0; /* Keep stats section consistent size */
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 60px; /* Consistent stat height */
}

.stat-value {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--gray-900);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--gray-700);
  margin-top: var(--space-1);
}

.activity-secondary {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: flex-end; /* Align pills to bottom */
  flex-grow: 1; /* Take up remaining space */
  align-content: flex-end; /* Push pills to bottom when wrapped */
}

.stat-pill {
  padding: var(--space-1) var(--space-2);
  background: var(--gray-100);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--gray-800);
}

/* ============================================================================
   7. BUTTONS - Touch Optimized
   ============================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  min-width: 48px;
  padding: 0 var(--space-6);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--primary-blue);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background: #1976D2;
}

.btn-primary:active {
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: transparent;
  color: var(--primary-blue);
  border: 2px solid var(--primary-blue);
}

.btn-secondary:hover {
  background: rgba(33, 150, 243, 0.05);
}

.btn-warning {
  background: #FF9800;
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-warning:hover {
  background: #F57C00;
}

.btn-warning:active {
  box-shadow: var(--shadow-sm);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-icon:hover {
  background: var(--gray-100);
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-icon svg {
  width: 24px;
  height: 24px;
}

/* Floating Action Button */
.fab {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  right: var(--space-4);
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--primary-blue);
  color: white;
  border: none;
  box-shadow: var(--shadow-xl);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.fab:active {
  transform: scale(0.95);
}

.fab svg {
  width: 24px;
  height: 24px;
}

/* ============================================================================
   8. LOADING STATES - Skeleton Screens
   ============================================================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-100) 25%,
    var(--gray-300) 50%,
    var(--gray-100) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

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

.skeleton-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-md);
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: var(--space-3);
}

.skeleton-text {
  height: 16px;
  width: 100%;
  margin-bottom: var(--space-2);
}

.skeleton-text:last-of-type {
  width: 80%;
}

.skeleton-button {
  height: 48px;
  width: 120px;
  margin-top: var(--space-4);
}

/* Spinner (when necessary) */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-300);
  border-top-color: var(--primary-blue);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

/* ============================================================================
   9. ANIMATIONS & TRANSITIONS
   ============================================================================ */

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

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

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.fade-in {
  animation: fadeIn 0.3s var(--ease-out);
}

.slide-up {
  animation: slideUp 0.4s var(--ease-out);
}

.scale-in {
  animation: scaleIn 0.3s var(--ease-out);
}

.pulse {
  animation: pulse 2s var(--ease-in-out) infinite;
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================================
   10. TOAST NOTIFICATIONS & ERROR BANNERS
   ============================================================================ */

.toast {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  left: var(--space-4);
  right: var(--space-4);
  padding: var(--space-4);
  background: #1E1E1E;
  color: #FFFFFF;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  z-index: 2000;
  animation: slideUp 0.3s var(--ease-out);
}

/* Sync Error Banner - Inline above dashboard */
.sync-error-banner {
  background: rgba(213, 0, 0, 0.1);
  border: 2px solid #D50000;
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  animation: slideUp 0.3s var(--ease-out);
}

.sync-error-icon {
  font-size: 24px;
  flex-shrink: 0;
  line-height: 1;
}

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

.sync-error-content strong {
  display: block;
  color: #D50000;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

.sync-error-content p {
  margin: 0;
  color: var(--gray-800);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.sync-error-close {
  padding: var(--space-1);
  background: transparent;
  border: none;
  color: #D50000;
  cursor: pointer;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
}

.sync-error-close:hover {
  background: rgba(213, 0, 0, 0.1);
}

.sync-error-close:active {
  transform: scale(0.95);
}

.sync-error-close svg {
  width: 20px;
  height: 20px;
}

/* Last Sync Time Display */
.last-sync-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2);
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
  color: var(--gray-600);
  text-align: center;
}

.last-sync-info .sync-icon {
  font-size: 16px;
  opacity: 0.7;
}

.last-sync-info .sync-time {
  font-weight: var(--weight-medium);
  color: var(--gray-700);
}

.toast-success {
  background: #00C853;
  color: #212121;
}

.toast-error {
  background: #D50000;
  color: #FFFFFF;
}

.toast-warning {
  background: #FFB300;
  color: #212121;
}

.toast-icon {
  font-size: 24px;
  flex-shrink: 0;
}

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

.toast-message {
  margin: 0;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
}

.toast-close {
  padding: var(--space-1);
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-close svg {
  width: 20px;
  height: 20px;
}

/* ============================================================================
   11. CHARTS - Responsive
   ============================================================================ */

.chart-container {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-md);
}

.chart-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: var(--space-3);
}

.chart-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: 0;
  margin-bottom: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chart-description {
  font-size: var(--text-sm);
  color: var(--gray-600);
  margin: 0;
  line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
  .chart-description {
    color: var(--gray-400);
  }
}

/* Info Icon & Tooltip */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--gray-400);
  color: var(--gray-700);
  font-size: 11px;
  font-weight: var(--weight-bold);
  cursor: help;
  position: relative;
  transition: all 0.2s ease;
  user-select: none;
}

.info-icon:hover {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
  color: white;
  transform: scale(1.1);
}

.info-icon.active {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
  color: white;
}

/* Dark mode support for info icon */
@media (prefers-color-scheme: dark) {
  .info-icon {
    border-color: var(--gray-500);
    color: var(--gray-400);
  }

  .info-icon:hover,
  .info-icon.active {
    background: var(--primary-blue);
    border-color: var(--primary-blue);
    color: white;
  }
}

/* Tooltip Overlay - Modal Style */
.info-tooltip {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30vw;
  height: 30vh;
  min-width: 150px;
  min-height: 120px;
  max-width: 95vw;
  max-height: 95vh;
  background: rgba(30, 41, 59, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(59, 130, 246, 0.5);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  color: #ffffff;
  padding: var(--space-5);
  padding-top: var(--space-8);
  padding-bottom: var(--space-7);
  border-radius: var(--radius-xl);
  font-size: var(--text-sm);
  line-height: 1.6;
  z-index: 10000;
  overflow: auto;
  overscroll-behavior: contain;
  resize: both;
  animation: tooltipFadeIn 0.2s ease-out;
}

/* Resize handle indicator */
.info-tooltip::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  background: linear-gradient(
    135deg,
    transparent 0%,
    transparent 40%,
    rgba(255, 255, 255, 0.3) 40%,
    rgba(255, 255, 255, 0.3) 45%,
    transparent 45%,
    transparent 55%,
    rgba(255, 255, 255, 0.3) 55%,
    rgba(255, 255, 255, 0.3) 60%,
    transparent 60%,
    transparent 70%,
    rgba(255, 255, 255, 0.3) 70%,
    rgba(255, 255, 255, 0.3) 75%,
    transparent 75%
  );
  pointer-events: none;
}

/* Backdrop for tooltip */
.info-tooltip::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: -1;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -45%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.info-icon.active .info-tooltip {
  display: block;
}

/* Close button for tooltip */
.info-tooltip-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  color: #ffffff;
  transition: all 0.2s ease;
  z-index: 1;
}

.info-tooltip-close:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.1);
}

.info-tooltip-close:active {
  transform: scale(0.95);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .info-tooltip {
    background: rgba(15, 23, 42, 0.98);
    border-color: rgba(59, 130, 246, 0.6);
    color: #ffffff;
    box-shadow:
      0 20px 60px rgba(0, 0, 0, 0.7),
      0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  }

  .info-tooltip::before {
    background: rgba(0, 0, 0, 0.85);
  }

  .info-tooltip-close {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
  }

  .info-tooltip-close:hover {
    background: rgba(255, 255, 255, 0.2);
  }
}

/* Mobile optimization */
@media (max-width: 640px) {
  .info-tooltip {
    width: 50vw;
    height: 40vh;
    min-width: 120px;
    min-height: 100px;
    max-width: 95vw;
    max-height: 90vh;
    font-size: var(--text-xs);
    padding: var(--space-3);
    padding-top: var(--space-6);
    padding-bottom: var(--space-6);
  }

  .info-tooltip-close {
    top: var(--space-2);
    right: var(--space-2);
    width: 28px;
    height: 28px;
    font-size: 18px;
  }

  .info-tooltip::after {
    width: 12px;
    height: 12px;
    bottom: 2px;
    right: 2px;
  }
}

/* Tablet optimization */
@media (min-width: 641px) and (max-width: 1024px) {
  .info-tooltip {
    width: 35vw;
    height: 35vh;
    min-width: 180px;
    min-height: 150px;
  }
}

/* Desktop: Hover to show tooltip */
@media (min-width: 768px) {
  .info-icon:hover .info-tooltip {
    display: block;
  }
}

/* Large desktop optimization */
@media (min-width: 1025px) {
  .info-tooltip {
    width: 25vw;
    height: 30vh;
    min-width: 200px;
    min-height: 180px;
    max-width: 800px;
    max-height: 85vh;
    font-size: var(--text-base);
  }
}

.chart-filters {
  display: flex;
  gap: var(--space-1);
}

.filter-pill {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: transparent;
  color: var(--gray-700);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 32px;
}

.filter-pill.active {
  background: var(--primary-blue);
  color: white;
}

.chart-wrapper {
  position: relative;
  height: 300px;
}

@media (min-width: 768px) {
  .chart-wrapper {
    height: 400px;
  }
}

/* ============================================================================
   12. UTILITY CLASSES
   ============================================================================ */

.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ============================================================================
   13. RESPONSIVE BREAKPOINTS
   ============================================================================ */

/* Small phones */
@media (max-width: 374px) {
  :root {
    --text-5xl: 40px;
    --text-4xl: 32px;
  }
}

/* Standard phones */
@media (min-width: 375px) and (max-width: 428px) {
  /* Mobile-first styles applied by default */
}

/* Large phones */
@media (min-width: 429px) and (max-width: 767px) {
  .container {
    padding: var(--space-5);
  }
}

/* Tablets and Desktop */
@media (min-width: 768px) {
  body {
    padding-top: 80px; /* Taller header on desktop */
    padding-bottom: 0; /* No bottom nav on desktop, footer is inline */
  }
}

/* Tablets */
@media (min-width: 768px) and (max-width: 1024px) {
  .container {
    padding: var(--space-6);
  }
}

/* Desktop */
@media (min-width: 1025px) {
  .container {
    padding: var(--space-8);
  }

  body {
    padding-bottom: 0; /* No bottom nav on desktop, footer is inline */
  }
}
