/*
 * WiseLeaf Mobile-Only Responsive Fixes
 * Targeted fixes for mobile devices without affecting desktop
 */

/* Mobile-only fixes (max-width: 767px) */
@media (max-width: 767px) {
  
  /* Fix z-index layering issues - ensure header stays above navigation */
  html body .header,
  html body header.header {
    position: sticky !important;
    top: 0 !important;
    z-index: 1050 !important; /* Higher than any other element */
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(10px) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    /* Override any gradient backgrounds */
    background-image: none !important;
  }
  
  /* Ensure navigation menu is below header */
  html body .nav-menu,
  html body nav.nav-menu {
    position: relative !important;
    z-index: 999 !important; /* Lower than header */
    background: #0c4a60 !important;
    padding: 0.5rem 0 !important;
    margin-top: 0 !important;
  }
  
  /* Fix header links positioning on mobile */
  html body .header-links,
  html body .header .header-links {
    position: relative !important;
    z-index: 1051 !important; /* Highest to stay clickable */
    display: flex !important;
    gap: 0.5rem !important;
  }
  
  html body .header-links a,
  html body .header .header-links a {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.875rem !important;
    background: rgba(12, 74, 96, 0.05) !important;
    border-radius: 6px !important;
    border: 1px solid rgba(12, 74, 96, 0.1) !important;
    color: #0c4a60 !important;
    font-weight: 500 !important;
    text-decoration: none !important;
    transition: all 0.2s ease !important;
    white-space: nowrap !important;
    position: relative !important;
    z-index: 1052 !important;
  }
  
  html body .header-links a:hover,
  html body .header .header-links a:hover {
    background: rgba(12, 74, 96, 0.1) !important;
    border-color: #0c4a60 !important;
    transform: none !important; /* Remove any transforms that might cause positioning issues */
  }
  
  /* Ensure header container has proper stacking */
  html body .header-container,
  html body .header .header-container {
    position: relative !important;
    z-index: 1051 !important;
    padding: 0.75rem 1rem !important;
    height: auto !important;
    min-height: 70px !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }
  
  /* Fix logo on mobile */
  .logo {
    font-size: 1.25rem !important;
    padding: 0.5rem 0 !important;
  }
  
  .logo i {
    font-size: 1.5rem !important;
    margin-right: 0.5rem !important;
  }
  
  /* Fix navigation links layout */
  .nav-links {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    margin: 0 !important;
    padding: 0 1rem !important;
    list-style: none !important;
  }
  
  .nav-links li {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
  }
  
  .nav-links li:last-child {
    border-bottom: none !important;
  }
  
  .nav-links a {
    display: block !important;
    padding: 1rem 0 !important;
    color: white !important;
    text-decoration: none !important;
    font-size: 1rem !important;
    transition: all 0.2s ease !important;
  }
  
  .nav-links a:hover {
    color: rgba(255, 255, 255, 0.8) !important;
    padding-left: 0.5rem !important;
  }
  
  /* Fix any overlapping issues by ensuring proper document flow */
  .nav-container {
    max-width: 100% !important;
    margin: 0 auto !important;
    padding: 0 !important;
    position: relative !important;
    z-index: 999 !important;
  }
}

/* Hero Image Responsive Fixes */
@media (max-width: 767px) {
  .hero {
    min-height: 40vh !important;
    padding: 2rem 1rem !important;
    background-size: cover !important;
    background-position: center center !important;
    background-attachment: scroll !important;
    position: relative !important;
  }
  
  /* Ensure hero image scales properly */
  .hero[style*="background-image"] {
    background-size: cover !important;
    background-position: center center !important;
    background-repeat: no-repeat !important;
  }
  
  .hero-content {
    max-width: 100% !important;
    padding: 1rem !important;
    position: relative !important;
    z-index: 1 !important;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .hero {
    min-height: 50vh !important;
    padding: 3rem 1.5rem !important;
    background-size: cover !important;
    background-position: center center !important;
  }
}

/* Tablet adjustments for header */
@media (min-width: 768px) and (max-width: 1023px) {
  .header-links a {
    padding: 0.75rem 1rem !important;
    font-size: 0.9rem !important;
  }
  
  .nav-links {
    display: flex !important;
    flex-direction: row !important;
    gap: 1rem !important;
    padding: 0 1.5rem !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  .nav-links a {
    white-space: nowrap !important;
    padding: 1rem 0.75rem !important;
  }
}

/* Prevent any transform or position issues */
@media (max-width: 767px) {
  .header-links a::after {
    display: none !important; /* Remove any pseudo-elements that might cause positioning issues */
  }
  
  /* Force proper stacking context */
  .header, .header-container, .header-links {
    transform: none !important;
    will-change: auto !important;
  }
  
  /* Ensure clickable area is maintained */
  .header-links a {
    min-height: 44px !important; /* Touch-friendly target */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* Additional safety for navigation visibility */
@media (max-width: 767px) {
  /* Ensure navigation doesn't interfere with header */
  body {
    padding-top: 0 !important;
  }
  
  /* Make sure sections don't overlap */
  .search-section {
    margin-top: 0 !important;
    padding-top: 2rem !important;
  }
  
  /* Fix any potential scrolling issues */
  html, body {
    overflow-x: hidden !important;
  }
}

/* Final override to ensure mobile fixes take precedence */
@media screen and (max-width: 767px) {
  /* Nuclear option - highest specificity possible */
  html body div.header,
  html body header#header.header {
    position: sticky !important;
    z-index: 10000 !important;
    background: rgba(255, 255, 255, 0.98) !important;
    background-image: none !important;
    background-color: rgba(255, 255, 255, 0.98) !important;
    top: 0 !important;
  }
  
  html body div.header .header-links a,
  html body header#header.header .header-links a {
    position: relative !important;
    z-index: 10001 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #0c4a60 !important;
    background: rgba(12, 74, 96, 0.05) !important;
    border: 1px solid rgba(12, 74, 96, 0.1) !important;
    border-radius: 6px !important;
    padding: 0.5rem 0.75rem !important;
    min-height: 44px !important;
    text-decoration: none !important;
    font-weight: 500 !important;
  }
  
  /* Ensure navigation stays below */
  html body nav.nav-menu,
  html body div.nav-menu {
    position: relative !important;
    z-index: 999 !important;
    margin-top: 0 !important;
  }
}

/* Debug helper - remove in production */
/*
@media (max-width: 767px) {
  .header {
    border: 2px solid red !important;
  }
  .nav-menu {
    border: 2px solid blue !important;
  }
  .header-links {
    border: 2px solid green !important;
  }
}
*/