/* ==========================================================================
   UNIVERSAL VARIATION SWATCHES
   ========================================================================== */

/* ==========================================================================
   SINGLE PRODUCT PAGE SWATCHES
   ========================================================================== */

.hema-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-base);
}

/* IMAGE SWATCHES - Big buttons with image + text */
.hema-swatches-image {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.hema-swatches-image .hema-swatch {
  display: flex;
  align-items: center;
  gap: var(--space-base);
  padding: var(--space-xs);
  border: 1px solid var(--c-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  background: var(--c-white);
  width: 100%;
}

.hema-swatches-image .hema-swatch:hover {
  border-color: var(--c-border-medium);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.hema-swatches-image .hema-swatch.selected {
  border-color: var(--c-black);
  background: var(--c-bg-secondary);
}

.hema-swatches-image .hema-swatch img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* Show label even without image */
.hema-swatches-image .hema-swatch-label {
  display: block;
}

/* COLOR SWATCHES - Circle with color + text */
.hema-swatches-color .hema-swatch {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border: 2px solid var(--c-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  background: var(--c-white);
  min-width: 160px;
}

.hema-swatches-color .hema-swatch:hover {
  border-color: var(--c-border-medium);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.hema-swatches-color .hema-swatch.selected {
  border-color: var(--c-black);
  background: var(--c-bg-secondary);
}

.hema-swatches-color .hema-swatch-color {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--c-border-light);
  flex-shrink: 0;
  display: block;
}

/* BUTTON SWATCHES - Text only */
.hema-swatches-button .hema-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-lg);
  border: 2px solid var(--c-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  background: var(--c-white);
  min-width: 80px;
}

.hema-swatches-button .hema-swatch:hover {
  border-color: var(--c-border-medium);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.hema-swatches-button .hema-swatch.selected {
  border-color: var(--c-black);
  background: var(--c-black);
  color: var(--c-white);
}

.hema-swatches-button .hema-swatch.selected .hema-swatch-label {
  color: var(--c-white);
}

/* COMMON SWATCH LABEL STYLES */
.hema-swatch-label {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--c-text-primary);
  line-height: 1.2;
}

.hema-swatch.selected .hema-swatch-label {
  font-weight: 700;
}

/* Hide original select */
.hema-swatches + select {
  display: none !important;
}

/* Force variations table to full width */
.variations {
  width: 100% !important;
  table-layout: fixed !important;
}

/* Reposition WooCommerce variation table for swatches */
.variations tr:has(.hema-swatches) {
  display: flex !important;
  flex-direction: column !important;
  gap: var(--space-base) !important;
  margin-bottom: var(--space-lg) !important;
  width: 100% !important;
}

.variations tr:has(.hema-swatches) .label {
  display: block !important;
  width: 100% !important;
  padding: 0 !important;
}

.variations tr:has(.hema-swatches) .label label {
  font-size: var(--text-lg) !important;
  font-weight: 600 !important;
  font-family: var(--font-body) !important;
  color: var(--c-text-primary) !important;
  margin: 0 !important;
}

.variations tr:has(.hema-swatches) .value {
  display: block !important;
  width: 100% !important;
  padding: 0 !important;
}

/* ==========================================================================
   SHOP / ARCHIVE PAGE SWATCHES
   ========================================================================== */

.hema-shop-swatches-wrapper {
  padding: 0 var(--space-base);
  margin-top: var(--space-sm);
}

.hema-shop-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-xs);
}

/* IMAGE SWATCHES - Small thumbnails */
.hema-shop-swatch-image {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--c-border-light);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.hema-shop-swatch-image:hover {
  border-color: var(--c-black);
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 2;
}

.hema-shop-swatch-image.active {
  border-color: var(--c-black);
  box-shadow: 0 0 0 1px var(--c-black);
}

.hema-shop-swatch-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* COLOR SWATCHES - Small circles */
.hema-shop-swatch-color {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--c-border-light);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hema-shop-swatch-color:hover {
  border-color: var(--c-black);
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 2;
}

.hema-shop-swatch-color.active {
  border-color: var(--c-black);
  box-shadow: 0 0 0 1px var(--c-black);
}

.hema-shop-swatch-color .hema-swatch-color {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
  /* Force full width for all swatch types */
  .hema-swatches {
    width: 100% !important;
  }
  
  /* Single product swatches - IMAGE (stack vertically) */
  .hema-swatches-image {
    width: 100%;
    flex-direction: column;
  }
  
  .hema-swatches-image .hema-swatch {
    width: 100%;
    padding: var(--space-xs);
    gap: var(--space-lg);
  }
  
  .hema-swatches-image .hema-swatch img {
    width: 120px;
    height: 120px;
  }
  
  /* Single product swatches - BUTTON & COLOR (stay in row) */
  .hema-swatches-button,
  .hema-swatches-color {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  .hema-swatches-button .hema-swatch,
  .hema-swatches-color .hema-swatch {
    flex: 0 1 auto;
    min-width: auto;
    padding: var(--space-xs) var(--space-base);
  }

  .hema-swatches-color .hema-swatch-color {
    width: 28px;
    height: 28px;
  }

  .hema-swatch-label {
    font-size: var(--text-sm);
  }
  
  /* Shop swatches */
  .hema-shop-swatch-image {
    width: 48px;
    height: 48px;
  }
  
  .hema-shop-swatch-color {
    width: 24px;
    height: 24px;
  }
}




/* ==========================================================================
   OUT OF STOCK SWATCH STYLING 
   ========================================================================== */

/* Out of stock state for all swatch types */
.hema-swatch.out-of-stock {
  opacity: 0.4;
  position: relative;
  cursor: not-allowed;
  filter: grayscale(60%);
}

.hema-swatch.out-of-stock:hover {
  border-color: var(--c-border-light);
  box-shadow: none;
  transform: none;
}

/* Out of stock badge */
.hema-swatch.out-of-stock::after {
  content: 'Out of stock';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.75);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 10;
}

.hema-swatch.out-of-stock:hover::after {
  opacity: 1;
}

/* IMAGE SWATCHES - Different layout for badge */
.hema-swatches-image .hema-swatch.out-of-stock::after {
  content: 'Out of stock';
  position: static;
  transform: none;
  display: block;
  margin-top: 8px;
  background: transparent;
  color: var(--c-text-muted);
  padding: 0;
  opacity: 1;
  font-size: 11px;
}

.hema-swatches-image .hema-swatch.out-of-stock:hover::after {
  opacity: 1;
}

/* Prevent selection when out of stock */
.hema-swatch.out-of-stock.selected {
  border-color: var(--c-border-light) !important;
  background: transparent !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .hema-swatch.out-of-stock::after {
    font-size: 9px;
    padding: 3px 6px;
  }
}