/**
 * SUPERPRECIO - QUANTITY SELECTOR
 * Mobile-First Quantity Controls with Gamification
 * Corporate Identity: Forest Green #136213
 */

/* ==================================
   QUANTITY SELECTOR - INLINE (Search Results)
   Replaces add-to-cart button after first add
   ================================== */

.sp-qty-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-top: 1rem;
  width: 100%;
  max-width: 220px;
  margin-left: auto;
  margin-right: auto;
  background: linear-gradient(135deg, #f0fdf4 0%, #e6f4e6 100%);
  border: 2px solid var(--sp-color-primary, #136213);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(19, 98, 19, 0.15);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 44px;
}

.sp-qty-selector:hover {
  box-shadow: 0 6px 20px rgba(19, 98, 19, 0.25);
}

/* Minus / Plus Buttons */
.sp-qty-selector__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--sp-color-primary, #136213);
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.sp-qty-selector__btn:hover:not(:disabled) {
  background: var(--sp-color-primary, #136213);
  color: white;
}

.sp-qty-selector__btn:active:not(:disabled) {
  transform: scale(0.9);
}

.sp-qty-selector__btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Remove button (minus when qty=1 becomes trash) */
.sp-qty-selector__btn--remove {
  color: var(--sp-color-danger, #dc3545);
}

.sp-qty-selector__btn--remove:hover:not(:disabled) {
  background: var(--sp-color-danger, #dc3545);
  color: white;
}

/* Quantity Display */
.sp-qty-selector__value {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 56px;
  height: 44px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--sp-color-primary-dark, #0a4a0a);
  background: white;
  border-left: 1px solid rgba(19, 98, 19, 0.15);
  border-right: 1px solid rgba(19, 98, 19, 0.15);
  font-variant-numeric: tabular-nums;
  position: relative;
  overflow: hidden;
}

/* Quantity number animation */
.sp-qty-selector__num {
  display: inline-block;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.sp-qty-selector__num--up {
  animation: sp-qty-slide-up 0.25s ease;
}

.sp-qty-selector__num--down {
  animation: sp-qty-slide-down 0.25s ease;
}

@keyframes sp-qty-slide-up {
  0% { transform: translateY(100%); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes sp-qty-slide-down {
  0% { transform: translateY(-100%); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* ==================================
   QUANTITY SELECTOR - CART PAGE (Compact)
   Used inside grouped product cards
   ================================== */

.sp-qty-selector--compact {
  max-width: 140px;
  min-height: 36px;
  margin: 0;
  border-radius: 8px;
  border-width: 1.5px;
}

.sp-qty-selector--compact .sp-qty-selector__btn {
  width: 36px;
  height: 36px;
  font-size: 1rem;
}

.sp-qty-selector--compact .sp-qty-selector__value {
  min-width: 40px;
  height: 36px;
  font-size: 1rem;
}

/* ==================================
   QUANTITY BADGE (on add-to-cart button when in cart)
   Small indicator showing current quantity
   ================================== */

.sp-qty-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  background: linear-gradient(135deg, var(--sp-color-primary, #136213), var(--sp-color-primary-dark, #0a4a0a));
  color: white;
  border-radius: 11px;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(19, 98, 19, 0.3);
  z-index: 2;
  font-variant-numeric: tabular-nums;
}

/* ==================================
   GAMIFICATION - QUANTITY MILESTONES
   Visual rewards for adding more items
   ================================== */

/* Sparkle burst on quantity change */
.sp-qty-selector--burst {
  animation: sp-qty-burst 0.4s ease-out;
}

@keyframes sp-qty-burst {
  0% { transform: scale(1); }
  30% { transform: scale(1.08); }
  60% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

/* Milestone celebration toast */
.sp-qty-milestone {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, var(--sp-color-primary, #136213), var(--sp-color-primary-dark, #0a4a0a));
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(19, 98, 19, 0.4);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}

.sp-qty-milestone--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sp-qty-milestone__icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.sp-qty-milestone__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sp-qty-milestone__title {
  font-weight: 800;
  font-size: 0.95rem;
}

.sp-qty-milestone__subtitle {
  font-weight: 400;
  font-size: 0.8rem;
  opacity: 0.85;
}

/* Savings highlight - shows total savings when qty > 1 */
.sp-qty-savings {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--sp-color-primary, #136213);
  opacity: 0;
  transform: translateY(-5px);
  transition: all 0.3s ease;
}

.sp-qty-savings--visible {
  opacity: 1;
  transform: translateY(0);
}

.sp-qty-savings__icon {
  font-size: 0.85rem;
}

/* ==================================
   CART PAGE QUANTITY DISPLAY
   Shows quantity in grouped product cards
   ================================== */

.sp-grouped-product__quantity-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.5rem;
}

.sp-grouped-product__quantity-label {
  font-size: var(--sp-font-size-xs, 0.8rem);
  color: var(--sp-color-text-secondary, #6c757d);
  font-weight: 600;
  white-space: nowrap;
}

/* Market-level quantity in expanded accordion */
.sp-market-price-item__quantity {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ==================================
   FLOATING CART QUANTITY INDICATOR
   ================================== */

.sp-floating-cart__qty-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  background: linear-gradient(135deg, var(--sp-color-primary, #136213), var(--sp-color-primary-dark, #0a4a0a));
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 0 5px;
  margin-left: 0.375rem;
  flex-shrink: 0;
}

/* ==================================
   ADD-TO-CART BUTTON STATES
   ================================== */

/* Container for button + quantity selector transition */
.sp-cart-action-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* When product is already in cart, show quantity selector */
.sp-cart-action-wrapper .add-to-cart-button.sp-in-cart {
  background: linear-gradient(135deg, #f0fdf4 0%, #e6f4e6 100%);
  color: var(--sp-color-primary, #136213);
  border: 2px solid var(--sp-color-primary, #136213);
  box-shadow: 0 4px 12px rgba(19, 98, 19, 0.15);
  position: relative;
}

.sp-cart-action-wrapper .add-to-cart-button.sp-in-cart:hover:not(:disabled) {
  background: linear-gradient(135deg, #e6f4e6 0%, #d4edda 100%);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(19, 98, 19, 0.25);
}

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

@media (min-width: 768px) {
  .sp-qty-selector {
    margin-left: auto;
    margin-right: 0;
    max-width: 200px;
  }

  .sp-qty-selector__btn {
    width: 44px;
    height: 42px;
  }

  .sp-qty-selector__value {
    height: 42px;
  }
}

@media (max-width: 374px) {
  .sp-qty-selector {
    max-width: 100%;
  }

  .sp-qty-selector__btn {
    width: 44px;
  }
}

/* ==================================
   ACCESSIBILITY
   ================================== */

@media (prefers-reduced-motion: reduce) {
  .sp-qty-selector__num--up,
  .sp-qty-selector__num--down {
    animation: none;
  }

  .sp-qty-selector--burst {
    animation: none;
  }

  .sp-qty-milestone {
    transition: opacity 0.1s;
  }
}

@media (prefers-contrast: high) {
  .sp-qty-selector {
    border-width: 3px;
  }

  .sp-qty-selector__value {
    border-left-width: 2px;
    border-right-width: 2px;
  }
}

@media print {
  .sp-qty-selector__btn {
    display: none;
  }

  .sp-qty-milestone {
    display: none;
  }
}

/* =============================================
   CART ADD SUCCESS TOAST
   Brief confirmation when product is added
   ============================================= */

.sp-cart-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #136213;
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 1060;
  box-shadow: 0 8px 24px rgba(19, 98, 19, 0.35);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.sp-cart-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sp-cart-toast i {
  font-size: 1.1rem;
}

@media (prefers-reduced-motion: reduce) {
  .sp-cart-toast {
    transition: none;
  }
}
