/**
 * SwaraPlace Theme - Product Variations CSS
 * File: /assets/css/product-variations.css
 * 
 * Shopee-style variations with button interface
 * Modern, responsive, and user-friendly design
 */

/* ==========================================================================
   CSS Variables for Variations
   ========================================================================== */

:root {
  /* Variation Colors */
  --variation-border-color: #e5e7eb;
  --variation-border-hover: var(--swaraplace-primary);
  --variation-bg-default: #ffffff;
  --variation-bg-hover: rgba(var(--swaraplace-primary-rgb), 0.08);
  --variation-bg-selected: var(--swaraplace-primary);
  --variation-bg-disabled: #f9fafb;
  
  /* Text Colors */
  --variation-text-default: black;
  --variation-text-hover: var(--swaraplace-primary);
  --variation-text-selected: #ffffff;
  --variation-text-disabled: #9ca3af;
  
  /* Shadows */
  --variation-shadow-default: 0 1px 2px rgba(0, 0, 0, 0.05);
  --variation-shadow-hover: 0 2px 4px rgba(var(--swaraplace-primary-rgb), 0.15);
  --variation-shadow-selected: 0 2px 8px rgba(var(--swaraplace-primary-rgb), 0.3);
  --variation-shadow-disabled: none;
  
  /* Transitions */
  --variation-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --variation-transition-fast: all 0.15s ease;
}

/* ==========================================================================
   Product Variations Container
   ========================================================================== */

.product-variations {
  margin-bottom: var(--swaraplace-space-6);
  padding: var(--swaraplace-space-6);
  background-color: var(--swaraplace-white);
  border: 1px solid var(--swaraplace-gray-200);
  border-radius: var(--swaraplace-radius-lg);
  box-shadow: var(--swaraplace-shadow-sm);
}

.variation-group {
  margin-bottom: var(--swaraplace-space-5);
  position: relative;
}

.variation-group:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   Variation Labels
   ========================================================================== */

.variation-label {
  display: block;
  font-weight: 600;
  color: var(--swaraplace-gray-800);
  margin-bottom: var(--swaraplace-space-3);
  font-size: 0.9375rem;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.variation-label::after {
  content: '*';
  color: var(--swaraplace-error);
  margin-left: 4px;
  font-weight: 400;
}

/* ==========================================================================
   Variation Options Container
   ========================================================================== */

.variation-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--swaraplace-space-2);
  align-items: flex-start;
}

/* ==========================================================================
   Variation Option Buttons - Main Styling
   ========================================================================== */

.variation-option-btn {
  /* Layout */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--swaraplace-space-3) var(--swaraplace-space-4);
  min-width: 65px;
  min-height: 44px;
  
  /* Typography */
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
  
  /* Appearance - Default: White Background */
  background-color: #ffffff;
  border: 1.5px solid var(--variation-border-color);
  border-radius: var(--swaraplace-radius);
  color: grey;
  box-shadow: var(--variation-shadow-default);
  
  /* Interaction */
  cursor: pointer;
  user-select: none;
  transition: var(--variation-transition);
  
  /* Remove default button styles */
  outline: none;
  text-decoration: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

/* ==========================================================================
   Variation Button States
   ========================================================================== */

/* Hover State - Orange Highlight */
.variation-option-btn:hover:not(.disabled):not(.selected) {
  background-color: rgba(var(--swaraplace-primary-rgb), 0.08);
  border-color: var(--swaraplace-primary);
  color: var(--swaraplace-primary);
  box-shadow: 0 2px 6px rgba(var(--swaraplace-primary-rgb), 0.15);
  transform: translateY(-1px);
}

/* Focus State */
.variation-option-btn:focus:not(.disabled) {
  border-color: var(--swaraplace-primary);
  box-shadow: 0 0 0 3px rgba(var(--swaraplace-primary-rgb), 0.15);
}

/* Active/Pressed State */
.variation-option-btn:active:not(.disabled) {
  transform: translateY(0);
  background-color: rgba(var(--swaraplace-primary-rgb), 0.12);
  box-shadow: 0 1px 3px rgba(var(--swaraplace-primary-rgb), 0.2);
}

/* Selected State - Reverse Colors (Orange Background, White Text) */
.variation-option-btn.selected {
  background-color: var(--swaraplace-primary);
  border-color: var(--swaraplace-primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(var(--swaraplace-primary-rgb), 0.35);
  z-index: 2;
  position: relative;
  transform: translateY(-1px);
}

.variation-option-btn.selected:hover {
  background-color: rgba(var(--swaraplace-primary-rgb), 0.9);
  border-color: rgba(var(--swaraplace-primary-rgb), 0.9);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(var(--swaraplace-primary-rgb), 0.4);
}

.variation-option-btn.selected::before {
  content: '';
  position: absolute;
  inset: -3px;
  border: 2px solid rgba(var(--swaraplace-primary-rgb), 0.3);
  border-radius: calc(var(--swaraplace-radius) + 3px);
  pointer-events: none;
  animation: selectedPulse 1.8s ease-out;
}

/* Disabled State */
.variation-option-btn.disabled {
  background-color: var(--variation-bg-disabled);
  border-color: var(--swaraplace-gray-200);
  color: var(--variation-text-disabled);
  cursor: not-allowed;
  box-shadow: var(--variation-shadow-disabled);
  position: relative;
  overflow: hidden;
}

.variation-option-btn.disabled::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 4px;
  right: 4px;
  height: 1px;
  background-color: var(--variation-text-disabled);
  transform: translateY(-50%) rotate(-12deg);
  pointer-events: none;
}

.variation-option-btn.disabled::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    rgba(156, 163, 175, 0.1) 4px,
    rgba(156, 163, 175, 0.1) 8px
  );
  pointer-events: none;
}

/* ==========================================================================
   Size Variations (Special Styling)
   ========================================================================== */

.variation-options[data-attribute*="size"] .variation-option-btn,
.variation-options[data-attribute*="ukuran"] .variation-option-btn {
  min-width: 50px;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

/* ==========================================================================
   Color Variations (Special Styling)
   ========================================================================== */

.variation-options[data-attribute*="color"] .variation-option-btn,
.variation-options[data-attribute*="warna"] .variation-option-btn {
  position: relative;
  padding-left: var(--swaraplace-space-8);
}

.variation-options[data-attribute*="color"] .variation-option-btn::before,
.variation-options[data-attribute*="warna"] .variation-option-btn::before {
  content: '';
  position: absolute;
  left: var(--swaraplace-space-2);
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--swaraplace-gray-300);
  background-color: currentColor;
}

/* ==========================================================================
   Cart Actions Section
   ========================================================================== */

.cart-actions {
  display: flex;
  flex-direction: column;
  gap: var(--swaraplace-space-5);
  margin-top: var(--swaraplace-space-6);
  padding-top: var(--swaraplace-space-6);
  border-top: 1px solid var(--swaraplace-gray-200);
}

/* ==========================================================================
   Quantity Controls
   ========================================================================== */

.quantity-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--swaraplace-space-2);
  max-width: 200px;
}

.quantity-wrapper label {
  font-weight: 600;
  color: var(--swaraplace-gray-800);
  font-size: 0.875rem;
  line-height: 1.4;
}

.quantity-controls {
  display: flex;
  align-items: center;
  width: fit-content;
  border: 1.5px solid var(--swaraplace-gray-300);
  border-radius: var(--swaraplace-radius);
  overflow: hidden;
  background-color: var(--swaraplace-white);
  box-shadow: var(--swaraplace-shadow-sm);
  transition: var(--variation-transition-fast);
  min-width: -webkit-fill-available !important;
}

.quantity-controls:hover {
  border-color: var(--swaraplace-primary);
  box-shadow: 0 2px 4px rgba(var(--swaraplace-primary-rgb), 0.1);
}

.quantity-controls:focus-within {
  border-color: var(--swaraplace-primary);
  box-shadow: 0 0 0 3px rgba(var(--swaraplace-primary-rgb), 0.1);
}

/* Quantity Buttons */
.qty-btn {
  width: 42px;
  height: 42px;
  border: none;
  background-color: var(--swaraplace-gray-50);
  color: var(--swaraplace-gray-600);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--variation-transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.qty-btn:hover {
  background-color: var(--swaraplace-primary);
  color: var(--swaraplace-white);
}

.qty-btn:active {
  background-color: rgba(var(--swaraplace-primary-rgb), 0.9);
  transform: scale(0.95);
}

.qty-btn:disabled {
  background-color: var(--swaraplace-gray-100);
  color: var(--swaraplace-gray-400);
  cursor: not-allowed;
}

/* Quantity Input */
.quantity-controls input[type="number"] {
  width: 100%;
  height: 42px;
  border: none;
  border-left: 1px solid var(--swaraplace-gray-300);
  border-right: 1px solid var(--swaraplace-gray-300);
  text-align: center;
  font-size: 0.9375rem;
  font-weight: 600;
  background-color: var(--swaraplace-white);
  color: var(--swaraplace-gray-800);
  outline: none;
  transition: var(--variation-transition-fast);
}

.quantity-controls input[type="number"]:focus {
  background-color: rgba(var(--swaraplace-primary-rgb), 0.02);
}

/* Remove number input arrows */
.quantity-controls input[type="number"]::-webkit-outer-spin-button,
.quantity-controls input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.quantity-controls input[type="number"] {
  -moz-appearance: textfield;
}

/* ==========================================================================
   Add to Cart Button Enhancement
   ========================================================================== */

.single_add_to_cart_button {
  /* Layout */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--swaraplace-space-2);
  width: 100%;
  padding: var(--swaraplace-space-4) var(--swaraplace-space-6);
  
  /* Typography */
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  
  /* Appearance */
  background-color: var(--swaraplace-primary);
  color: var(--swaraplace-white);
  border: 2px solid var(--swaraplace-primary);
  border-radius: var(--swaraplace-radius-lg);
  box-shadow: 0 2px 4px rgba(var(--swaraplace-primary-rgb), 0.2);
  
  /* Interaction */
  cursor: pointer;
  transition: var(--variation-transition);
  user-select: none;
  outline: none;
}

.single_add_to_cart_button:hover:not(:disabled) {
  background-color: rgba(var(--swaraplace-primary-rgb), 0.9);
  border-color: rgba(var(--swaraplace-primary-rgb), 0.9);
  color: var(--swaraplace-white);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(var(--swaraplace-primary-rgb), 0.3);
}

.single_add_to_cart_button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(var(--swaraplace-primary-rgb), 0.2);
}

.single_add_to_cart_button:focus {
  box-shadow: 0 0 0 3px rgba(var(--swaraplace-primary-rgb), 0.2);
}

/* Disabled State */
.single_add_to_cart_button.disabled,
.single_add_to_cart_button:disabled {
  background-color: var(--swaraplace-gray-300);
  border-color: var(--swaraplace-gray-300);
  color: var(--swaraplace-gray-500);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Loading State */
.single_add_to_cart_button.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.single_add_to_cart_button.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: buttonSpin 0.8s linear infinite;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes selectedPulse {
  0% {
    opacity: 0;
    transform: scale(0.95);
  }
  40% {
    opacity: 1;
    transform: scale(1.03);
  }
  100% {
    opacity: 0;
    transform: scale(1.08);
  }
}

@keyframes buttonSpin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Tablet */
@media (max-width: 768px) {
  .product-variations {
    padding: var(--swaraplace-space-4);
    margin-bottom: var(--swaraplace-space-4);
  }
  
  .variation-options {
    gap: var(--swaraplace-space-1);
  }
  
  .variation-option-btn {
    min-width: 50px;
    min-height: 36px;
    padding: var(--swaraplace-space-1) var(--swaraplace-space-3);
    font-size: 0.8125rem;
  }
  
  .cart-actions {
    gap: var(--swaraplace-space-4);
  }
  
  .quantity-controls {
    width: 100%;
    max-width: 160px;
  }
  
  .qty-btn {
    width: 36px;
    height: 36px;
    font-size: 1.125rem;
  }
  
  .quantity-controls input[type="number"] {
    height: 36px;
    font-size: 0.875rem;
  }
  
  .single_add_to_cart_button {
    padding: var(--swaraplace-space-3) var(--swaraplace-space-4);
    font-size: 0.9375rem;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .product-variations {
    padding: var(--swaraplace-space-3);
    border-radius: var(--swaraplace-radius);
  }
  
  .variation-group {
    margin-bottom: var(--swaraplace-space-4);
  }
  
  .variation-label {
    font-size: 0.875rem;
    margin-bottom: var(--swaraplace-space-2);
  }
  
  .variation-options {
    gap: var(--swaraplace-space-1);
  }
  
  .variation-option-btn {
    min-width: 45px;
    min-height: 32px;
    padding: var(--swaraplace-space-1) var(--swaraplace-space-2);
    font-size: 0.75rem;
  }
  
  .quantity-wrapper {
    max-width: 140px;
  }
  
  .qty-btn {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }
  
  .quantity-controls input[type="number"] {
    width: 100%;
    height: auto;
    font-size: 0.8125rem;
  }
  
  .single_add_to_cart_button {
    padding: var(--swaraplace-space-3);
    font-size: 0.875rem;
    border-radius: var(--swaraplace-radius);
  }
}

/* ==========================================================================
   Dark Mode Support (Optional)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
  :root {
    --variation-border-color: #374151;
    --variation-bg-default: #1f2937;
    --variation-bg-hover: rgba(var(--swaraplace-primary-rgb), 0.1);
    --variation-bg-disabled: #111827;
    --variation-text-default: #d1d5db;
    --variation-text-disabled: #6b7280;
  }
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

@media (prefers-contrast: high) {
  .variation-option-btn {
    border-width: 2px;
  }
  
  .variation-option-btn.selected {
    border-width: 3px;
  }
  
  .single_add_to_cart_button {
    border-width: 3px;
  }
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .variation-option-btn,
  .qty-btn,
  .single_add_to_cart_button,
  .quantity-controls {
    transition: none;
  }
  
  .variation-option-btn:hover,
  .single_add_to_cart_button:hover {
    transform: none;
  }
  
  .variation-option-btn.selected::before {
    animation: none;
  }
  
  .single_add_to_cart_button.loading::after {
    animation: none;
  }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
  .product-variations,
  .cart-actions {
    border: 1px solid #000;
    box-shadow: none;
    background: white;
  }
  
  .variation-option-btn.selected {
    background: #000;
    color: white;
  }
  
  .single_add_to_cart_button {
    background: white;
    color: #000;
    border: 2px solid #000;
  }
}