/* ============================================================
   CART DRAWER — Tu Cajita
   Drawer lateral derecho, overlay, items, qty, footer.
   ============================================================ */

/* --- Overlay backdrop --- */

.cart-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(46, 28, 38, 0.50);
  z-index: calc(var(--z-drawer) - 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.cart-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* --- Drawer --- */

.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  background-color: var(--color-white);
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  box-shadow: -8px 0 40px rgba(46, 28, 38, 0.18);
}

.cart-drawer.open {
  transform: translateX(0);
}

/* --- Cabecera del drawer --- */

.cart-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.cart-drawer-title {
  font-family: var(--font-serif);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.cart-count-label {
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-light);
}

.btn-cart-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  color: var(--color-text-light);
  background: none;
  border: none;
  cursor: pointer;
  transition: background-color var(--transition-fast),
              color var(--transition-fast);
}

.btn-cart-close:hover {
  background-color: var(--color-accent-subtle);
  color: var(--color-accent);
}

/* --- Cuerpo: scrollable --- */

.cart-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* --- Estado vacío --- */

.cart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-4);
  text-align: center;
  padding: var(--space-12) var(--space-6);
}

.cart-empty-icon {
  font-size: 3rem;
  opacity: 0.25;
  line-height: 1;
}

.cart-empty p {
  font-size: var(--font-size-md);
  color: var(--color-text-light);
}

/* --- Lista de items --- */

.cart-items {
  padding: var(--space-2) var(--space-6);
}

.cart-item {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border);
  align-items: flex-start;
}

.cart-item:last-child {
  border-bottom: none;
}

.cart-item-img-link {
  display: block;
  width: 76px;
  height: 76px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: var(--color-bg);
}

.cart-item-img-link img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cart-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.cart-item-name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semi);
  color: var(--color-text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  display: block;
}

.cart-item-name:hover {
  color: var(--color-accent);
}

.cart-item-unit-price {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
}

.cart-item-subtotal {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

/* Qty mini control dentro del item */
.cart-qty-control {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.cart-qty-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: var(--font-size-md);
  color: var(--color-text);
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  transition: background-color var(--transition-fast),
              color var(--transition-fast);
}

.cart-qty-btn:hover {
  background-color: var(--color-accent-subtle);
  color: var(--color-accent);
}

.cart-qty-value {
  min-width: 30px;
  text-align: center;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semi);
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  padding: 0 var(--space-1);
  user-select: none;
  line-height: 28px;
}

/* Botón eliminar */
.cart-item-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  color: var(--color-text-light);
  background: none;
  border: none;
  cursor: pointer;
  margin-top: 2px;
  transition: background-color var(--transition-fast),
              color var(--transition-fast);
}

.cart-item-remove:hover {
  background-color: var(--color-accent-subtle);
  color: var(--color-accent);
}

/* --- Footer: subtotal + checkout --- */

.cart-drawer-footer {
  flex-shrink: 0;
  padding: var(--space-5) var(--space-6) var(--space-6);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background-color: var(--color-white);
}

.cart-subtotal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cart-subtotal-label {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.cart-subtotal-amount {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

/* Barra de progreso hacia envío gratis */
.cart-shipping-progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.cart-shipping-note {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
  text-align: center;
}

.cart-progress-bar {
  height: 4px;
  background-color: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.cart-progress-fill {
  height: 100%;
  background-color: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
  max-width: 100%;
}

.btn-checkout {
  width: 100%;
  padding: var(--space-4);
  font-size: var(--font-size-base);
}

/* --- Responsive --- */

@media (max-width: 480px) {
  .cart-drawer {
    width: 100vw;
  }

  /* Padding extra en iOS para el home indicator */
  .cart-drawer-footer {
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  }
}

/* Tap targets mínimos en móvil */
@media (hover: none) {
  .cart-qty-btn,
  .cart-item-remove,
  .btn-cart-close {
    min-width: 44px;
    min-height: 44px;
  }
}
