/*
 * Site header.
 *
 * Two states share the same DOM:
 *   1. Desktop / tablet — fixed top bar, transparent at scroll = 0, fades
 *      a #DDE9FF background in once the page is scrolled (.is-scrolled).
 *   2. Mobile (≤ 640px) — burger toggles a full-screen overlay
 *      (.is-menu-open) per Figma nodes 1:4056 / 1:4106.
 *
 * The .site-header__top wrapper around logo + toggle uses `display: contents`
 * on wider screens so logo and toggle sit alongside nav and CTA in the
 * inner flex row. On mobile it becomes a real flex container spanning
 * the full width.
 */

.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  height: 80px;
  z-index: 100;
  isolation: isolate;
  /* Background and height transition smoothly when the menu opens / closes.
     Single easing curve across header + toggle so they read as one motion. */
  transition:
    background-color .25s cubic-bezier(.4, 0, .2, 1),
    height           .35s cubic-bezier(.4, 0, .2, 1);
}

/* Glassmorphism — only kicks in once the user starts scrolling. At
   scroll = 0 the header is fully transparent (no blur, no tint) so the
   page hero shows through cleanly. Both the blur and the tint fade in
   together via .is-scrolled. */
.site-header {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  transition:
    background-color .25s cubic-bezier(.4, 0, .2, 1),
    height           .35s cubic-bezier(.4, 0, .2, 1),
    backdrop-filter  .25s ease,
    -webkit-backdrop-filter .25s ease;
}

.site-header.is-scrolled {
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
}

.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(221, 233, 255, 0.70) 0,
    rgba(221, 233, 255, 0.70) 55px,
    rgba(221, 233, 255, 0)    80px
  );
  opacity: 0;
  transition: opacity .25s ease;
}

.site-header.is-scrolled::before {
  opacity: 1;
}

/* ---------------------------------------------------------------- *
 * Inner row
 * ---------------------------------------------------------------- */

.site-header__inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-2xl);
  height: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-l);
}

/*
 * On desktop the .site-header__top wrapper is "transparent" to layout —
 * its children (logo + toggle) participate in the inner flex row directly.
 * The toggle itself stays display:none on desktop (see below).
 */
.site-header__top {
  display: contents;
}

/* ---------------------------------------------------------------- *
 * Logo
 * ---------------------------------------------------------------- */

.site-header__logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}

.site-header__logo-img {
  display: block;
  height: 32px;
  width: auto;
}

/*
 * Default text-mark — used until the owner uploads a real SVG via
 * Customizer → Site Identity → Logo. Jonova Bold + small brand-blue dot.
 */
.site-header__logo-text {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--font-primary);
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
  color: var(--color-text-980);
  letter-spacing: -.02em;
}

.site-header__logo-text::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-blue-700);
  align-self: center;
  margin-bottom: 2px;
}

/* ---------------------------------------------------------------- *
 * Primary nav (desktop / tablet inline state)
 * ---------------------------------------------------------------- */

.site-header__nav {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  justify-content: center;
}

.site-header__menu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3xs);
}

.site-header__menu li {
  position: relative;
}

.site-header__menu a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  padding: var(--space-m) var(--space-l);
  border-radius: var(--radius-circle);
  font-family: var(--font-primary);
  font-size: var(--text-sm-size);
  line-height: var(--btn-text-sm-line);
  color: var(--color-text-980);
  text-decoration: none;
  transition: color .15s ease;
}

/* Hover state only fires on devices that genuinely support hover —
   on touch devices the same selector would otherwise activate on tap and
   leave a blue afterglow on the link until the user touches elsewhere. */
@media (hover: hover) {
  .site-header__menu a:hover {
    color: var(--color-text-700);
  }
}
.site-header__menu a:focus-visible {
  color: var(--color-text-700);
}

.site-header__menu .current-menu-item > a,
.site-header__menu .current-menu-parent > a {
  color: var(--color-text-700);
}

/* Chevron for items with a sub-menu. CSS-drawn from two borders rotated
   45° → renders as a downward caret. Flips on `[data-submenu-open]`. */
.site-header__menu .menu-item-has-children > a::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-left: 4px;
  margin-top: -3px;
  transition: transform .2s ease, margin-top .2s ease;
}

.site-header__menu .menu-item-has-children[data-submenu-open] > a::after {
  transform: rotate(-135deg);
  margin-top: 1px;
}

/* Sub-menu (Resources dropdown). Hidden by default; appears on hover/focus
   on desktop. On mobile it's repositioned to inline expand — see below. */
.site-header__menu .sub-menu {
  position: absolute;
  top: calc(100% + var(--space-2xs));
  left: 0;
  min-width: 180px;
  list-style: none;
  margin: 0;
  padding: var(--space-2xs);
  background: rgba(245, 249, 255, 0.95);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .15s ease, transform .15s ease, visibility 0s linear .15s;
  box-shadow: 0 8px 24px rgba(37, 36, 45, .08);
}

.site-header__menu li:hover > .sub-menu,
.site-header__menu li:focus-within > .sub-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0s, 0s, 0s;
}

.site-header__menu .sub-menu a {
  display: flex;
  width: 100%;
  justify-content: center;
  text-align: center;
  padding: var(--space-m) var(--space-l);
  font-size: var(--text-xs-size);
  line-height: 1;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- *
 * CTA
 * ---------------------------------------------------------------- */

.site-header__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-m) var(--space-l);
  border-radius: var(--radius-circle);
  background: var(--color-blue-900);
  color: var(--color-text-0);
  text-decoration: none;
  flex-shrink: 0;
  transition: background-color .15s ease, transform .15s ease;
}

.site-header__cta:hover,
.site-header__cta:focus-visible {
  background: var(--color-blue-700);
  transform: translateY(-1px);
}

.site-header__cta:active {
  transform: translateY(0);
}

/* ---------------------------------------------------------------- *
 * Toggle (burger ⇄ X)
 * ---------------------------------------------------------------- */

.site-header__toggle {
  display: none;
  width: 44px;
  height: 44px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 8px;
  flex-shrink: 0;
  /* Allow precise transforms on the lines. */
  position: relative;
}

.site-header__toggle-line {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-text-980);
  border-radius: 2px;
  /* Pure CSS morph between burger and ✕. Easing matches the header height
     transition so the two read as one coordinated motion. */
  transition:
    transform .35s cubic-bezier(.4, 0, .2, 1),
    opacity   .2s  ease;
  transform-origin: center;
}

/* Burger → X: middle line fades; outer lines rotate to meet at center.
   Active in any open state (desktop won't see this — toggle is display:none). */
.site-header.is-menu-open .site-header__toggle-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.site-header.is-menu-open .site-header__toggle-line:nth-child(2) {
  opacity: 0;
  transform: scaleX(.4);
}
.site-header.is-menu-open .site-header__toggle-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ---------------------------------------------------------------- *
 * Responsive
 * ---------------------------------------------------------------- */

@media (max-width: 1024px) {
  .site-header__inner {
    padding: 0 var(--space-l);
  }
  .site-header__menu {
    gap: 0;
  }
  .site-header__menu a {
    padding: var(--space-s) var(--space-m);
  }
}

/*
 * Mobile (≤ 640px) — Figma node 1:4143 (closed) and 1:4056 / 1:4106 (open).
 *
 * Layout principle: on mobile the inner is **always a flex column**, with
 * `.site-header__top` as the first 80px slot. Closed state hides nav + CTA
 * (display: none) so only the top slot is visible — i.e. the inner equals
 * the bar. Open state expands the header to 100dvh, reveals nav + CTA, and
 * the top slot stays right where it is (start of the column). No absolute
 * positioning, no compensating padding, no flex-direction switching during
 * the transition — therefore no logo "jump".
 */
@media (max-width: 640px) {

  /* Mobile inner: column-flex, top to bottom. Stays this way in both
     closed and open states — no flex-direction transition. */
  .site-header__inner {
    flex-direction: column;
    align-items: stretch;
    padding: 0 20px;
    gap: 0;
  }

  /* The top slot — first column item, fixed 80px tall. Logo on the left,
     toggle on the right. Identical coordinates closed and open. */
  .site-header__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 80px;
  }

  .site-header__nav,
  .site-header__cta {
    display: none;
  }

  .site-header__toggle {
    display: inline-flex;
  }

  /*
   * Open state — overlay covering the viewport.
   * Background uses the same blue-50 the Figma frame uses (#F5F9FF).
   */
  .site-header.is-menu-open {
    height: 100dvh;
    background: var(--color-bg-blue-50);
  }
  /* Disable the scroll-fade gradient when fully open — the solid bg owns it. */
  .site-header.is-menu-open::before {
    opacity: 0;
  }

  /* Inner expands to fill the now-tall header. Top slot keeps its 80px;
     nav + CTA take the remaining vertical space. No top padding — the
     top slot is a real flex item, not an absolute overlay. */
  .site-header.is-menu-open .site-header__inner {
    height: 100%;
    padding: 0 20px 60px;
  }

  /* Decorative vertical centre line (matches the BG line in Figma). */
  .site-header.is-menu-open .site-header__inner::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    background: linear-gradient(
      to bottom,
      #deecff,
      rgba(222, 236, 255, .2) 20%,
      #deecff
    );
    pointer-events: none;
    z-index: 0;
  }

  .site-header.is-menu-open .site-header__inner > * {
    position: relative;
    z-index: 1;
  }

  /* Nav fills the remaining space, items stacked centred vertically. */
  .site-header.is-menu-open .site-header__nav {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    overflow-y: auto;
  }

  .site-header.is-menu-open .site-header__menu {
    flex-direction: column;
    align-items: center;
    gap: var(--space-m);
    width: 100%;
  }

  .site-header.is-menu-open .site-header__menu a {
    /* Larger tap targets, matches Figma 18/18 spacing. */
    font-size: var(--text-base-size);
    line-height: var(--btn-text-base-line);
    padding: var(--space-m) var(--space-l);
  }

  /*
   * On mobile-open, every <li> becomes a centred column container — that's
   * what keeps "Resources" + its expanded sub-menu items glued to the same
   * vertical centre axis (Figma 1:4106). Without this, a list-item <li>
   * content-sizes to its widest child (often the sub-menu) and the parent
   * <a> visually shifts left when the dropdown opens.
   */
  .site-header.is-menu-open .site-header__menu li {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  /*
   * Sub-menu inline expansion (Resources).
   *
   * Always rendered (display: flex) — visibility/animation handled via
   * max-height + opacity. Switching `display: none ↔ flex` is non-animatable,
   * so the previous version snapped open/closed instantly.
   */
  .site-header.is-menu-open .site-header__menu .sub-menu {
    position: static;
    background: transparent;
    backdrop-filter: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    transform: none;
    margin: 0;
    width: auto;

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;

    /* Collapsed state. */
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    transition:
      max-height .35s ease,
      opacity    .25s ease,
      margin-top .3s  ease,
      visibility 0s   linear .35s;
  }

  /* Expanded state — JS toggles [data-submenu-open] on the parent <li>. */
  .site-header.is-menu-open .site-header__menu .menu-item-has-children[data-submenu-open] > .sub-menu {
    /* 600px is far above any realistic sub-menu height (4 items × ~50px); the
       transition still feels right because content rarely fills it. */
    max-height: 600px;
    opacity: 1;
    visibility: visible;
    margin-top: var(--space-s);
    transition:
      max-height .35s ease,
      opacity    .3s  ease .05s,
      margin-top .3s  ease,
      visibility 0s   linear 0s;
  }

  /* Active "Resources" link colour when its sub-menu is open — matches the
     blue-accent state in the Figma open-menu frame. */
  .site-header.is-menu-open .site-header__menu .menu-item-has-children[data-submenu-open] > a {
    color: var(--color-text-700);
  }

  /* Sub-menu items — smaller font (14px) per Figma. */
  .site-header.is-menu-open .site-header__menu .sub-menu a {
    font-size: var(--text-xs-size);
    line-height: var(--text-xs-size);
    padding: var(--space-m) var(--space-l);
    color: var(--color-text-950);
    background: transparent;
  }

  /* CTA appears at the bottom of the open menu. */
  .site-header.is-menu-open .site-header__cta {
    display: inline-flex;
    /* Larger pill matching Figma "Try Mark app" — 32×20 padding, 18px font. */
    padding: 20px 32px;
    font-size: var(--text-base-size);
    line-height: var(--btn-text-base-line);
    background: var(--color-btn-bg-700);
    align-self: center;
    flex-shrink: 0;
  }
}

/* When the menu is open, lock body scroll. */
body.is-menu-locked {
  overflow: hidden;
  /* Keep layout stable when the scrollbar disappears on desktop —
     this only triggers on ≤ 640 in practice, where overlay scrollbars
     are common, so reserve-gutter is a no-op for most devices. */
  scrollbar-gutter: stable;
}
