/* Enhanced Scroll to Top Button Styles - Following Scroll Position */
.scroll-to-top {
  position: fixed;
  right: 20px;
  bottom: 20px; /* Initial position - will be dynamically updated */
  z-index: 9998; /* Higher z-index but below critical modals (9999+) */
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  cursor: pointer;
  /* Smooth transitions for visibility and hover effects */
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              opacity 0.15s ease-out;
  opacity: 0;
  visibility: hidden;
  transform: translateY(25px) scale(0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.25),
    0 4px 16px rgba(0, 0, 0, 0.15);
  /* Enhanced accessibility and mobile support */
  outline: none;
  -webkit-tap-highlight-color: transparent;
  will-change: transform, opacity, bottom;
  /* Smooth hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  /* Ensure button stays interactive while following scroll */
  pointer-events: auto;
}

.scroll-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  animation: slideInUp 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Hover effects - enhanced for desktop, optimized for mobile */
.scroll-to-top:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-3px) scale(1.05);
  box-shadow: 
    0 12px 48px rgba(0, 0, 0, 0.35),
    0 6px 24px rgba(0, 0, 0, 0.2);
}

/* Active/pressed state */
.scroll-to-top:active {
  transform: translateY(-1px) scale(0.98);
  transition-duration: 0.1s;
}

/* Loading state while scrolling */
.scroll-to-top.scrolling {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(0) scale(0.95);
}

.scroll-to-top.scrolling svg {
  animation: pulse 1s ease-in-out infinite;
}

.scroll-to-top svg {
  width: 24px;
  height: 24px;
  stroke-width: 2.5;
  transition: transform 0.3s ease;
}

/* Focus state for accessibility */
.scroll-to-top:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* Animations */
@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(25px) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Tablet responsive adjustments - Dynamic positioning compatible */
@media (max-width: 768px) {
  .scroll-to-top {
    right: 16px;
    /* bottom is dynamically controlled by JS */
    width: 48px;
    height: 48px;
    /* Enhanced mobile optimizations */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    /* Optimized transitions for mobile viewport positioning */
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 0.1s ease-out;
  }
  
  .scroll-to-top svg {
    width: 22px;
    height: 22px;
    stroke-width: 2.5;
  }
  
  /* Reduce hover effects on touch devices */
  .scroll-to-top:hover {
    transform: translateY(-2px) scale(1.02);
  }
}

/* Mobile responsive adjustments - Dynamic positioning optimized */
@media (max-width: 640px) {
  .scroll-to-top {
    right: 14px;
    /* bottom is dynamically controlled by JS for better following behavior */
    width: 46px;
    height: 46px;
    /* Enhanced mobile touch target */
    min-width: 44px;
    min-height: 44px;
    /* Ensure smooth performance on mobile */
    will-change: transform, opacity, bottom;
    /* Force hardware acceleration for better mobile performance */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
  
  /* Ensure visibility on mobile when active */
  .scroll-to-top.visible {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }
  
  .scroll-to-top svg {
    width: 20px;
    height: 20px;
  }
}

/* Small mobile screens - Dynamic positioning */
@media (max-width: 480px) {
  .scroll-to-top {
    right: 12px;
    /* bottom position managed dynamically */
    width: 44px;
    height: 44px;
    /* Ensure adequate spacing from screen edges */
    margin-bottom: 0;
  }
  
  .scroll-to-top svg {
    width: 18px;
    height: 18px;
  }
}

/* Landscape orientation on mobile - Dynamic positioning aware */
@media (max-width: 768px) and (orientation: landscape) {
  .scroll-to-top {
    right: 12px;
    /* bottom position will be adjusted by JS for landscape mode */
    width: 42px;
    height: 42px;
    /* Smooth transitions for landscape viewport */
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .scroll-to-top {
    border-width: 0.5px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .scroll-to-top {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
  }
  
  .scroll-to-top:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
  }
}

/* Enhanced Mobile Responsiveness */
@media (max-width: 768px) {
  .scroll-to-top {
    width: 48px;
    height: 48px;
    right: 12px;
    bottom: 12px;
    /* Ensure it's always visible when shown on mobile */
    z-index: 9998 !important;
  }
}

@media (max-width: 480px) {
  .scroll-to-top {
    width: 44px;
    height: 44px;
    right: 10px;
    bottom: 10px;
  }
}

/* Ensure proper stacking when any modal is open */
.modal-open .scroll-to-top,
body:has(#gallery-modal:not(.hidden)) .scroll-to-top,
body:has(#product-modal:not(.hidden)) .scroll-to-top,
body:has(#modal-overlay[style*="display: flex"]) .scroll-to-top {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(25px) scale(0.8) !important;
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .scroll-to-top {
    transition: opacity 0.2s ease;
  }
  
  .scroll-to-top.visible {
    animation: none;
  }
  
  .scroll-to-top.scrolling svg {
    animation: none;
  }
}
