/* ===========================================
   SISTEMA DE CARRITO Y FAVORITOS - NUEVO
   ========================================= */

/* CARRITO SIDEBAR */
.cart-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  overflow: hidden;
  pointer-events: none; /* No bloquea clicks cuando está invisible */
}

.cart-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto; /* Bloquea clicks cuando está visible */
}

.cart-sidebar {
  position: fixed !important;
  top: 0 !important;
  bottom: 0 !important;
  right: -100%;
  width: 100%;
  max-width: 400px;
  height: auto !important;
  min-height: 100vh;
  max-height: 100vh;
  background: white;
  z-index: 1001 !important;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.cart-sidebar.active {
  right: 0 !important;
}

/* Estado body con carrito abierto: desactiva scroll de página */
body.body-cart-open {
  overflow: hidden;
}

.cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  flex-shrink: 0; /* No se comprime */
}

.cart-header h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
}

.cart-close-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.cart-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.cart-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  min-height: 0; /* Importante para que flex funcione correctamente */
}

.cart-items {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cart-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
  transition: all 0.2s ease;
}

.cart-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.cart-item-info {
  flex: 1;
}

.cart-item-info h4 {
  margin: 0 0 4px 0;
  font-size: 0.95rem;
  color: #374151;
  font-weight: 600;
}

.cart-item-meta {
  font-size: 0.8rem;
  color: #6b7280;
  margin: 0 0 4px 0;
}

.cart-item-price {
  font-weight: 600;
  color: #667eea;
  font-size: 0.9rem;
  margin: 0;
}

.cart-item-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cart-item-quantity {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 8px;
}

.qty-btn {
  background: #667eea;
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.qty-btn:hover {
  background: #5a67d8;
  transform: scale(1.1);
}

.qty-btn:active {
  transform: scale(0.95);
}

.qty-display {
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 24px;
  text-align: center;
  color: #374151;
}

.cart-item-subtotal {
  font-weight: 700;
  color: #374151;
  font-size: 1rem;
}

.cart-item-image {
  width: 60px;
  height: 60px;
  border-radius: 6px;
  background: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.cart-item-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: #374151;
}

.cart-item-code {
  font-size: 0.8rem;
  color: #6b7280;
  margin-bottom: 4px;
}

.cart-quantity-btn {
  background: #667eea;
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.cart-quantity-btn:hover {
  background: #5a67d8;
  transform: scale(1.1);
}

.cart-quantity-btn:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  transform: none;
}

.cart-quantity {
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 20px;
  text-align: center;
}

.cart-item-remove {
  background: #ef4444;
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all 0.2s ease;
}

.cart-item-remove:hover {
  background: #dc2626;
  transform: scale(1.1);
}

.cart-empty {
  text-align: center;
  padding: 40px 20px;
  color: #6b7280;
}

.cart-empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.cart-empty p {
  margin: 0 0 8px 0;
  font-weight: 600;
}

.cart-empty-subtitle {
  font-size: 0.9rem;
  opacity: 0.8;
}

.cart-footer {
  border-top: 1px solid #e5e7eb;
  padding: 20px;
  background: #f9fafb;
  flex-shrink: 0; /* No se comprime */
}

.cart-summary {
  margin-bottom: 16px;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #374151;
}

.cart-total span:last-child {
  color: #667eea;
}

.cart-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cart-checkout-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.95rem;
}

.cart-checkout-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.cart-clear-btn {
  background: transparent;
  border: 2px solid #ef4444;
  color: #ef4444;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
}

.cart-clear-btn:hover {
  background: #ef4444;
  color: white;
}

/* MODAL DE FAVORITOS */
.favorites-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.favorites-modal.active {
  opacity: 1;
  visibility: visible;
}

.favorites-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
}

.favorites-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 95%;
  max-width: 800px;
  max-height: 90vh;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.favorites-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
  color: white;
}

.favorites-header h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
}

.favorites-close-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.favorites-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.favorites-body {
  max-height: 60vh;
  overflow-y: auto;
  padding: 24px;
}

.favorites-items {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.favorite-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
  transition: all 0.3s ease;
}

.favorite-item:hover {
  border-color: #ec4899;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.favorite-item-image {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  background: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

.favorite-item-info {
  flex: 1;
}

.favorite-item-name {
  font-weight: 600;
  margin-bottom: 4px;
  color: #374151;
}

.favorite-item-brand {
  font-size: 0.9rem;
  color: #6b7280;
  margin-bottom: 4px;
}

.favorite-item-code {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-bottom: 8px;
}

.favorite-item-price {
  font-weight: 700;
  font-size: 1.1rem;
  color: #ec4899;
}

.favorite-item-stock {
  font-size: 0.8rem;
  margin-top: 4px;
}

.favorite-item-stock.available {
  color: #10b981;
}

.favorite-item-stock.out-of-stock {
  color: #ef4444;
}

.favorite-item-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.favorite-add-cart-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.favorite-add-cart-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.favorite-add-cart-btn:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

.favorite-remove-btn {
  background: transparent;
  border: none;
  color: #ef4444;
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.favorite-remove-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  transform: scale(1.1);
}

.favorites-empty {
  text-align: center;
  padding: 60px 20px;
  color: #6b7280;
}

.favorites-empty-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  opacity: 0.5;
}

.favorites-empty p {
  margin: 0 0 8px 0;
  font-weight: 600;
  font-size: 1.1rem;
}

.favorites-empty-subtitle {
  font-size: 0.9rem;
  opacity: 0.8;
}

/* RESPONSIVE DESIGN */
@media (min-width: 768px) {
  .cart-sidebar {
    max-width: 420px;
  }

  .favorites-content {
    width: 90%;
    max-width: 900px;
  }

  .favorites-items {
    grid-template-columns: 1fr 1fr;
  }

  .favorite-item-actions {
    flex-direction: row;
    gap: 12px;
  }
}

@media (min-width: 1024px) {
  .favorites-items {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
