/* Ritual cart: header Cart button, slide-out drawer, cart page. Builds on styles.css tokens. */

/* Header button */
.cart-btn {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 6px;
  background: none; border: 0; color: var(--ink); cursor: pointer;
  font: 400 var(--step-body)/1 var(--text);
  transition: color .15s ease;
}
.cart-btn .cart-count {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px;
  font: 600 var(--step-small)/1 var(--text); font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--muted);
  transition: background-color .15s ease, color .15s ease;
}
.cart-btn[data-filled="true"] .cart-count { background: var(--accent); color: var(--accent-ink); }
@media (hover: hover) and (pointer: fine) { .cart-btn:hover .cart-words { text-decoration: underline; text-underline-offset: .2em; } }
@media (max-width: 720px) {
  .cart-btn .cart-words { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .cart-btn { min-width: 44px; justify-content: center; }
}

/* Scrim and drawer. Closed: off to the right and invisible once the slide-out has finished. */
.cart-scrim {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .65);
  opacity: 0; visibility: hidden;
  transition: opacity .3s ease-out, visibility 0s linear .3s;
}
.cart-scrim[data-open] { opacity: 1; visibility: visible; transition: opacity .45s var(--ease-drawer), visibility 0s; }

.drawer {
  position: fixed; top: 0; right: 0; z-index: 61;
  display: flex; flex-direction: column;
  width: min(460px, 100vw); height: 100dvh;
  background: var(--surface); color: var(--ink);
  transform: translateX(100%); visibility: hidden;
  transition: transform .3s var(--ease), visibility 0s linear .3s;
  contain: layout paint;
}
.drawer[data-open] { transform: none; visibility: visible; transition: transform .45s var(--ease-drawer), visibility 0s; }

/* Drawer contents rise in once the panel opens; on close they stay put until it has slid away. */
.drawer .reveal { opacity: 0; transform: translateY(var(--oy, 10px)); transition: opacity 0s linear .3s, transform 0s linear .3s; }
.drawer[data-open] .reveal { opacity: 1; transform: none; transition: opacity .25s var(--ease) var(--d, 0s), transform .25s var(--ease) var(--d, 0s); }
.drawer .cart-line.reveal { --oy: 0px; transform: translateX(16px); }
.drawer[data-open] .cart-line.reveal { transform: none; }

.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 24px 20px; background: var(--surface-2); }
.drawer-count { font-size: var(--step-small); color: var(--muted); }
.drawer-title { margin-top: 4px; font: 800 2.25rem/.9 var(--display); text-transform: uppercase; letter-spacing: -0.01em; }
.drawer-close {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px;
  background: var(--surface); color: var(--muted); border: 0; cursor: pointer;
  transition: color .15s ease, background-color .15s ease, transform .16s var(--ease);
}
.drawer-close:hover { color: var(--ink); background: var(--bg); }
.drawer-close:active { transform: scale(.97); }

.drawer-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 24px 16px; scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent; }
.drawer-foot { padding: 20px 24px calc(20px + env(safe-area-inset-bottom)); background: var(--surface-2); }
.drawer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.drawer-actions .btn { padding: 0 12px; }
/* Signed out: one big sign-in button in place of View cart and Checkout */
.drawer-signin, .cp-signin { margin-top: 20px; }
.cp-signin { margin-top: 24px; }
.signin-big { width: 100%; min-height: 60px; font-size: var(--step-lead); }
.signin-note { margin-top: 10px; font-size: var(--step-small); color: var(--muted); text-align: center; }
.cart-page .signin-note { font-size: var(--step-body); }
.drawer-foot .btn-dark { background: var(--surface); }
.drawer-foot .btn-dark:hover { background: var(--bg); }

.drawer-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 32px 24px; text-align: center; }
.drawer-empty .cart-undo-slot { align-self: stretch; text-align: left; }
.drawer-empty-title { font: 800 2.5rem/.95 var(--display); text-transform: uppercase; color: var(--muted); }
.drawer-empty-note { color: var(--muted); margin-bottom: 12px; }

/* Lines: shared by the drawer and the cart page */
.cart-lines { list-style: none; margin: 0; padding: 0; }
.cart-line { --t: var(--lilac); }
.cart-line[data-tone="rose"] { --t: var(--rose); }
.cart-line[data-tone="sage"] { --t: var(--sage); }
.cart-line[data-tone="slate"] { --t: var(--slate); }
.cl-inner { transition: opacity .2s var(--ease), transform .2s var(--ease); }
.cart-line[data-leaving] .cl-inner { opacity: 0; transform: translateX(-24px); }
.cl-row { display: flex; gap: 16px; padding: 16px 0; }
.cl-pic { flex: none; width: 96px; aspect-ratio: 16 / 10; overflow: hidden; background: var(--bg); align-self: flex-start; }
.cl-pic img { width: 100%; height: 100%; object-fit: cover; }
.cl-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cl-name { width: fit-content; font-weight: 500; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; transition: color .15s ease; }
.cl-name:hover { color: var(--t); }
.cl-meta { font-size: var(--step-small); color: var(--muted); }
.cl-warn { font-size: var(--step-small); color: var(--rose); }
.cl-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: auto; padding-top: 8px; }
.cl-price { font-variant-numeric: tabular-nums; font-weight: 500; }
.cl-remove {
  min-height: 44px; padding: 0 2px; background: none; border: 0; cursor: pointer;
  font: 400 var(--step-small)/1 var(--text); color: var(--muted);
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: .25em;
  transition: color .15s ease, text-decoration-color .15s ease;
}
.cl-remove:hover { color: var(--rose); text-decoration-color: currentColor; }

/* "<name> removed · Undo" */
.cart-undo { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; font-size: var(--step-small); color: var(--muted); }
.cart-undo button {
  min-height: 44px; padding: 0 2px; background: none; border: 0; cursor: pointer;
  font: 500 var(--step-small)/1 var(--text); color: var(--ink); text-decoration: underline; text-underline-offset: .25em;
}
.cart-undo button:hover { color: var(--accent); }
@starting-style { .cart-undo { opacity: 0; transform: translateY(-6px); } }
.cart-undo { transition: opacity .2s var(--ease), transform .2s var(--ease); }

/* Totals */
.cart-totals { margin: 0; display: grid; gap: 8px; font-size: var(--step-small); }
.cart-totals div { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); }
.cart-totals dt { margin: 0; }
.cart-totals dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; text-align: right; }
.cart-totals .cart-total { align-items: baseline; margin-top: 12px; }
.cart-total dt { font-size: var(--step-body); color: var(--ink); }
.cart-total dd { font: 800 2.25rem/1 var(--display); display: inline-block; transform-origin: right center; }

/* The cart page */
.cp-head { padding: clamp(40px, 6vw, 96px) var(--margin) 0; }
.cp-title { font: 800 var(--step-head)/.9 var(--display); text-transform: uppercase; letter-spacing: -0.01em; }
.cp-count { margin-top: 12px; font-size: var(--step-lead); color: var(--muted); }
.cart-page {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); gap: clamp(32px, 5vw, 72px); align-items: start;
  padding: 40px var(--margin) 0; min-height: 40svh;
}
.cp-lines .cart-line { background: var(--surface); margin-bottom: 10px; }
.cp-lines .cl-row { padding: 16px; }
.cp-lines .cl-pic { width: 160px; }
.cp-lines .cl-name { font: 800 clamp(1.5rem, 1.2rem + 1vw, 2rem)/1 var(--display); text-transform: uppercase; letter-spacing: -0.01em; }
.cp-summary { position: sticky; top: 24px; padding: 24px; background: var(--surface); }
.cp-checkout { width: 100%; margin-top: 24px; min-height: 56px; }
.cp-keep { display: flex; align-items: center; justify-content: center; min-height: 44px; margin-top: 8px; color: var(--muted); font-size: var(--step-small); }
.cp-keep:hover { color: var(--ink); }
.cp-cfg { margin-top: 24px; }
.cp-cfg-title { font-size: var(--step-small); font-weight: 500; color: var(--muted); }
.cp-cfg .cfg-file { margin-top: 10px; min-height: 0; padding: 16px; font-size: 14px; white-space: pre-wrap; }
.cp-empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: flex-start; gap: 20px; padding: 48px 24px; background: var(--surface); }
.cp-empty .cart-undo-slot { align-self: stretch; }
.cp-empty-title { font: 800 2.75rem/.95 var(--display); text-transform: uppercase; color: var(--muted); }
.cp-empty-note { max-width: 52ch; font-size: var(--step-body); }

@media (max-width: 900px) {
  .cart-page { grid-template-columns: 1fr; }
  .cp-summary { position: static; }
}
@media (max-width: 720px) {
  .drawer-head, .drawer-body, .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .cp-lines .cl-pic { width: 104px; }
  .cp-lines .cl-row { padding: 12px; gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  /* No slide: closed, it waits off screen (so nothing invisible sits over the page); open, it fades in place */
  .drawer { opacity: 0; transform: translateX(100%); transition: opacity .15s ease, visibility 0s linear .15s; }
  .drawer[data-open] { opacity: 1; transform: none; transition: opacity .15s ease, visibility 0s; }
  /* The staggered reveal is motion too: contents are simply there, and the drawer fades as a whole */
  .drawer .reveal, .drawer[data-open] .reveal, .drawer .cart-line.reveal { opacity: 1; transform: none; }
  .cart-line[data-leaving] .cl-inner { transform: none; }
}

/* On the cart page there's room, so details and totals read at body size */
.cart-page .cl-meta, .cart-page .cl-warn, .cart-page .cl-remove, .cart-page .cart-undo, .cart-page .cart-undo button,
.cart-page .cart-totals, .cart-page .cp-keep, .cart-page .cp-cfg-title { font-size: var(--step-body); }

/* ---------- The cart drawer: fluid.js owns its position, so CSS stops animating it ---------- */
.drawer, .drawer[data-open] { transition: none; visibility: visible; will-change: transform; touch-action: pan-y; }
.drawer:not([data-open]) { pointer-events: none; }
.cart-scrim, .cart-scrim[data-open] { transition: none; }
.drawer-head { cursor: grab; }
.drawer.dragging, .drawer.dragging .drawer-head { cursor: grabbing; user-select: none; }

@media (prefers-reduced-motion: reduce) {
  .drawer { transition: opacity .2s ease !important; }
}
