/* === Cart drawer, Quick Add sheet, and the shared option pickers ===
   Loaded on every storefront page (script.js injects it when a page does not
   link it itself). Class prefixes: .cui-* shared, .cd-* drawer, .qa-* sheet,
   .opt-* size/scent pickers (also used by the product page). */
:root {
  --cui-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --cui-ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --cui-z-scrim: 300;
  --cui-z-panel: 310;
}

/* ------------------------------------------------------------------ Scrim */
.cui-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--cui-z-scrim);
  background: var(--modal-bg);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 0s linear 200ms;
}
.cui.is-cart-open .cui-scrim,
.cui.is-sheet-open .cui-scrim { opacity: 1; visibility: visible; transition: opacity 260ms ease, visibility 0s; }

.cui-x {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--soft-tint);
  color: var(--soft-tint-text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 140ms var(--cui-ease-out), filter 0.15s ease;
}
.cui-x svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.cui-x:active { transform: scale(0.94); }
.cui-x:focus-visible,
.cui button:focus-visible,
.cui a:focus-visible { outline: 3px solid var(--pink-400); outline-offset: 2px; }


/* ----------------------------------------------------------------- Drawer */
.cd {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: var(--cui-z-panel);
  width: min(440px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px rgba(43, 11, 62, 0.28);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 240ms var(--cui-ease-drawer), visibility 0s linear 240ms;
}
.cui.is-cart-open .cd { transform: none; visibility: visible; transition: transform 380ms var(--cui-ease-drawer), visibility 0s; }

.cd-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 14px;
}
.cd-head h2 { margin: 0; font-size: 1.5rem; flex: 1; }
.cd-head h2 small {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-left: 8px;
  font-variant-numeric: tabular-nums;
}

.cd-meter { margin: 0 20px 6px; }
.cd-meter .ship-meter { margin: 0; }

.cd-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cd-line {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.cd-line.is-new { animation: cd-line-in 520ms var(--cui-ease-out) both; }
@keyframes cd-line-in {
  0%   { opacity: 0; transform: translateY(10px) scale(0.97); box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.55); }
  60%  { opacity: 1; transform: none; box-shadow: 0 0 0 6px rgba(236, 72, 153, 0.18); }
  100% { box-shadow: var(--shadow); }
}
.cd-thumb {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--pdp-art-bg);
}
.cd-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cd-info { min-width: 0; }
.cd-name {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.2;
  color: var(--heading);
}
.cd-name:hover { color: var(--pink-600); }
.cd-meta { margin: 3px 0 8px; font-size: 0.82rem; color: var(--ink-soft); line-height: 1.35; }
.cd-controls { display: flex; align-items: center; gap: 6px; }
.cd-controls .qty button { width: 36px; height: 36px; }
.cd-controls .qty span { font-variant-numeric: tabular-nums; }
.cd-remove {
  min-height: 36px;
  padding: 0 10px;
  border: none;
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.cd-remove:hover { background: var(--soft-tint); color: var(--soft-tint-text); }
.cd-price { align-self: start; font-weight: 800; color: var(--pink-600); font-variant-numeric: tabular-nums; }
[data-theme="dark"] .cd-price { color: var(--pink-300); }

.cd-empty {
  margin: auto 0;
  text-align: center;
  padding: 24px 12px;
}
.cd-empty-art { width: 120px; height: 120px; margin: 0 auto 18px; border-radius: 28px; overflow: hidden; box-shadow: var(--shadow-lg); }
.cd-empty h3 { font-size: 1.35rem; margin-bottom: 6px; }
.cd-empty p { margin: 0 auto 18px; max-width: 280px; }
.cd-empty-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; }
[data-theme="dark"] .cd-full,
[data-theme="dark"] .qa-more,
[data-theme="dark"] .cd-name:hover { color: var(--pink-300); }
[data-theme="dark"] .cui .btn-outline { color: var(--pink-200); border-color: var(--pink-400); }
[data-theme="dark"] .cui .btn-outline:hover { background: var(--pink-500); border-color: var(--pink-500); color: #fff; }

.cd-foot {
  padding: 16px 20px calc(18px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -12px 30px -18px rgba(43, 11, 62, 0.35);
}
.cd-total { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.cd-total span:first-child { font-weight: 700; color: var(--ink); }
.cd-total strong { font-family: var(--font-display); font-size: 1.6rem; color: var(--heading); font-variant-numeric: tabular-nums; }
.cd-note { margin: 0 0 14px; font-size: 0.82rem; }
.cd-foot .btn-primary { min-height: 52px; font-size: 1.02rem; }
.cd-full {
  display: block;
  text-align: center;
  margin-top: 6px;
  padding: 10px;
  font-size: 0.88rem;
  font-weight: 700;
}

/* Cart count pops when something is added */
[data-cart-count].is-bump { animation: cui-bump 420ms var(--cui-ease-out); display: inline-block; }
@keyframes cui-bump { 35% { transform: scale(1.45); } }

/* ------------------------------------------------- Shared option pickers */
.opt-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft-tint-text);
}
.opt-label em {
  font-style: normal;
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.92rem;
  color: var(--ink);
}
.opt-sizes { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; }
.opt-size {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 62px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, transform 140ms var(--cui-ease-out);
}
.opt-size b { font-size: 0.98rem; color: var(--heading); }
.opt-size span { font-size: 0.9rem; font-weight: 700; color: var(--pink-600); font-variant-numeric: tabular-nums; }
[data-theme="dark"] .opt-size span { color: var(--pink-300); }
.opt-size:active { transform: scale(0.97); }
.opt-size[aria-pressed="true"] {
  border-color: var(--pink-500);
  background: var(--soft-tint);
  box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.14);
}

.opt-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.opt-chips.is-long { max-height: 190px; overflow-y: auto; overscroll-behavior: contain; padding: 2px 4px 2px 2px; }
.opt-chip {
  --wax: #fbc4dc;
  --glow: #ec4899;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 15px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background 0.15s ease, transform 140ms var(--cui-ease-out);
}
.opt-chip i {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--wax) 55%, var(--glow) 130%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--glow) 50%, transparent);
}
.opt-chip:active { transform: scale(0.96); }
.opt-chip[aria-pressed="true"] {
  border-color: var(--glow);
  background: color-mix(in srgb, var(--glow) 14%, var(--surface));
  color: var(--heading);
}
.opt-chip[hidden] { display: none; }
.opt-chip .opt-heart { width: 13px; height: 13px; fill: var(--pink-500); }
.opt-filter {
  width: 100%;
  height: 44px;
  margin-bottom: 10px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}
.opt-filter:focus { outline: none; border-color: var(--pink-500); box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.15); }
@media (hover: hover) and (pointer: fine) {
  .opt-size:not([aria-pressed="true"]):hover,
  .opt-chip:not([aria-pressed="true"]):hover { border-color: var(--pink-300); }
}

/* -------------------------------------------------------- Quick Add sheet */
.qa {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: var(--cui-z-panel);
  width: min(520px, calc(100vw - 32px));
  max-height: min(680px, calc(100dvh - 32px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px;
  border-radius: 28px;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -50%) scale(0.96);
  transition: opacity 150ms ease, transform 150ms ease, visibility 0s linear 150ms;
}
.cui.is-sheet-open .qa {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%);
  transition: opacity 220ms ease, transform 260ms var(--cui-ease-out), visibility 0s;
}
.qa-head { display: grid; grid-template-columns: 92px 1fr auto; gap: 16px; align-items: center; margin-bottom: 20px; }
.qa-thumb { width: 92px; height: 92px; border-radius: 20px; overflow: hidden; background: var(--pdp-art-bg); box-shadow: var(--shadow); }
.qa-thumb img { width: 100%; height: 100%; object-fit: cover; }
.qa-head .cui-x { align-self: start; }
.qa-kicker { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--pink-500); }
.qa-head h3 { font-size: 1.4rem; line-height: 1.15; margin: 2px 0 4px; }
.qa-price { margin: 0; font-weight: 800; font-size: 1.15rem; color: var(--pink-600); font-variant-numeric: tabular-nums; }
[data-theme="dark"] .qa-price { color: var(--pink-300); }
.qa-price small { font-weight: 600; font-size: 0.85rem; color: var(--ink-soft); }
.qa-group { margin-bottom: 18px; }
.qa-foot { display: flex; gap: 12px; align-items: center; margin-top: 22px; }
.qa-foot .qty { flex-shrink: 0; }
.qa-foot .qty button { width: 44px; height: 50px; }
.qa-foot .qty span { font-variant-numeric: tabular-nums; }
.qa-foot .btn { flex: 1; min-height: 52px; font-size: 1.02rem; }
.qa-add span { font-variant-numeric: tabular-nums; }
.qa-more { display: block; text-align: center; margin-top: 8px; padding: 10px; font-size: 0.88rem; font-weight: 700; }

@media (max-width: 600px) {
  /* Bottom sheet on phones */
  .qa {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: 88dvh;
    padding: 20px 18px calc(16px + env(safe-area-inset-bottom));
    border-radius: 26px 26px 0 0;
    border-width: 1px 0 0;
    opacity: 1;
    transform: translateY(100%);
    transition: transform 220ms var(--cui-ease-drawer), visibility 0s linear 220ms;
  }
  .cui.is-sheet-open .qa { transform: none; transition: transform 380ms var(--cui-ease-drawer), visibility 0s; }
  .qa-head { grid-template-columns: 72px 1fr auto; gap: 12px; }
  .qa-thumb { width: 72px; height: 72px; border-radius: 16px; }
  .qa-head h3 { font-size: 1.2rem; }
  .cd-line { grid-template-columns: 60px 1fr auto; gap: 12px; }
  .cd-thumb { width: 60px; height: 60px; }
}

/* ------------------------------------------- Quick Add button on the cards */
.quick-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  margin-left: auto;
  padding: 0 13px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--pink-500), var(--purple-700));
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 140ms var(--cui-ease-out), filter 0.15s ease;
}
.quick-add svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; }
.quick-add:active { transform: scale(0.95); }
.quick-add:focus-visible { outline: 3px solid var(--pink-400); outline-offset: 2px; }
.quick-add.is-out { background: var(--soft-tint); color: var(--soft-tint-text); box-shadow: none; cursor: default; }
@media (hover: hover) and (pointer: fine) { .quick-add:not(.is-out):hover { filter: brightness(1.08); } }
.product-row:has(.quick-add) { flex-wrap: wrap; }
.product-row:has(.quick-add) .product-price { white-space: nowrap; font-variant-numeric: tabular-nums; }
.product-price small {
  display: block;
  margin-bottom: 2px;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
/* Two-up phone grid: the button gets its own full-width row */
@media (max-width: 640px) { .quick-add { flex: 1 1 100%; min-height: 44px; } }

@media (prefers-reduced-motion: reduce) {
  .cd, .qa { transform: none !important; }
  .qa { left: 50%; top: 50%; transform: translate(-50%, -50%) !important; }
  .cd-line.is-new, [data-cart-count].is-bump { animation: none !important; }
}
@media (prefers-reduced-motion: reduce) and (max-width: 600px) {
  .qa { left: 0; top: auto; transform: none !important; }
}

/* Mix-and-match savings in the cart drawer */
.cd-deal:empty { display: none; }
.cd-deal { margin-bottom: 10px; display: grid; gap: 6px; }
.cd-deal p { margin: 0; font-size: 0.9rem; }
.cd-deal-saved { display: flex; justify-content: space-between; color: #15803d; font-weight: 700; }
[data-theme="dark"] .cd-deal-saved { color: #4ade80; }
.cd-deal-saved strong { font-variant-numeric: tabular-nums; }
.cd-deal-nudge { padding: 9px 12px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--pink-300); color: var(--ink); }
.cd-deal-nudge a { font-weight: 700; white-space: nowrap; }
