/**
 * 📱 Mobile Homepage Fixes for Linkaaat
 * Ensures proper visibility and functionality on mobile devices
 * 
 * SAFETY GUARANTEES:
 * - Mobile-first responsive design
 * - Touch-optimized interactions
 * - Backward compatible with existing styles
 * - Safe area support for modern devices
 */

/* Enhanced mobile navbar visibility */
@media (max-width: 768px) {
  /* Ensure navbar is always visible */
  nav {
    position: relative;
    z-index: 50;
    background: white !important;
    border-bottom: 1px solid #E5E7EB;
  }

  /* Enhanced logo visibility on mobile */
  nav img[alt="Linkaaat"] {
    height: 32px !important;
    width: auto !important;
    min-height: 32px;
    display: block;
  }

  /* Mobile navigation container */
  .container {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  /* Mobile header layout */
  nav .flex.justify-between {
    height: 64px !important; /* Taller for better mobile UX */
    align-items: center;
  }

  /* Mobile menu button enhanced visibility */
  nav .md\:hidden button {
    background: white !important;
    border: 2px solid var(--brand-primary) !important;
    color: var(--brand-primary) !important;
    padding: 0.75rem !important;
    min-height: 48px !important;
    min-width: 48px !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
    position: relative;
    z-index: 51;
  }

  nav .md\:hidden button:hover {
    background: #F0FDF4 !important;
    border-color: var(--brand-primary-hover) !important;
    transform: scale(1.02);
  }

  /* Mobile menu icon sizing */
  nav .md\:hidden button svg {
    width: 24px !important;
    height: 24px !important;
  }

  /* Mobile menu overlay enhanced */
  nav .fixed.inset-0 {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 100 !important;
    background: rgba(0, 0, 0, 0.5) !important;
  }

  /* Mobile menu panel */
  nav .absolute.top-0.right-0 {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 320px !important;
    max-width: 85vw !important;
    background: white !important;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15) !important;
    border-left: 2px solid #E5E7EB !important;
    z-index: 101 !important;
    overflow-y: auto !important;
  }

  /* Mobile menu content spacing */
  nav .space-y-2 > * + * {
    margin-top: 0.75rem !important;
  }

  /* Enhanced mobile touch targets */
  nav .space-y-2 a,
  nav .space-y-2 button {
    min-height: 56px !important;
    padding: 1rem !important;
    border-radius: 0.75rem !important;
    font-size: 1rem !important;
    font-weight: 500 !important;
  }

  /* Mobile menu header */
  nav .border-b.bg-gradient-to-r {
    padding: 1rem !important;
    padding-top: calc(1rem + env(safe-area-inset-top)) !important;
  }

  /* Mobile menu footer */
  nav .border-t.border-gray-100 {
    padding: 1rem !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
  }
}

/* Ultra-small mobile screens */
@media (max-width: 480px) {
  nav .container {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  nav .absolute.top-0.right-0 {
    width: 100vw !important;
    max-width: 100vw !important;
  }

  /* Logo adjustment for very small screens */
  nav img[alt="Linkaaat"] {
    height: 28px !important;
  }
}

/* Mobile menu animation improvements */
@media (max-width: 768px) {
  nav .absolute.top-0.right-0 {
    animation: slideInFromRight 0.3s ease-out;
  }
}

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

/* High contrast mode mobile fixes */
@media (max-width: 768px) and (prefers-contrast: high) {
  nav .md\:hidden button {
    border-color: #000000 !important;
    color: #000000 !important;
  }

  nav .absolute.top-0.right-0 {
    border-left: 3px solid #000000 !important;
  }
}

/* Reduced motion mobile fixes */
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  nav .absolute.top-0.right-0 {
    animation: none !important;
    transition: none !important;
  }

  nav .md\:hidden button {
    transition: none !important;
  }
}

/* Landscape mobile adjustments */
@media (max-width: 768px) and (orientation: landscape) and (max-height: 500px) {
  nav .flex.justify-between {
    height: 56px !important;
  }

  nav .md\:hidden button {
    min-height: 40px !important;
    min-width: 40px !important;
    padding: 0.5rem !important;
  }

  nav .md\:hidden button svg {
    width: 20px !important;
    height: 20px !important;
  }
}

/* Force visibility and proper layering */
@media (max-width: 768px) {
  /* Ensure mobile menu is always above everything */
  nav .md\:hidden {
    position: relative;
    z-index: 52;
  }

  /* Ensure backdrop is properly positioned */
  nav [class*="bg-black"] {
    position: fixed !important;
    inset: 0 !important;
    z-index: 100 !important;
  }

  /* Debug borders for development (remove in production) */
  body[data-debug="mobile"] nav {
    border: 2px solid red !important;
  }

  body[data-debug="mobile"] nav .md\:hidden button {
    border: 2px solid blue !important;
  }

  body[data-debug="mobile"] nav .fixed.inset-0 {
    border: 2px solid green !important;
  }
}

/* Ensure proper scrolling behavior */
.mobile-menu-open {
  overflow: hidden !important;
  height: 100vh !important;
  position: fixed !important;
  width: 100% !important;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 768px) {
    nav {
      -webkit-overflow-scrolling: touch;
    }
    
    nav .absolute.top-0.right-0 {
      -webkit-overflow-scrolling: touch;
      overscroll-behavior: contain;
    }
  }
}

/* Android specific fixes */
@media (max-width: 768px) {
  nav .md\:hidden button {
    -webkit-tap-highlight-color: rgba(16, 185, 129, 0.1) !important;
    outline: none;
  }

  nav a {
    -webkit-tap-highlight-color: rgba(16, 185, 129, 0.1) !important;
    outline: none;
  }
}

/* Ensure visibility hierarchy */
@media (max-width: 768px) {
  /* Main navbar */
  nav {
    z-index: 50 !important;
  }

  /* Mobile menu button */
  nav .md\:hidden {
    z-index: 51 !important;
  }

  /* Mobile menu overlay */
  nav .fixed.inset-0 {
    z-index: 100 !important;
  }

  /* Mobile menu panel */
  nav .absolute.top-0.right-0 {
    z-index: 101 !important;
  }
}
