/**
 * WarnIQ - Mobile Menu COMPLETE FIX v2.0
 * Fixes z-index hierarchy and visibility issues
 * CRITICAL: This file must be loaded AFTER all other stylesheets
 */

/* ==================================
   FORCE Z-INDEX HIERARCHY
   ================================== */

/* Ensure overlay is BEHIND the nav menu */
.mobile-menu-overlay,
#mobileMenuOverlay {
  z-index: 99998 !important; /* Lower than everything */
}

/* Ensure nav menu is ABOVE the overlay */
.nav,
#mainNav {
  z-index: 99999 !important; /* Higher than overlay */
}

/* Hamburger button stays on top */
.mobile-menu-toggle,
#mobileMenuToggle {
  z-index: 100000 !important; /* Highest of all */
}

/* ==================================
   MOBILE MENU - COMPLETE REBUILD
   ================================== */

@media (max-width: 768px) {
  
  /* Body management for menu */
  body.menu-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100vh !important;
  }
  
  /* Header must allow overflow */
  .header {
    overflow: visible !important;
  }
  
  .header-container {
    overflow: visible !important;
    padding: 0 16px !important; /* Reduce padding on mobile for better spacing */
  }
  
  /* Mobile toggle button - ensure visibility */
  .mobile-menu-toggle,
  #mobileMenuToggle {
    display: flex !important;
    position: relative !important;
    z-index: 100000 !important; /* Above everything */
    flex-direction: column !important;
    gap: 5px !important;
    background: transparent !important;
    border: none !important;
    cursor: pointer !important;
    padding: 8px !important;
    width: 40px !important;
    height: 40px !important;
    justify-content: center !important;
    align-items: center !important;
    margin-right: 12px !important; /* CRITICAL: Add right margin for comfortable spacing */
  }
  
  .hamburger-line {
    display: block !important;
    width: 24px !important;
    height: 2px !important;
    background: #ffffff !important; /* Bright white */
    transition: all 0.3s ease !important;
  }
  
  /* Hamburger animation when active */
  .mobile-menu-toggle.active .hamburger-line:nth-child(1),
  #mobileMenuToggle.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px) !important;
  }
  
  .mobile-menu-toggle.active .hamburger-line:nth-child(2),
  #mobileMenuToggle.active .hamburger-line:nth-child(2) {
    opacity: 0 !important;
  }
  
  .mobile-menu-toggle.active .hamburger-line:nth-child(3),
  #mobileMenuToggle.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px) !important;
  }
  
  /* ==================================
     NAVIGATION MENU - RIGHT SLIDE PANEL
     ================================== */
  
  .nav,
  #mainNav {
    /* Critical positioning - slide from RIGHT */
    position: fixed !important;
    top: var(--header-height, 70px) !important;
    right: 0 !important;
    left: auto !important;
    bottom: 0 !important;
    
    /* Dimensions */
    width: 85% !important;
    max-width: 400px !important;
    height: calc(100vh - var(--header-height, 70px)) !important;
    
    /* Visual styling - HIGH CONTRAST */
    background: linear-gradient(180deg, #1a1a1a 0%, #0f0f0f 100%) !important;
    border-left: 2px solid rgba(59, 130, 246, 0.5) !important;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.9) !important;
    
    /* Layout */
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: var(--space-8, 2rem) !important;
    gap: var(--space-2, 0.5rem) !important;
    
    /* Scrolling */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    
    /* CRITICAL: Hidden by default, slide in from right */
    transform: translateX(100%) !important;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
    
    /* Stacking - ABOVE overlay */
    z-index: 99999 !important;
    
    /* Reset any conflicting properties */
    margin: 0 !important;
    box-sizing: border-box !important;
  }
  
  /* Active state - menu visible */
  .nav.active,
  #mainNav.active {
    transform: translateX(0) !important;
  }
  
  /* ==================================
     NAVIGATION LINKS - HIGH VISIBILITY
     ================================== */
  
  .nav .nav-link,
  #mainNav .nav-link {
    display: block !important;
    width: 100% !important;
    padding: var(--space-5, 1.25rem) var(--space-6, 1.5rem) !important;
    margin-bottom: var(--space-2, 0.5rem) !important;
    
    /* HIGH CONTRAST TYPOGRAPHY */
    font-size: 16px !important;
    font-weight: 500 !important;
    color: #ffffff !important; /* Pure white for maximum visibility */
    text-align: left !important;
    text-transform: none !important;
    letter-spacing: 0.02em !important;
    line-height: 1.5 !important;
    text-decoration: none !important;
    
    /* Visible border and background */
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 12px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    
    transition: all 0.25s ease !important;
    cursor: pointer !important;
    position: relative !important;
    z-index: 1 !important;
  }
  
  /* Remove conflicting pseudo-elements */
  .nav .nav-link::after,
  #mainNav .nav-link::after {
    display: none !important;
    content: none !important;
  }
  
  /* Hover state - bright and obvious */
  .nav .nav-link:hover,
  #mainNav .nav-link:hover {
    background: rgba(59, 130, 246, 0.20) !important;
    border-color: rgba(59, 130, 246, 0.6) !important;
    color: #ffffff !important;
    transform: translateX(-4px) !important;
  }
  
  /* Active state - clearly highlighted */
  .nav .nav-link.active,
  #mainNav .nav-link.active {
    background: rgba(59, 130, 246, 0.25) !important;
    border-color: rgba(59, 130, 246, 0.7) !important;
    color: #ffffff !important;
    font-weight: 600 !important;
  }
  
  /* ==================================
     BUTTONS IN MENU - HIGH VISIBILITY
     ================================== */
  
  .nav .btn,
  #mainNav .btn {
    width: 100% !important;
    margin-top: var(--space-6, 1.5rem) !important;
    padding: var(--space-5, 1.25rem) var(--space-6, 1.5rem) !important;
    justify-content: center !important;
    display: flex !important;
    border-radius: 12px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    text-transform: none !important;
    text-decoration: none !important;
    transition: all 0.25s ease !important;
    position: relative !important;
    z-index: 1 !important;
  }
  
  /* Primary button - bright and visible */
  .nav .btn-primary,
  #mainNav .btn-primary {
    background: rgb(59, 130, 246) !important;
    color: #ffffff !important;
    border: 2px solid rgb(59, 130, 246) !important;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3) !important;
  }
  
  .nav .btn-primary:hover,
  #mainNav .btn-primary:hover {
    background: rgb(37, 99, 235) !important;
    border-color: rgb(37, 99, 235) !important;
    color: #ffffff !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4) !important;
  }
  
  /* Ghost button - visible alternative */
  .nav .btn-ghost,
  #mainNav .btn-ghost {
    background: transparent !important;
    border: 2px solid rgba(255, 255, 255, 0.3) !important;
    color: #ffffff !important;
  }
  
  .nav .btn-ghost:hover,
  #mainNav .btn-ghost:hover {
    border-color: rgba(255, 255, 255, 0.6) !important;
    background: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
  }
  
  /* ==================================
     OVERLAY - BEHIND MENU
     ================================== */
  
  .mobile-menu-overlay,
  #mobileMenuOverlay {
    position: fixed !important;
    top: var(--header-height, 70px) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    
    background: rgba(0, 0, 0, 0.75) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
    z-index: 99998 !important; /* BELOW nav panel */
  }
  
  .mobile-menu-overlay.active,
  #mobileMenuOverlay.active {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }
  
  /* ==================================
     CONTENT PROTECTION
     ================================== */
  
  main,
  #main-content {
    position: relative !important;
    z-index: 1 !important;
  }
  
  /* Ensure scrollbar is styled for dark theme */
  .nav::-webkit-scrollbar,
  #mainNav::-webkit-scrollbar {
    width: 6px !important;
  }
  
  .nav::-webkit-scrollbar-track,
  #mainNav::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05) !important;
    border-radius: 3px !important;
  }
  
  .nav::-webkit-scrollbar-thumb,
  #mainNav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2) !important;
    border-radius: 3px !important;
  }
  
  .nav::-webkit-scrollbar-thumb:hover,
  #mainNav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3) !important;
  }
}

/* ==================================
   TABLET ADJUSTMENTS
   ================================== */

@media (min-width: 481px) and (max-width: 768px) {
  .nav,
  #mainNav {
    width: 70% !important;
    max-width: 380px !important;
  }
  
  .nav .nav-link,
  .nav .btn,
  #mainNav .nav-link,
  #mainNav .btn {
    font-size: 15px !important;
  }
}

/* ==================================
   SMALL MOBILE ADJUSTMENTS
   ================================== */

@media (max-width: 480px) {
  .nav,
  #mainNav {
    width: 90% !important;
    padding: var(--space-6, 1.5rem) !important;
  }
  
  .nav .nav-link,
  #mainNav .nav-link {
    font-size: 15px !important;
    padding: var(--space-4, 1rem) var(--space-5, 1.25rem) !important;
  }
  
  .nav .btn,
  #mainNav .btn {
    font-size: 15px !important;
  }
}

/* ==================================
   DESKTOP - RESET TO NORMAL
   ================================== */

@media (min-width: 769px) {
  /* Hide mobile elements */
  .mobile-menu-toggle,
  #mobileMenuToggle {
    display: none !important;
  }
  
  .mobile-menu-overlay,
  #mobileMenuOverlay {
    display: none !important;
  }
  
  /* Reset nav to horizontal */
  .nav,
  #mainNav {
    position: static !important;
    transform: none !important;
    width: auto !important;
    height: auto !important;
    flex-direction: row !important;
    padding: 0 !important;
    gap: var(--space-8, 2rem) !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
  }
  
  /* Reset link styles */
  .nav .nav-link,
  #mainNav .nav-link {
    width: auto !important;
    margin: 0 !important;
    padding: var(--space-2, 0.5rem) 0 !important;
    background: transparent !important;
    border: none !important;
    color: var(--color-text-secondary, #a0a0a0) !important;
    font-size: var(--font-size-sm, 14px) !important;
  }
  
  .nav .nav-link:hover,
  .nav .nav-link.active,
  #mainNav .nav-link:hover,
  #mainNav .nav-link.active {
    color: var(--color-text-primary, #ffffff) !important;
    background: transparent !important;
    transform: none !important;
  }
  
  /* Restore underline effect for desktop */
  .nav .nav-link::after,
  #mainNav .nav-link::after {
    display: block !important;
    content: '' !important;
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 0 !important;
    height: 1px !important;
    background: var(--color-primary, rgb(59, 130, 246)) !important;
    transition: width var(--transition-base, 0.3s ease) !important;
  }
  
  .nav .nav-link:hover::after,
  .nav .nav-link.active::after,
  #mainNav .nav-link:hover::after,
  #mainNav .nav-link.active::after {
    width: 100% !important;
  }
  
  /* Reset buttons */
  .nav .btn,
  #mainNav .btn {
    width: auto !important;
    margin: 0 !important;
    padding: var(--space-4, 1rem) var(--space-8, 2rem) !important;
  }
}
