/**
 * AbayaFemme base layer — layout primitives, accessibility utilities.
 *
 * DELIBERATELY ADDITIVE.
 *
 * This stylesheet loads on every page, but 44 pages and every WooCommerce
 * surface are still rendered by WoodMart defaults. A global typographic or
 * `body` takeover here would regress all of them at once, so nothing in this
 * file restyles a bare element selector outside the two documented exceptions
 * below (focus ring and reduced motion, both accessibility fixes that are
 * safe and desirable everywhere).
 *
 * Each surface adopts the design system as it is rebuilt, by adding the
 * `af-scope` class to its root and loading its own route stylesheet. That
 * keeps every visual change traceable to the surface it belongs to.
 */

/* ---------------------------------------------------------------------------
 * Accessibility, applied globally on purpose.
 * ------------------------------------------------------------------------- */

/*
 * Anchors and focus targets clear the sticky header.
 *
 * The storefront header is `position: sticky; top: 0`, so anything the browser scrolls to — a
 * `#fragment` link, a form control the browser brings into view on focus, an error message a
 * validation jump lands on — arrived *underneath* it. It is not a rare case: every skip link,
 * every in-page anchor and every keyboard tab into an off-screen field hit it.
 *
 * `scroll-padding-top` is the one property that fixes all of those at once, and it needs the
 * header's real height — a `clamp()` that also grows by 32px with the administration bar — which
 * `header.js` measures and publishes as `--af-header-height`. The `0px` fallback means a page
 * without that script behaves exactly as it did.
 */
html {
  scroll-padding-top: calc(var(--af-header-height, 0px) + 1rem);
}

/* WCAG 2.2 AA: focus must be visible everywhere, including on WoodMart's own
 * controls. `:focus-visible` keeps mouse users from seeing rings.
 *
 * Only outline properties are set. Touching border-radius here would visibly
 * reshape pill-shaped buttons at the moment they receive focus; browsers
 * already follow the element's own radius when drawing an outline. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: var(--af-focus-width) solid var(--af-color-focus);
  outline-offset: var(--af-focus-offset);
}

/* Reduced motion.
 *
 * Deliberately NOT a global `* { animation: none !important }`. That blanket
 * pattern also freezes WoodMart's AJAX loading spinners, which are functional
 * indicators rather than decoration — a motionless spinner reads as a broken
 * page. Motion is therefore neutralised inside the surfaces we own, plus
 * scroll behaviour globally, which is safe for any theme.
 *
 * An element inside our scope whose animation IS functional opts back in with
 * `data-af-motion="essential"`. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .af-scope :where(*):not([data-af-motion="essential"]) {
    animation-duration: var(--af-duration-base);
    transition-duration: var(--af-duration-base);
  }
}

/* ---------------------------------------------------------------------------
 * Utilities.
 * ------------------------------------------------------------------------- */

.af-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Visible again on focus, for skip links and "reveal on focus" controls. */
.af-visually-hidden:focus-visible,
.af-visually-hidden-focusable:focus-visible {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip-path: none;
  white-space: normal;
}

/* Hidden by clipping, not by an offset transform.
 *
 * The first version used `translateY(-200%)`, which only clears the viewport when the
 * link's positioned ancestor starts at the top of the page. It did not: the link was
 * emitted inside WoodMart's `position: relative` page wrapper, which begins 66px down,
 * below the announcement bar — so 85px of upward travel left its bottom half on
 * screen at rest, over the wordmark. Clipping cannot be defeated by an offset
 * ancestor, whatever precedes the links in the document. */
.af-skip-link {
  position: absolute;
  z-index: 10000;
  top: var(--af-space-2);
  left: var(--af-space-2);
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  background: var(--af-surface-raised);
  color: var(--af-text-default);
  font-family: var(--af-font-ui);
  font-size: var(--af-text-sm);
  white-space: nowrap;
  text-decoration: none;
  border: 1px solid var(--af-border-strong);
  border-radius: var(--af-radius-sm);
  box-shadow: var(--af-shadow-md);
}

.af-skip-link:focus,
.af-skip-link:focus-visible {
  width: auto;
  height: auto;
  padding: var(--af-space-3) var(--af-space-4);
  overflow: visible;
  clip-path: none;
}

/* ---------------------------------------------------------------------------
 * Scope root.
 *
 * `af-scope` opts a subtree into AbayaFemme typography and colour. Applied to
 * a template root, it never touches the surfaces we have not rebuilt yet.
 * ------------------------------------------------------------------------- */

.af-scope {
  font-family: var(--af-font-ui);
  font-size: var(--af-text-body);
  line-height: var(--af-leading-body);
  color: var(--af-text-default);
  -webkit-font-smoothing: antialiased;
}

.af-scope :where(h1, h2, h3, h4, .af-display) {
  font-family: var(--af-font-display);
  font-weight: 500;
  line-height: var(--af-leading-heading);
  /* WoodMart forces `text-transform: capitalize` on headings site-wide.
   * Integration override, documented in TEMPLATE_OVERRIDE_AUDIT.md. */
  text-transform: none;
  color: inherit;
}

.af-scope :where(h1) { font-size: var(--af-text-h1); line-height: var(--af-leading-display); }
.af-scope :where(h2) { font-size: var(--af-text-h2); }
.af-scope :where(h3) { font-size: var(--af-text-h3); }
.af-scope :where(h4) { font-size: var(--af-text-h4); font-family: var(--af-font-ui); font-weight: 600; }

.af-scope :where(p, li) {
  font-size: inherit;
  line-height: var(--af-leading-body);
}

.af-scope :where(a) {
  color: var(--af-text-link);
  text-underline-offset: 0.18em;
}

/* Eyebrow label — short uppercase kicker. Never used for paragraphs. */
.af-eyebrow {
  font-family: var(--af-font-ui);
  font-size: var(--af-text-micro);
  font-weight: 600;
  letter-spacing: var(--af-tracking-eyebrow);
  text-transform: uppercase;
  color: var(--af-text-muted);
}

/* ---------------------------------------------------------------------------
 * Layout primitives.
 * ------------------------------------------------------------------------- */

.af-container {
  width: 100%;
  max-width: var(--af-container-max);
  margin-inline: auto;
  padding-inline: var(--af-gutter);
}

.af-container--article { max-width: var(--af-measure-article); }
.af-container--form { max-width: var(--af-measure-form); }
.af-container--flush { padding-inline: 0; }

/* Vertical rhythm without margin collapsing surprises. */
.af-stack { display: flex; flex-direction: column; gap: var(--af-stack-gap, var(--af-space-4)); }
.af-stack--tight { --af-stack-gap: var(--af-space-2); }
.af-stack--loose { --af-stack-gap: var(--af-space-6); }

.af-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--af-cluster-gap, var(--af-space-3));
}

.af-section { padding-block: var(--af-space-7); }
.af-section--tight { padding-block: var(--af-space-6); }
.af-section--loose { padding-block: var(--af-space-8); }

/* Responsive grid driven by a minimum readable card width rather than by
 * breakpoint-specific column counts. Cards never get narrower than their
 * title/price/CTA needs (DESIGN.md section 7.3). */
.af-grid {
  display: grid;
  gap: var(--af-grid-gap, var(--af-space-5));
  grid-template-columns: repeat(
    auto-fill,
    minmax(min(var(--af-grid-min, 15rem), 100%), 1fr)
  );
}

.af-grid--products { --af-grid-min: 13rem; }
.af-grid--editorial { --af-grid-min: 18rem; }

/* Fixed-ratio media box. Prevents layout shift and keeps grids aligned. */
.af-media {
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--af-media-ratio, var(--af-ratio-product));
  background: var(--af-surface-sunken);
}

.af-media > :where(img, video) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.af-media--tall { --af-media-ratio: var(--af-ratio-product-tall); }
.af-media--editorial { --af-media-ratio: var(--af-ratio-editorial); }

/* Any wide child (table, code block, diagram) scrolls inside itself so the
 * page body never scrolls horizontally. */
.af-scroll-x {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
