/* ==========================================================================
   CART — drawer, checkout screen, payment, order confirmation.

   Both dialogs sit over the page on one z-layer scheme:
     drawer  300   checkout  400
   ========================================================================== */

:root {
  --z-drawer:   300;
  --z-checkout: 400;
  --drawer-w:   min(460px, 100vw);
}

/* --------------------------------------------------------------------------
   1. NAV BADGE — the bump when the count changes
   -------------------------------------------------------------------------- */
@keyframes badge-bump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.nav__cart.is-bumped .nav__cart-count {
  animation: badge-bump 340ms var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  .nav__cart.is-bumped .nav__cart-count { animation: none; }
}

/* --------------------------------------------------------------------------
   2. SCRIM — shared by every overlay
   -------------------------------------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease);
}

.is-open > .scrim { opacity: 1; }

/* --------------------------------------------------------------------------
   3. DRAWER
   -------------------------------------------------------------------------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
}

.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-w);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: var(--rule-strong);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease);
}

.drawer.is-open .drawer__panel { transform: translateX(0); }

@media (prefers-reduced-motion: reduce) {
  .drawer__panel { transition: none; }
}

.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-5) var(--sp-5) var(--sp-6);
  border-bottom: var(--rule);
}

.drawer__title {
  font-size: var(--fs-h3);
  text-transform: uppercase;
  letter-spacing: var(--tr-tight);
}

.drawer__close {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: var(--rule);
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}

.drawer__close:hover { color: var(--text); border-color: var(--rule-color-strong); }
.drawer__close svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.5; }

.drawer__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.drawer__foot {
  border-top: var(--rule);
  padding: var(--sp-5) var(--sp-6) var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.drawer__foot:empty { display: none; }

.drawer__checkout {
  width: 100%;
  justify-content: space-between;
}

.drawer__nudge,
.drawer__fineprint {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.drawer__nudge { color: var(--text-muted); }

.drawer__empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-4);
  padding: var(--sp-8) var(--sp-6);
}

.drawer__empty-copy {
  color: var(--text-muted);
  max-width: 34ch;
}

/* --- Bag items ------------------------------------------------------------ */
.bag-list { display: flex; flex-direction: column; }

.bag-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: var(--rule);
}

.bag-item__image {
  width: 64px;
  height: 80px;
  object-fit: cover;
  border: var(--rule);
  opacity: 0.9;
}

.bag-item__detail {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
}

.bag-item__category {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.bag-item__title {
  font-size: 1rem;
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--tr-tight);
  line-height: 1.15;
}

.bag-item__unit {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.bag-item__total {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bag-item__controls {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-top: var(--sp-3);
  flex-wrap: wrap;
}

.bag-item__remove {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-faint);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--dur-fast) var(--ease);
}

.bag-item__remove:hover { color: var(--accent); }

/* --- Stepper -------------------------------------------------------------- */
.stepper {
  display: inline-flex;
  align-items: stretch;
  border: var(--rule);
}

.stepper__btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1;
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}

.stepper__btn:hover:not([disabled]) { background: var(--c-porcelain); color: var(--c-black); }
.stepper__btn[disabled] { color: var(--c-porcelain-30); cursor: not-allowed; }

.stepper__value {
  min-width: 34px;
  display: grid;
  place-items: center;
  border-inline: var(--rule);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

/* --- Totals (shared by drawer and checkout) ------------------------------- */
.totals {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.totals__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.totals__row dt, .totals__row dd {
  margin: 0;
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  font-size: var(--fs-micro);
}

.totals__row dd { font-variant-numeric: tabular-nums; }

.totals__row--grand {
  margin-top: var(--sp-3);
  padding-top: var(--sp-4);
  border-top: var(--rule);
  color: var(--text);
}

.totals__row--grand dt,
.totals__row--grand dd {
  font-size: var(--fs-body);
  font-weight: var(--fw-bold);
}

/* --------------------------------------------------------------------------
   4. CHECKOUT
   -------------------------------------------------------------------------- */
.checkout {
  position: fixed;
  inset: 0;
  z-index: var(--z-checkout);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--dur-base) var(--ease),
              transform var(--dur-base) var(--ease);
}

.checkout.is-open { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .checkout { transition: opacity var(--dur-fast) linear; transform: none; }
}

.checkout__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--gutter);
  border-bottom: var(--rule);
}

.checkout__brand {
  font-family: var(--font-display);
  font-weight: var(--fw-black);
  font-size: 1rem;
  letter-spacing: var(--tr-tight);
  text-transform: uppercase;
}

.checkout__body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(var(--sp-6), 5vw, var(--sp-9)) var(--gutter) var(--sp-9);
}

.checkout__inner {
  width: 100%;
  max-width: 680px;
  margin-inline: auto;
}

/* --- Step bar ------------------------------------------------------------- */
.steps {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: clamp(var(--sp-6), 4vw, var(--sp-8));
  padding-bottom: var(--sp-5);
  border-bottom: var(--rule);
}

.steps__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.steps__item[data-state="current"] { color: var(--text); }
.steps__item[data-state="done"] { color: var(--text-muted); }

.steps__num {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: var(--rule);
  border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
}

.steps__item[data-state="current"] .steps__num {
  background: var(--c-porcelain);
  border-color: var(--c-porcelain);
  color: var(--c-black);
}

.steps__item[data-state="done"] .steps__num { border-color: var(--rule-color-strong); }

/* The connector between the two steps, drawn off the first item. */
.steps__item:first-child { flex: 1; }

.steps__item:first-child::after {
  content: "";
  flex: 1;
  height: var(--rule-width);
  margin-left: var(--sp-2);
  background: var(--rule-color);
}

/* --- Step content --------------------------------------------------------- */
.checkout__step-title {
  font-size: var(--fs-h2);
  text-transform: uppercase;
  letter-spacing: var(--tr-display);
  margin-bottom: var(--sp-3);
  outline: none;
}

.checkout__step-note {
  color: var(--text-muted);
  max-width: var(--measure);
  margin-bottom: clamp(var(--sp-6), 4vw, var(--sp-7));
}

/* --- Fields --------------------------------------------------------------- */
.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-5);
  border: 0;
  padding: 0;
  margin: 0;
}

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field--wide { grid-column: 1 / -1; }

@media (max-width: 620px) {
  .fields { grid-template-columns: minmax(0, 1fr); }
}

.field__label {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.field__input {
  width: 100%;
  padding: 0.9rem 1rem;
  background: var(--bg-raised);
  border: var(--rule);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  transition: border-color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}

.field__input::placeholder { color: var(--c-porcelain-30); }
.field__input:hover { border-color: var(--rule-color-strong); }
.field__input:focus {
  outline: none;
  border-color: var(--c-porcelain);
  background: var(--bg-pressed);
}

select.field__input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--c-porcelain-50) 50%),
                    linear-gradient(135deg, var(--c-porcelain-50) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.75rem;
}

.field--invalid .field__input { border-color: var(--accent); }

.field__error {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.06em;
  color: var(--accent);
}

/* --- Step actions --------------------------------------------------------- */
.checkout__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-4);
  margin-top: clamp(var(--sp-6), 4vw, var(--sp-7));
  padding-top: var(--sp-6);
  border-top: var(--rule);
}

.checkout__actions .btn--primary { margin-right: auto; order: -1; }

@media (max-width: 620px) {
  .checkout__actions .btn { width: 100%; justify-content: space-between; }
}

/* --- Summary -------------------------------------------------------------- */
.summary-block {
  padding: var(--sp-6) 0;
  border-top: var(--rule);
}

.summary-block:last-child { border-bottom: var(--rule); }

.summary-block__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
}

.summary-block__title {
  font-size: var(--fs-micro);
  font-family: var(--font-mono);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--sp-4);
}

.summary-block__edit {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.summary-block__edit:hover { color: var(--text); }

.summary-block__address { line-height: 1.6; }
.summary-block__email { color: var(--text-muted); margin-top: var(--sp-3); }

.summary-lines {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.summary-line {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: var(--sp-3);
  align-items: baseline;
}

.summary-line__qty {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.summary-line__title {
  text-transform: uppercase;
  letter-spacing: var(--tr-tight);
  font-weight: var(--fw-medium);
}

.summary-line__price {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   5. PAYMENT — the Stripe Payment Element and its simulated stand-in
   -------------------------------------------------------------------------- */
.payment {
  padding: var(--sp-6) 0;
  border-top: var(--rule);
}

.payment__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
}

.payment__head .summary-block__title { margin-bottom: var(--sp-5); }

.payment__mode {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.payment__element { min-height: 44px; }

.payment__error {
  margin-top: var(--sp-4);
  padding: var(--sp-4);
  border: var(--rule-width) solid var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  line-height: 1.6;
  letter-spacing: 0.06em;
  color: var(--accent);
}

/* The stand-in only appears when Stripe.js could not load. It is labelled
   so nobody mistakes it for a real card field. */
.payment__sim {
  border: var(--rule-width) dashed var(--rule-color-strong);
  padding: var(--sp-5);
}

.payment__sim-flag {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--sp-3);
}

.payment__sim-copy,
.payment__sim-hint {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-muted);
  margin-bottom: var(--sp-5);
  max-width: var(--measure);
}

.payment__sim-hint { margin: var(--sp-5) 0 0; }

.payment__sim-hint code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text);
  white-space: nowrap;
}

/* --- Button busy state ---------------------------------------------------- */
.btn--busy { cursor: progress; }
.btn--busy .btn__arrow { display: none; }

.btn--busy::after {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 700ms linear infinite;
}

@keyframes btn-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .btn--busy::after { animation-duration: 2s; }
}

.btn[disabled] { opacity: 0.75; }

/* --------------------------------------------------------------------------
   6. ORDER CONFIRMATION
   -------------------------------------------------------------------------- */
.confirm__tracking {
  padding: var(--sp-6);
  margin-bottom: var(--sp-6);
  border: var(--rule-strong);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-3);
}

/* The one number the reader came here for. */
.confirm__number {
  font-family: var(--font-mono);
  font-size: clamp(1.375rem, 1.1rem + 1.4vw, 2.25rem);
  font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  word-break: break-all;
}

.confirm__copy {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--text-muted);
  border: var(--rule);
  padding: 0.45rem 0.9rem;
  transition: color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}

.confirm__copy:hover { background: var(--c-porcelain); color: var(--c-black); }

.confirm__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 720px) {
  .confirm__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-7); }
  .confirm__grid .summary-block:last-child { border-bottom: 0; }
}

.confirm__fineprint {
  margin-top: var(--sp-5);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  line-height: 1.6;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  max-width: var(--measure);
}
