/* The bag: Dawn's cart drawer restyled as a bottom sheet on phones and a right-hand drawer from 750px, and the /cart page.
   Dawn's markup, ids and custom elements (cart-drawer, cart-drawer-items, cart-items, quantity-input, cart-remove-button) are
   unchanged, so its scripts keep working; this file only changes how they look. Loaded after Dawn's cart CSS. Uses ui.css tokens.
   Sections: 1 sheet and drawer . 2 lines . 3 footer . 4 empty . 5 the /cart page */

/* ---------- 1. Sheet (phones) and drawer (750px and up) ---------- */
cart-drawer.drawer { background: transparent; align-items: flex-end; justify-content: center; }
cart-drawer .cart-drawer__overlay { background: var(--ui-backdrop); opacity: 0; transition: opacity 0.22s ease; }
cart-drawer.active .cart-drawer__overlay { opacity: 1; }
.ct-drawer { width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.ct-drawer .drawer__inner {
  position: relative; display: flex; flex-direction: column; width: 100%; max-width: none;
  height: auto; max-height: 85vh; max-height: 85dvh; padding: 0; overflow: hidden;
  background: var(--ui-surface); color: var(--ui-text);
  border: 1px solid var(--ui-line); border-bottom: 0; border-radius: 20px 20px 0 0;
  transform: translateY(100%); transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ct-drawer .drawer__inner::before {   /* grab handle */
  content: ""; flex: none; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--ui-line-strong);
}
cart-drawer.drawer.active .drawer__inner { transform: none; }
cart-drawer.is-empty .ct-drawer .drawer__inner { display: flex; padding: 0; }
.ct-drawer .drawer__header { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 4px var(--ui-gutter); min-height: 52px; background: transparent; }
.ct-drawer .drawer__heading { margin: 0; font-size: 1.8rem; line-height: 1.3; }
.ct-count {
  display: inline-block; min-width: 22px; padding: 0 7px; margin-left: 6px; border-radius: var(--ui-pill); vertical-align: 2px;
  background: var(--ui-surface-2); color: var(--ui-muted); font-size: 1.2rem; line-height: 22px; text-align: center;
}
.ct-drawer .drawer__close {
  position: static; display: grid; place-items: center; width: var(--ui-tap); height: var(--ui-tap); min-width: 0; min-height: 0; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--ui-text); box-shadow: none;
}
.ct-drawer .drawer__close:hover { background: var(--ui-surface-2); }
.ct-drawer .drawer__close svg { width: 18px; height: 18px; }
.ct-drawer cart-drawer-items { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--ui-gutter); -webkit-overflow-scrolling: touch; }
.ct-drawer .cart-drawer__form { display: block; flex-grow: 0; }
.ct-drawer .drawer__contents { display: block; }
@media screen and (max-height: 650px) {
  .ct-drawer cart-drawer-items { overflow-y: auto; }
  .ct-drawer .drawer__inner { overflow: hidden; }
}
@media screen and (min-width: 750px) {
  cart-drawer.drawer { align-items: stretch; justify-content: flex-end; }
  .ct-drawer { width: 440px; max-width: 100vw; align-items: stretch; }
  .ct-drawer .drawer__inner {
    height: 100%; max-height: none; border: 0; border-left: 1px solid var(--ui-line); border-radius: 0; transform: translateX(100%);
  }
  .ct-drawer .drawer__inner::before { display: none; }
  .ct-drawer .drawer__header { padding: 8px 8px 4px 20px; }
  .ct-drawer cart-drawer-items { padding: 0 20px; }
}
@media (prefers-reduced-motion: reduce) {
  cart-drawer .cart-drawer__overlay, .ct-drawer .drawer__inner { transition: none; }
}

/* ---------- 2. Lines ---------- */
.ct-lines { list-style: none; margin: 0; padding: 0; }
.cart-drawer .cart-item.ct-line, .cart-item.ct-line {
  display: grid; grid-template: none; grid-template-columns: 64px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 4px;
  padding: 14px 0; margin: 0; border-bottom: 1px solid var(--ui-line); position: relative;
}
.ct-lines > .ct-line:last-child { border-bottom: 0; }
.ct-drawer .ct-lines > .cart-item.ct-line:last-child { margin-bottom: 0; }
.ct-line__img { grid-row: 1 / span 2; display: block; width: 64px; height: 64px; border-radius: var(--ui-radius-sm); overflow: hidden; background: var(--ui-surface-2); }
.ct-line__img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ct-line__main { min-width: 0; }
.ct-line .ct-line__name {
  display: block; font-family: var(--ui-font-mono); font-weight: 600; font-size: 1.5rem; line-height: 1.3; color: var(--ui-text);
  text-decoration: none; overflow-wrap: anywhere;
}
.ct-line a.ct-line__name { min-height: 44px; margin-top: -8px; padding-top: 8px; }   /* a 44px target that still lines up with the image */
.ct-line a.ct-line__name:hover { text-decoration: underline; text-underline-offset: 3px; }
.ct-line__meta { margin: 2px 0 0; font-size: 1.4rem; line-height: 1.35; color: var(--ui-muted); overflow-wrap: anywhere; }
.ct-line__price { position: relative; text-align: right; padding: 0; }
.ct-line__price .price { font-family: var(--ui-font-mono); font-weight: 600; font-size: 1.5rem; white-space: nowrap; color: var(--ui-text); }
.ct-line .loading-overlay { top: 2px; right: 0; left: auto; bottom: auto; padding: 0; }
.ct-line__actions { grid-column: 2 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.ct-line cart-remove-button { display: block; margin: 0; width: auto; height: auto; }
.ct-stepper {
  display: inline-flex; align-items: center; flex: none; width: auto; min-height: 0; padding: 0;
  border: 1px solid var(--ui-line-strong); border-radius: var(--ui-pill); background: var(--ui-ink);
}
.ct-stepper::before, .ct-stepper::after { content: none; }
.ct-stepper .quantity__button {
  width: var(--ui-tap); height: var(--ui-tap); margin: 0; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: transparent; color: var(--ui-text); cursor: pointer;
}
.ct-stepper .quantity__button:hover { background: var(--ui-surface-2); }
.ct-stepper .quantity__button.disabled { color: var(--ui-muted); opacity: 1; cursor: not-allowed; }
.ct-stepper .quantity__button svg { width: 12px; height: 12px; }
.ct-stepper .quantity__input,
.ct-stepper .quantity__input[type="number"] {
  width: 38px; min-width: 0; height: var(--ui-tap); flex: none; padding: 0; margin: 0; border: 0; background: transparent;
  color: var(--ui-text); opacity: 1; text-align: center; font-family: var(--ui-font-mono); font-weight: 700; font-size: 1.6rem;
  -moz-appearance: textfield; appearance: textfield;
}
.ct-stepper .quantity__input:focus-visible, .ct-stepper .quantity__button:focus-visible { outline: 2px solid var(--ui-signal); outline-offset: 1px; z-index: 2; }
.ct-remove {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--ui-tap); padding: 0 10px; margin: 0; border: 0; background: none;
  color: var(--ui-muted); font: inherit; font-size: 1.4rem; text-decoration: none; cursor: pointer; border-radius: var(--ui-radius-sm);
}
.ct-remove:hover { color: var(--ui-text); background: var(--ui-surface-2); }
.ct-remove .icon-remove { width: 14px; height: 14px; }
.ct-line__error { grid-column: 2 / -1; margin: 0; min-width: 0; width: auto; color: var(--ui-bad); }
.ct-line__error:has(.cart-item__error-text:empty) { display: none; }
.ct-line__error .cart-item__error-text { font-size: 1.3rem; order: 0; }
.ct-line__error .cart-item__error-text + svg { order: -1; }
.cart__items--disabled { pointer-events: none; opacity: 0.7; }

/* ---------- 3. Footer: subtotal, what it earns, Checkout ---------- */
.ct-drawer .drawer__footer {
  flex: none; margin: 0; padding: 12px var(--ui-gutter) calc(12px + var(--ui-safe-bottom)); background: var(--ui-surface);
  border-top: 1px solid var(--ui-line);
}
@media screen and (min-width: 750px) { .ct-drawer .drawer__footer { padding: 14px 20px 20px; } }
.ct-drawer .drawer__footer > details, .ct-note-box details { margin: 0; border: 0; }
.ct-drawer .drawer__footer summary {
  display: flex; align-items: center; min-height: 44px; padding: 0; cursor: pointer; list-style: none;
  font-size: 1.4rem; color: var(--ui-muted);
}
.ct-drawer .drawer__footer summary::-webkit-details-marker { display: none; }
.ct-drawer .drawer__footer summary .summary__title { display: flex; align-items: center; gap: 6px; }
.ct-drawer .drawer__footer summary .icon-caret { width: 10px; height: 6px; position: static; }
.ct-drawer details[open] > summary .icon-caret { transform: rotate(180deg); }
.ct-drawer .drawer__footer > details[open] { padding-bottom: 8px; }
.ct-drawer .cart-drawer__footer { padding: 4px 0 0; }
.ct-drawer .cart-drawer__footer > * + * { margin-top: 6px; }
.ct-total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.ct-total .totals__total { margin: 0; font-family: var(--ui-font-mono); font-weight: 600; font-size: 1.5rem; color: var(--ui-muted); }
.ct-total .totals__total-value { margin: 0; font-family: var(--ui-font-mono); font-weight: 700; font-size: 2rem; color: var(--ui-text); }
.ct-discounts { margin: 0; padding: 0; list-style: none; font-size: 1.4rem; color: var(--ui-muted); }
.ct-earn { margin: 0; display: flex; align-items: center; gap: 8px; font-family: var(--ui-font-mono); font-weight: 600; font-size: 1.4rem; color: var(--ui-signal); }
.ct-earn__plus {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--ui-signal-tint);
  font-size: 1.4rem; line-height: 1;
}
.ct-note { display: block; font-size: 1.3rem; line-height: 1.4; color: var(--ui-muted); }
.ct-drawer .cart__ctas, .ct-summary .cart__ctas { margin-top: 12px; }
.cart__ctas .ui-btn { width: 100%; }
.cart__checkout-button { margin: 0; }
.ct-note-box textarea {
  width: 100%; min-height: 72px; margin: 0 0 4px; padding: 10px 12px; background: var(--ui-surface-2); color: var(--ui-text);
  border: 1px solid var(--ui-line-strong); border-radius: var(--ui-radius-sm); font: inherit; font-size: 16px; resize: vertical;
}
.ct-note-box textarea::placeholder { color: var(--ui-muted); opacity: 1; }
.ct-note-box::before, .ct-note-box::after, .ct-note-box .field__input::before, .ct-note-box .field__input::after { content: none; }
#CartDrawer-CartErrors:not(:empty), #cart-errors:not(:empty) { margin: 8px 0 0; color: var(--ui-bad); font-size: 1.4rem; }

/* ---------- 4. Empty bag ---------- */
.ct-drawer .drawer__inner-empty { position: relative; flex: 1; display: flex; flex-direction: column; padding: 0 var(--ui-gutter) calc(20px + var(--ui-safe-bottom)); background: transparent; overflow: auto; height: auto; }
.ct-drawer .cart-drawer__warnings { flex: 1; justify-content: center; padding: 28px 0 8px; text-align: center; }
.ct-drawer .cart-drawer__empty-content { display: grid; gap: 10px; }
.ct-drawer .cart-drawer__warnings .drawer__close { position: absolute; top: 6px; right: 0; }
.cart__empty-text { margin: 0; font-size: 2rem; line-height: 1.3; }
.ct-empty__text { margin: 0 0 8px; color: var(--ui-muted); font-size: 1.5rem; }
.ct-empty__login { margin: 6px 0 0; color: var(--ui-muted); font-size: 1.4rem; }
.ct-drawer .cart-drawer__collection { margin: 16px 0 0; }
.ct-drawer .cart-drawer__collection .card__inner { border-radius: var(--ui-radius-sm); overflow: hidden; }
cart-drawer:not(.is-empty) .cart-drawer__warnings, cart-drawer:not(.is-empty) .cart-drawer__collection { display: none; }

/* ---------- 5. The /cart page ---------- */
.ct-layout { max-width: 1100px; margin: 0 auto; padding: 20px var(--ui-gutter) 32px; }
.ct-page { display: block; }
.ct-page__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 8px; }
.ct-page__title { margin: 0; font-size: 2.4rem; line-height: 1.2; }
.ct-page.is-empty .ct-page__head { display: none; }
.ct-page .ct-empty { display: none; }
.ct-page.is-empty .ct-empty { display: grid; justify-items: start; gap: 12px; padding: 24px 0; text-align: left; }
.ct-page.is-empty .ct-empty .ui-btn { width: 100%; max-width: 320px; }
.ct-page .cart__items { padding: 0; border: 0; }
.ct-page .ct-lines { border-top: 1px solid var(--ui-line); }
.ct-page .cart-item.ct-line { grid-template-columns: 88px minmax(0, 1fr) auto; column-gap: 16px; }
.ct-page .ct-line__img { width: 88px; height: 88px; }
.ct-page .ct-line img { width: 100%; height: 100%; }
.ct-summary { margin-top: 20px; }
.ct-summary.is-empty { display: none; }
.ct-summary__card { padding: var(--ui-gutter); background: var(--ui-surface); border: 1px solid var(--ui-line); border-radius: var(--ui-radius); display: block; }
.ct-summary__card > * + * { margin-top: 12px; }
.ct-summary cart-note { display: block; margin: 0 0 14px; }
.ct-summary cart-note .ui-label { margin-bottom: 6px; }
.ct-summary .js-contents > div > * + * { margin-top: 8px; }
.ct-summary .cart__footer-wrapper, .cart__footer-wrapper { padding: 0; }
@media screen and (min-width: 750px) { .ct-layout { padding: 32px 32px 48px; } .ct-page__title { font-size: 2.8rem; } }
@media screen and (min-width: 990px) {
  .ct-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; column-gap: 40px; align-items: start; }
  .ct-summary { margin-top: 0; position: sticky; top: calc(var(--ui-header-h) + 20px); }
  .ct-layout:has(.ct-page.is-empty) { display: block; }
}
