/**
 * HTMX Transitions and Animations
 * Smooth transitions for HTMX requests and swaps
 *
 * @package FastTheme
 */

/* ===========================
 * HTMX Core Classes
 * =========================== */

/**
 * During swap phase
 * Applied to the target element during the swap
 * Hide content while Alpine.js initializes to prevent FOUC
 */
.htmx-swapping {
  opacity: 0 !important;
  /* No transition here - we want instant hide */
}

/**
 * After swap is complete and Alpine has initialized
 * Smooth fade-in transition
 */
.htmx-swapped {
  opacity: 1 !important;
  animation: smoothFadeIn 0.2s ease-out;
}

/**
 * During settle phase
 * Applied after the swap is complete
 */
.htmx-settling {
  opacity: 1;
}

/**
 * When new content is added
 */
.htmx-added {
  animation: fadeIn var(--htmx-transition-duration) var(--htmx-transition-timing);
}

/**
 * During request
 * Applied to the element making the request
 */
.htmx-request {
  /* Keep relative only if you plan to overlay locally.
     Disabled overlay to avoid white dimming during shop filters. */
  position: relative;
}

/* Disabled the default full-surface white overlay during requests
   because it was dimming large containers like the shop layout. */
.htmx-request::after {
  content: none !important;
}

/* ===========================
 * Loading Indicators
 * =========================== */

/**
 * Show loading indicator only during request
 */
.htmx-indicator {
  opacity: 0;
  transition: opacity var(--transition-base) ease-out;
  pointer-events: none;
}

.htmx-request .htmx-indicator {
  opacity: 1;
  transition: opacity var(--transition-base) ease-in;
}

/**
 * Global loading spinner
 */
.loading-spinner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
}

/* ===========================
 * Animation Keyframes
 * =========================== */

@keyframes smoothFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

@keyframes slideInLeft {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

/* ===========================
 * Specific HTMX Swap Animations
 * =========================== */

/**
 * Fade transition
 */
.htmx-swap-fade {
  animation: fadeIn var(--htmx-transition-duration) var(--htmx-transition-timing);
}

/**
 * Slide from right (for mini-cart, sidebars)
 */
.htmx-swap-slide-right {
  animation: slideInRight var(--htmx-transition-duration) var(--htmx-transition-timing);
}

/**
 * Slide from left
 */
.htmx-swap-slide-left {
  animation: slideInLeft var(--htmx-transition-duration) var(--htmx-transition-timing);
}

/**
 * Slide up
 */
.htmx-swap-slide-up {
  animation: slideInUp var(--htmx-transition-duration) var(--htmx-transition-timing);
}

/**
 * Scale in (for modals)
 */
.htmx-swap-scale {
  animation: scaleIn var(--htmx-transition-duration) var(--htmx-transition-timing);
}

/* ===========================
 * Skeleton Loading States
 * =========================== */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-gray-200) 0%,
    var(--color-gray-100) 50%,
    var(--color-gray-200) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: var(--radius-md);
}

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-text:last-child {
  width: 80%;
}

.skeleton-avatar {
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-full);
}

.skeleton-product {
  height: 300px;
}

/* ===========================
 * Product Grid Loading
 * =========================== */

.products-loading {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
}

.products-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3rem;
  height: 3rem;
  border: 4px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ===========================
 * Cart Update Animations
 * =========================== */

.cart-item-removing {
  animation: fadeOut var(--htmx-transition-duration) var(--htmx-transition-timing) forwards;
}

.cart-count-update {
  animation: pulse var(--transition-base) ease-in-out;
}

/* ===========================
 * Mini Cart Animations
 * =========================== */

.mini-cart {
  transition: transform var(--htmx-transition-duration) var(--htmx-transition-timing);
}

.mini-cart.open {
  transform: translateX(0);
}

.mini-cart:not(.open) {
  transform: translateX(100%);
}

/* ===========================
 * Page Transition Overlay
 * =========================== */

.page-transition-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
  z-index: var(--z-overlay);
}

.htmx-request ~ .page-transition-overlay {
  opacity: 1;
}

/* ===========================
 * Progress Bar
 * =========================== */

.htmx-request .progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--color-primary);
  z-index: var(--z-toast);
  animation: progressBar var(--transition-slower) ease-out;
}

@keyframes progressBar {
  from {
    width: 0%;
  }
  to {
    width: 100%;
  }
}

/* ===========================
 * Notification Animations
 * =========================== */

.notification-enter {
  animation: slideInUp var(--transition-base) var(--htmx-transition-timing);
}

.notification-exit {
  animation: fadeOut var(--transition-base) var(--htmx-transition-timing);
}

/* ===========================
 * Bottom Sheet Styles
 * Professional Ant Design inspired
 * =========================== */

.bottom-sheet-content {
  padding: 0;
  background: #f9fafb;
}

/* Always hide breadcrumbs and related products in bottom sheet */
.bottom-sheet-content .breadcrumbs,
.bottom-sheet-content .woocommerce-breadcrumb,
.bottom-sheet-content .related-products,
.bottom-sheet-content .upsells,
.bottom-sheet-content .cross-sells {
  display: none !important;
}

/* Mobile: Hide sidebar and force single column */
@media (max-width: 1023px) {
  .bottom-sheet-content aside,
  .bottom-sheet-content .sidebar,
  .bottom-sheet-content .product-sidebar {
    display: none !important;
  }

  /* Ensure main content takes full width in mobile */
  .bottom-sheet-content .woocommerce-product-details,
  .bottom-sheet-content .product-single,
  .bottom-sheet-content main {
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Force single column layout in mobile */
  .bottom-sheet-content .grid,
  .bottom-sheet-content [class*="grid-cols"] {
    grid-template-columns: 1fr !important;
  }
}

/* Desktop: Maintain 2-column layout (gallery + details) */
@media (min-width: 1024px) {
  /* Only hide sidebar in desktop, keep main grid layout */
  .bottom-sheet-content aside,
  .bottom-sheet-content .sidebar,
  .bottom-sheet-content .product-sidebar {
    display: none !important;
  }

  /* Ensure main content area uses full available width */
  .bottom-sheet-content .woocommerce-product-details,
  .bottom-sheet-content .product-single {
    max-width: 100% !important;
    padding: 2rem !important;
  }
}

/* Smooth scrolling for bottom sheet */
.bottom-sheet-content {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar for bottom sheet */
.bottom-sheet-content::-webkit-scrollbar {
  width: 8px;
}

.bottom-sheet-content::-webkit-scrollbar-track {
  background: transparent;
}

.bottom-sheet-content::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 10px;
}

.bottom-sheet-content::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Handle bar styling */
.sheet-handle-bar {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Animate content loading in bottom sheet */
.bottom-sheet-content .woocommerce-product-details,
.bottom-sheet-content .product-single {
  animation: fadeIn 0.3s ease-out;
}

/* Bottom Sheet Skeleton Loader */
.skeleton-shimmer {
  background: linear-gradient(
    90deg,
    #f3f4f6 0%,
    #e5e7eb 20%,
    #f3f4f6 40%,
    #f3f4f6 100%
  );
  background-size: 200% 100%;
  animation: shimmer-sweep 1.5s ease-in-out infinite;
}

@keyframes shimmer-sweep {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Product card hover improvements */
.product-card {
  will-change: transform, box-shadow;
}

.product-card:hover .product-image {
  transform: scale(1.05);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Quick view button pulse effect */
@keyframes pulseScale {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.quick-view-trigger:hover {
  animation: pulseScale 0.5s ease-in-out;
}

/* ===========================
 * Accessibility
 * =========================== */

/**
 * Respect user preference for reduced motion
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .htmx-swapping,
  .htmx-settling,
  .htmx-added {
    animation: none;
    transition: none;
  }

  .product-card:hover .product-image,
  .quick-view-trigger:hover {
    animation: none;
    transform: none;
  }
}
