/* brandonlehmanshow.com: the Patriot Store bag (drawer, bag lines, quantity stepper).
   Loaded on store pages by scripts/build-shop.mjs and injected by cart.js elsewhere.
   Tokens and type roles come from experience.css; every value maps to a token or a
   rule in .claude/skills/brandon-lehman-design/SKILL.md (section 0 records the
   2026-09-29 store decisions this file implements). */

/* 1. Drawer: a modal <dialog> from the right, min(440px, 100vw), panel surface.
   Entry: translateX from 100% over 420ms --ease-drawer (@starting-style), the
   backdrop fades to .6 of --bg-deep over 300ms. Exit (.is-closing, cart.js) runs
   at ~75% of the entrance. Reduced motion and html.motion-paused: instant. */
.bag-drawer {
  position: fixed; inset: 0 0 0 auto;
  width: min(440px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh;
  margin: 0; padding: 0;
  display: none; flex-direction: column;
  border: 0; border-left: 1px solid var(--line); border-radius: var(--r-0);
  background: var(--panel); color: var(--ink);
  overscroll-behavior: contain;
}
.bag-drawer[open] { display: flex; }
.bag-drawer::backdrop { background: rgba(22, 16, 11, 0.6); }

@media (prefers-reduced-motion: no-preference) {
  html:not(.motion-paused) .bag-drawer[open] { transition: translate var(--t-drawer) var(--ease-drawer); }
  html:not(.motion-paused) .bag-drawer[open]::backdrop { transition: opacity 300ms var(--ease-out); }
  html:not(.motion-paused) .bag-drawer.is-closing { translate: 100% 0; transition: translate 320ms var(--ease-drawer); }
  html:not(.motion-paused) .bag-drawer.is-closing::backdrop { opacity: 0; transition: opacity 240ms var(--ease-out); }
  @starting-style {
    html:not(.motion-paused) .bag-drawer[open] { translate: 100% 0; }
    html:not(.motion-paused) .bag-drawer[open]::backdrop { opacity: 0; }
  }
}
/* The page behind a modal dialog should not scroll under the finger. */
html.bag-open { overflow: hidden; scrollbar-gutter: stable; }

.bag-drawer__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  flex: none;
  min-height: var(--nav-h);
  padding: var(--s-2) var(--s-5);
  border-bottom: 1px solid var(--line);
}
.bag-drawer__title { display: flex; align-items: baseline; gap: var(--s-3); font: 400 28px/1.15 var(--font-display); letter-spacing: -0.02em; }
.bag-drawer__count { font: 500 13px/1.4 var(--font-body); letter-spacing: 0.02em; color: var(--muted); font-variant-numeric: tabular-nums; }
.bag-drawer__close {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; margin-right: calc(-1 * var(--s-2)); padding-inline: var(--s-2);
  font: 500 13px/1.4 var(--font-body); letter-spacing: 0.02em; color: var(--ink-85);
  transition: color var(--t-state) var(--ease-out), scale var(--t-press) var(--ease-out);
}
.bag-drawer__close:active { scale: 0.97; }

.bag-drawer__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--s-5); }
.bag-drawer__error { padding-block: var(--s-6); color: var(--ink-85); }
/* After an add that hit the 10-per-line cap: one plain sentence in cream. */
.bag-drawer__cap { padding-block: var(--s-4); border-top: 1px solid var(--line); font: 500 13px/1.4 var(--font-body); letter-spacing: 0.02em; color: var(--ink); }

.bag-drawer__foot {
  flex: none;
  display: grid; gap: var(--s-3);
  padding: var(--s-5) var(--s-5) max(var(--s-5), env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.bag-drawer__foot[hidden] { display: none; }
.bag-sum { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); font: 500 15px/1.4 var(--font-body); }
.bag-sum .price { font-size: 17px; }
.bag-note { font: 400 13px/1.5 var(--font-body); color: var(--muted); }
.bag-drawer__checkout { width: 100%; margin-top: var(--s-2); }
.bag-drawer__view { justify-self: start; color: var(--ink-85); }

/* Empty state: one sentence and the way back to the store. */
.bag-empty { padding-block: var(--s-8) var(--s-6); }
.bag-empty__title { font: 400 28px/1.15 var(--font-display); letter-spacing: -0.02em; text-wrap: balance; }
.bag-empty .text-link { margin-top: var(--s-3); }

/* 2. Bag lines. Hairline rows: 4:5 thumbnail (88px), name + price on one
   line, colour and size in muted, then the stepper and a quiet Remove. */
.bag-lines { display: grid; }
.bag-line {
  position: relative;
  display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: var(--s-4);
  padding-block: var(--s-5);
  border-bottom: 1px solid var(--line);
}
.bag-line:last-child { border-bottom: 0; }
.bag-line__thumb { display: block; width: 88px; aspect-ratio: 4 / 5; background: var(--bg-deep); outline: 1px solid var(--outline-img); outline-offset: -1px; overflow: hidden; }
.bag-line__thumb img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; }
.bag-line__info { display: flex; flex-direction: column; min-width: 0; }
.bag-line__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.bag-line__title { min-width: 0; }
.bag-line__name {
  font: 400 15px/1.45 var(--font-body); color: var(--ink);
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; text-decoration-thickness: 1px;
  transition: text-decoration-color var(--t-state) var(--ease-out);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
  /* A 44px tap target without moving the layout: the box grows, the margins give it back. */
  padding-block: 11px; margin-block: -11px;
}
.bag-line__price { flex: none; font-size: 15px; line-height: 1.45; text-align: right; }
.bag-line__each { display: block; font: 400 13px/1.4 var(--font-body); color: var(--muted); }
.bag-line__meta { margin-top: 2px; font: 400 13px/1.45 var(--font-body); color: var(--muted); }
.bag-line__actions { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: auto; padding-top: var(--s-3); }
.bag-line__qty-static { margin-top: var(--s-1); font: 400 13px/1.45 var(--font-body); color: var(--muted); font-variant-numeric: tabular-nums; }
.bag-line__remove {
  display: inline-flex; align-items: center; min-height: 44px; padding-inline: var(--s-2); margin-right: calc(-1 * var(--s-2));
  font: 500 13px/1.4 var(--font-body); letter-spacing: 0.02em; color: var(--muted);
  text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 5px; text-decoration-thickness: 1px;
  transition: color var(--t-state) var(--ease-out), scale var(--t-press) var(--ease-out);
}
.bag-line__remove:active { scale: 0.97; }

/* The line just added: a 1px gold outline that fades over 900ms. Opacity only,
   so it also plays (as a fade) under reduced motion. */
.bag-line::after {
  content: ""; position: absolute; inset: var(--s-2) calc(-1 * var(--s-2));
  border: 1px solid var(--gold); opacity: 0; pointer-events: none;
}
.bag-line.is-added::after { animation: bag-added 900ms var(--ease-out) forwards; }
@keyframes bag-added { 0%, 30% { opacity: 1; } 100% { opacity: 0; } }

/* 3. Quantity stepper: 44px minus/plus, the value between them. The glyphs are
   drawn hairlines, not characters. aria-disabled (not disabled) keeps focus
   on the button at the limits. */
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); }
.qty__btn {
  position: relative; display: inline-flex; width: 44px; height: 44px; flex: none;
  color: var(--ink);
  transition: color var(--t-state) var(--ease-out), background-color var(--t-state) var(--ease-out);
}
.qty__btn::before, .qty__btn--plus::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 1px;
  background: currentColor; translate: -50% -50%;
}
.qty__btn--plus::after { rotate: 90deg; }
.qty__btn[aria-disabled="true"] { color: var(--line-strong); cursor: default; }
.qty__btn:focus-visible { outline-offset: -2px; }
.qty__value {
  min-width: 2ch; text-align: center;
  font: 500 15px/1 var(--font-body); font-variant-numeric: tabular-nums;
}

/* 4. Nav count lives in experience.css (the shell); motion gates below. */
.motion-paused .bag-drawer__close:active, .motion-paused .bag-line__remove:active { scale: 1; }

@media (hover: hover) {
  .bag-drawer__close:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 1px; }
  .bag-line__name:hover { text-decoration-color: var(--line-strong); }
  .bag-line__remove:hover { color: var(--ink); text-decoration-color: currentColor; }
  .qty__btn:not([aria-disabled="true"]):hover { background: var(--bg-deep); }
  .bag-drawer__view:hover { color: var(--ink); }
}
