/* Cart feedback: add buttons, the header badge, the add confirmation and the
   in-place cart page. Driven by cart-client.js; plain forms work without it. */

/* Add-to-cart buttons: the label changes in place, no spinner. */
.cart-add { position: relative; transition: background-color .15s ease, opacity .15s ease, transform .1s ease; }
.cart-add:active:not(:disabled) { transform: scale(.98); }
.cart-add-icon { width: 1.1em; height: 1.1em; flex-shrink: 0; }
.cart-add-check { display: none; }
.cart-add.is-done .cart-add-idle { display: none; }
.cart-add.is-done .cart-add-check { display: block; animation: cart-pop .3s ease-out; }
.cart-add.is-done { background-color: #1d6b4a !important; }
.cart-add[aria-busy="true"] { cursor: progress; }
.cart-add[aria-busy="true"]::after {
  content: ""; position: absolute; left: 12%; right: 12%; bottom: 5px; height: 2px; border-radius: 2px;
  background: currentColor; opacity: .55; transform-origin: left; animation: cart-progress .8s ease-in-out infinite;
}

/* Header badge bump when the count changes. */
.cart-badge.is-bumped { animation: cart-pop .35s ease-out; }

/* Add confirmation / mini cart. */
.cart-toast {
  position: fixed; z-index: 60; top: 84px; right: 24px; width: min(360px, calc(100vw - 24px));
  background: #fff; color: var(--color-text); border: 1px solid var(--color-border-strong, #d8e7f0);
  border-radius: 14px; box-shadow: 0 12px 32px rgba(31, 87, 121, .18); padding: 14px;
  animation: cart-toast-in .22s ease-out;
}
.cart-toast[hidden] { display: none; }
.cart-toast-main { display: flex; gap: 12px; align-items: flex-start; }
.cart-toast-image { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; border: 1px solid var(--color-border); flex-shrink: 0; }
.cart-toast-body { flex: 1; min-width: 0; }
.cart-toast-title { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: .95rem; color: #1d6b4a; }
.cart-toast-title::before {
  content: ""; width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  background: #1d6b4a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.cart-toast-text { margin-top: 2px; font-size: .875rem; overflow-wrap: anywhere; }
.cart-toast-meta { margin-top: 4px; font-size: .8rem; color: var(--color-text-muted); }
.cart-toast-meta:empty { display: none; }
.cart-toast-close {
  width: 32px; height: 32px; margin: -6px -6px 0 0; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; color: var(--color-text-muted); flex-shrink: 0;
}
.cart-toast-close:hover { background: #f1f6f9; }
.cart-toast-close svg { width: 18px; height: 18px; }
.cart-toast-actions { display: flex; gap: 8px; margin-top: 12px; }
.cart-toast-primary, .cart-toast-secondary {
  flex: 1; text-align: center; padding: 9px 12px; border-radius: 8px; font-size: .875rem; font-weight: 500;
}
.cart-toast-primary { background: var(--color-primary); color: #fff; }
.cart-toast-primary:hover { background: #17455f; }
.cart-toast-secondary { color: var(--color-text-link, var(--color-primary)); border: 1px solid var(--color-border-strong, #d8e7f0); }
.cart-toast-secondary:hover { background: #f1f6f9; }
.cart-toast.is-error { border-color: #f0cdb9; }
.cart-toast.is-error .cart-toast-title { color: #9b2517; }
.cart-toast.is-error .cart-toast-title::before {
  background: #9b2517 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M12 7v6M12 17h.01'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.cart-toast.is-error .cart-toast-secondary { display: none; }
@media (max-width: 767px) {
  .cart-toast { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); left: 12px; right: 12px; width: auto; animation-name: cart-toast-up; }
}

/* Cart page. */
.cart-banner { margin-bottom: 1rem; padding: .75rem 1rem; border-radius: .5rem; font-size: .875rem; }
.cart-banner[hidden] { display: none; }
.cart-banner-ok { background: #eef7f1; border: 1px solid #c3e2cf; color: #1d6b4a; }
.cart-banner-error { background: #fdf3ee; border: 1px solid #f0cdb9; color: #9b2517; }
.cart-undo { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: #f4f8fb; border: 1px solid var(--color-border-strong, #d8e7f0); color: var(--color-text); }
.cart-undo[hidden] { display: none; }
.cart-undo-button { font-weight: 600; color: var(--color-primary); text-decoration: underline; text-underline-offset: 3px; padding: .25rem .5rem; border-radius: .375rem; }
.cart-undo-button:hover { background: #e7f1f6; }

.cart-item { transition: opacity .2s ease, transform .2s ease; }
.cart-item.is-leaving { opacity: 0; transform: translateX(12px); }
.cart-item.is-saving .cart-qty-value { opacity: .6; }
.cart-stepper { display: flex; align-items: center; border: 1px solid var(--color-border); border-radius: .375rem; }
.cart-stepper button {
  width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center;
  font-size: .95rem; color: var(--color-text-muted); transition: background-color .15s ease;
}
.cart-stepper button:first-child { border-radius: .375rem 0 0 .375rem; }
.cart-stepper button:last-child { border-radius: 0 .375rem .375rem 0; }
.cart-stepper button:hover:not(:disabled) { background: #f3f4f6; }
.cart-stepper button:disabled { opacity: .3; cursor: not-allowed; }
.cart-qty-value { min-width: 2rem; text-align: center; font-size: .875rem; font-weight: 500; color: var(--color-text); transition: opacity .15s ease; font-variant-numeric: tabular-nums; }
.cart-remove {
  height: 2rem; padding: 0 .5rem; display: flex; align-items: center; justify-content: center; gap: .375rem;
  border-radius: .375rem; color: var(--color-primary-active); border: 1px solid var(--color-border); transition: background-color .15s ease;
}
.cart-remove:hover { background: #fef2f2; }
/* The remove action stays an icon on phones and gains its word from 640px.
   The word uses the darker danger ink so 12px text keeps 4.5:1 on white. */
.cart-remove-label { display: none; }
@media (min-width: 640px) {
  .cart-remove-label { display: inline; font-size: .75rem; font-weight: 600; color: #9b2517; }
  .cart-remove { padding: 0 .625rem; }
}
.cart-summary-value { transition: color .3s ease; }
.cart-summary-value.is-updated { color: var(--color-primary); }

@keyframes cart-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes cart-progress { 0% { transform: scaleX(0); } 50% { transform: scaleX(1); } 100% { transform: scaleX(0); transform-origin: right; } }
@keyframes cart-toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes cart-toast-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .cart-add, .cart-item, .cart-qty-value, .cart-summary-value { transition: none; }
  .cart-add:active:not(:disabled) { transform: none; }
  .cart-add.is-done .cart-add-check, .cart-badge.is-bumped, .cart-toast { animation: none; }
  .cart-add[aria-busy="true"]::after { animation: none; transform: none; opacity: .35; }
  .cart-item.is-leaving { transform: none; }
}
