/**
 * Header: sticky translucent bar, everything on one row, the menu shows as a
 * megamenu. Below lg (992px) the bar keeps the brand, the header links and the
 * hamburger; the search field and the CTA move into the menu panel.
 * Structural classes (.nav-global, .nav-container, .nav-icons, .nav-links)
 * are used by js/scripts.js.
 */

header {
  position: sticky;
  z-index: 100;
  top: 0;
  padding: 0;
  background-color: var(--tz-header-bg);
  color: var(--bs-body-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bs-border-color);

  .nav-global {
    padding: 0;
  }

  /* Horizontal padding comes from the container gutter (style.css). */
  .nav-container {
    width: 100%;
    min-height: 4.75rem;
    padding-block: 0.75rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem clamp(0.875rem, 0.5895rem + 1.2183vw, 1.625rem); /* 14→26px */
  }

  /* BRAND MARK */
  .navbar-brand {
    display: flex;
    align-items: center;
    flex: none;
    margin-right: 0;
    padding: 0;

    .site-logo {
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }

    .site-logo img {
      width: auto;
      height: 1.375rem;

      &:first-child {
        height: 1.875rem;
      }
    }
  }

  /* SEARCH FIELD: the box (border/bg/height) sits on the <form>; the <input>
     inside it is borderless and transparent. Same form in the bar and at the
     top of the mobile menu panel (header-search-form.html.twig). */
  form[role="search"] {
    min-width: 0;
    display: flex;
    align-items: center;
    height: 2.375rem;
    gap: 0.5rem;
    padding: 0 0.625rem;
    border: 1px solid var(--tz-border-2);
    border-radius: var(--bs-border-radius);
    background: var(--bs-tertiary-bg);
    transition: border-color .18s;

    &:hover,
    &:focus-within {
      border-color: var(--bs-primary);
    }

    /* Magnifier before the placeholder (header-search-form.html.twig). */
    .search-icon {
      flex: 0 0 auto;
      color: var(--bs-tertiary-color);
    }

    /* No button beside it: the input fills the box (.form-control has no
       intrinsic width in a flex row). */
    .form-control {
      width: 100%;
      border: 0;
      background: transparent;
      padding: 0;
      font-size: var(--fs-xs);
      text-overflow: ellipsis;
    }

    .form-control:focus {
      box-shadow: none;
    }
  }

  .nav-container > form[role="search"] {
    flex: 1 1 21.5rem;
    max-width: 27.5rem;
  }

  /* HEADER LINKS: language, account, CTA, hamburger. */
  .nav-icons {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex: 0 1 auto;
    min-width: 0;
  }

  .nav-link {
    color: var(--bs-secondary-color);
    font-family: var(--tz-font-body);
    font-weight: 500;
    text-transform: none;
    transition: none;
    padding: 0.25rem 0 !important;
    border-bottom: 2px solid transparent;

    &:hover,
    &.is-active {
      color: var(--bs-body-color);
      border-bottom-color: var(--bs-primary);
      cursor: pointer;
    }
  }
}

/* Account link: icon-only .btn-outline-primary */
.btn-icon {
  --bs-btn-padding-x: 0;
  --bs-btn-padding-y: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.375rem;
  height: 2.375rem;
  flex: none;
}

/* Language switcher: Bootstrap dropdown (click and keyboard), themed through
   its own --bs-dropdown-* variables. */
header .language-switcher-language-url {
  padding-right: 0.75rem;
  border-right: 1px solid var(--bs-border-color);

  /* Native Bootstrap .btn.dropdown-toggle, themed through --bs-btn-* only:
     text-like button (no padding, border or background), native caret. */
  .dropdown-toggle {
    --bs-btn-padding-x: 0;
    --bs-btn-padding-y: 0.25rem;
    --bs-btn-font-family: var(--tz-font-body);
    --bs-btn-font-size: var(--fs-sm);
    --bs-btn-font-weight: 600;
    --bs-btn-color: var(--bs-tertiary-color);
    --bs-btn-hover-color: var(--bs-body-color);
    --bs-btn-active-color: var(--bs-body-color);
    --bs-btn-border-width: 0;
    --bs-btn-focus-box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), .25);
    text-transform: uppercase;
  }

  .dropdown-menu {
    --bs-dropdown-min-width: 0;
    --bs-dropdown-padding-y: 0.25rem;
    --bs-dropdown-font-size: var(--fs-sm);
    --bs-dropdown-border-color: var(--tz-border-2);
    --bs-dropdown-border-radius: var(--bs-border-radius);
    --bs-dropdown-item-padding-x: 0.875rem;
    --bs-dropdown-link-color: var(--bs-secondary-color);
    --bs-dropdown-link-hover-color: var(--bs-primary);
    --bs-dropdown-link-hover-bg: var(--bs-tertiary-bg);
    --bs-dropdown-link-active-color: var(--bs-body-color);
    --bs-dropdown-link-active-bg: transparent;
  }

  .dropdown-item {
    font-weight: 600;
    text-transform: uppercase;
  }

  /* The current language is the toggle, not a menu entry. */
  li.is-active {
    display: none;
  }
}

/* HAMBURGER: below lg only (Bootstrap hides it from lg up). */
header .navbar-toggler {
  border: none;
  padding: 0;

  &:focus {
    box-shadow: none;
  }

  &:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
  }

  .hamburger-toggle {
    position: relative;
    display: block;
    width: 1.875rem;
    height: 1.875rem;
  }

  .hamburger {
    position: absolute;
    inset: 17.5% 20%;
    pointer-events: none;
  }

  .hamburger span {
    position: absolute;
    left: 0;
    width: 100%;
    height: 1.75px;
    background: var(--bs-body-color);
    border-radius: 2px;
    transition: transform .2s cubic-bezier(0.77, 0.2, 0.05, 1), width .2s;

    &:first-child {
      top: 10%;
    }

    &:nth-child(2) {
      top: 50%;
      transform: translateY(-50%);
    }

    &:last-child {
      bottom: 10%;
    }
  }

  /* Open: the outer bars cross, the middle one shrinks away. */
  .hamburger.active span {
    &:first-child,
    &:last-child {
      top: 50%;
      bottom: auto;
    }

    &:first-child {
      transform: translateY(-50%) rotate(45deg);
    }

    &:nth-child(2) {
      left: 50%;
      width: 0;
    }

    &:last-child {
      transform: translateY(-50%) rotate(-45deg);
    }
  }
}

/* MENU AND MEGAMENU: the megamenu panel is shown on hover by js/scripts.js
   (.show on .dropdown-mega-menu), full width under the header; the mobile-
   only submenu lists are hidden. */
header .nav-links {
  flex: none;

  .navigation-list {
    gap: 0 1.625rem;
    font-size: var(--fs-sm);
    font-weight: 500;
    white-space: nowrap;
  }

  > ul.navigation-list[data-page="0"] {
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  ul.navigation-list[data-page="1"],
  ul.navigation-list[data-page="2"] {
    display: none;
  }

  /* Megamenu entries with children: a chevron hints that hovering shows
     them in the next column. */
  li.has-child > .sub-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;

    &::after {
      content: '';
      flex: none;
      width: 1em;
      height: 1em;
      background: currentColor;
      mask: url(../images/svg/arrow-right.svg) no-repeat center / contain;
    }
  }
}

header .dropdown-mega-menu {
  top: 100%;
  left: 0;
  margin: 0;
  padding-block: var(--space-card) !important;
  border: 0;
  border-top: 1px solid var(--bs-border-color);
  border-radius: 0;
  background: #fff;
  box-shadow: 0 24px 40px -32px rgba(var(--bs-body-color-rgb), .45);
  text-align: left;
  white-space: normal;

  h2 {
    margin: 0 0 0.75rem;
    font-size: var(--fs-h3);
  }

  p {
    color: var(--bs-secondary-color);
  }

  ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  a {
    color: var(--bs-body-color);
    text-decoration: none;

    &:hover {
      color: var(--bs-primary);
    }
  }

  [data-level="2"] li,
  [data-level="3"] li {
    padding: 0.375rem 0;
  }
}

/* Added to the navbar by the megamenu JS while a panel is open. */
.border-color {
  border-bottom: 2px solid var(--bs-primary);
}

/* ADMIN UI: toolbar offsets and content preview. */
body.toolbar-fixed header {
  top: 2.4375rem;
}

body.toolbar-fixed.gin--horizontal-toolbar header {
  top: 3.3125rem;
}

body.toolbar-fixed.toolbar-tray-open header {
  top: 4.875rem;
}

/* Administration submenu toolbar on mobile */
body.toolbar-tray-open.toolbar-vertical.toolbar-fixed {
  margin-left: 0;
}

/* Content preview mode container */
.node-preview-container {
  position: sticky;
  background: white;
}

.node-preview-backlink {
  margin-right: 1.5rem;
}

/* BELOW LG: bar, menu panel, admin toolbar. .nav-links is a Bootstrap
   collapse toggled by the hamburger: a panel right under the bar, positioned
   against .navbar. Submenus are stacked panels sliding in from the right
   (.navigation-list-active, set by js/scripts.js). */
@media (max-width: 991.98px) {
  /* The bar only keeps the brand and the header links: the search field and
     the CTA move into the menu panel (.nav-links-search, .nav-links-cta). */
  header .nav-container > form[role="search"],
  header .nav-icons .block-header-cta {
    display: none;
  }

  header .nav-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: calc(100dvh - var(--header-height));
    overflow-x: hidden;
    overflow-y: auto;
    background: #fff;
    border-top: 1px solid var(--bs-border-color);

    &.collapsing {
      transition: none;
    }

    .navigation-list {
      gap: 0;
      font-size: inherit;
      font-weight: inherit;
      white-space: normal;
    }

    > ul.navigation-list[data-page="0"] {
      flex-direction: column;
      align-items: stretch;
      padding: 1rem calc(var(--bs-gutter-x) * .5);
    }

    ul {
      list-style: none;
      padding-left: 0;
    }

    /* Level 0 entries. */
    .nav-item {
      align-self: stretch !important;
      border-bottom: 1px solid var(--bs-border-color);
    }

    .nav-link {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 1rem 0 !important;
      border-bottom: 0;
      font-family: var(--tz-font-heading);
      font-size: var(--fs-h3);
      font-weight: 600;
      letter-spacing: var(--ls-snug);
      color: var(--bs-body-color);

      &.is-active {
        color: var(--bs-primary);
      }
    }

    /* Levels 1 and 2: full panels over the previous level. */
    ul.navigation-list[data-page="1"],
    ul.navigation-list[data-page="2"] {
      position: absolute;
      inset: 0;
      z-index: 1;
      display: block;
      margin: 0;
      padding: 1.5rem calc(var(--bs-gutter-x) * .5);
      overflow-y: auto;
      background: #fff;
      text-align: left;
      transform: translateX(100%);
      visibility: hidden;
      transition: transform .25s ease-out, visibility 0s .25s;
    }

    ul.navigation-list.navigation-list-active {
      transform: none;
      visibility: visible;
      transition: transform .25s ease-out;
    }

    .navigation-list-item-back {
      display: flex;
      align-items: center;
      gap: 0.625rem;
      font-size: var(--fs-sm);
      font-weight: 600;
      color: var(--bs-primary);
      cursor: pointer;

      &::before {
        content: '';
        width: 1.25rem;
        height: 1.25rem;
        background: currentColor;
        mask: url(../images/svg/arrow-left.svg) no-repeat center / contain;
      }
    }

    .navigation-list-item-title {
      margin: 1.25rem 0 1rem;

      h2 {
        margin: 0 0 0.5rem;
        font-size: var(--fs-h3);
      }

      a {
        font-size: var(--fs-sm);
        color: var(--bs-secondary-color);
      }
    }

    .sub-nav-link,
    li.has-child > .sub-nav-link {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0;
      padding: 0.75rem 0;
      border-bottom: 1px solid var(--bs-border-color);
      font-size: var(--fs-lg);
      font-weight: 500;
      color: var(--bs-body-color);
      text-decoration: none;

      &:hover {
        color: var(--bs-primary);
      }
    }

    /* Entries with children open a submenu: arrow on the right. */
    li.has-child > .nav-link::after,
    li.has-child > .sub-nav-link::after {
      content: '';
      flex: none;
      width: 1.5rem;
      height: 1.5rem;
      background: currentColor;
      mask: url(../images/svg/arrow-right.svg) no-repeat center / contain;
    }

    /* The desktop megamenu panel is never shown here. */
    .dropdown-mega-menu {
      display: none !important;
    }
  }

  /* Header search field, at the top of the panel (see
     block--tenderz-main-menu.html.twig). */
  header .nav-links-search {
    padding: 1.25rem calc(var(--bs-gutter-x) * .5) 0;
  }

  /* Header CTA, at the bottom of the panel (see
     block--tenderz-main-menu.html.twig). */
  header .nav-links-cta {
    padding: 0.5rem calc(var(--bs-gutter-x) * .5) 2rem;

    .btn {
      display: flex !important;
      justify-content: center;
      width: 100%;
    }

    p {
      margin: 0;
    }
  }

  /* Admin toolbar offsets (its layout changes below lg). */
  body.toolbar-fixed.toolbar-tray-open header {
    top: unset;
  }

  body.toolbar-vertical.gin--horizontal-toolbar header,
  body.toolbar-fixed.toolbar-tray-open.gin--horizontal-toolbar header {
    top: 2.4375rem;
  }

  .node-preview-container {
    display: none;
  }
}
