:root {
  --cpo-bg: #f4f6f9;
  --cpo-panel-bg: #fff;
  --cpo-text: #1a1a1a;
  --cpo-muted: #6b7280;
  --cpo-border: #e5e7eb;
  --cpo-accent: #2563eb;
  --cpo-accent-hover: #1d4ed8;
  --cpo-danger: #ef4444;
  --cpo-radius: 12px;
  --cpo-font: system-ui, -apple-system, sans-serif;
}

#cpo-overlay {
  position: fixed;
  top: var(--cpo-top, 0px);
  bottom: var(--cpo-bottom, 0px);
  left: 0;
  right: 0;
  z-index: 9000;
  display: block;
  overflow: auto;
  background: var(--cpo-bg);
  font-family: var(--cpo-font);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

#cpo-overlay.cpo-open { opacity: 1; visibility: visible; pointer-events: auto; z-index: 2147483000; }
/* Mientras el popup del buscador está abierto, este carrito queda DETRÁS */
body.crfs-modal-open #cpo-overlay.cpo-open { z-index: 7000 !important; }

#cpo-updating.cpo-hidden { display: none; }

#cpo-backdrop {
  position: absolute;
  inset: 0;
  background: transparent;
}

#cpo-panel {
  position: relative;
  width: 100%;
  max-width: 1180px;
  min-height: 100%;
  margin: 0 auto;
  padding: 0 22px;
  background: var(--cpo-bg);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  box-shadow: none;
  overflow: visible;
  animation: cpo-slideUp 0.25s ease;
}

@keyframes cpo-slideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#cpo-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 24px;
  background: var(--cpo-panel-bg);
  border: 1px solid var(--cpo-border);
  border-radius: var(--cpo-radius);
  flex-shrink: 0;
  width: 100%;
  margin: 22px 0 0;
  box-sizing: border-box;
}

#cpo-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--cpo-text);
}

#cpo-count {
  color: var(--cpo-muted);
  font-size: 14px;
}

#cpo-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--cpo-muted);
  line-height: 1;
  padding: 0 4px;
}

#cpo-close:hover { color: var(--cpo-text); }

#cpo-body {
  flex: 1;
  padding: 24px;
  display: flex;
  gap: 32px;
  width: 100%;
  background: var(--cpo-panel-bg);
  border: 1px solid var(--cpo-border);
  border-radius: var(--cpo-radius);
  margin: 18px 0 22px;
  box-sizing: border-box;
}

#cpo-items { flex: 1; min-width: 0; }

.cpo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--cpo-border);
}

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

.cpo-item-img img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
}

.cpo-item-info { flex: 1; min-width: 0; }

.cpo-item-name {
  display: block;
  font-weight: 500;
  color: var(--cpo-text);
  font-size: 14px;
  line-height: 1.3;
}

.cpo-item-price {
  display: block;
  color: var(--cpo-muted);
  font-size: 13px;
  margin-top: 2px;
}

.cpo-item-qty {
  display: flex;
  align-items: center;
  border: 1px solid var(--cpo-border);
  border-radius: 6px;
  overflow: hidden;
}

.cpo-qty-btn {
  background: #f9fafb;
  border: none;
  width: 32px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  color: var(--cpo-text);
}

.cpo-qty-btn:hover { background: #e5e7eb; }

.cpo-qty-input {
  width: 64px;
  height: 34px;
  text-align: center;
  border: none;
  border-left: 1px solid var(--cpo-border);
  border-right: 1px solid var(--cpo-border);
  font-size: 13px;
  padding: 0;
  -moz-appearance: textfield;
}

/* Refuerzo de especificidad: gana sobre estilos del tema o plugins de cantidad */
#cpo-overlay .cpo-item-qty .cpo-qty-input,
#cpo-overlay input.cpo-qty-input {
  width: 64px !important;
  min-width: 64px !important;
  max-width: 64px !important;
  padding: 0 !important;
  margin: 0 !important;
  flex: 0 0 64px !important;
}

.cpo-qty-input::-webkit-inner-spin-button,
.cpo-qty-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cpo-item-subtotal {
  font-weight: 600;
  font-size: 15px;
  color: var(--cpo-text);
  min-width: 70px;
  text-align: right;
}

.cpo-item-remove {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--cpo-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.cpo-item-remove:hover { color: var(--cpo-danger); }

#cpo-summary { width: 320px; flex-shrink: 0; }

#cpo-coupon {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#cpo-coupon-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--cpo-border);
  border-radius: 6px;
  font-size: 13px;
}

#cpo-coupon-btn {
  padding: 8px 14px;
  background: var(--cpo-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

#cpo-coupon-btn:hover { background: var(--cpo-accent-hover); }
#cpo-coupon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#cpo-shipping { margin-bottom: 16px; }

#cpo-shipping h4 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--cpo-text);
}

.cpo-shipping-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  cursor: pointer;
  font-size: 13px;
}

.cpo-shipping-option input { accent-color: var(--cpo-accent); }
.cpo-shipping-option span:last-child { margin-left: auto; }

#cpo-totals {
  border-top: 2px solid var(--cpo-border);
  padding-top: 12px;
}

.cpo-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
  color: var(--cpo-muted);
}

.cpo-total-row span:last-child { font-weight: 500; }

.cpo-total-row.cpo-coupon-row span:first-child {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cpo-remove-coupon {
  background: none;
  border: none;
  color: var(--cpo-danger);
  cursor: pointer;
  font-size: 16px;
  padding: 0;
}

.cpo-total-final {
  border-top: 1px solid var(--cpo-border);
  margin-top: 8px;
  padding-top: 10px;
  font-size: 18px;
  color: var(--cpo-text);
}

.cpo-total-final span:last-child { font-weight: 700; }

#cpo-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

#cpo-continue {
  padding: 11px;
  border: 1px solid var(--cpo-border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
  color: var(--cpo-text);
}

#cpo-continue:hover { background: #f9fafb; }

#cpo-checkout {
  display: block;
  text-align: center;
  padding: 11px;
  border-radius: 8px;
  background: var(--cpo-accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

#cpo-checkout:hover { background: var(--cpo-accent-hover); }

#cpo-updating {
  position: fixed;
  inset: 0;
  background: rgba(244, 246, 249, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--cpo-muted);
  z-index: 10;
}

#cpo-error {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #fef2f2;
  color: var(--cpo-danger);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 11;
  white-space: nowrap;
}

.cpo-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--cpo-muted);
  font-size: 16px;
}

@media (max-width: 700px) {
  #cpo-panel { width: 100%; padding: 0 12px; min-height: 100%; margin: 0 auto; border-radius: 0; }
  #cpo-body { flex-direction: column; padding: 12px 16px; }
  #cpo-summary { width: 100%; }
  .cpo-item { flex-wrap: wrap; }
  .cpo-item-img img { width: 48px; height: 48px; }
  .cpo-item-qty { order: 1; }
  .cpo-item-subtotal { order: 2; min-width: auto; }
}
