/**
 * Mobile Gold-Standard Design System for LevoroFit
 * Industry-standard mobile UX patterns with premium UI/UX
 * 
 * Based on:
 * - Material Design 3 guidelines
 * - iOS Human Interface Guidelines
 * - Health & Fitness app best practices
 * - WCAG 2.1 accessibility standards
 * 
 * Key Features:
 * - 44px minimum touch targets (industry standard)
 * - Safe area insets for iOS notch/status bar
 * - Smooth animations (60fps)
 * - Thumb-friendly navigation zones
 * - Progressive disclosure patterns
 * - Micro-interactions
 * - Skeleton loading states
 * - Pull-to-refresh support
 * - Bottom sheet modals
 * - Swipe gestures
 */

/* ============================================
   MOBILE DESIGN TOKENS (Design System Variables)
   ============================================ */
:root {
  /* Spacing Scale (8px base) */
  --mobile-space-xs: 0.25rem;   /* 4px */
  --mobile-space-sm: 0.5rem;    /* 8px */
  --mobile-space-md: 1rem;      /* 16px */
  --mobile-space-lg: 1.5rem;    /* 24px */
  --mobile-space-xl: 2rem;      /* 32px */
  --mobile-space-2xl: 3rem;     /* 48px */
  
  /* Touch Targets */
  --touch-target-min: 44px;    /* Industry standard minimum */
  --touch-target-comfortable: 48px;
  --touch-target-large: 56px;
  
  /* Typography Scale */
  --mobile-text-xs: 0.75rem;    /* 12px */
  --mobile-text-sm: 0.875rem;   /* 14px */
  --mobile-text-base: 1rem;     /* 16px - prevents iOS zoom */
  --mobile-text-lg: 1.125rem;   /* 18px */
  --mobile-text-xl: 1.25rem;    /* 20px */
  --mobile-text-2xl: 1.5rem;    /* 24px */
  --mobile-text-3xl: 1.875rem;  /* 30px */
  --mobile-text-4xl: 2.25rem;   /* 36px */
  
  /* Border Radius */
  --mobile-radius-sm: 0.5rem;   /* 8px */
  --mobile-radius-md: 0.75rem;  /* 12px */
  --mobile-radius-lg: 1rem;     /* 16px */
  --mobile-radius-xl: 1.5rem;   /* 24px */
  --mobile-radius-full: 9999px;
  
  /* Shadows (optimized for mobile) */
  --mobile-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --mobile-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --mobile-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  
  /* Animation Durations */
  --mobile-duration-fast: 150ms;
  --mobile-duration-base: 200ms;
  --mobile-duration-slow: 300ms;
  
  /* Z-Index Scale */
  --z-base: 1;
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-sidebar: 9999;
  --z-overlay: 9998;
}

/* ============================================
   MOBILE-FIRST BASE STYLES
   ============================================ */
@media (max-width: 768px) {
  /* Base Typography - Prevent iOS zoom on input focus */
  html {
    font-size: 16px; /* Critical: Prevents iOS zoom */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  
  body {
    font-size: var(--mobile-text-base);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent horizontal scroll */
    overflow-x: hidden;
    width: 100%;
    position: relative;
  }
  
  /* Heading Hierarchy */
  h1 {
    font-size: var(--mobile-text-3xl);
    line-height: 1.2;
    font-weight: 700;
    margin-bottom: var(--mobile-space-md);
  }
  
  h2 {
    font-size: var(--mobile-text-2xl);
    line-height: 1.3;
    font-weight: 600;
    margin-bottom: var(--mobile-space-md);
  }
  
  h3 {
    font-size: var(--mobile-text-xl);
    line-height: 1.4;
    font-weight: 600;
    margin-bottom: var(--mobile-space-sm);
  }
  
  h4 {
    font-size: var(--mobile-text-lg);
    line-height: 1.4;
    font-weight: 600;
    margin-bottom: var(--mobile-space-sm);
  }
  
  /* Paragraphs */
  p {
    font-size: var(--mobile-text-base);
    line-height: 1.7;
    margin-bottom: var(--mobile-space-md);
  }
}

/* ============================================
   TOUCH TARGETS (Industry Standard: 44px minimum)
   ============================================ */
@media (max-width: 768px) {
  /* All interactive elements */
  button,
  a.btn,
  .btn,
  input[type="button"],
  input[type="submit"],
  input[type="checkbox"],
  input[type="radio"],
  .clickable,
  .touch-target,
  nav a,
  .navbar-link,
  .menu-item,
  .sidebar-nav-item,
  .card-clickable {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding: var(--mobile-space-sm) var(--mobile-space-md);
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(22, 163, 74, 0.15);
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
  }
  
  /* Comfortable touch targets for primary actions */
  .btn-primary,
  .cta-primary,
  button.primary {
    min-height: var(--touch-target-comfortable);
    padding: var(--mobile-space-md) var(--mobile-space-lg);
  }
  
  /* Large touch targets for critical actions */
  .btn-large,
  .cta-large {
    min-height: var(--touch-target-large);
    padding: var(--mobile-space-lg) var(--mobile-space-xl);
  }
}

/* ============================================
   MOBILE CARDS (Gold-Standard Design)
   ============================================ */
@media (max-width: 768px) {
  .mobile-card {
    background: white;
    border-radius: var(--mobile-radius-lg);
    padding: var(--mobile-space-lg);
    margin-bottom: var(--mobile-space-md);
    box-shadow: var(--mobile-shadow-md);
    transition: transform var(--mobile-duration-base), box-shadow var(--mobile-duration-base);
  }
  
  .mobile-card:active {
    transform: scale(0.98);
    box-shadow: var(--mobile-shadow-sm);
  }
  
  /* Card Header */
  .mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--mobile-space-md);
    padding-bottom: var(--mobile-space-sm);
    border-bottom: 1px solid #e5e7eb;
  }
  
  .mobile-card-title {
    font-size: var(--mobile-text-lg);
    font-weight: 600;
    color: #111827;
  }
  
  /* Card Content */
  .mobile-card-content {
    color: #6b7280;
    font-size: var(--mobile-text-base);
    line-height: 1.6;
  }
  
  /* Card Actions */
  .mobile-card-actions {
    display: flex;
    gap: var(--mobile-space-sm);
    margin-top: var(--mobile-space-md);
    padding-top: var(--mobile-space-md);
    border-top: 1px solid #e5e7eb;
  }
}

/* ============================================
   MOBILE FORMS (Optimized for Mobile)
   ============================================ */
@media (max-width: 768px) {
  /* Form Groups */
  .form-group,
  .form-field {
    margin-bottom: var(--mobile-space-lg);
  }
  
  /* Labels */
  label {
    display: block;
    font-size: var(--mobile-text-sm);
    font-weight: 600;
    color: #374151;
    margin-bottom: var(--mobile-space-sm);
  }
  
  /* Inputs - Critical: 16px font prevents iOS zoom */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  textarea,
  select {
    font-size: var(--mobile-text-base) !important; /* Prevents iOS zoom */
    min-height: var(--touch-target-min);
    width: 100%;
    padding: var(--mobile-space-md);
    border: 1px solid #d1d5db;
    border-radius: var(--mobile-radius-md);
    background: white;
    color: #111827;
    transition: border-color var(--mobile-duration-base), box-shadow var(--mobile-duration-base);
  }
  
  input:focus,
  textarea:focus,
  select:focus {
    outline: none;
    border-color: #16a34a;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
  }
  
  /* Select Dropdowns - Custom styling */
  select {
    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='%23374151' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--mobile-space-md) center;
    padding-right: 2.5rem;
    -webkit-appearance: none;
    appearance: none;
  }
  
  /* Textarea */
  textarea {
    min-height: 120px;
    resize: vertical;
  }
  
  /* Checkboxes and Radios - Larger touch targets */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    margin-right: var(--mobile-space-sm);
  }
}

/* ============================================
   MOBILE NAVIGATION (Thumb-Friendly Zones)
   ============================================ */
@media (max-width: 768px) {
  /* Bottom Navigation Bar (Thumb Zone) */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: var(--mobile-space-sm) 0;
    padding-bottom: calc(var(--mobile-space-sm) + env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: var(--z-fixed);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }
  
  .mobile-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--mobile-space-xs);
    padding: var(--mobile-space-sm);
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    color: #6b7280;
    text-decoration: none;
    font-size: var(--mobile-text-xs);
    transition: color var(--mobile-duration-base);
  }
  
  .mobile-bottom-nav-item.active {
    color: #16a34a;
  }
  
  .mobile-bottom-nav-item i {
    font-size: var(--mobile-text-xl);
  }
  
  /* Mobile Menu */
  #mobile-menu {
    padding: 0;
  }
  
  #mobile-menu a {
    padding: var(--mobile-space-md) var(--mobile-space-lg);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    font-size: var(--mobile-text-base);
    color: #374151;
    text-decoration: none;
    border-bottom: 1px solid #f3f4f6;
    transition: background-color var(--mobile-duration-base);
  }
  
  #mobile-menu a:active {
    background-color: #f9fafb;
  }
}

/* ============================================
   MOBILE MODALS (Bottom Sheet Pattern)
   ============================================ */
@media (max-width: 768px) {
  /* Bottom Sheet Modal */
  .mobile-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--mobile-radius-xl) var(--mobile-radius-xl) 0 0;
    max-height: 90vh;
    z-index: var(--z-modal);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform var(--mobile-duration-slow) cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .mobile-bottom-sheet.open {
    transform: translateY(0);
  }
  
  /* Bottom Sheet Handle */
  .mobile-bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: var(--mobile-radius-full);
    margin: var(--mobile-space-sm) auto;
  }
  
  /* Bottom Sheet Header */
  .mobile-bottom-sheet-header {
    padding: var(--mobile-space-lg);
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .mobile-bottom-sheet-title {
    font-size: var(--mobile-text-xl);
    font-weight: 600;
    color: #111827;
  }
  
  /* Bottom Sheet Content */
  .mobile-bottom-sheet-content {
    padding: var(--mobile-space-lg);
    max-height: calc(90vh - 120px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Modal Overlay */
  .mobile-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    transition: opacity var(--mobile-duration-base);
    backdrop-filter: blur(2px);
  }
  
  .mobile-modal-overlay.open {
    opacity: 1;
  }
}

/* ============================================
   MOBILE LOADING STATES (Skeleton Loaders)
   ============================================ */
@media (max-width: 768px) {
  /* Skeleton Loader */
  .mobile-skeleton {
    background: linear-gradient(
      90deg,
      #f0f0f0 25%,
      #e0e0e0 50%,
      #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--mobile-radius-md);
  }
  
  @keyframes skeleton-loading {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }
  
  .mobile-skeleton-text {
    height: 1rem;
    margin-bottom: var(--mobile-space-sm);
  }
  
  .mobile-skeleton-title {
    height: 1.5rem;
    width: 60%;
    margin-bottom: var(--mobile-space-md);
  }
  
  .mobile-skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--mobile-radius-full);
  }
  
  .mobile-skeleton-card {
    height: 120px;
    margin-bottom: var(--mobile-space-md);
  }
  
  /* Loading Spinner */
  .mobile-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e5e7eb;
    border-top-color: #16a34a;
    border-radius: var(--mobile-radius-full);
    animation: spin 0.8s linear infinite;
  }
  
  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }
}

/* ============================================
   MOBILE ANIMATIONS (60fps Smooth)
   ============================================ */
@media (max-width: 768px) {
  /* Fade In */
  @keyframes mobile-fade-in {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  /* Slide Up */
  @keyframes mobile-slide-up {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  /* Scale In */
  @keyframes mobile-scale-in {
    from {
      opacity: 0;
      transform: scale(0.95);
    }
    to {
      opacity: 1;
      transform: scale(1);
    }
  }
  
  /* Apply animations */
  .mobile-fade-in {
    animation: mobile-fade-in var(--mobile-duration-slow) ease-out;
  }
  
  .mobile-slide-up {
    animation: mobile-slide-up var(--mobile-duration-slow) ease-out;
  }
  
  .mobile-scale-in {
    animation: mobile-scale-in var(--mobile-duration-base) ease-out;
  }
  
  /* Reduce motion for accessibility */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* ============================================
   MOBILE SPACING UTILITIES
   ============================================ */
@media (max-width: 768px) {
  /* Padding */
  .mobile-p-xs { padding: var(--mobile-space-xs); }
  .mobile-p-sm { padding: var(--mobile-space-sm); }
  .mobile-p-md { padding: var(--mobile-space-md); }
  .mobile-p-lg { padding: var(--mobile-space-lg); }
  .mobile-p-xl { padding: var(--mobile-space-xl); }
  
  /* Margin */
  .mobile-m-xs { margin: var(--mobile-space-xs); }
  .mobile-m-sm { margin: var(--mobile-space-sm); }
  .mobile-m-md { margin: var(--mobile-space-md); }
  .mobile-m-lg { margin: var(--mobile-space-lg); }
  .mobile-m-xl { margin: var(--mobile-space-xl); }
  
  /* Gap */
  .mobile-gap-xs { gap: var(--mobile-space-xs); }
  .mobile-gap-sm { gap: var(--mobile-space-sm); }
  .mobile-gap-md { gap: var(--mobile-space-md); }
  .mobile-gap-lg { gap: var(--mobile-space-lg); }
  .mobile-gap-xl { gap: var(--mobile-space-xl); }
}

/* ============================================
   MOBILE SAFE AREA INSETS (iOS Notch/Status Bar)
   ============================================ */
@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 768px) {
    /* Safe area for fixed headers */
    header.fixed,
    nav.fixed,
    .navbar.fixed {
      padding-top: calc(var(--mobile-space-md) + env(safe-area-inset-top));
    }
    
    /* Safe area for fixed footers */
    footer.fixed,
    .mobile-bottom-nav {
      padding-bottom: calc(var(--mobile-space-md) + env(safe-area-inset-bottom));
    }
    
    /* Safe area for full-screen elements */
    .fullscreen {
      padding-top: env(safe-area-inset-top);
      padding-bottom: env(safe-area-inset-bottom);
      padding-left: env(safe-area-inset-left);
      padding-right: env(safe-area-inset-right);
    }
    
    /* Dashboard header safe area */
    .dashboard-page header {
      padding-top: calc(var(--mobile-space-sm) + env(safe-area-inset-top));
    }
    
    /* Sidebar safe area */
    #sidebar {
      padding-top: calc(var(--mobile-space-md) + env(safe-area-inset-top));
    }
  }
}

/* ============================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Reduce shadows for better performance */
  .shadow-lg,
  .shadow-xl,
  .shadow-2xl {
    box-shadow: var(--mobile-shadow-md);
  }
  
  /* Optimize backdrop filters */
  .backdrop-blur-lg,
  .backdrop-blur-xl {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  
  /* Optimize transforms */
  * {
    will-change: auto;
  }
  
  /* Optimize images */
  img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* ============================================
   MOBILE ACCESSIBILITY ENHANCEMENTS
   ============================================ */
@media (max-width: 768px) {
  /* Better focus states */
  *:focus-visible {
    outline: 2px solid #16a34a;
    outline-offset: 2px;
    border-radius: var(--mobile-radius-sm);
  }
  
  /* Better contrast for small text */
  .text-sm,
  .text-xs {
    color: #374151; /* Darker gray for better readability */
  }
  
  /* Screen reader only */
  .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;
  }
}

/* ============================================
   MOBILE UTILITY CLASSES
   ============================================ */
@media (max-width: 768px) {
  /* Display */
  .mobile-hide { display: none !important; }
  .mobile-show { display: block !important; }
  .mobile-flex { display: flex !important; }
  
  /* Width */
  .mobile-full-width { width: 100% !important; }
  .mobile-half-width { width: 50% !important; }
  
  /* Stack */
  .mobile-stack { flex-direction: column !important; }
  
  /* Text */
  .mobile-text-center { text-align: center !important; }
  .mobile-text-left { text-align: left !important; }
  .mobile-text-right { text-align: right !important; }
  
  /* Spacing */
  .mobile-no-padding { padding: 0 !important; }
  .mobile-no-margin { margin: 0 !important; }
}

