/* Mobile-specific styles with enhanced responsiveness */
@media (max-width: 768px) {
  /* Optimized mobile navbar */
  nav, .navbar {
    min-height: 56px;
    max-height: 64px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  
  /* Hamburger menu button optimization */
  .navbar-toggle, .mobile-menu-toggle, .hamburger-btn {
    width: 44px;
    height: 44px;
    padding: 10px;
    border-radius: 8px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s ease, transform 0.1s ease;
  }
  
  .navbar-toggle:active, .mobile-menu-toggle:active, .hamburger-btn:active {
    transform: scale(0.95);
    background-color: rgba(0, 0, 0, 0.05);
  }
  
  .navbar-toggle i, .mobile-menu-toggle i, .hamburger-btn i {
    font-size: 1.25rem;
    line-height: 1;
  }
  
  /* Mobile navbar brand/logo sizing */
  .navbar-brand {
    font-size: 1.125rem;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 6px;
  }
  
  /* Page container with proper navbar clearance */
  .page-container, .main-content {
    padding-top: 72px; /* 56px navbar + 16px clearance */
    min-height: calc(100vh - 72px);
  }
  
  /* Mobile navigation links in navbar */
  .navbar-nav .nav-link {
    padding: 10px 14px;
    margin: 2px 4px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    min-height: 40px;
    display: flex;
    align-items: center;
  }
  
  /* Enhanced readability on small screens */
  p, li, blockquote {
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 1rem;
  }
  
  /* Improved form elements with better touch targets */
  input, select, textarea, button {
    width: 100%;
    margin-bottom: 16px;
    padding: 14px 16px;
    border-radius: 8px;
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 48px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    transition: all 0.2s ease;
  }
  
  /* Enhanced container spacing for mobile */
  .container {
    padding: 0 16px;
    max-width: 100%;
  }
  
  /* Optimized mobile spacing classes */
  .py-12 {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }
  
  .py-8 {
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
  }
  
  .py-6 {
    padding-top: 1rem;
    padding-bottom: 1rem;
  }
  
  /* Enhanced card layouts for mobile */
  .card, .grid > div {
    width: 100%;
    margin-bottom: 1rem;
    border-radius: 12px;
    overflow: hidden;
  }
  
  /* Responsive grid layouts */
  .grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  
  .grid-cols-3 {
    grid-template-columns: repeat(2, 1fr); /* Reduce to 2 columns on mobile */
    gap: 0.5rem;
  }
  
  /* Enhanced touch targets with accessibility improvements */
  .nav-link, .btn, button, a.btn, input[type="button"], .touch-target {
    padding: 14px 20px;
    min-height: 48px;
    min-width: 48px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
  }
  
  /* Improved navigation link spacing */
  .nav-link {
    margin: 4px 8px;
    border-radius: 6px;
  }
  
  /* Enhanced camera button for mobile */
  .camera-button {
    min-height: 60px;
    min-width: 60px;
    padding: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(8px);
  }
  
  .camera-button:active {
    transform: scale(0.95);
  }
  
  .camera-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  }
  
  /* Enhanced mobile tables with horizontal scroll */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  table th, table td {
    padding: 12px 16px;
    min-width: 120px;
  }
  
  /* Improved fixed elements positioning */
  .modal, .navbar-sticky, nav.fixed {
    position: fixed;
    width: 100%;
    left: 0;
    z-index: 9999;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  
  /* Enhanced modal positioning for mobile */
  .modal {
    top: 0;
    right: 0;
    bottom: 0;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .modal-content {
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    border-radius: 12px;
  }
  
  /* Optimized images for mobile */
  img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
  }
  
  /* Enhanced typography hierarchy */
  h1 {
    font-size: 1.875rem;
    line-height: 1.2;
    margin-bottom: 1rem;
  }
  
  h2 {
    font-size: 1.5rem;
    line-height: 1.3;
    margin-bottom: 0.75rem;
  }
  
  h3 {
    font-size: 1.25rem;
    line-height: 1.4;
    margin-bottom: 0.5rem;
  }
  
  h4, h5, h6 {
    font-size: 1.125rem;
    line-height: 1.4;
    margin-bottom: 0.5rem;
  }
  
  /* Enhanced spacing between elements */
  .mb-8 {
    margin-bottom: 1.5rem;
  }
  
  .my-8 {
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
  }
  
  .mt-8 {
    margin-top: 1.5rem;
  }
  
  /* Improved mobile maps with better controls */
  .map-container {
    height: 300px;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
  }
  
  .map-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .map-control-btn {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  /* Enhanced link tap targets */
  a {
    padding: 4px 8px;
    margin: -4px -8px;
    border-radius: 4px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    transition: background-color 0.2s ease;
  }
  
  a:active {
    background-color: rgba(0, 0, 0, 0.05);
  }
  
  /* Enhanced list item spacing */
  li {
    margin-bottom: 0.5rem;
    padding: 0.25rem 0;
  }
  
  /* Improved input focus states */
  input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
  }
  
  /* Enhanced button states */
  button:focus, .btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
  
  button:disabled, .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
  }

  /* Enhanced DescansoCard mobile adjustments */
  .descanso-card {
    margin-bottom: 1.25rem;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .descanso-card .h-64 {
    height: 220px;
  }

  .descanso-card .md\:h-96 {
    height: 280px;
  }

  /* Enhanced action buttons for mobile */
  .action-btn {
    padding: 0.625rem;
    min-width: 44px;
    min-height: 44px;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    transition: all 0.2s ease;
    touch-action: manipulation;
  }

  .action-btn i {
    font-size: 1rem;
  }

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

  /* Enhanced quality badge for mobile */
  .quality-badge {
    font-size: 0.8rem;
    padding: 0.375rem 0.625rem;
    border-radius: 6px;
    font-weight: 600;
    backdrop-filter: blur(4px);
  }

  /* Enhanced distance indicator for mobile */
  .distance-indicator {
    font-size: 0.8rem;
    padding: 0.375rem 0.625rem;
    border-radius: 6px;
    font-weight: 500;
    backdrop-filter: blur(4px);
  }

  /* Improved contributor info for mobile */
  .contributor-avatar {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
  }

  .contributor-info {
    font-size: 0.8rem;
    font-weight: 500;
  }

  /* Enhanced stats counter for mobile */
  .stats-counter {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
  }

  /* Touch-friendly interaction states */
  .descanso-card .group-hover\:opacity-100 {
    opacity: 1;
  }

  .descanso-card .group-hover\:scale-105 {
    transform: scale(1);
  }

  /* Enhanced text readability on mobile */
  .descanso-card .line-clamp-2 {
    -webkit-line-clamp: 3;
    line-height: 1.5;
  }

  /* Mobile-specific animations with performance optimization */
  @media (prefers-reduced-motion: reduce) {
    .descanso-card,
    .action-btn,
    .stats-counter,
    .camera-button,
    .nav-link {
      transition: none;
      animation: none;
    }
  }

  /* Enhanced mobile search and filter UI */
  .search-container {
    position: sticky;
    top: 5rem;
    z-index: 100;
    background: var(--light);
    padding: 1rem;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .search-input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 16px;
    background: white;
  }

  .search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(0, 0, 0, 0.5);
  }

  /* Enhanced mobile navigation improvements */
  .mobile-nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  .mobile-nav-overlay.active {
    opacity: 1;
  }

  .mobile-nav-drawer {
    position: fixed;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100vh;
    background: var(--light, #ffffff);
    z-index: 9999;
    transition: right 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    overflow-y: auto;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    border-left: 1px solid rgba(0, 0, 0, 0.08);
  }

  .mobile-nav-drawer.open {
    right: 0;
  }

  .mobile-nav-header {
    padding: 1rem;
    min-height: 64px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .mobile-nav-close {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--text-dark, #333);
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  .mobile-nav-close:active {
    transform: scale(0.95);
    background: rgba(0, 0, 0, 0.1);
  }

  .mobile-nav-links {
    padding: 0.5rem;
  }

  .mobile-nav-link {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 4px;
    text-decoration: none;
    font-weight: 500;
    font-size: 1rem;
    color: var(--text-dark, #333);
    transition: all 0.2s ease;
    min-height: 48px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  .mobile-nav-link i {
    margin-right: 12px;
    width: 20px;
    text-align: center;
    opacity: 0.7;
  }

  .mobile-nav-link:hover,
  .mobile-nav-link:active {
    background: rgba(0, 0, 0, 0.05);
    transform: translateX(2px);
  }

  .mobile-nav-link.active {
    background: var(--primary, #007bff);
    color: white;
  }
  
  .mobile-nav-link.active i {
    opacity: 1;
  }
  
  /* Mobile nav user section */
  .mobile-nav-user {
    padding: 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    margin-top: auto;
  }
  
  .mobile-nav-user-info {
    display: flex;
    align-items: center;
    padding: 12px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    margin-bottom: 0.5rem;
  }
  
  .mobile-nav-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary, #007bff);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    margin-right: 12px;
  }
}

/* Enhanced PWA display properties */
@media (display-mode: standalone) {
  /* Add styles for when the app is installed and running as a PWA */
  body {
    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);
  }
  
  /* Remove browser UI elements when in PWA mode */
  .hide-in-pwa {
    display: none;
  }
  
  /* Enhanced PWA navbar */
  nav {
    padding-top: calc(env(safe-area-inset-top) + 8px);
  }
  
  .page-container {
    padding-top: calc(env(safe-area-inset-top) + 5rem);
  }
}

/* Enhanced support for notched devices */
@supports (padding: max(0px)) {
  body {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  
  .container {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* Enhanced orientation change handling */
@media screen and (orientation: portrait) {
  .orientation-content {
    flex-direction: column;
  }
  
  .mobile-layout {
    padding: 1rem;
  }
}

@media screen and (orientation: landscape) {
  .orientation-content {
    flex-direction: row;
  }
  
  .mobile-layout {
    padding: 0.5rem 1rem;
  }
  
  /* Adjust navbar height for landscape */
  @media (max-width: 768px) {
    nav {
      min-height: 56px;
      padding: 4px 0;
    }
    
    .page-container {
      padding-top: 4rem;
    }
  }
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {
  /* Reduce motion for better performance on low-end devices */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
  
  /* Optimize scrolling performance */
  .scroll-container {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
  }
  
  /* Optimize touch performance */
  .touch-optimized {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
}

/* Enhanced accessibility for mobile */
@media (max-width: 768px) {
  /* High contrast mode support */
  @media (prefers-contrast: high) {
    button, .btn {
      border: 2px solid currentColor;
    }
    
    .card {
      border: 1px solid currentColor;
    }
  }
  
  /* Dark mode enhancements */
  @media (prefers-color-scheme: dark) {
    .mobile-nav-drawer {
      background: #1a1a1a;
      color: white;
    }
    
    .search-input {
      background: #2a2a2a;
      color: white;
      border-color: #444;
    }
  }
  
  /* Focus management for keyboard navigation */
  .focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
  }
}

/* Ultra-wide mobile screens */
@media (max-width: 768px) and (min-aspect-ratio: 2/1) {
  .ultra-wide-layout {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
  
  .navbar-brand {
    font-size: 1.25rem;
  }
}

/* Very small screens (older or budget phones) */
@media (max-width: 360px) {
  .container {
    padding: 0 12px;
  }
  
  .btn, button {
    font-size: 14px;
    padding: 10px 16px;
  }
  
  h1 {
    font-size: 1.5rem;
  }
  
  h2 {
    font-size: 1.25rem;
  }
  
  .page-container {
    padding-top: 4rem;
  }
  
  nav {
    min-height: 56px;
  }
}

/* Additional breakpoints for better responsiveness */
@media (min-width: 480px) and (max-width: 768px) {
  /* Small tablet optimizations */
  .grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .container {
    padding: 0 24px;
  }
}

/* Responsive navbar height adjustments for different screen sizes */
@media (max-width: 768px) {
  /* Base mobile navbar styling */
  @media (max-height: 480px) {
    /* Very short screens (landscape phones) */
    nav, .navbar {
      min-height: 48px;
      max-height: 52px;
      padding: 4px 0;
    }
    
    .page-container, .main-content {
      padding-top: 56px;
    }
    
    .navbar-brand {
      font-size: 1rem;
      padding: 6px 10px;
    }
    
    .navbar-toggle, .mobile-menu-toggle, .hamburger-btn {
      width: 40px;
      height: 40px;
      padding: 8px;
    }
    
    .navbar-nav .nav-link {
      padding: 8px 12px;
      font-size: 0.9rem;
      min-height: 36px;
    }
  }
  
  @media (min-height: 481px) and (max-height: 640px) {
    /* Medium height screens (portrait phones) */
    nav, .navbar {
      min-height: 56px;
      max-height: 64px;
      padding: 8px 0;
    }
    
    .page-container, .main-content {
      padding-top: 72px;
    }
    
    .navbar-brand {
      font-size: 1.125rem;
      padding: 8px 12px;
    }
  }
  
  @media (min-height: 641px) {
    /* Tall screens (large phones, small tablets) */
    nav, .navbar {
      min-height: 60px;
      max-height: 68px;
      padding: 10px 0;
    }
    
    .page-container, .main-content {
      padding-top: 76px;
    }
    
    .navbar-brand {
      font-size: 1.25rem;
      padding: 10px 14px;
    }
    
    .navbar-nav .nav-link {
      padding: 12px 16px;
      min-height: 44px;
    }
  }
}

/* Enhanced breakpoints for different mobile device categories */
@media (max-width: 320px) {
  /* Very small screens (older phones) */
  nav, .navbar {
    min-height: 52px;
    padding: 6px 0;
  }
  
  .page-container, .main-content {
    padding-top: 60px;
  }
  
  .navbar-brand {
    font-size: 1rem;
  }
  
  .navbar-toggle, .mobile-menu-toggle, .hamburger-btn {
    width: 40px;
    height: 40px;
  }
}

@media (min-width: 321px) and (max-width: 480px) {
  /* Standard mobile screens */
  nav, .navbar {
    min-height: 56px;
    padding: 8px 0;
  }
  
  .page-container, .main-content {
    padding-top: 72px;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  /* Large mobile screens and small tablets */
  nav, .navbar {
    min-height: 60px;
    padding: 10px 0;
  }
  
  .page-container, .main-content {
    padding-top: 76px;
  }
  
  .navbar-brand {
    font-size: 1.25rem;
  }
  
  /* Show more navigation items on larger mobile screens */
  .navbar-nav .nav-link {
    margin: 2px 6px;
  }
}

/* Touch target optimization for different screen densities */
@media (max-width: 768px) {
  @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* High DPI screens - optimize touch targets */
    .navbar-toggle, .mobile-menu-toggle, .hamburger-btn {
      min-width: 44px;
      min-height: 44px;
      border: 2px solid transparent;
    }
    
    .navbar-nav .nav-link {
      min-height: 44px;
      border: 1px solid transparent;
    }
  }
  
  @media (-webkit-max-device-pixel-ratio: 1.5), (max-resolution: 144dpi) {
    /* Lower DPI screens - can use slightly smaller targets */
    .navbar-toggle, .mobile-menu-toggle, .hamburger-btn {
      min-width: 40px;
      min-height: 40px;
    }
    
    .navbar-nav .nav-link {
      min-height: 40px;
    }
  }
}