/**
 * Cart Performance Optimizations CSS
 * Styles for virtual scrolling, lazy loading, and performance enhancements
 */

/* Virtual Scrolling Styles */
.virtual-scroll-wrapper {
  height: 600px;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #ffffff;
}

.virtual-scroll-content {
  position: relative;
  width: 100%;
}

.virtual-scroll-wrapper .cart-item {
  position: absolute;
  width: 100%;
  box-sizing: border-box;
  padding: 16px;
  border-bottom: 1px solid #f3f4f6;
  background: #ffffff;
  transition: none;
  /* Disable transitions for better performance */
}

/* Performance optimizations for cart items */
.cart-item {
  contain: layout style paint;
  /* CSS containment for better performance */
  will-change: auto;
  /* Let browser optimize */
}

.cart-item:hover {
  transform: translateZ(0);
  /* Force hardware acceleration */
}

/* Lazy loading states */
.cart-integration-loading {
  opacity: 0.7;
  pointer-events: none;
}

.cart-integration-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Optimized button states */
.add-to-cart {
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.add-to-cart.loading {
  background-color: #9ca3af;
  cursor: not-allowed;
}

.add-to-cart.success {
  background-color: #10b981;
  transform: scale(1.02);
}

.add-to-cart.error {
  background-color: #ef4444;
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-4px);
  }

  75% {
    transform: translateX(4px);
  }
}

/* Performance-optimized toast notifications */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 6px;
  color: white;
  font-weight: 500;
  z-index: 10000;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.toast.show {
  transform: translateX(0);
}

.toast.success {
  background-color: #10b981;
}

.toast.error {
  background-color: #ef4444;
}

.toast.info {
  background-color: #3b82f6;
}

.toast.warning {
  background-color: #f59e0b;
}

/* Optimized quantity controls */
.quantity-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quantity-btn {
  width: 32px !important;
  height: 32px !important;
  border: 1px solid #d1d5db !important;
  background: #ffffff !important;
  border-radius: 4px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: background-color 0.15s ease !important;
  user-select: none !important;
  color: #374151 !important;
  font-size: 14px !important;
}

.quantity-btn i {
  color: #374151 !important;
  font-size: 12px !important;
}

.quantity-btn:hover:not(:disabled) {
  background-color: #f9fafb !important;
}

.quantity-btn:hover:not(:disabled) i {
  color: #111827 !important;
}

.quantity-btn:disabled {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  background: #e5e7eb !important;
}

.quantity-btn:disabled i {
  color: #9ca3af !important;
}

.quantity-input {
  width: 60px;
  height: 32px;
  text-align: center;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
}

/* Cart count indicator optimizations */
.cart-count {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cart-count:not([style*="display: none"]) {
  transform: scale(1);
}

/* Loading states */
.cart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #6b7280;
}

.cart-loading .spinner {
  width: 24px;
  height: 24px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 12px;
}

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

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

/* Error states */
.cart-error {
  text-align: center;
  padding: 40px 20px;
  color: #6b7280;
}

.cart-error .error-icon {
  font-size: 48px;
  color: #ef4444;
  margin-bottom: 16px;
}

.error-retry-btn {
  background: #3b82f6;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  margin-top: 16px;
  transition: background-color 0.2s ease;
}

.error-retry-btn:hover {
  background: #2563eb;
}

/* Network error specific styles */
.network-error {
  text-align: center;
  padding: 60px 20px;
}

.network-error-icon {
  font-size: 64px;
  color: #f59e0b;
  margin-bottom: 24px;
}

.network-error h3 {
  color: #374151;
  margin-bottom: 12px;
  font-size: 24px;
}

.network-error p {
  color: #6b7280;
  margin-bottom: 24px;
  line-height: 1.6;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .virtual-scroll-wrapper {
    height: 400px;
    /* Smaller height on mobile */
  }

  .cart-item {
    padding: 12px;
    /* Reduced padding on mobile */
  }

  .quantity-controls {
    gap: 4px;
    /* Tighter spacing on mobile */
  }

  .quantity-btn {
    width: 28px;
    height: 28px;
  }

  .quantity-input {
    width: 50px;
    height: 28px;
    font-size: 13px;
  }

  .toast {
    right: 10px;
    left: 10px;
    transform: translateY(-100%);
  }

  .toast.show {
    transform: translateY(0);
  }
}

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

  .cart-item,
  .add-to-cart,
  .toast,
  .cart-count {
    transition: none;
    animation: none;
  }

  .add-to-cart.success {
    transform: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .cart-item {
    border-color: #000000;
  }

  .quantity-btn {
    border-color: #000000;
  }

  .virtual-scroll-wrapper {
    border-color: #000000;
  }
}