/* cart.css — Consolidated cart styles (compact + amz + feedback + mobile-a11y) */

/* === Variables === */
:root{
  --cart-border: rgba(255,255,255,0.12);
  --cart-bg: rgba(255,255,255,0.02);
  --cart-bg-alt: rgba(255,255,255,0.04);
  --cart-text-muted: rgba(255,255,255,0.7);
}

/* === Base cart layout === */
.cart-page, .cart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.cart-empty, .empty-cart { text-align:center; padding: 30px 0; }
.cart-empty .btn, .empty-cart .btn { margin-top: 8px; }

.cart-list, .cart-items { display: grid; gap: 12px; }

/* === Cart item/row (compact + amz styles merged) === */
.cart-row, .cart-item {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--cart-border);
  border-radius: 12px;
  background: var(--cart-bg);
}

.cart-item {
  grid-template-columns: 96px 1fr auto;
}

.cr-media img, .cart-item__media img {
  width: 88px; height: 88px; object-fit: cover; border-radius: 8px;
  background: var(--cart-bg-alt);
}

.cart-item__media img {
  width: 96px; height: 96px;
  background: rgba(255,255,255,0.06);
}

.cr-title, .cart-item__title {
  margin: 0 0 2px 0;
  font-size: 15px; line-height: 1.35;
}

.cart-item__title {
  font-size: 16px;
  margin: 0 0 4px 0;
  line-height: 1.3;
}

.cr-sku {
  font-size: 12px;
  color: var(--cart-text-muted);
  margin-bottom: 4px;
}

.cart-item__meta { font-size: 12px; color: rgba(255,255,255,0.7); margin-bottom: 8px; }
.cart-item__meta .stock.ok { color: #7ce38b; }

/* === Price × Quantity = Subtotal === */
.cr-line {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: baseline;
  gap: 6px;
  font-size: 14px;
  margin-bottom: 8px;
}
.cr-unit { opacity: .9; }
.cr-subtotal { font-weight: 700; }
.cr-times, .cr-equals { opacity:.7; }

/* === Controls === */
.cr-controls, .cart-item__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
}

.qty-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--cart-bg-alt);
  border: 1px solid var(--cart-border);
  padding: 6px;
  border-radius: 999px;
}
.qty-form .qty {
  width: 56px;
  max-width: 64px;
  height: 36px;
  text-align: center;
  border-radius: 10px;
  font-size: 15px;
  -moz-appearance: textfield;
}
.qty-form .qty::-webkit-outer-spin-button,
.qty-form .qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-form .btn.icon {
  width: 36px; height: 36px; border-radius: 999px;
  padding: 0; display: inline-flex; align-items:center; justify-content:center;
}

/* === Subtotal lateral en desktop === */
.cr-side, .cart-item__price {
  min-width: 96px;
  text-align: right;
  display: grid;
  place-items: center end;
}
.cr-side-sub { font-weight: 700; font-size: 16px; }

.cart-item__price {
  gap: 10px;
  align-content: center;
}
.cart-item__price .unit { opacity: 0.9; font-size: 14px; }
.cart-item__price .subtotal { font-weight: 700; font-size: 16px; }

/* === Summary === */
.cart-summary {
  position: sticky; top: 12px;
  align-self: start;
  border: 1px solid var(--cart-border);
  border-radius: 12px;
  padding: 12px;
  background: var(--cart-bg);
  display: grid; gap: 10px;
}
.sum-row, .cart-summary .summary-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 15px;
}
.cart-summary .summary-row {
  font-size: 16px;
}
.summary-checkout textarea {
  width: 100%; min-height: 86px; margin-bottom: 8px;
}
.summary-checkout .btn.full, .cart-summary .summary-checkout .btn.full {
  width: 100%; min-height: 44px; border-radius: 12px;
}

.muted { color: var(--cart-text-muted); }
.small { font-size: 12px; }

/* === Button utilities === */
.btn.sm { padding: 6px 10px; font-size: .92rem; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: var(--cart-border); }
.btn.icon { display:inline-flex; align-items:center; justify-content:center; }
.btn .material-symbols-rounded { font-size: 20px; line-height: 1; vertical-align: middle; }
.btn .btn-label { margin-left: 6px; }

/* === Desktop: summary on the right === */
@media (min-width: 960px) {
  .cart-page { grid-template-columns: 1fr 340px; align-items: start; }
}
@media (min-width: 900px) {
  .cart-grid { grid-template-columns: 1fr 320px; align-items: start; }
}

/* === Mobile === */
@media (max-width: 640px) {
  .cart-row, .cart-item { grid-template-columns: 72px 1fr; }
  .cr-media img { width: 72px; height: 72px; }

  /* Subtotal pasa abajo y en línea con el detalle */
  .cr-side, .cart-item__price {
    grid-column: 1 / -1;
    text-align: left;
    place-items: start;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    align-items: baseline;
  }
  .cr-side-sub::before { content: 'Subtotal: '; opacity: .7; font-weight: 400; margin-right: 6px; }
  .cart-item__price .unit::before { content: 'Precio: '; opacity: 0.7; font-weight: 400; }
  .cart-item__price .subtotal::before { content: 'Subtotal: '; opacity: 0.7; font-weight: 400; }

  /* Controles más compactos */
  .qty-form { padding: 4px; gap: 4px; }
  .qty-form .qty { width: 48px; height: 34px; font-size: 14px; }
  .qty-form .btn.icon { width: 34px; height: 34px; }

  .cart-item__controls { gap: 8px; }
  .remove-form { width: 100%; }
  .remove-form .btn { padding: 8px; }
  .remove-form .btn .btn-label { display: none; }
  .remove-form .btn[data-mobile-icon="true"] .btn-label { display: none; }
  .remove-form .btn[data-mobile-icon="true"] { padding: 8px; min-width: 40px; }
}

/* === Accessibility focus === */
:where(a,button,input,textarea).btn:focus-visible,
:where(a,button,input,textarea).qty:focus-visible {
  outline:2px solid #2684FF; outline-offset:2px;
}

/* === Flash animation on update === */
.cart-row.flash, .cart-item.flash { animation: cartFlash 600ms ease; }
@keyframes cartFlash {
  0%{background:rgba(0,160,0,0.12)}
  100%{background:var(--cart-bg)}
}

/* === Visual feedback for "Añadir" button === */
@keyframes cartPulse {
  0%   { transform: scale(1); box-shadow: 0 0 0 rgba(0,0,0,0); }
  15%  { transform: scale(0.96); }
  45%  { transform: scale(1.03); box-shadow: 0 0 0 rgba(0,0,0,0); }
  75%  { transform: scale(1.00); box-shadow: 0 0 0 8px rgba(0, 150, 80, 0.20); }
  100% { transform: scale(1); box-shadow: 0 0 0 rgba(0,0,0,0); }
}
.btn.cart-added, .btn.icon.cart-added {
  animation: cartPulse 650ms ease-in-out;
  outline: none;
}
@media (max-width: 420px) {
  .btn.cart-added, .btn.icon.cart-added { animation-duration: 550ms; }
}
@keyframes cartNudge {
  0% { transform: translateY(0); }
  35% { transform: translateY(-2px); }
  70% { transform: translateY(0); }
  100% { transform: translateY(0); }
}
.topbar a[href="/cart.php"].nudge, .topbar a[aria-label="Carrito"].nudge {
  animation: cartNudge 450ms ease;
}

/* === Mobile accessibility - actions below content === */
@media (max-width: 640px) {
  .table.cart-table .priceqtyline { width: 100%; min-width: 0; flex-wrap: wrap; }
  .table.cart-table .priceqtyline .price,
  .table.cart-table .priceqtyline .times,
  .table.cart-table .priceqtyline .qty,
  .table.cart-table .priceqtyline .equals,
  .table.cart-table .priceqtyline .subtotal { flex: 0 0 auto; }

  .table.cart-table td.actions-cell {
    display: block !important;
    padding-top: 8px;
    width: 100%;
    clear: both;
  }
  .table.cart-table td.actions-cell .actions-row {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
  }
  .table.cart-table td.actions-cell form.inline {
    display: inline-flex !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .table.cart-table td.actions-cell .btn.icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
  }

  /* Prevent overflow from long names */
  .table.cart-table td.name-cell { overflow-wrap: anywhere; }

  /* Safety: rows contain their children visually */
  .table.cart-table tr { overflow: hidden; }
}
