/**
 * Product Carousel Block Styles
 *
 * Styles for the custom Gutenberg product carousel block
 * Integrates with existing product card styles and Owl Carousel
 */

/* ============================================
   Pre-initialization State - FOUC Prevention
   ============================================
   These styles prevent Flash of Unstyled Content by displaying
   products in a single row BEFORE Owl Carousel JavaScript initializes.
   The :not(.owl-loaded) selector ensures these only apply before JS runs.
   CSS variables are dynamically set from PHP block attributes.
   ============================================ */

.blaze-product-carousel:not(.owl-loaded) {
  display: flex !important;
  flex-wrap: nowrap !important;
  overflow: hidden;
  gap: var(--carousel-margin, 24px);
}

.blaze-product-carousel:not(.owl-loaded) > .product {
  flex: 0 0 var(--carousel-desktop-flex, calc(25% - 18px));
  max-width: var(--carousel-desktop-flex, calc(25% - 18px));
  min-width: 0;
}

/* Tablet: matches carousel responsive settings */
@media (max-width: 999px) {
  .blaze-product-carousel:not(.owl-loaded) > .product {
    flex: 0 0 var(--carousel-tablet-flex, calc(50% - 12px));
    max-width: var(--carousel-tablet-flex, calc(50% - 12px));
  }
}

/* Mobile: matches carousel responsive settings */
@media (max-width: 767px) {
  .blaze-product-carousel:not(.owl-loaded) > .product {
    flex: 0 0 var(--carousel-mobile-flex, calc(50% - 12px));
    max-width: var(--carousel-mobile-flex, calc(50% - 12px));
  }
}

/* ============================================ */

/* Carousel Wrapper */
.blaze-product-carousel-wrapper {
  position: relative;
  margin: 2rem 0;
}

/* Carousel Container */
.blaze-product-carousel {
  position: relative;
}

/* Product Cards in Carousel */
.blaze-product-carousel .product {
  margin-bottom: 0 !important;
  height: auto;
  display: flex;
  flex-direction: column;
}

/* Ensure consistent product card heights */
.blaze-product-carousel .product>* {
  flex-shrink: 0;
}

.blaze-product-carousel .product .woocommerce-loop-product__title {
  flex-grow: 0;
  display: flex;
  align-items: center;
  min-height: 2.5em;
}

/* Hide navigation on mobile */
@media (max-width: 767px) {
  .blaze-product-carousel .owl-nav {
    display: none !important;
  }
}

/* Dots Pagination */
.blaze-product-carousel .owl-dots {
  text-align: center;
  margin-top: 2rem;
}

.blaze-product-carousel .owl-dots .owl-dot {
  display: inline-block;
}

/* Loading State */
.blaze-product-carousel.loading {
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.blaze-product-carousel.loading::before {
  content: "";
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--theme-palette-color-1, #007cba);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Responsive Adjustments */
@media (max-width: 1199px) {
  .blaze-product-carousel .owl-nav .owl-prev {
    left: -20px;
  }

  .blaze-product-carousel .owl-nav .owl-next {
    right: -20px;
  }
}

@media (max-width: 991px) {
  .blaze-product-carousel .owl-nav .owl-prev {
    left: -15px;
  }

  .blaze-product-carousel .owl-nav .owl-next {
    right: -15px;
  }

  .blaze-product-carousel .owl-nav button {
    width: 40px !important;
    height: 40px !important;
    font-size: 16px !important;
  }
}

/* Integration with existing product card styles */
.blaze-product-carousel .products[data-products] .product {
  border-radius: var(--product-card-border-radius, 8px);
  border-width: var(--product-card-border-width, 1px);
  border-style: var(--product-card-border-style, solid);
  border-color: var(--product-card-border-color, transparent);
  overflow: hidden;
}

/* Ensure proper spacing in carousel context */
.blaze-product-carousel .product>* {
  padding-left: var(--product-card-element-spacing, 16px) !important;
  padding-right: var(--product-card-element-spacing, 16px) !important;
}

.blaze-product-carousel .product>figure {
  padding: 0 !important;
  margin-bottom: var(--product-card-element-spacing, 16px) !important;
}

/* Mobile responsive spacing */
@media screen and (max-width: 768px) {
  .blaze-product-carousel .product>* {
    padding-left: var(--mobile-product-card-element-spacing, 12px) !important;
    padding-right: var(--mobile-product-card-element-spacing, 12px) !important;
  }

  .blaze-product-carousel .product>figure {
    margin-bottom: var(--mobile-product-card-element-spacing, 12px) !important;
  }
}

/* Block Editor Specific Styles */
.wp-block-blaze-blocksy-product-carousel {
  margin: 2rem 0;
}

/* Ensure carousel works in editor preview */
.editor-styles-wrapper .blaze-product-carousel-wrapper {
  margin: 1rem 0;
}

/* Fix for potential conflicts with theme styles */
.blaze-product-carousel .owl-stage-outer {
  overflow: hidden;
}

.blaze-product-carousel .owl-stage {
  display: flex;
  align-items: stretch;
}

.blaze-product-carousel .owl-item {
  display: flex;
  align-items: stretch;
}

.blaze-product-carousel .owl-item .product {
  width: 100%;
  height: 100%;
  padding-bottom: 18px;
}

/* Accessibility improvements */
.blaze-product-carousel .owl-nav button {
  outline: none;
}

/* RTL Support */
[dir="rtl"] .blaze-product-carousel .owl-nav .owl-prev {
  right: -25px;
  left: auto;
}

[dir="rtl"] .blaze-product-carousel .owl-nav .owl-next {
  left: -25px;
  right: auto;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .blaze-product-carousel .owl-nav button {
    background: #fff !important;
    border: 2px solid #000 !important;
    color: #000 !important;
  }

  .blaze-product-carousel .owl-dots .owl-dot span {
    background: #000;
    border: 1px solid #fff;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

  .blaze-product-carousel .owl-nav button,
  .blaze-product-carousel .owl-dots .owl-dot span {
    transition: none;
  }

  .blaze-product-carousel.loading::before {
    animation: none;
  }
}

/* ============================================
   Product Card Hover Effects
   ============================================ */

/* Add-to-cart button base state */
.blaze-product-carousel .product .ct-woo-card-actions a {
  transition: all 0.3s ease;
  transform: translateY(0);
}

/* Hover effect on add-to-cart when product card is hovered */
.blaze-product-carousel .product:hover .ct-woo-card-actions a {
  background-color: var(--theme-palette-color-1, #007cba);
  color: #fff;
  border-color: var(--theme-palette-color-1, #007cba);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Active state for better feedback */
.blaze-product-carousel .product:hover .ct-woo-card-actions a:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Reduced motion support for hover effects */
@media (prefers-reduced-motion: reduce) {
  .blaze-product-carousel .product .ct-woo-card-actions a {
    transition: none;
  }

  .blaze-product-carousel .product:hover .ct-woo-card-actions a {
    transform: none;
    box-shadow: none;
  }
}