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

/* Payback (paybacknutrition.com): white sticky header, brown text, and a
   solid Payback Brown line along the bottom. Full copy of the parent's
   header.css (a child copy replaces the parent file, it doesn't cascade). */

/* Sticky on the template part wrapper, not .site-header itself - the wrapper
   is exactly as tall as the header, so a sticky .site-header would have no
   room to stick within it. Offset by the admin bar when it's showing. */
header.wp-block-template-part:has(> .site-header) {
  position: sticky;
  top: var(--wp-admin--admin-bar--height, 0);
  z-index: 999;
}

.site-header {
  background-color: var(--wp--preset--color--white);
  border-bottom: 4px solid var(--wp--custom--color--primary);
  color: var(--wp--custom--color--primary);
  /* Narrow side margins at every width, like the live site, so the logo,
     nav and always-visible search fit on one row. */
  padding: var(--wp--preset--spacing--30) var(--wp--preset--spacing--50);
}

.site-header__logo img {
  height: 50px;
  width: auto;
}

.site-header__inner {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--wp--preset--spacing--40);
  justify-content: space-between;

  /* Desktop: logo, nav and search always share one row. */
  @media screen and (min-width: 1200px) {
    flex-wrap: nowrap;
  }
}

.site-header__logo {
  flex-shrink: 0;
}

/* ============================= NAVIGATION ============================= */

/* Payback: nav sits left, next to the logo; search stays on the right. */
.site-header__nav-wrapper {
  align-items: center;
  display: none;
  column-gap: var(--wp--preset--spacing--40);
  justify-content: flex-start;
  margin: 0 -2rem !important;
  width: calc(100% + 4rem);

  @media screen and (min-width: 1200px) {
    display: flex;
    flex: 1;
    flex-direction: row;
    margin: 0 !important;
    width: unset;
  }
}

/* Mobile menu opens on the header's white background. */
.site-header__nav-wrapper.is-visible {
  background-color: var(--wp--preset--color--white);
  display: flex;
  flex-direction: column;

  @media screen and (min-width: 1200px) {
    flex-direction: row;
  }
}

/* Mobile menu open: lock the page behind it. The sticky header scrolls on
   its own instead, so a menu taller than the screen stays reachable. */
@media screen and (max-width: 1199px) {
  html:has(.site-header__nav-wrapper.is-visible) {
    overflow: hidden;
  }

  header.wp-block-template-part:has(.site-header__nav-wrapper.is-visible) {
    max-height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

ul.site-header__navigation {
  flex: 1;
  gap: var(--wp--preset--spacing--60);
}
ul.site-header__navigation .wp-block-navigation-item {
  width: unset;
}
ul.site-header__navigation .wp-block-navigation-item__content {
  text-align: right;
  text-decoration: none;
}

.site-header__actions {
  margin: 0;
}

.main-navigation .menu > li.nav-item .menu-item-chevron {
  transform: rotate(0deg);
}

.main-navigation .menu li.nav-item.open > .menu-item > .menu-item-chevron {
  transform: rotate(180deg);
}

.main-navigation .nav-item.hidden {
  display: block;
}

.site-header .main-navigation .sub-menu .menu-item {
  border-block-start: 1px solid #ccc;
  @media screen and (min-width: 1200px) {
    border-block-start: none;
  }
}

/* Nav link colors, "Display as button" items (Primary button here), open
   and submenu states are in assets/css/blocks/mega-menu.css, attached to
   the acf/mega-menu block. */

/* ============================= SEARCH ============================= */

/* Payback search:
   - Mobile menu: first item in the open menu (above the nav links).
   - 1200-1399px: parent-style icon toggle with the field dropping below the
     header, since the full field and nav don't fit side by side.
   - 1400px+: the field is always visible on the right, no toggle. */
.site-header__search-wrapper {
  margin: 0;
  order: -1;
  padding: 0 var(--wp--preset--spacing--50);
  position: relative;
  width: 100%;

  @media screen and (min-width: 1200px) {
    flex-shrink: 0;
    margin-inline-start: auto;
    order: 0;
    width: unset;
  }
}

.site-header__search-toggle {
  align-items: center;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  display: none;
  padding: var(--wp--preset--spacing--20);

  @media screen and (min-width: 1200px) and (max-width: 1399px) {
    display: flex;
  }
}

.site-header__search-toggle:focus {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* The icon's fill is hard-coded white in parts/header.html - recolor it to
   the header's brown text, and Rose while the search is open. */
.site-header__search-toggle svg path {
  fill: currentColor;
}

.site-header__search-toggle[aria-expanded="true"] svg path {
  fill: var(--wp--custom--color--accent-1);
}

.site-header__search {
  margin: 0;
  width: 100%;

  /* Toggle range: hidden until the toggle opens it below the header. */
  @media screen and (min-width: 1200px) and (max-width: 1399px) {
    clip: rect(1px, 1px, 1px, 1px);
    height: 1px;
    margin-block-start: var(--wp--preset--spacing--40);
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    position: absolute;
    right: 0;
    top: 100%;
    transition: opacity 0.3s ease;
    width: 1px;
  }

  @media screen and (min-width: 1400px) {
    width: 220px;
  }

  /* The live site's 300px once there's room for it beside the nav. */
  @media screen and (min-width: 1600px) {
    width: 300px;
  }
}

@media screen and (min-width: 1200px) and (max-width: 1399px) {
  .site-header__search-wrapper.is-active .site-header__search {
    background-color: var(--wp--preset--color--white);
    clip: auto;
    height: auto;
    opacity: 1;
    pointer-events: auto;
    width: 300px;
    z-index: 2;
  }
}

/* Live site: square-ish field with a 2px outline, rather than a pill. */
.site-header__search-wrapper .wp-block-search__inside-wrapper {
  border: 2px solid var(--wp--custom--color--primary);
  border-radius: 7px;
  padding: 0 var(--wp--preset--spacing--30);
}

.site-header__search-wrapper .wp-block-search__button {
  background-color: var(--wp--preset--color--white);
  padding: var(--wp--preset--spacing--20);
}

.site-header__search-wrapper .wp-block-search__button svg path {
  fill: var(--wp--custom--color--primary);
}

/* ============================= MOBILE TOGGLE ============================= */

.site-header__mobile-toggle {
  background-color: transparent;
  border: none;
  cursor: pointer;
  height: 20px;
  margin: 0;
  position: relative;
  width: 28px;

  @media screen and (min-width: 1200px) {
    display: none;
  }
}

.site-header__mobile-toggle__line {
  background-color: var(--wp--custom--color--primary);
  height: 2px;
  position: absolute;
  left: 50%;
  width: 28px;
  transform: translateX(-50%);
  transition: all .3s ease;
}

.site-header__mobile-toggle__line:nth-child(1) {
  transform-origin: top left;
  top: 0;
}

.site-header__mobile-toggle__line:nth-child(2) {
  bottom: 9px;
}

.site-header__mobile-toggle__line:nth-child(3) {
  transform-origin: bottom left;
  bottom: 0;
}

.site-header__mobile-toggle.is-open .site-header__mobile-toggle__line:nth-child(1) {
  left: 3px;
  transform: rotate(45deg);
  width: 26px;
}

.site-header__mobile-toggle.is-open .site-header__mobile-toggle__line:nth-child(2) {
  opacity: 0;
}

.site-header__mobile-toggle.is-open .site-header__mobile-toggle__line:nth-child(3) {
  left: 3px;
  transform: rotate(-45deg);
  width: 26px;
}
