/* ========================================
   MOBILE VIEWPORT & VISIBILITY FIXES
   File: static/store/css/mobile_fixes.css
======================================== */

/* Reset body margins */
html, body {
  margin: 0 !important;
  padding: 0 !important;
  width: 100%;
  overflow-x: hidden;
  position: relative;
}

/* ========================================
   FIX MOBILE NAVBAR BEING CUT OFF
======================================== */

@media (max-width: 991px) {
  /* Make mobile topbar fixed and fully visible */
  .mobile-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1060 !important;
    background: #ffffff !important;
    padding: 0.75rem 1rem !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
    margin: 0 !important;
  }

  /* CRITICAL: Add padding to body so content doesn't hide under fixed navbar */
  body {
    padding-top: 65px !important;
  }

  /* Adjust main content */
  main.main-full {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }

  /* When mobile search is visible, add more top padding */
  body.search-visible {
    padding-top: 120px !important;
  }

  .mobile-search-wrapper.visible {
    position: fixed !important;
    top: 60px !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1050 !important;
  }
}

/* ========================================
   FIX DESKTOP NAVBAR - MAKE IT STICKY
======================================== */

@media (min-width: 992px) {
  .top-navbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 1030 !important;
  }

  .nav-links-bar {
    position: sticky !important;
    top: 82px !important; /* Height of top navbar */
    z-index: 999 !important;
  }

  .nav-links-bar.scrolled {
    top: 74px !important; /* Adjusted when scrolled */
  }

  body {
    padding-top: 0 !important;
  }
}

/* ========================================
   FIX OFFCANVAS TOP CUT OFF - CRITICAL FIX
======================================== */

.offcanvas {
  top: 0 !important;
  height: 100vh !important;
  max-height: 100vh !important;
  padding: 0 !important;
  margin: 0 !important;
  position: fixed !important;
}

.offcanvas .offcanvas-header {
  padding: 1.25rem 1rem !important;
  margin: 0 !important;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  position: relative !important;
  top: 0 !important;
}

/* Cart offcanvas specific */
#cartOffcanvas {
  top: 0 !important;
  padding-top: 0 !important;
}

#cartOffcanvas .offcanvas-header {
  background: linear-gradient(135deg, #f6da50 0%, #f9e165 100%);
  border-bottom: 2px solid rgba(255, 255, 255, 0.3);
  padding-top: 1.25rem !important;
  margin-top: 0 !important;
}

/* Mobile menu drawer */
#mobileMegaMenu,
.mobile-menu-drawer {
  top: 0 !important;
  padding-top: 0 !important;
}

#mobileMegaMenu .offcanvas-header,
.mobile-menu-drawer .offcanvas-header {
  background: linear-gradient(135deg, #f6da50 0%, #f9e165 100%);
  padding-top: 1.25rem !important;
  margin-top: 0 !important;
}

.offcanvas .offcanvas-body {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  padding-top: 0.5rem !important;
}

/* ========================================
   Z-INDEX FIXES
======================================== */

.offcanvas-backdrop {
  z-index: 1055 !important;
}

.offcanvas {
  z-index: 1065 !important;
}

@media (max-width: 991px) {
  .mobile-topbar,
  .top-navbar {
    z-index: 1060 !important;
  }
}

.dropdown-menu {
  z-index: 1100 !important;
}

.mobile-topbar .dropdown,
.top-navbar .dropdown {
  position: relative;
  z-index: 1100;
}

/* ========================================
   iOS SAFE AREA SUPPORT
======================================== */

@supports (padding: max(0px)) {
  @media (max-width: 991px) {
    .mobile-topbar {
      padding-top: max(0.75rem, env(safe-area-inset-top)) !important;
      padding-top: max(0.75rem, constant(safe-area-inset-top)) !important; /* iOS 11.0-11.2 */
    }

    body {
      padding-top: max(65px, calc(65px + env(safe-area-inset-top))) !important;
      padding-top: max(65px, calc(65px + constant(safe-area-inset-top))) !important; /* iOS 11.0-11.2 */
    }

    .offcanvas {
      padding-top: 0 !important;
    }

    .offcanvas .offcanvas-header {
      padding-top: max(1.25rem, calc(1.25rem + env(safe-area-inset-top))) !important;
      padding-top: max(1.25rem, calc(1.25rem + constant(safe-area-inset-top))) !important; /* iOS 11.0-11.2 */
    }
  }
}

/* ========================================
   PREVENT BODY SCROLL WHEN OFFCANVAS OPEN
======================================== */

body.offcanvas-open {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100vh;
}

/* ========================================
   MOBILE TOUCH IMPROVEMENTS
======================================== */

@media (max-width: 991px) {
  .mobile-topbar button,
  .mobile-topbar-btn,
  .mobile-nav-link {
    min-height: 44px;
    min-width: 44px;
  }

  .mobile-topbar button,
  .cart-btn,
  .mobile-topbar-btn {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
  }

  .mobile-topbar button,
  .mobile-nav-link {
    -webkit-user-select: none;
    user-select: none;
  }
}

/* ========================================
   SMOOTH TRANSITIONS
======================================== */

.offcanvas {
  transition: transform 0.3s ease-in-out !important;
}

.mobile-topbar {
  transition: all 0.3s ease;
}

/* ========================================
   SCROLLBAR STYLING
======================================== */

.offcanvas-body::-webkit-scrollbar {
  width: 6px;
}

.offcanvas-body::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.offcanvas-body::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.offcanvas-body::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

/* ========================================
   ADDITIONAL MOBILE FIXES
======================================== */

@media (max-width: 991px) {
  /* Ensure content doesn't jump */
  .container,
  .container-fluid {
    padding-top: 0 !important;
  }

  /* Fix for hero banner on home */
  .hero-banner {
    margin-top: 0 !important;
  }

  /* Ensure footer is below content */
  .footer {
    margin-top: 2rem;
  }
}

/* ========================================
   VIEWPORT META FIX FOR MOBILE
======================================== */

@viewport {
  width: device-width;
}

@-ms-viewport {
  width: device-width;
}
