/* =============================================================================
 * Awareness That Heals — Site header (parts/header.html)
 *
 * Ported from the Phase 0 artifact design/site-header-v2.html (v2), minus the
 * review-tools bar, brand toggle, and demo content. Consumes the semantic
 * --color-* / --font-* tokens from brand-active.css (→ brand-tokens-ath.css),
 * so it follows the auto/light/dark mode cycle.
 *
 * The header is authored as Custom HTML (not core blocks): v2's responsive
 * nav-label cascade needs per-link .nav-long/.nav-short spans, which the
 * core/navigation block can't emit. Global resets from the artifact are
 * scoped to .site-header / .mobile-menu here so nothing leaks site-wide.
 * =============================================================================*/

/* Page canvas — follow the mode tokens so the toggle reskins the whole page,
 * not just the header. (Content blocks/cards still use theme.json presets;
 * full token migration of those is follow-up.) */
html body {
  background-color: var(--color-bg-page);
  color: var(--color-text-primary);
  transition: background-color 200ms ease, color 200ms ease;
}

/* Scoped resets (artifact relied on global a/button/:focus-visible rules) */
.site-header a,
.mobile-menu a { color: inherit; text-decoration: none; }
.site-header button,
.mobile-menu button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.site-header a:focus-visible,
.site-header button:focus-visible,
.mobile-menu a:focus-visible,
.mobile-menu button:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 3px;
  border-radius: 2px;
}

/* =============================================================================
 * SITE HEADER
 * =========================================================================== */

/* parts/header.html composes topbar-tagline + header-main via wp:template-part.
 * WP wraps each part's output in <div class="wp-block-template-part">, which
 * — left to itself — picks up the block-layout flow margin (~1.5em) between
 * siblings. display:contents makes those wrappers transparent for layout so
 * the .ath-topbar--tagline / .header-main / .mobile-menu blocks sit exactly where
 * they used to in the unsplit header.
 *
 * --wp--style--block-gap reset: the .site-header wrapper is a core/group in
 * default (block-flow) layout, which adds margin-block between children via
 * the layout-engine rule `.is-layout-flow > * + *`. Setting the variable to
 * 0 at .site-header scope zeroes the margin without needing a !important
 * override. We can't set blockGap in the part's block attrs without WP
 * emitting an inline style that fails strict block validation. */
.site-header {
  --wp--style--block-gap: 0;
}
.site-header > .wp-block-template-part,
body > .wp-block-template-part:has(> .mobile-menu) {
  display: contents;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 90;
  background: var(--color-bg-page);
  transition: background-color 280ms ease, box-shadow 280ms ease, border-color 280ms ease;
  border-bottom: 1px solid transparent;
}
.site-header.is-scrolled {
  background: var(--header-bg-blur);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom-color: var(--color-border-subtle);
  box-shadow: var(--shadow-sm);
}

/* ---- Tagline topbar (parts/topbar-tagline.html) ----
 *
 * parts/topbar-tagline.html is a <section> core/group in flex layout
 * containing three core/paragraph children interleaved with two
 * wp:html .ath-topbar__dot blocks. Each dot is a real flex item so
 * (a) it shows up in the Site Editor as a Block: Custom HTML the
 * user can move/delete like any other, and (b) the spacing between
 * every adjacent pair (text ↔ dot ↔ text) is uniform under a single
 * flex `gap` value rather than per-dot margins.
 *
 * Cascade safety: .ath-topbar (base) in interim-header.css sets
 * border-bottom 0.5px and font-family Jost; .ath-topbar--tagline
 * here overrides with 1px border + italic Cormorant. Equal
 * specificity, but variant rules load after the base via the
 * ath-interim-header stylesheet dependency declared in functions.php.
 *
 * --wp--style--block-gap: 14px is the layout-engine variable WP's
 * flex layout reads for gap between flex children. Setting it via
 * CSS (rather than in the block attrs as style.spacing.blockGap)
 * avoids the strict block-validator complaint about inline-style
 * mismatches. */
.ath-topbar--tagline {
  --wp--style--block-gap: 14px;
  padding: 9px 32px;
  border-bottom: 1px solid var(--color-border-subtle);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
  color: var(--color-text-secondary);
  text-align: center;
  max-height: 60px;
  overflow: hidden;
  opacity: 1;
  transition: max-height 320ms ease, padding 320ms ease, opacity 220ms ease, border-color 220ms ease;
}
.site-header.is-scrolled .ath-topbar--tagline {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  border-bottom-color: transparent;
}
.ath-topbar--tagline p {
  margin: 0;
}

/* ---- Main row ---- */
.header-main {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 20px 32px;
  max-width: 1440px;
  margin: 0 auto;
  transition: padding 280ms ease;
}
.site-header.is-scrolled .header-main { padding: 14px 32px; }

/* ---- Brand ---- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--color-text-primary);
  flex: 0 0 auto;
  min-width: 0;
}
.brand:hover .brand-mark { transform: translateY(-1px); }
.brand-mark {
  width: 40px;
  height: 28px;
  flex-shrink: 0;
  transition: transform 240ms ease, width 280ms ease, height 280ms ease;
}
.site-header.is-scrolled .brand-mark { width: 32px; height: 22px; }
.brand-wordmark {
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-primary);
  line-height: 1.05;
  white-space: nowrap;
  transition: font-size 280ms ease, letter-spacing 280ms ease;
}
.site-header.is-scrolled .brand-wordmark { font-size: 1rem; letter-spacing: 0.10em; }

/* ---- Primary nav ---- */
.primary-nav {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-left: auto;
}
.primary-nav a {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  padding: 8px 2px;
  position: relative;
  transition: color 180ms ease;
  white-space: nowrap;
}
.primary-nav a::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--color-brand-primary);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 240ms ease;
}
.primary-nav a:hover { color: var(--color-text-primary); }
.primary-nav a:hover::after { transform: scaleX(1); }
.primary-nav a.is-external::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--color-brand-accent);
  vertical-align: middle;
  position: relative;
  top: -2px;
}

/* Long/short label swap */
.nav-long { display: inline; }
.nav-short { display: none; }

@media (max-width: 1180px) {
  .primary-nav { gap: 20px; }
  .primary-nav a { font-size: 0.74rem; letter-spacing: 0.12em; }
  .nav-long { display: none; }
  .nav-short { display: inline; }
  .brand-wordmark { font-size: 1.05rem; letter-spacing: 0.09em; }
}
@media (max-width: 1040px) {
  .primary-nav { gap: 14px; }
  .primary-nav a { font-size: 0.72rem; letter-spacing: 0.10em; }
  .brand-wordmark { font-size: 0.95rem; letter-spacing: 0.06em; }
  .header-main { gap: 22px; }
}

/* ---- Utility ---- */
.utility {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--color-text-secondary);
  transition: background-color 180ms ease, color 180ms ease;
}
.icon-btn:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text-primary);
}
.icon-btn svg { width: 19px; height: 19px; stroke-width: 1.6; }

.btn-donate {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  background: var(--color-accent-bg);
  color: var(--color-accent-fg);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transition: background-color 200ms ease, transform 200ms ease, box-shadow 200ms ease;
  margin-left: 10px;
  white-space: nowrap;
}
.btn-donate:hover {
  background: var(--color-accent-bg-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-donate svg { width: 14px; height: 14px; stroke-width: 2; }

/* ---- Hamburger ---- */
.menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--color-text-primary);
  margin-left: auto;     /* right-aligned at the 960 breakpoint */
}
.menu-toggle .bars {
  width: 22px;
  height: 14px;
  position: relative;
  display: block;
}
.menu-toggle .bars::before,
.menu-toggle .bars::after,
.menu-toggle .bars span {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 1.5px;
  background: currentColor;
  transition: transform 240ms ease, opacity 200ms ease, top 240ms ease;
}
.menu-toggle .bars::before { top: 0; }
.menu-toggle .bars span    { top: 6px; }
.menu-toggle .bars::after  { top: 12px; }

/* =============================================================================
 * MOBILE BREAKPOINT — brand + hamburger only in the top bar
 * =========================================================================== */
@media (max-width: 960px) {
  .primary-nav,
  .header-main .icon-btn,
  .header-main .btn-donate { display: none; }
  .menu-toggle { display: inline-flex; }
  .header-main { gap: 16px; padding: 16px 20px; }
  .site-header.is-scrolled .header-main { padding: 12px 20px; }
  .ath-topbar--tagline { display: none; }      /* tagline desktop-only */
  .brand { margin-right: auto; }
  .brand-wordmark { font-size: 1.02rem; letter-spacing: 0.10em; }
  .site-header.is-scrolled .brand-wordmark { font-size: 0.9rem; letter-spacing: 0.08em; }
}

@media (max-width: 420px) {
  .brand-wordmark { font-size: 0.86rem; letter-spacing: 0.08em; }
  .brand-mark { width: 34px; height: 24px; }
  .site-header.is-scrolled .brand-wordmark { font-size: 0.76rem; }
}

/* =============================================================================
 * MOBILE MENU — thumb-zone anchored
 * =========================================================================== */
.mobile-menu {
  position: fixed;
  inset: 0;
  background: var(--color-bg-page);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 20px 20px max(28px, env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 240ms ease, visibility 240ms ease, transform 240ms ease;
}
body.menu-open .mobile-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.mobile-menu-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--color-border-subtle);
}
.mobile-menu-top .brand { flex: 1; min-width: 0; }
.mobile-menu-top .brand-wordmark { font-size: 1.02rem; letter-spacing: 0.10em; }
.mobile-menu-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.mobile-menu-actions .icon-btn { color: var(--color-text-primary); }

/* Tagline lives in the menu (the header strip is desktop-only) */
.mobile-menu-tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1rem;
  color: var(--color-text-secondary);
  text-align: center;
  padding: 28px 8px 0;
  margin-bottom: auto;       /* pushes nav + cta into the thumb zone */
}

.mobile-menu-nav {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-bottom: 12px;
}
.mobile-menu-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 400;
  color: var(--color-text-primary);
  padding: 14px 4px;
  border-bottom: 1px solid var(--color-border-subtle);
  letter-spacing: -0.005em;
}
.mobile-menu-nav a:last-child { border-bottom: none; }
.mobile-menu-nav a:active { background: var(--color-bg-subtle); }
.mobile-menu-nav a .ext-arrow {
  font-size: 0.85em;
  color: var(--color-brand-accent);
  font-family: var(--font-body);
  font-weight: 500;
}

.mobile-menu-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  background: var(--color-accent-bg);
  color: var(--color-accent-fg);
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 18px 24px;
  border-radius: 999px;
  margin-top: 12px;
  transition: background-color 200ms ease, transform 200ms ease;
}
.mobile-menu-cta:active { transform: scale(0.98); }
.mobile-menu-cta svg { width: 18px; height: 18px; stroke-width: 2; }

/* Hide the top-bar hamburger while the menu is open (close-X lives in menu) */
body.menu-open .menu-toggle { display: none; }
.mobile-menu-close {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--color-text-primary);
  transition: background-color 180ms ease;
}
.mobile-menu-close:hover { background: var(--color-bg-subtle); }
.mobile-menu-close svg { width: 22px; height: 22px; stroke-width: 1.6; }

/* Reduced motion — drop header/menu transitions. */
@media (prefers-reduced-motion: reduce) {
  .site-header,
  .site-header *,
  .mobile-menu,
  .mobile-menu * {
    transition: none !important;
  }
}
