/* I.89.a — Cart drawer + add-to-cart toast.
 *
 * Slide-in panel from the right (desktop) / full-screen (mobile).
 * WCAG AAA contrast against bg-elev-1; respects prefers-reduced-motion.
 *
 * The drawer pins its own color scheme (dark surface + light text) so it
 * looks consistent across light/dark page themes. The storefront CSS
 * variables (--bg-elev-1, --text-primary) switch with the OS theme, but
 * the drawer is a transient overlay and reads best with a fixed
 * surface contrast.
 */
.cart-drawer {
  --cd-surface: #1a1f26;
  --cd-surface-deep: #0e1217;
  --cd-text: #f1f5f9;
  --cd-text-muted: #cbd5e1;
  --cd-stroke: #2a313b;
  --cd-accent: #4f8cff;
  --cd-accent-strong: #a8c8ff;
  --cd-success: #5ee094;
  --cd-error: #ff8585;
}

/* ---- Scrim ----------------------------------------------------------- */
.cart-drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 990;
  opacity: 0;
  transition: opacity 200ms ease;
}
.cart-drawer-scrim.is-open {
  opacity: 1;
}

/* ---- Drawer panel ---------------------------------------------------- */
.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(440px, 100vw);
  max-width: 100vw;
  background: var(--cd-surface);
  color: var(--cd-text);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 240ms ease;
  border-left: 1px solid var(--cd-stroke);
}
.cart-drawer.is-open {
  transform: translateX(0);
}

.cart-drawer[hidden] {
  display: flex;
}

/* Mobile: full-screen overlay */
@media (max-width: 600px) {
  .cart-drawer {
    width: 100vw;
    height: 100vh;
    border-left: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cart-drawer,
  .cart-drawer-scrim {
    transition: none;
  }
}

/* ---- Header ---------------------------------------------------------- */
.cart-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--cd-stroke);
  flex-shrink: 0;
}
.cart-drawer-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--cd-text);
}
.cart-drawer-count {
  font-weight: 400;
  color: var(--cd-text-muted);
  margin-left: 0.25rem;
}
.cart-drawer-close {
  background: transparent;
  border: 2px solid transparent;
  color: var(--cd-text);
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
}
.cart-drawer-close:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--cd-accent);
}
/* I.109 — Replace `outline: none` with an explicit focus ring. The
 * previous rule shared with :hover suppressed the default UA outline
 * AND only changed border-color → keyboard users couldn't see focus
 * against the drawer body (which already has a soft border). */
.cart-drawer-close:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: 2px solid var(--cd-accent);
  outline-offset: 2px;
}

/* ---- Body ------------------------------------------------------------ */
.cart-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.cart-drawer-loading {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--cd-text-muted);
}

.cart-drawer-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.cart-drawer-item {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--cd-stroke);
}
.cart-drawer-item:last-child {
  border-bottom: none;
}
.cart-drawer-item-thumb {
  width: 60px;
  height: 60px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--cd-surface-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cart-drawer-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cart-drawer-item-thumb-placeholder {
  font-size: 1.5rem;
  color: var(--cd-text-muted);
}
.cart-drawer-item-info {
  min-width: 0;
}
.cart-drawer-item-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--cd-text);
  margin: 0 0 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cart-drawer-item-variant {
  font-size: 0.85rem;
  color: var(--cd-text-muted);
  margin: 0 0 0.25rem;
}
.cart-drawer-item-qty-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--cd-text-muted);
}
.cart-drawer-item-qty-label {
  font-weight: 500;
}
.cart-drawer-item-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
}
.cart-drawer-item-price {
  font-weight: 600;
  color: var(--cd-text);
}
.cart-drawer-item-remove {
  background: transparent;
  border: none;
  color: var(--cd-text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 0.25rem;
  min-height: 32px;
}
.cart-drawer-item-remove:hover {
  color: var(--cd-accent);
}
/* I.109 — Explicit focus ring (was masking with outline:none). */
.cart-drawer-item-remove:focus-visible {
  color: var(--cd-accent);
  outline: 2px solid var(--cd-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.cart-drawer-empty {
  text-align: center;
  padding: 2rem 1rem;
}
.cart-drawer-empty p {
  margin: 0 0 1rem;
  color: var(--cd-text-muted);
}

/* ---- Voucher box (reuses .voucher-* styles from /cart) -------------- */
.cart-drawer-voucher {
  margin: 0;
  padding: 0.85rem;
  border: 1px dashed var(--cd-stroke);
  border-radius: 6px;
}
.cart-drawer-voucher label strong {
  display: inline-block;
  margin-right: 0.25rem;
}
.cart-drawer-voucher-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.cart-drawer-voucher-row input {
  flex: 1;
  padding: 0.5rem;
  font-size: 1rem;
  text-transform: uppercase;
  min-height: 44px;
}
.cart-drawer-voucher-row button {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  cursor: pointer;
  min-height: 44px;
}
.cart-drawer-voucher .voucher-applied {
  margin: 0;
}
.cart-drawer-voucher .voucher-check {
  color: #5ee094;
  font-weight: bold;
  margin-right: 0.25rem;
}
.cart-drawer-voucher .voucher-msg {
  margin: 0.5rem 0 0;
  min-height: 1.2em;
}
.cart-drawer-voucher .voucher-msg.is-error { color: #ff8585; }
.cart-drawer-voucher .voucher-msg.is-ok { color: #5ee094; }
.cart-drawer-voucher .link-button {
  background: none;
  border: none;
  color: var(--cd-accent-strong);
  text-decoration: underline;
  cursor: pointer;
  padding: 0 0.25rem;
  font-size: inherit;
  min-height: 32px;
}

/* ---- Totals ---------------------------------------------------------- */
.cart-drawer-totals {
  margin: 0;
  padding: 0.85rem;
  background: var(--cd-surface-deep);
  border-radius: 6px;
}
.cart-drawer-totals-row {
  display: flex;
  justify-content: space-between;
  margin: 0 0 0.4rem;
}
.cart-drawer-totals-row dt,
.cart-drawer-totals-row dd {
  margin: 0;
}
.cart-drawer-totals-row dt {
  color: var(--cd-text-muted);
}
.cart-drawer-totals-row dd {
  color: var(--cd-text);
  font-weight: 500;
}
.cart-drawer-totals-total {
  border-top: 1px solid var(--cd-stroke);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}
.cart-drawer-totals-total dt,
.cart-drawer-totals-total dd {
  font-weight: 700;
  font-size: 1.05rem;
}
.cart-drawer-caveat {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--cd-text-muted);
}
[data-cd-totals-discount] {
  color: #5ee094 !important;
}

/* ---- Footer ---------------------------------------------------------- */
.cart-drawer-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--cd-stroke);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}
.cart-drawer-checkout {
  display: block;
  text-align: center;
  padding: 0.85rem 1rem;
  font-weight: 600;
  border-radius: 6px;
  text-decoration: none;
  min-height: 44px;
}
.cart-drawer-continue-btn {
  background: transparent;
  border: 2px solid var(--cd-stroke);
  color: var(--cd-text);
  padding: 0.75rem 1rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
}
.cart-drawer-continue-btn:hover {
  border-color: var(--cd-accent);
}
/* I.109 — Explicit focus ring. */
.cart-drawer-continue-btn:focus-visible {
  border-color: var(--cd-accent);
  outline: 2px solid var(--cd-accent);
  outline-offset: 2px;
}
.cart-drawer-full-view-link {
  text-align: center;
  font-size: 0.85rem;
  color: var(--cd-text-muted);
  text-decoration: underline;
  padding: 0.5rem;
}
.cart-drawer-full-view-link:hover,
.cart-drawer-full-view-link:focus-visible {
  color: var(--cd-accent-strong);
}

/* ===================================================================== */
/* I.89.a — Add-to-cart toast (.atc-toast).                                */
/* Separate class from the per-page #cart-toast so the global helper       */
/* doesn't collide with the existing /product page toast.                  */
/* ===================================================================== */
.atc-toast {
  /* Inherit the same scoped palette as the drawer so the toast looks
     consistent with it (since the toast is a teaser for the drawer). */
  --cd-surface: #1a1f26;
  --cd-text: #f1f5f9;
  --cd-stroke: #2a313b;
  --cd-accent-strong: #a8c8ff;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 980;
  background: var(--cd-surface);
  color: var(--cd-text);
  border: 1px solid var(--cd-stroke);
  border-left: 4px solid #5ee094;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: auto;
}
.atc-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.atc-toast-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}
.atc-toast-check {
  color: #5ee094;
  font-weight: bold;
  flex-shrink: 0;
}
.atc-toast-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.atc-toast-link {
  background: transparent;
  border: none;
  color: var(--cd-accent-strong);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
  text-align: left;
  align-self: flex-start;
  min-height: 32px;
}
.atc-toast-link:hover {
  color: var(--cd-accent-strong);
}
/* I.109 — Explicit focus ring (was masking with outline:none). */
.atc-toast-link:focus-visible {
  color: var(--cd-accent-strong);
  outline: 2px solid var(--cd-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (max-width: 600px) {
  .atc-toast {
    right: 0.75rem;
    left: 0.75rem;
    bottom: 0.75rem;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .atc-toast {
    transition: opacity 0ms;
  }
}

/* Body lock when drawer is open */
body.cart-drawer-open {
  overflow: hidden;
}
