/* ==========================================================
   balance. — MOBILE RESPONSIVE
   Single-pass mobile layout. Targets class hooks where they
   exist and structural fallbacks where they don't.
   Breakpoints:
     md (tablet):   max-width: 960px
     sm (phone):    max-width: 720px
     xs (compact):  max-width: 480px
   ========================================================== */

/* ==========================================================
   ACCESSIBILITY UTILITIES
   ========================================================== */

/* Visually-hidden: content remains in the a11y tree and focusable
   but is not rendered visually. Use for SR-only labels on custom UIs. */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.sr-only:focus,
.sr-only:focus-visible {
  position: static !important;
  width: auto; height: auto; clip: auto; white-space: normal;
  margin: 0; padding: 8px 12px;
  background: var(--forest); color: var(--bg);
}

/* Force a visible focus indicator for keyboard users on every
   interactive element. Many custom-styled buttons here have colored
   backgrounds that obscure the default ring, so we replace it. */
*:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[role="radio"]:focus-visible,
[role="checkbox"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

/* Skip-link: first focusable element, hidden until focused */
.skip-link {
  position: absolute; top: -40px; left: 8px;
  background: var(--forest); color: var(--bg);
  padding: 10px 16px; border-radius: 6px;
  font-family: var(--font-mono); font-size: 12px;
  letter-spacing: 0.1em; text-transform: uppercase;
  text-decoration: none; z-index: 9999;
  transition: top 160ms var(--ease-out);
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 8px;
  outline: 2px solid var(--chart);
  outline-offset: 2px;
}

/* Respect users who request reduced motion (vestibular-disorder safety) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- GLOBAL CONTAINER TIGHTENING ---------- */
@media (max-width: 720px) {
  :root {
    --pad: 20px;
  }

  body { font-size: 15px; }

  /* Typography scale-down — Fraunces display is heavy on narrow.
     Tracking is also relaxed here: negative letter-spacing costs the most
     legibility at small sizes, where counters and stroke gaps are already
     tight. Desktop keeps the tighter editorial setting. */
  h1, .display-xl {
    font-size: clamp(2.625rem, 11vw, 4rem) !important;
    line-height: 1.06 !important;
    letter-spacing: -0.02em !important;
  }
  h2, .display-lg {
    font-size: clamp(1.875rem, 8vw, 2.75rem) !important;
    line-height: 1.06 !important;
    letter-spacing: -0.015em !important;
  }
  h3 { font-size: clamp(1.25rem, 5vw, 1.5rem) !important; }

  .lede { font-size: 1.0625rem !important; line-height: 1.5 !important; }

  /* Sections breathe a little less on phones */
  .section { padding-block: clamp(34px, 8vw, 52px) !important; }
  .section-sm { padding-block: clamp(24px, 6vw, 40px) !important; }

  /* Program tiles were ~540px tall on phones — far too big. Shrink them. */
  .prog-tile { min-height: 0 !important; border-radius: 16px !important; }
  .prog-tile-img-wrap { height: 172px !important; }
  /* image was 115% tall inside a clipped wrap -> cut off. Contain it. */
  .prog-tile-img { height: 100% !important; max-height: 100% !important; }
  /* Product cards: trim the min-height so they're not oversized on mobile */
  .product-card { min-height: 0 !important; }

  /* Buttons — easier to tap, wrap naturally */
  .btn { padding: 13px 20px !important; font-size: 14px !important; }
  .btn--lg { padding: 15px 22px !important; font-size: 14.5px !important; }
  .btn--sm { padding: 9px 14px !important; font-size: 12.5px !important; }
}

/* ==========================================================
   HOMEPAGE GRIDS
   ========================================================== */

/* ----- HERO ----- */
@media (max-width: 960px) {
  .hero-split {
    grid-template-columns: 1fr !important;
    min-height: auto !important;
    gap: 26px !important;
  }
  /* on mobile, editorial right column follows left */
  .hero-split > :nth-child(2) {
    min-height: 380px;
  }
}
/* Hero right column — tame the product specimen on mobile */
@media (max-width: 960px) {
  .hero-split > :nth-child(2) {
    margin: 0 !important;
    border-radius: 20px !important;
    min-height: 320px;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  /* min-width: 0 on the grid item so it can shrink to track width */
  .hero-split > * {
    min-width: 0;
  }
}
@media (max-width: 560px) {
  .hero-split > :nth-child(2) {
    min-height: 280px;
  }
  /* BL Rx detail card — stack to 3 cols, lose dividers */
  .hero-split > :nth-child(2) > div:last-child {
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 10px !important;
    padding: 14px !important;
  }
  .hero-split > :nth-child(2) > div:last-child > div[style*="width: 1px"],
  .hero-split > :nth-child(2) > div:last-child > div[style*="width:1px"] {
    display: none !important;
  }
  /* Clinician chip — hide label, keep avatar */
  .hero-split > :nth-child(2) > div:nth-child(4) > div:last-child {
    display: none;
  }
}

@media (max-width: 720px) {
  /* .hero-proof is used by pages/safety.jsx (the homepage hero no longer has
     a proof strip). Keep these rules until that page stops using the class. */
  .hero-proof {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0 !important;
  }
  .hero-proof > * {
    padding: 14px 12px !important;
    border-left: none !important;
    border-bottom: 1px solid var(--ink-15);
  }
  .hero-proof > *:nth-child(odd) { border-right: 1px solid var(--ink-15); }
  .hero-proof > *:nth-last-child(-n+2) { border-bottom: none; }

  /* Hero spec strip — stack the 3 spec pills in 2 rows */
  .hero-spec {
    grid-template-columns: 1fr 1px 1fr !important;
    grid-template-rows: auto auto !important;
    row-gap: 10px !important;
  }
}

/* ----- STATS ----- */
@media (max-width: 720px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 24px !important;
  }
  .stats-grid > * {
    padding-left: 0 !important;
    border-left: none !important;
    padding-top: 16px;
    border-top: 1px solid var(--ink-15);
  }
  .stats-grid > *:first-child,
  .stats-grid > *:nth-child(2) {
    border-top: none;
    padding-top: 0;
  }
}

/* ----- PROGRAM TILES ----- */
@media (max-width: 960px) {
  .prog-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}
@media (max-width: 560px) {
  .prog-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ----- HOW IT WORKS ----- */
@media (max-width: 960px) {
  .how-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 560px) {
  .how-grid { grid-template-columns: 1fr !important; }
}

/* ----- SCIENCE ----- */
@media (max-width: 960px) {
  .sci-grid { grid-template-columns: 1fr !important; }
}

/* ----- COMPARE ----- */
@media (max-width: 860px) {
  .cmp {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }
  .cmp > * {
    border-radius: 0 !important;
  }
  .cmp > *:first-child { border-radius: var(--r-lg) var(--r-lg) 0 0 !important; }
  .cmp > *:last-child { border-radius: 0 0 var(--r-lg) var(--r-lg) !important; }
}

/* ----- ED/SEXUAL ----- */
@media (max-width: 860px) {
  .ed-grid { grid-template-columns: 1fr !important; }
}

/* ----- CLINICIANS ----- */
@media (max-width: 960px) {
  .docs-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 480px) {
  .docs-grid { grid-template-columns: 1fr !important; }
}

/* ----- TESTIMONIALS ----- */
@media (max-width: 960px) {
  .t-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 560px) {
  .t-grid { grid-template-columns: 1fr !important; }
}

/* ----- FAQ ----- */
@media (max-width: 860px) {
  .faq-grid { grid-template-columns: 1fr !important; gap: 32px !important; }
}

/* ----- PRICE GUARANTEE ----- */
@media (max-width: 860px) {
  .guar-grid { grid-template-columns: 1fr !important; }
}

/* ==========================================================
   HEADER / NAV
   ========================================================== */
@media (max-width: 960px) {
  /* Hide desktop nav and the inline "Start assessment" CTA;
     show the hamburger trigger instead. Inline display:flex on
     <nav class="desktop-nav"> requires !important to override. */
  header .desktop-nav { display: none !important; }
  header .btn--primary.hide-sm { display: none !important; }
}

@media (max-width: 560px) {
  /* Header row: just logo + cart + hamburger */
  header .header-account { display: none !important; }
}

/* ==========================================================
   ANNOUNCEMENT BAR - speed up on mobile, it's long
   ========================================================== */
@media (max-width: 720px) {
  .announcement-marquee { animation-duration: 24s !important; gap: 24px !important; }
  .announcement-marquee > span { gap: 24px !important; }
}

/* ==========================================================
   FOOTER (already has its own media queries, but reinforce)
   ========================================================== */
@media (max-width: 720px) {
  footer.surface-ink {
    padding: 64px 0 28px !important;
  }
}

/* ==========================================================
   TWEAKS PANEL — smaller on mobile, anchored bottom
   ========================================================== */
@media (max-width: 560px) {
  [data-tweaks-panel] {
    right: 12px !important;
    left: 12px !important;
    bottom: 12px !important;
    width: auto !important;
    max-height: 70vh !important;
  }
}

/* ==========================================================
   ASSESSMENT / FUNNELS / CHECKOUT — generic fixes
   ========================================================== */
@media (max-width: 720px) {
  .funnel-columns,
  .assessment-columns,
  .checkout-columns {
    grid-template-columns: 1fr !important;
  }
}

/* ==========================================================
   CHECKOUT LAYOUT
   ========================================================== */
@media (max-width: 860px) {
  .co-grid { grid-template-columns: 1fr !important; min-height: auto !important; }
}
@media (max-width: 560px) {
  .co-fields { grid-template-columns: 1fr !important; }
  .co-fields > div[style*="gridColumn"] { grid-column: auto !important; }
  .co-summary { grid-template-columns: 1fr !important; }
}

/* Express-pay buttons — restore keyboard focus outline stripped by `all: unset` */
.co-express-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: 10px;
}

/* Mobile compact order summary shown above checkout form */
@media (max-width: 860px) {
  .co-mobile-summary { display: flex !important; }
}

/* Minimum tap target for small buttons on mobile — 44x44 per WCAG */
@media (max-width: 560px) {
  .btn { min-height: 44px; }
  .co-express-btn { min-height: 48px; }
  /* Ensure form inputs are comfortable on touch */
  .input, .select, .textarea { min-height: 44px; font-size: 16px; /* prevent iOS zoom on focus */ }
}

/* ==========================================================
   PDP LAYOUT
   ========================================================== */
@media (max-width: 860px) {
  .pdp-grid {
    grid-template-columns: 1fr !important;
    gap: 40px !important;
  }
}

/* ==========================================================
   ASSESSMENT LAYOUT
   ========================================================== */
@media (max-width: 960px) {
  .assess-layout {
    grid-template-columns: 1fr !important;
  }
  .assess-side { order: 2; }
}
@media (max-width: 640px) {
  .assess-grid-2 {
    grid-template-columns: 1fr !important;
  }
  .assess-body { padding: 28px 20px !important; }
  .assess-side { padding: 32px 20px !important; }
}

/* ==========================================================
   FUNNEL HEADER / PROGRESS
   ========================================================== */
.funnel-header {
  padding: 18px 0 0;
  border-bottom: 1px solid var(--ink-15);
  background: var(--bg-paper);
  padding-top: max(18px, env(safe-area-inset-top));
}
.funnel-header__row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-bottom: 18px;
}
.funnel-header__brand { display: flex; align-items: center; gap: 16px; }
.funnel-header__meta {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-50);
}
.funnel-header__exit {
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-50);
}
.funnel-header__exit-short { display: none; }

/* Mobile collapsed progress — visible ONLY on small */
.funnel-header__mobileprog { display: none; }

@media (max-width: 720px) {
  .funnel-header__row { gap: 10px; padding-bottom: 12px; }
  .funnel-header__meta { display: none; }
  .funnel-header__exit-long { display: none; }
  .funnel-header__exit-short { display: inline; }

  .funnel-header__mobileprog { display: block; border-top: 1px solid var(--ink-15); overflow: hidden; }
  .funnel-header__mobileprog-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0 8px;
    font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--ink-70);
  }
  .funnel-header__mobileprog-track {
    height: 3px; background: var(--ink-15); overflow: hidden;
    margin: 0 calc(-1 * var(--pad));
  }
  .funnel-header__mobileprog-fill {
    height: 100%; background: var(--chart);
    transition: width 400ms var(--ease-out);
  }

  /* Hide the desktop multi-section progress on mobile */
  .funnel-sections-desktop { display: none !important; }

  /* Main: make room for sticky footer, tighter top */
  .funnel-main {
    padding: 24px 0 160px !important;
    justify-content: flex-start !important;
  }
}

/* ==========================================================
   FUNNEL FOOTER — always visible
   ========================================================== */
.funnel-footer {
  padding: 20px 0 32px;
  border-top: 1px solid var(--ink-15);
  background: var(--bg-paper);
}
.funnel-footer__row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px;
}
.funnel-footer__status {
  font-size: 11px; letter-spacing: 0.12em; color: var(--ink-50);
  text-transform: uppercase; flex: 1; text-align: center;
}

@media (max-width: 720px) {
  .funnel-footer {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    padding: 12px 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(15, 19, 16, 0.06);
  }
  .funnel-footer__row { gap: 10px; }
  .funnel-footer__status { display: none; }
  .funnel-footer__back {
    padding: 12px 16px !important;
    flex-shrink: 0;
  }
  .funnel-footer__back-label { display: none; }
  .funnel-footer__next {
    flex: 1;
    justify-content: center;
    padding: 14px 20px !important;
    font-size: 14.5px !important;
  }
}

/* ==========================================================
   FUNNEL INTRO BULLETS — stack on mobile
   ========================================================== */
.funnel-intro__bullets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border: 1px solid var(--ink-15);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 40px;
}
.funnel-intro__bullet {
  padding: 20px;
  border-right: 1px solid var(--ink-15);
  background: var(--bg-paper);
}
.funnel-intro__bullet:last-child { border-right: none; }
.funnel-intro__bullet-n {
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--chart-text); margin-bottom: 8px;
}
.funnel-intro__bullet-l {
  font-size: 14px; color: var(--ink-70); line-height: 1.45;
}
@media (max-width: 640px) {
  .funnel-intro__bullets { grid-template-columns: 1fr; }
  .funnel-intro__bullet {
    border-right: none;
    border-bottom: 1px solid var(--ink-15);
  }
  .funnel-intro__bullet:last-child { border-bottom: none; }
}

/* ==========================================================
   FUNNEL QUESTION — tighter on phones
   ========================================================== */
@media (max-width: 720px) {
  .q-headline {
    font-size: clamp(1.5rem, 6.2vw, 2rem) !important;
    margin-bottom: 20px !important;
  }
  .q-number {
    padding: 16px 20px !important;
    max-width: 100% !important;
  }
  .q-number__input { font-size: 44px !important; }
  .q-duo { gap: 10px !important; }
  .q-duo__cell {
    padding: 14px 16px !important;
    max-width: none !important;
  }
  .q-duo__input { font-size: 32px !important; }
  .q-text { font-size: 18px !important; padding: 16px 20px !important; }
}

/* ==========================================================
   RX MEDIA / PRODUCT TILES — keep scale sane
   ========================================================== */
@media (max-width: 560px) {
  .rx-placeholder {
    min-height: 160px !important;
    padding: 16px !important;
  }
  .rx-placeholder__name {
    font-size: 1.1rem !important;
  }
}

/* ==========================================================
   SAFE AREA — iOS notch
   ========================================================== */
@supports (padding: max(0px)) {
  @media (max-width: 720px) {
    body {
      padding-left: env(safe-area-inset-left);
      padding-right: env(safe-area-inset-right);
    }
  }
}

/* ==========================================================
   LANDING PAGES (lp-*.html) — ad-funnel pages
   These pages are one-off React trees, not the shared Header/Footer
   layout, so they get their own class hooks here rather than reusing
   .hero-split etc. (which assume the homepage's specific DOM shape).
   ========================================================== */
@media (max-width: 860px) {
  .lp-split {
    grid-template-columns: 1fr !important;
  }
  /* Image half of a hero/feature split: cap height so it doesn't eat
     the whole viewport above the fold on a phone. */
  .lp-split > div:has(> img) {
    max-height: 320px;
  }
}
@media (max-width: 640px) {
  .lp-split-tight {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }
}
@media (max-width: 480px) {
  /* Phone CTA: keep the number, drop the subtext — there isn't room
     for both next to the logo on a phone-width header. */
  .lp-phone-sub { display: none !important; }
  .lp-phone-btn { padding: 8px 14px !important; font-size: 13.5px !important; }
}

/* ==========================================================
   MOBILE NAV DRAWER
   ========================================================== */
.mobile-trigger {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  border: 1px solid var(--ink-30);
  background: transparent;
  cursor: pointer;
  color: var(--ink);
  transition: background 180ms var(--ease);
}
.mobile-trigger:hover { background: var(--bg-fog); }
.mobile-trigger svg { display: block; }

@media (max-width: 960px) {
  .mobile-trigger { display: inline-flex; }
}

.mobile-drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 320ms var(--ease-out);
  overflow-y: auto;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
}
.mobile-drawer[data-open="true"] { transform: translateX(0); }
/* Keep drawer fully out of the a11y tree and tab order when closed */
.mobile-drawer[data-open="false"] { visibility: hidden; }
.mobile-drawer[data-open="true"] { visibility: visible; }

.mobile-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--ink-15);
  margin-bottom: 24px;
}

.mobile-drawer__group {
  padding: 16px 0;
  border-bottom: 1px solid var(--ink-15);
}
.mobile-drawer__group-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-50);
  margin-bottom: 14px;
}
.mobile-drawer__link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  font-family: var(--font-display);
  font-weight: 400; /* serif minimum per DESIGN.md — 300 failed legibility */
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--ink);
}
/* Hover/focus recolor uses --forest, not --chart-deep: chartreuse text on the
   drawer background is 1.90:1, so the old rule made a link *less* readable the
   moment you focused it. */
.mobile-drawer__link:hover { color: var(--forest); text-decoration: underline; }
.mobile-drawer__link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
  border-radius: 4px;
  color: var(--forest);
}
.mobile-drawer__link .mono {
  font-size: 11px;
  color: var(--ink-50);
  letter-spacing: 0.1em;
}

.mobile-drawer__cta {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mobile-drawer__cta .btn {
  width: 100%;
  justify-content: center;
  padding: 16px 22px !important;
  font-size: 15px !important;
}

/* Prevent body scroll when drawer open */
body[data-drawer-open="true"] {
  overflow: hidden;
}
