/*
 * Site header. Two layouts, picked per site by the token
 * settings.custom.header.layout (body class .has-header-{layout}):
 *
 *   stacked  solid bar; hero (with breadcrumbs per hero tokens) below it
 *   overlay  transparent header on top of the hero image; one visual unit.
 *            Only when the page has a hero (anywhere), otherwise it falls
 *            back to stacked so the header never sits on a white page.
 *
 * Tokens: --wp--custom--header--*
 */

.site-header {
  --header-text: var(--wp--custom--header--text);
  --header-pad: 1.5rem; /* vertical padding; the dropdown tab spans it */

  position: relative;
  z-index: 50;
  background: var(--wp--custom--header--background);
  color: var(--header-text);
  padding-block: var(--header-pad);
}

.site-header__bar {
  gap: 2rem;
}

.site-header__logo {
  flex: none;
}

.site-header__nav {
  gap: 0.75rem;
}

.site-header__main {
  align-items: center;
  gap: 1.5rem;
}

/* ---------- Menu ---------- */

.site-header .wp-block-navigation {
  color: inherit;
}

.site-header__menu .wp-block-navigation-item__content {
  padding-block: 0.35em;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.45em;
  transition: text-decoration-color 0.2s ease;
}
.site-header__menu .wp-block-navigation-item__content:hover,
.site-header__menu .current-menu-item > .wp-block-navigation-item__content,
.site-header__menu .current-menu-ancestor > .wp-block-navigation-item__content {
  text-decoration-color: var(--wp--custom--header--active-indicator);
}

/*
 * Dropdown (desktop). The open parent item becomes a "tab" that runs down to
 * the header's bottom edge and joins the panel below it.
 * Tokens: header.submenuBackground / submenuText (tab + panel),
 *         header.indicator (closed ▼), radius.small (tab/panel corners).
 */
.site-header__menu {
  --submenu-bg: var(--wp--custom--header--submenu-background);
  --submenu-text: var(--wp--custom--header--submenu-text);
  --tab-radius: var(--wp--custom--radius--small);
}

.site-header__menu
  .wp-block-navigation__responsive-container:not(.is-menu-open) {
  & .wp-block-navigation-item.has-child {
    position: relative;
    gap: 0;
    padding: 0.4rem 0.6rem 0.4rem 0.75rem;
    border-radius: var(--tab-radius) var(--tab-radius) 0 0;
    transition:
      background-color 0.15s ease,
      color 0.15s ease;
  }

  /* Tab extension: from the item down to the header's bottom edge. */
  & .wp-block-navigation-item.has-child::after {
    content: '';
    position: absolute;
    inset-inline: 0;
    top: 100%;
    height: var(--submenu-drop, var(--header-pad)); /* measured by header.js */
    background: inherit;
  }

  &
    .wp-block-navigation-item.has-child:is(
      :hover,
      :focus-within,
      :has(> [aria-expanded='true'])
    ) {
    background: var(--submenu-bg);
    color: var(--submenu-text);
  }

  /* Panel */
  & .wp-block-navigation__submenu-container {
    top: calc(100% + var(--submenu-drop, var(--header-pad))) !important;
    left: 0 !important;
    /* As wide as the longest item, within limits; long items wrap beyond that. */
    width: max-content !important;
    min-width: 16rem !important;
    max-width: min(30rem, 100vw - 2rem) !important;
    padding-block: 1rem;
    border: 0 !important;
    border-radius: 0 var(--tab-radius) var(--tab-radius) var(--tab-radius);
    background: var(--submenu-bg) !important;
    color: var(--submenu-text) !important;
    box-shadow: var(--wp--preset--shadow--drop);
  }
  & .wp-block-navigation__submenu-container .wp-block-navigation-item__content {
    padding: 0.45rem 1.5rem;
  }

  /* The last  menu item opens towards the left, so a wide panel stays on screen. */
  &
    .wp-block-navigation-item.has-child:nth-last-child(-n + 1)
    > .wp-block-navigation__submenu-container {
    left: auto !important;
    right: 0 !important;
    border-radius: var(--tab-radius) 0 var(--tab-radius) var(--tab-radius);
  }
}

/* Child indicator: small filled triangle ▼, ▲ when open. */
.site-header__menu .wp-block-navigation__submenu-icon {
  display: inline-grid;
  place-items: center;
  width: 0.9em;
  height: 0.9em;
  margin-inline-start: 0.35em;
  padding: 0;
  color: var(--wp--custom--header--indicator);

  & svg {
    display: none;
  }
  &::before {
    content: '';
    border-inline: 0.3em solid transparent;
    border-top: 0.36em solid currentColor;
    transition: transform 0.2s ease;
  }
}
.site-header__menu
  .has-child:is(:hover, :focus-within, :has(> [aria-expanded='true']))
  > .wp-block-navigation__submenu-icon {
  color: inherit;

  &::before {
    transform: rotate(180deg);
  }
}

/* Hamburger up to 1340px (core switches at a fixed 600px). Between 600 and
   1339px: hide the inline menu and show the open button. */
@media (min-width: 600px) and (max-width: 1339px) {
  .site-header__menu .wp-block-navigation__responsive-container-open:not(.always-shown) {
    display: flex;
  }
  .site-header__menu .wp-block-navigation__responsive-container:not(.hidden-by-default):not(.is-menu-open) {
    display: none;
  }
}

/* ---------- Hamburger overlay menu ----------
 * Clear hierarchy: top-level items large + bold with a divider; sub-items
 * smaller, indented, with an accent line. Always dark text on white.
 */
.site-header .wp-block-navigation__responsive-container.is-menu-open {
  padding: 1.25rem clamp(1.25rem, 6vw, 3rem) 2.5rem;
  background: var(--wp--preset--color--white) !important;
  color: var(--wp--preset--color--text) !important; /* core forces #000 */
  animation: arbo-menu-in 0.2s ease-out;

  /* Everything left-aligned (the menu is right-aligned on desktop). */
  & .wp-block-navigation-item,
  & .wp-block-navigation__submenu-container {
    align-items: flex-start !important;
    justify-content: flex-start !important;
    text-align: start;
  }
  & .wp-block-navigation-item__content {
    color: inherit;
    text-decoration: none !important;
  }

  & .wp-block-navigation__responsive-container-content {
    padding-top: 3.5rem;
    align-items: stretch !important;
  }

  & .wp-block-navigation__container {
    width: 100%;
    gap: 0 !important;
    align-items: stretch !important;
  }

  /* Top level */
  & .wp-block-navigation__container > .wp-block-navigation-item {
    flex-direction: column;
    align-items: flex-start !important;
    width: 100%;
    padding: 0.9rem 0 !important;
    border-bottom: 1px solid color-mix(in srgb, var(--wp--preset--color--text) 14%, transparent);
    background: none !important;
  }
  & .wp-block-navigation__container > .wp-block-navigation-item > .wp-block-navigation-item__content {
    padding: 0 !important;
    font-size: var(--wp--preset--font-size--large-medium);
    font-weight: 700;
    line-height: 1.2;
  }

  /* Sub-items */
  & .wp-block-navigation__submenu-container {
    gap: 0 !important;
    width: 100%;
    margin-top: 0.6rem;
    padding: 0.15rem 0 0.15rem 1rem !important;
    border: 0 !important;
    border-left: 2px solid var(--wp--preset--color--accent) !important;
    border-radius: 0 !important;
    background: none !important;
    box-shadow: none !important;
  }
  & .wp-block-navigation__submenu-container .wp-block-navigation-item__content {
    padding: 0.4rem 0 !important;
    font-size: var(--wp--preset--font-size--normal);
    font-weight: 400;
  }

  /* Current page */
  & .current-menu-item > .wp-block-navigation-item__content {
    color: var(--wp--preset--color--accent);
    font-weight: 700;
  }

  /* Desktop dropdown triangles don't belong here. */
  & .wp-block-navigation__submenu-icon {
    display: none !important;
  }

  & .wp-block-navigation__responsive-container-close {
    top: 1.25rem;
    right: clamp(1.25rem, 6vw, 3rem);
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--wp--preset--color--background-medium);
    color: var(--wp--preset--color--text);
  }
}
@keyframes arbo-menu-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .site-header .wp-block-navigation__responsive-container.is-menu-open {
    animation: none;
  }
}

/* Hamburger button: same round shape as the search button. */
.site-header__menu .wp-block-navigation__responsive-container-open {
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
}

/* ---------- Search overlay (header search button, all screens; see header.js) ---------- */
.arbo-search-overlay {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 1.25rem clamp(1.25rem, 6vw, 3rem) 2.5rem;
  border: 0;
  background: var(--wp--preset--color--white);
  color: var(--wp--preset--color--text);
  overflow-y: auto;

  &[open] {
    animation: arbo-menu-in 0.2s ease-out;
  }
  &::backdrop {
    background: transparent;
  }

  & .arbo-search-overlay__inner {
    max-width: var(--wp--style--global--content-size);
    margin: 3.5rem auto 0;
  }
  & .arbo-search-overlay__close {
    position: absolute;
    top: 1.25rem;
    right: clamp(1.25rem, 6vw, 3rem);
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 50%;
    background: var(--wp--preset--color--background-medium);
    color: var(--wp--preset--color--text);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
  }
  /* Results flow in the overlay instead of floating. */
  & .arbo-live-search {
    position: static;
    margin-top: 0.75rem;
    box-shadow: none;
    border: 1px solid color-mix(in srgb, var(--wp--preset--color--text) 12%, transparent);
  }
  & .arbo-live-search__list {
    max-height: none;
  }
}

/* ---------- Search (icon button that expands) ---------- */

.site-header__search .wp-block-search__button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--wp--custom--header--search-background);
  color: var(--wp--custom--header--search-icon);
  cursor: pointer;
}
.site-header__search .wp-block-search__button svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: currentColor;
}
.site-header__search .wp-block-search__input {
  border-radius: var(--wp--custom--radius--medium);
}

/* ---------- Overlay layout ---------- */

body.has-header-overlay:has(.arbo-hero) .wp-site-blocks {
  position: relative;
}

body.has-header-overlay:has(.arbo-hero) .wp-site-blocks > header {
  position: absolute;
  inset-inline: 0;
  top: 0;
  z-index: 50;
}

body.has-header-overlay:has(.arbo-hero) .site-header {
  --header-text: var(--wp--custom--header--overlay-text);
  background: transparent;
}

/* Make room for the header inside the hero banner. --arbo-header-height is
   measured by assets/js/header.js; 8rem is the fallback. */
body.has-header-overlay .arbo-hero__banner {
  padding-top: var(--arbo-header-height, 8rem);
  min-height: calc(
    var(--wp--custom--hero--min-height-page) + var(--arbo-header-height, 8rem)
  );
}
body.has-header-overlay .arbo-hero--home .arbo-hero__banner {
  min-height: calc(
    var(--wp--custom--hero--min-height-home) + var(--arbo-header-height, 8rem)
  );
}

/* Extra shade behind the menu for readability on light photos. */
body.has-header-overlay .arbo-hero__banner::before {
  background:
    linear-gradient(
      180deg,
      rgb(0 0 0 / 0.3) 0,
      rgb(0 0 0 / 0) var(--arbo-header-height, 8rem)
    ),
    var(--wp--custom--hero--overlay);
}

/* ---------- Sticky + shrink (token header.behavior: sticky-shrink) ----------
 * The <header> keeps its full height in the page (--arbo-header-height, set by
 * header.js before shrinking), so shrinking never makes the content jump. Its
 * lower part is transparent and click-through; only the bar itself catches
 * pointer events.
 */

body.has-header-sticky .wp-site-blocks > header {
  position: sticky;
  top: var(--wp-admin--admin-bar--height, 0px);
  z-index: 50;
  height: var(--arbo-header-height, auto);
  pointer-events: none;
}

body.has-header-sticky .site-header {
  pointer-events: auto;
  transition:
    padding-block 0.3s ease,
    box-shadow 0.3s ease;
}

body.has-header-sticky .site-header__logo img {
  transition: width 0.3s ease;
}

body.has-header-sticky .site-header__utility {
  max-height: 3rem;
  overflow: hidden;
  transition:
    max-height 0.3s ease,
    opacity 0.2s ease,
    margin 0.3s ease;
}

body.has-header-sticky header.is-shrunk {
  & .site-header {
    --header-pad: 0.6rem;
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.08);
  }
  & .site-header__logo img {
    width: 120px !important;
    height: auto !important;
  }
  & .site-header__utility {
    max-height: 0;
    margin-block-end: -0.75rem; /* swallow the nav gap */
    opacity: 0;
    visibility: hidden;
  }
}

/* Overlay + sticky: the bar is fixed on top of the hero, which scrolls away
   underneath it. Once shrunk, the bar shows the same slice of the pinned hero
   photo behind it (position/size from blocks/hero/view.js), so it reads as
   the part of the hero that stays; solid colour if there is no photo. */
body.has-header-overlay.has-header-sticky:has(.arbo-hero)
  .wp-site-blocks
  > header {
  position: fixed;
  top: var(--wp-admin--admin-bar--height, 0px);
  inset-inline: 0;
  height: auto;
}

body.has-header-overlay.has-header-sticky:has(.arbo-hero) .site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    linear-gradient(
      180deg,
      rgb(0 0 0 / 0.3) 0,
      rgb(0 0 0 / 0) var(--arbo-header-height, 8rem)
    ),
    var(--wp--custom--hero--overlay),
    var(--arbo-hero-image, none) var(--arbo-hero-image-x, 0px)
      calc(
        var(--arbo-hero-image-y, 0px) - var(--wp-admin--admin-bar--height, 0px)
      ) /
      var(--arbo-hero-image-size, cover) no-repeat,
    var(--wp--custom--header--shrunk-background);
  opacity: 0;
  transition: opacity 0.3s ease;
}

body.has-header-overlay.has-header-sticky:has(.arbo-hero)
  header.is-shrunk
  .site-header {
  border-end-start-radius: var(--wp--custom--radius--extra-large);
  border-end-end-radius: var(--wp--custom--radius--extra-large);
  box-shadow: var(--wp--preset--shadow--drop);

  &::before {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.has-header-overlay.has-header-sticky .site-header::before,
  body.has-header-sticky .site-header,
  body.has-header-sticky .site-header__logo img,
  body.has-header-sticky .site-header__utility {
    transition: none;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 781px) {
  .site-header {
    --header-pad: 1rem;
  }
  .site-header__logo img {
    max-width: 140px;
    height: auto;
  }
  .site-header__utility {
    display: none;
  }
}
