/**
 * Mobile Optimizations for LevoroFit
 * Industry-standard mobile UX patterns and innovations
 * 
 * Key Features:
 * - Touch-optimized targets (44px minimum)
 * - Safe area insets for iOS
 * - Swipe gesture support
 * - Optimized typography scaling
 * - Enhanced spacing and padding
 * - Smooth animations
 * - Better form inputs
 */

/* ============================================
   MOBILE TOUCH TARGETS (Industry Standard: 44x44px minimum)
   ============================================ */
@media (max-width: 768px) {
  /* Ensure all interactive elements meet 44px minimum */
  button,
  a.btn,
  .btn,
  input[type="button"],
  input[type="submit"],
  .clickable,
  .touch-target {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(22, 163, 74, 0.2);
  }

  /* Navigation items */
  nav a,
  .navbar-link,
  .menu-item,
  .sidebar-nav-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    touch-action: manipulation;
  }

  /* Form inputs - prevent zoom on iOS */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    min-height: 44px;
    padding: 12px 16px;
  }
}

/* ============================================
   MOBILE TYPOGRAPHY SCALING
   ============================================ */
@media (max-width: 640px) {
  /* Base font size adjustment */
  body {
    font-size: 16px;
    line-height: 1.6;
  }

  /* Heading scaling */
  h1 {
    font-size: 2rem !important; /* 32px */
    line-height: 1.2;
  }

  h2 {
    font-size: 1.75rem !important; /* 28px */
    line-height: 1.3;
  }

  h3 {
    font-size: 1.5rem !important; /* 24px */
    line-height: 1.4;
  }

  h4 {
    font-size: 1.25rem !important; /* 20px */
    line-height: 1.4;
  }

  /* Paragraph spacing */
  p {
    margin-bottom: 1rem;
    line-height: 1.7;
  }
}

/* ============================================
   MOBILE SPACING OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Section padding reduction */
  section {
    padding-top: 3rem;
    padding-bottom: 3rem;
  }

  /* Container padding */
  .container,
  .max-w-7xl,
  .max-w-6xl,
  .max-w-4xl {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Card padding */
  .card,
  .plan-card,
  .feature-card {
    padding: 1.25rem;
  }

  /* Grid gaps */
  .grid {
    gap: 1rem;
  }

  /* Flex gaps */
  .flex {
    gap: 0.75rem;
  }
}

/* ============================================
   DASHBOARD MOBILE OPTIMIZATIONS (Gold-Standard)
   ============================================ */
@media (max-width: 1023px) {
  /* Dashboard header - compact on mobile */
  .dashboard-page header {
    height: 56px;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
    background: white;
    border-bottom: 1px solid #e5e7eb;
  }

  /* Dashboard cards - full width on mobile with gold-standard styling */
  .dashboard-page .stat-card,
  .dashboard-page .stat-detailed-card,
  .dashboard-page .meal-card,
  .dashboard-page .card {
    width: 100%;
    margin-bottom: 1rem;
    border-radius: 16px;
    padding: 1.25rem;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s, box-shadow 0.2s;
  }
  
  .dashboard-page .stat-card:active,
  .dashboard-page .meal-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  }

  /* Dashboard grid - single column with proper spacing */
  .dashboard-page .grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
  
  /* Profile completion card - mobile optimized */
  .dashboard-page .bg-gradient-to-r {
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1rem;
  }
  
  /* Achievement cards - mobile optimized */
  .dashboard-page .bg-gradient-to-r.from-yellow-50,
  .dashboard-page .bg-gradient-to-r.from-blue-50 {
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1rem;
  }

  /* Sidebar - optimized width for mobile */
  #sidebar {
    width: 280px;
    max-width: 85vw;
  }

  /* Main content padding - consistent spacing */
  .dashboard-page main {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }
  
  /* Dashboard section spacing */
  .dashboard-page .space-y-6,
  .dashboard-page .space-y-8 {
    gap: 1rem;
  }
  
  /* Stat numbers - better mobile sizing */
  .dashboard-page .text-3xl,
  .dashboard-page .text-4xl {
    font-size: 1.875rem; /* 30px */
    line-height: 1.2;
  }
  
  /* Meal cards - better mobile layout */
  .dashboard-page .meal-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
  
  /* Recommendations - mobile optimized */
  .dashboard-page .recommendations {
    border-radius: 16px;
    padding: 1.25rem;
  }
}

/* ============================================
   HOMEPAGE MOBILE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Hero section - optimized for mobile */
  .hero-section,
  section.hero-gradient {
    min-height: 60vh;
    padding: 2rem 1rem;
  }

  /* Hero title - better mobile sizing */
  .hero-title,
  h1.hero-title {
    font-size: 2rem !important;
    line-height: 1.2;
    margin-bottom: 1rem;
  }

  /* Hero description */
  .hero-description,
  .hero-content p {
    font-size: 1rem;
    margin-bottom: 1.5rem;
  }

  /* Feature cards - stack on mobile */
  .feature-card,
  .plan-card {
    width: 100%;
    margin-bottom: 1.5rem;
  }

  /* Feature grid - single column */
  .features-grid,
  .grid.grid-cols-1.md\\:grid-cols-2,
  .grid.grid-cols-1.md\\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }

  /* CTA buttons - full width on mobile */
  .cta-button,
  button.cta-primary,
  a.cta-primary {
    width: 100%;
    display: block;
    text-align: center;
  }
}

/* ============================================
   PLANS PAGE MOBILE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Plan cards - full width */
  .plan-card {
    width: 100%;
    margin-bottom: 1.5rem;
  }

  /* Pricing toggle - better mobile layout */
  .pricing-toggle {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  /* Plan grid - single column */
  .grid.grid-cols-1.md\\:grid-cols-3,
  .grid.grid-cols-1.md\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
  }

  /* Comparison table - horizontal scroll */
  .comparison-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .comparison-table table {
    min-width: 600px;
  }
}

/* ============================================
   ABOUT US PAGE MOBILE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Mission/Vision sections - stack on mobile */
  .grid.grid-cols-1.lg\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
  }

  /* Feature cards - single column */
  .feature-card {
    width: 100%;
    margin-bottom: 1.5rem;
  }

  /* Stats grid - 2 columns on mobile */
  .stats-grid.grid-cols-3 {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
}

/* ============================================
   SWIPE GESTURE SUPPORT
   ============================================ */
@media (max-width: 1023px) {
  /* Enable swipe gestures for sidebar */
  #sidebar {
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  /* Swipeable cards */
  .swipeable {
    touch-action: pan-x;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Prevent text selection during swipe */
  .swipeable * {
    user-select: none;
    -webkit-user-select: none;
  }
}

/* ============================================
   MOBILE NAVIGATION ENHANCEMENTS (Industry Standard)
   ============================================ */
@media (max-width: 768px) {
  /* Navbar - Industry Standard: Fixed 56px height */
  nav.backdrop-blur-lg {
    height: 56px;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }
  
  nav.backdrop-blur-lg > div {
    height: 100%;
  }
  
  nav.backdrop-blur-lg > div > div {
    height: 100%;
    align-items: center;
  }

  /* Logo - optimized for mobile */
  nav.backdrop-blur-lg a img {
    height: 32px;
    width: 32px;
  }

  nav.backdrop-blur-lg a span {
    font-size: 1.125rem;
  }

  /* Mobile Menu - Match actual HTML structure */
  /* Structure: #mobile-menu > .mobile-menu-content > .mobile-menu-section > .mobile-menu-item */
  
  /* Ensure menu is visible when opened - CRITICAL */
  #mobile-menu.show {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  #mobile-menu:not(.hidden).show {
    display: block !important;
    visibility: visible !important;
  }

  /* Menu content container - ensure it's visible */
  #mobile-menu .mobile-menu-content {
    display: block !important;
    width: 100% !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* Menu sections - ensure they're visible */
  #mobile-menu .mobile-menu-section {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* Menu items - Industry Standard: 48px touch targets */
  #mobile-menu .mobile-menu-item {
    min-height: 48px;
    display: flex !important;
    align-items: center;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100% !important;
  }
  
  /* Ensure ALL menu links are always visible */
  #mobile-menu a.mobile-menu-item {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Ensure icons are visible */
  #mobile-menu .mobile-menu-item i {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Ensure text spans are visible */
  #mobile-menu .mobile-menu-item span {
    display: inline !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Divider */
  #mobile-menu .mobile-menu-divider {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Mobile menu overlay */
  #mobile-menu-overlay {
    backdrop-filter: blur(2px);
  }
  
  /* Hamburger button - always visible on mobile */
  #mobile-btn {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    margin-left: auto;
  }
  
  /* Hide desktop auth buttons on mobile */
  nav.backdrop-blur-lg .hidden.md\:flex {
    display: none !important;
  }
}

/* Hide mobile button on desktop - MUST be after mobile styles */
/* Using Tailwind's md:hidden class in HTML, but adding extra protection */
@media (min-width: 768px) {
  #mobile-btn {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
  }
}

/* ============================================
   MOBILE FORM OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Form groups - better spacing */
  .form-group,
  .form-field {
    margin-bottom: 1.25rem;
  }

  /* Form labels - better visibility */
  label {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: block;
  }

  /* Input groups - full width */
  .input-group,
  .form-control-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  /* Select dropdowns - better mobile 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='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 2.5rem;
    -webkit-appearance: none;
    appearance: none;
  }
}

/* ============================================
   MOBILE IMAGE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Images - responsive and optimized */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Hero images - better mobile display */
  .hero-image,
  section[style*="background-image"] {
    background-size: cover;
    background-position: center;
    background-attachment: scroll; /* Better performance on mobile */
  }

  /* Card images - aspect ratio maintained */
  .card img,
  .feature-card img {
    width: 100%;
    object-fit: cover;
  }
}

/* ============================================
   MOBILE ANIMATIONS & TRANSITIONS
   ============================================ */
@media (max-width: 768px) {
  /* Reduce motion for better performance */
  * {
    animation-duration: 0.2s !important;
    transition-duration: 0.2s !important;
  }

  /* Disable hover effects on touch devices */
  @media (hover: none) {
    .hover\:shadow-xl:hover,
    .hover\:bg-gray-50:hover,
    .hover\:scale-105:hover {
      /* Hover effects disabled on touch */
    }
  }
}

/* ============================================
   MOBILE SAFE AREA INSETS (iOS)
   ============================================ */
@supports (padding: env(safe-area-inset-top)) {
  /* Safe area for fixed headers */
  header.fixed,
  nav.fixed,
  .navbar.fixed {
    padding-top: calc(0.75rem + env(safe-area-inset-top));
  }

  /* Safe area for fixed footers */
  footer.fixed {
    padding-bottom: calc(1rem + 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(0.5rem + env(safe-area-inset-top));
  }
}

/* ============================================
   MOBILE LOADING STATES
   ============================================ */
@media (max-width: 768px) {
  /* Loading spinners - optimized size */
  .spinner,
  .loading-spinner {
    width: 32px;
    height: 32px;
  }

  /* Skeleton loaders - better mobile display */
  .skeleton {
    border-radius: 8px;
  }
}

/* ============================================
   MOBILE MODAL & OVERLAY OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Modals - full screen on mobile */
  .modal,
  .modal-content {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    margin: 0;
  }

  /* Modal padding */
  .modal-body {
    padding: 1.5rem 1rem;
  }

  /* Overlay - better touch target */
  .overlay,
  #mobile-overlay {
    touch-action: manipulation;
  }
}

/* ============================================
   MOBILE UTILITY CLASSES
   ============================================ */
@media (max-width: 768px) {
  /* Hide on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Show only on mobile */
  .show-mobile {
    display: block !important;
  }

  /* Full width on mobile */
  .mobile-full-width {
    width: 100% !important;
  }

  /* Stack on mobile */
  .mobile-stack {
    flex-direction: column !important;
  }
}

/* ============================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================ */
@media (max-width: 768px) {
  /* Reduce shadows for better performance */
  .shadow-lg,
  .shadow-xl,
  .shadow-2xl {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  }

  /* Optimize backdrop filters */
  .backdrop-blur-lg,
  .backdrop-blur-xl {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
}

/* ============================================
   MOBILE ACCESSIBILITY ENHANCEMENTS
   ============================================ */
@media (max-width: 768px) {
  /* Better focus states */
  *:focus-visible {
    outline: 2px solid #16a34a;
    outline-offset: 2px;
  }

  /* Better contrast for small text */
  .text-sm,
  .text-xs {
    color: #374151; /* Darker gray for better readability */
  }
}

