/* =============================================================================
   ADDITIONAL MOBILE FIXES & ENHANCEMENTS
   Addresses edge cases and improves mobile user experience
   ============================================================================= */

/* Fix for iOS Safari viewport height issues */
@supports (-webkit-touch-callout: none) {
  .header-mobile {
    height: calc(var(--header-height-mobile) + env(safe-area-inset-top, 0px)) !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
  }

  .footer-mobile {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* Prevent horizontal scroll on mobile */
* {
  max-width: 100%;
  overflow-wrap: break-word;
}

html, body {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Enhanced mobile touch targets */
@media (max-width: 767.98px) {
  .header-tools__item,
  .mobile-nav-activator,
  .navigation__link,
  .footer-mobile__link {
    min-height: 44px !important;
    min-width: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Fix for small screens like iPhone SE */
  @media (max-width: 375px) {
    .header-mobile .container {
      padding-left: 8px !important;
      padding-right: 8px !important;
    }

    .navigation__link span {
      font-size: 10px !important;
    }

    .navigation__link i {
      font-size: 18px !important;
    }

    .footer-mobile__link {
      padding: 6px 2px !important;
    }

    .footer-mobile__link span {
      font-size: 10px !important;
    }
  }

  /* Fix for very large phones like iPhone 14 Pro Max */
  @media (min-width: 414px) and (max-width: 575.98px) {
    .header-mobile .logo__image {
      max-width: 140px !important;
    }

    .navigation__link {
      padding: 10px 8px !important;
    }

    .footer-mobile__link {
      padding: 10px 6px !important;
    }
  }
}

/* Tablet specific enhancements */
@media (min-width: 768px) and (max-width: 1024px) {
  /* iPad Pro specific fixes */
  @media (min-width: 1024px) and (max-width: 1024px) {
    .navigation {
      max-width: 550px !important;
    }

    .search-popup {
      width: 500px !important;
    }
  }

  /* iPad mini and standard iPad */
  @media (max-width: 1023px) {
    .header-tools {
      gap: 12px !important;
    }

    .navigation__link i {
      font-size: 18px !important;
    }

    .navigation__link span {
      font-size: 10px !important;
    }
  }
}

/* Landscape orientation specific fixes */
@media (orientation: landscape) and (max-width: 1024px) {
  .header-mobile {
    height: 50px !important;
    min-height: 50px !important;
  }

  .header-mobile .logo__image {
    max-height: 30px !important;
  }

  .footer-mobile {
    padding: 4px 0 6px 0 !important;
  }

  .footer-mobile__link {
    min-height: 45px !important;
    padding: 4px 2px !important;
  }

  .footer-mobile__link svg {
    width: 16px !important;
    height: 16px !important;
  }

  body {
    padding-bottom: 55px !important;
  }
}

/* Loading states for better UX */
.header-mobile .logo img,
.footer-store-info .logo img {
  transition: opacity 0.3s ease;
}

.header-mobile .logo img[src=""],
.footer-store-info .logo img[src=""] {
  opacity: 0;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .navigation__link,
  .footer-mobile__link,
  .header-tools__item,
  .footer__social-link {
    transition: none !important;
    transform: none !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .header-mobile,
  .footer-mobile {
    border: 2px solid currentColor !important;
  }

  .navigation__link,
  .footer-mobile__link {
    border: 1px solid currentColor !important;
  }
}

/* Dark mode support preparation */
@media (prefers-color-scheme: dark) {
  .header-mobile {
    background-color: #1a1a1a !important;
    color: #ffffff !important;
  }

  .header-mobile__navigation {
    background: rgba(26, 26, 26, 0.98) !important;
    border-top-color: #333 !important;
  }

  .footer-mobile {
    background: rgba(26, 26, 26, 0.95) !important;
    border-top-color: #333 !important;
  }

  .navigation__link,
  .footer-mobile__link {
    color: #ffffff !important;
  }

  .navigation__link:hover,
  .footer-mobile__link:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
  }
}

/* Fix for modal and overlay z-index conflicts */
.header-mobile,
.footer-mobile {
  z-index: 9999 !important;
}

.header-mobile__navigation {
  z-index: 9998 !important;
}

/* Smooth scrolling for the entire page */
html {
  scroll-behavior: smooth;
}

/* Focus styles for keyboard navigation */
.navigation__link:focus,
.footer-mobile__link:focus,
.header-tools__item:focus {
  outline: 2px solid #007bff !important;
  outline-offset: 2px !important;
  border-radius: 4px !important;
}

/* Performance optimizations */
.header-mobile,
.footer-mobile,
.navigation,
.search-popup {
  will-change: transform;
  transform: translateZ(0);
}

/* Print styles */
@media print {
  .header-mobile,
  .footer-mobile,
  .header-tools,
  .search-popup {
    display: none !important;
  }

  .footer {
    position: static !important;
    padding: 20px 0 !important;
  }
}

/* Fix for Android Chrome address bar */
@media screen and (max-width: 767.98px) {
  .mobile-viewport-fix {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }

  html {
    height: -webkit-fill-available;
  }
}

/* Improved button touch feedback */
@media (max-width: 767.98px) {
  .navigation__link,
  .footer-mobile__link,
  .header-tools__item {
    -webkit-tap-highlight-color: rgba(0, 123, 255, 0.2) !important;
    tap-highlight-color: rgba(0, 123, 255, 0.2) !important;
  }

  .navigation__link:active,
  .footer-mobile__link:active,
  .header-tools__item:active {
    transform: scale(0.95) !important;
    transition: transform 0.1s ease !important;
  }
}

/* Fix for sticky elements on iOS */
@supports (-webkit-overflow-scrolling: touch) {
  .header-mobile,
  .footer-mobile {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}

/* Enhanced search results mobile styling */
@media (max-width: 767.98px) {
  .search-popup {
    position: fixed !important;
    top: var(--header-height-mobile) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
  }

  .search-popup .container {
    padding: 15px !important;
  }

  .search-popup__input {
    font-size: 16px !important; /* Prevents zoom on iOS */
  }

  #box-content-search {
    max-height: calc(100vh - var(--header-height-mobile) - 100px) !important;
  }
}

/* Cart counter improvements */
.cart-amount {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  font-weight: 600 !important;
  text-align: center !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Loading spinner for search */
.search-loading {
  display: none;
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #007bff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: translateY(-50%) rotate(0deg); }
  100% { transform: translateY(-50%) rotate(360deg); }
}

/* Improved dropdown and menu animations */
.header-mobile__navigation {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.mobile-menu-opened .header-mobile__navigation {
  animation: slideDown 0.3s ease-out !important;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Footer mobile improvements */
@media (max-width: 575.98px) {
  .footer-mobile .col-4:nth-child(2) {
    order: 1; /* Move shop to center for better UX */
  }

  .footer-mobile .col-4:nth-child(1) {
    order: 2;
  }

  .footer-mobile .col-4:nth-child(3) {
    order: 3;
  }
}
