/* EGR site header.
   Design reference: doc/egr-html-prototype/assets/css/header.css

   Desktop nav layout lives in the header Element's GenerateBlocks styles. This
   file covers what blocks cannot reach: hover/focus states on the server
   rendered classic menu, the mobile drawer, body-level drawer state, the
   expanding search field and the sticky shadow. Everything is scoped to the
   header Element so no other surface changes. */

/* Drawer width is the one token both the drawer and the shifted page need, so
   it lives at the root exactly as in the prototype's variables.css. */
:root {
  --egr-drawer-width: 320px;
}

@media (max-width: 321px) {
  :root {
    --egr-drawer-width: 270px;
  }
}

/* The site's blocks declare the prototype's Work Sans stack; the header and
   announcement sit outside those wrappers and need to say so themselves. */
[data-egr-header],
[data-egr-announcement] {
  font-family: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

[data-egr-header] {
  --egr-header-text: #212121;
  --egr-nav-text: #3d4246;
  --egr-border: #e5e5e5;
  --egr-drawer-border: #d4d4d4;
  --egr-transition-fast: 0.2s linear;
  --egr-transition-nav: 0.25s ease 0.2s;
  --egr-transition-search: 0.5s cubic-bezier(0.445, 0.05, 0.55, 0.95);
  --egr-transition-drawer: 0.35s ease-out;
}

/* ------------------------------------------------------------------ shell */

[data-egr-header] [data-egr-shell] {
  position: relative;
  transition: box-shadow var(--egr-transition-fast);
}

[data-egr-header] [data-egr-shell].is-stuck {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* ----------------------------------------------------------------- search */

[data-egr-header] .egr-search {
  position: relative;
  display: flex;
  align-items: center;
  width: 26px;
  height: 38px;
  margin: 0;
  transition: width var(--egr-transition-search);
}

[data-egr-header] .egr-search.is-open {
  width: 180px;
}

[data-egr-header] .egr-search__input {
  width: 100%;
  min-width: 0;
  height: 38px;
  margin: 0;
  padding: 0 30px 0 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--egr-header-text);
  font-size: 14px;
  line-height: 21px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--egr-transition-search), border-color var(--egr-transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

[data-egr-header] .egr-search.is-open .egr-search__input {
  border-bottom-color: #777777;
  opacity: 1;
  pointer-events: auto;
}

[data-egr-header] .egr-search__input::placeholder {
  color: #757575;
  opacity: 1;
}

[data-egr-header] .egr-search__input:focus {
  outline: none;
}

[data-egr-header] .egr-search__input::-webkit-search-cancel-button {
  display: none;
}

[data-egr-header] .egr-search__toggle {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 38px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--egr-header-text);
  cursor: pointer;
  transition: opacity var(--egr-transition-fast);
}

[data-egr-header] .egr-search__toggle:hover {
  opacity: 0.7;
}

[data-egr-header] .egr-search__toggle svg {
  display: block;
  width: 22px;
  height: 22px;
}

[data-egr-header] .egr-search__toggle:focus-visible {
  outline: 2px solid var(--egr-header-text);
  outline-offset: 2px;
}

[data-egr-header] .egr-search__icon-open {
  line-height: 0;
}

/* -------------------------------------------------- navigation states */

/* GenerateBlocks ships black submenu items and a bordered container by default;
   the prototype's navigation is white and borderless. */
[data-egr-header] .gb-menu .gb-sub-menu .menu-item {
  background-color: transparent;
  color: var(--egr-header-text);
}

[data-egr-header] .gb-menu-container {
  border: 0;
}

/* Underline: the prototype grows it inside the item's padded box. */
[data-egr-header] .gb-menu > .menu-item::after {
  content: "";
  position: absolute;
  right: 24px;
  bottom: 11px;
  left: 24px;
  height: 1px;
  background: var(--egr-nav-text);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--egr-transition-nav);
  pointer-events: none;
}

[data-egr-header] .gb-menu > .menu-item:hover::after,
[data-egr-header] .gb-menu > .menu-item:focus-within::after {
  transform: scaleX(1);
}

/* The prototype marks the current page with an underline on the label. */
[data-egr-header] .gb-menu > .current-menu-item > .gb-menu-link,
[data-egr-header] .gb-menu > .current-menu-ancestor > .gb-menu-link {
  text-decoration: underline;
  text-underline-offset: 3px;
}

[data-egr-header] .gb-menu > .current-menu-item:hover > .gb-menu-link {
  text-decoration: none;
}

[data-egr-header] .gb-menu .gb-menu-link:focus-visible {
  outline: 2px solid var(--egr-nav-text);
  outline-offset: -2px;
}

[data-egr-header] .gb-menu .gb-sub-menu .gb-menu-link:hover,
[data-egr-header] .gb-menu .gb-sub-menu .gb-menu-link:focus-visible {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Dropdown rhythm: the prototype is 14px/1.3 with 15px between items.
   GenerateBlocks sizes the panel from the drawer's 17px body text. */
@media (min-width: 768px) {
  [data-egr-header] .gb-menu > .menu-item > .gb-sub-menu {
    color: #000000;
    font-size: 14px;
    line-height: 1.3;
  }

  [data-egr-header] .gb-menu > .menu-item > .gb-sub-menu .menu-item {
    margin: 15px 0;
  }

  [data-egr-header] .gb-menu > .menu-item > .gb-sub-menu .gb-menu-link {
    color: inherit;
    font-size: 14px;
    line-height: 1.3;
  }
}

/* Desktop carries no visible caret; keep the toggle focusable instead.
   GenerateBlocks appends the toggle inside the menu link, not after it. */
[data-egr-header] .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 24px;
  height: 100%;
  opacity: 0;
}

[data-egr-header] .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle:focus-visible {
  opacity: 1;
  outline: 2px solid var(--egr-nav-text);
  outline-offset: -2px;
}

/* The mobile toggle overlays the reserved slot in the mobile bar. */
[data-egr-header] .gb-navigation > .gb-menu-toggle {
  display: none;
}

/* -------------------------------------------------------- drawer extras */

/* Account and currency rows under the drawer menu. GenerateBlocks marks the
   block .gb-menu-show-on-toggled, so it only renders inside the drawer. */
[data-egr-header] .gb-menu-show-on-toggled {
  padding: 12px 15px 0;
  opacity: 0.6;
}

[data-egr-header] .gb-menu-show-on-toggled a {
  display: block;
  padding: 12px 0;
  color: inherit;
  font-size: 17px;
  line-height: 26px;
  text-decoration: none;
}

[data-egr-header] .gb-menu-show-on-toggled a:hover {
  text-decoration: underline;
}

[data-egr-header] .gb-menu-show-on-toggled > div {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 16px 0 0;
}

[data-egr-header] .gb-menu-show-on-toggled img {
  width: 33px;
  height: 22px;
  border: 1px solid var(--egr-header-text);
}

[data-egr-header] .gb-menu-show-on-toggled span {
  color: inherit;
  font-size: 14px;
  line-height: 19px;
}

/* ------------------------------------------------------------- backdrop */

/* Transparent click layer over the strip right of the drawer. The prototype
   pushes the page aside instead of dimming it, so this only catches clicks. */
.egr-header-backdrop {
  position: fixed;
  inset: 0 0 0 var(--egr-drawer-width);
  z-index: 100;
  display: none;
  background: transparent;
  cursor: pointer;
}

body[data-gb-menu-open] .egr-header-backdrop {
  display: block;
}

/* The drawer sits over the announcement bar and page top; the header and page
   are pushed right so the toggle stays reachable as the close control. */
body[data-gb-menu-open] {
  overflow: hidden;
}

/* ----------------------------------------------------------- mobile bar */

@media (max-width: 767px) {
  /* The prototype caps the mobile bar at 540px and centres it; between 541px
     and 767px the icons otherwise drift to the screen edges. */
  [data-egr-header] [data-egr-mobile] {
    position: relative;
    max-width: 540px;
    margin-right: auto;
    margin-left: auto;
  }

  /* The empty block reserves the toggle's slot; the prototype keeps the menu
     and search buttons flush, with no gap between them. */
  [data-egr-header] [data-egr-mobile] > div:first-child {
    gap: 0;
  }

  [data-egr-header] .gb-navigation > .gb-menu-toggle {
    position: absolute;
    top: 0;
    left: max(15px, calc(50% - 255px));
    z-index: 102;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 53px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--egr-header-text);
    cursor: pointer;
  }

  [data-egr-header] .gb-navigation > .gb-menu-toggle svg {
    display: block;
    width: 18px;
    height: 18px;
  }

  [data-egr-header] .gb-navigation > .gb-menu-toggle:focus-visible {
    outline: 2px solid var(--egr-header-text);
    outline-offset: 2px;
  }

  /* Drawer -------------------------------------------------------------- */

  /* The Element carries its own padding for this container; the extra `body`
     outranks it without resorting to !important. */
  body [data-egr-header] .gb-menu-container--mobile {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 101;
    display: block;
    width: var(--egr-drawer-width);
    max-width: 100%;
    height: 100%;
    max-height: 100dvh;
    padding: 25px 10px 45px;
    overflow-y: auto;
    background: #ffffff;
    border: 0;
    box-shadow: -9px 8px 16px #5f5c5c;
    transform: translateX(-100%);
    transition: transform var(--egr-transition-drawer);
    overscroll-behavior: contain;
  }

  /* GenerateBlocks hides an untoggled container with display:none, which would
     defeat the slide. Keep it rendered off-canvas instead, but out of reach for
     pointers and keyboard focus until it opens. */
  [data-egr-header] .gb-navigation--mobile .gb-menu-container--mobile:not(.gb-menu-container--toggled) {
    display: block;
    visibility: hidden;
    transition: transform var(--egr-transition-drawer), visibility 0s linear var(--egr-transition-drawer);
  }

  [data-egr-header] .gb-navigation--mobile .gb-menu-container--mobile.gb-menu-container--toggled {
    visibility: visible;
    transition: transform var(--egr-transition-drawer), visibility 0s;
  }

  [data-egr-header] .gb-menu-container--mobile.gb-menu-container--toggled {
    transform: translateX(0);
  }

  /* A logged-in editor carries WordPress's fixed 46px admin bar over the top
     of the drawer; without the offset the first menu row cannot be reached. */
  body.admin-bar [data-egr-header] .gb-menu-container--mobile {
    top: 46px;
    height: calc(100% - 46px);
    max-height: calc(100dvh - 46px);
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu {
    display: block;
    width: auto;
    min-height: 0;
    margin: 0 15px;
    opacity: 0.6;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    border-bottom: 1px solid var(--egr-drawer-border);
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item::after {
    display: none;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: space-between;
    column-gap: 10px;
    min-height: 46px;
    padding: 12px 0;
    color: var(--egr-header-text);
    font-size: 17px;
    line-height: 1.3;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item:first-child > .gb-menu-link {
    min-height: 0;
    padding-top: 0;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle {
    position: relative;
    display: flex;
    flex: 0 0 26px;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 20px;
    opacity: 1;
  }

  /* The prototype marks expandable rows with a plus that becomes a minus;
     GenerateBlocks renders a caret, so the indicator is redrawn in CSS and
     driven by the aria-expanded state the block already maintains. */
  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle svg {
    display: none;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle::before,
  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    background: currentColor;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle::before {
    width: 12px;
    height: 1px;
    transform: translate(-50%, -50%);
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle::after {
    width: 1px;
    height: 12px;
    transform: translate(-50%, -50%);
  }

  [data-egr-header] .gb-menu-container--mobile .gb-menu > .menu-item > .gb-menu-link .gb-submenu-toggle[aria-expanded="true"]::after {
    display: none;
  }

  /* Inside the drawer the submenu is accordion content, not the desktop
     dropdown: GenerateBlocks carries the floating panel styles over. */
  [data-egr-header] .gb-menu-container--mobile .gb-sub-menu {
    position: static;
    z-index: auto;
    flex: 0 0 100%;
    width: auto;
    max-width: 100%;
    padding: 0 0 12px 14px;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-sub-menu .menu-item {
    margin: 15px 0;
  }

  [data-egr-header] .gb-menu-container--mobile .gb-sub-menu .gb-menu-link {
    display: block;
    width: 255px;
    max-width: 100%;
    overflow: hidden;
    font-size: 17px;
    line-height: 22px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Mobile search expands under the bar, full width. */
  [data-egr-header] [data-egr-mobile] .egr-search {
    width: 46px;
    height: 46px;
  }

  [data-egr-header] [data-egr-mobile] .egr-search.is-open {
    position: absolute;
    top: 53px;
    right: 0;
    left: 0;
    z-index: 6;
    width: auto;
    height: 54px;
    padding: 8px 15px;
    background: #ffffff;
    border-bottom: 1px solid var(--egr-border);
  }

  [data-egr-header] [data-egr-mobile] .egr-search__toggle {
    top: auto;
    width: 46px;
    height: 46px;
  }

  [data-egr-header] [data-egr-mobile] .egr-search.is-open .egr-search__toggle {
    height: 38px;
  }

  [data-egr-header] [data-egr-mobile] .egr-search.is-open .egr-search__input {
    height: 38px;
  }

  /* The page and header shift right as a unit, exactly as the prototype pushes
     .egr-page: the drawer keeps the left edge, the toggle becomes the close
     control in the remaining strip. The header uses margins rather than a
     transform so the fixed drawer stays anchored to the viewport. Both moves
     are instant — the prototype only animates the drawer itself. */
  body[data-gb-menu-open] [data-egr-announcement],
  body[data-gb-menu-open] [data-egr-header] {
    margin-left: var(--egr-drawer-width);
    margin-right: calc(-1 * var(--egr-drawer-width));
  }

  body[data-gb-menu-open] [data-egr-header] {
    z-index: 102;
  }

  body[data-gb-menu-open] #page {
    transform: translateX(var(--egr-drawer-width));
  }
}
