/* Header: top bar, brand bar, navigation (mobile panel < 960px, mega/dropdown >= 960px). */

/* Scroll sentinel: when it leaves the viewport, nav.js adds .is-compact to the header. */
.header-sentinel {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 140px;
  pointer-events: none;
}

/* The top bar scrolls away; the brand bar stays stuck to the top. */
.site-header {
  position: sticky;
  top: calc(-1 * var(--topbar-h));
  z-index: 50;
  color: var(--color-on-brand);
}

.site-header :focus-visible {
  outline-color: var(--color-focus-on-brand);
}

/* ---- Top bar ---- */
.topbar {
  background: var(--color-primary-dark);
  font-size: 0.8125rem;
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--topbar-h);
}

.topbar ul {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.topbar a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2rem;
  color: var(--color-on-brand);
  text-decoration: none;
}

.topbar a:hover {
  color: var(--color-on-brand);
  text-decoration: underline;
}

.topbar .icon {
  opacity: 0.9;
}

.topbar__social a {
  justify-content: center;
  min-width: 2rem;
}

.topbar__social .icon {
  width: 1.05rem;
  height: 1.05rem;
}

/* On small screens the e-mail shows as an icon; the address stays in the accessible name. */
.topbar__contact li:nth-child(2) span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Brand bar ---- */
.mainbar {
  position: relative;
  border-top: 1px solid #32c4dd;
  background: var(--gradient-header-original);
}

/* Light rays across the bar, centred (theme overlay-rays.png). */
.mainbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../img/theme/overlay-rays.png") 50% 50% / auto 100% no-repeat;
  pointer-events: none;
}

.mainbar__inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--mainbar-h-compact);
}

/* The logo artwork is navy on transparent and sits straight on the gradient, as on the original. */
.site-logo {
  position: relative;
  display: block;
  flex: none;
}

.site-logo img {
  width: 116px;
  height: auto;
  transition: width var(--duration) var(--ease);
}

.nav-burger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  padding: 0 var(--space-3);
  border: 1px solid rgb(255 255 255 / 0.45);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-on-brand);
  font-weight: 600;
}

.nav-burger .icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Without JS the burger cannot work: the navigation is shown as a plain list instead. */
html:not(.js) .nav-burger {
  display: none;
}

html:not(.js) .mainbar__inner {
  flex-wrap: wrap;
  padding-block: var(--space-3);
}

/* ---- Navigation: mobile (default) ---- */
.site-nav {
  color: var(--color-text);
}

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

html:not(.js) .site-nav {
  flex-basis: 100%;
  border-radius: var(--radius);
  background: #fff;
}

.js .site-nav {
  display: none;
}

.js .site-nav.is-open {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: block;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  animation: nav-in var(--duration) var(--ease);
}

@keyframes nav-in {
  from { opacity: 0; transform: translateY(-8px); }
}

.site-nav :focus-visible {
  outline-color: var(--color-focus);
}

.site-nav__head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--mainbar-h-compact);
  padding-inline: var(--gutter);
  background: var(--gradient-header);
  color: var(--color-on-brand);
}

html:not(.js) .site-nav__head {
  display: none;
}

.site-nav__title {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.nav-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid rgb(255 255 255 / 0.45);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-on-brand);
}

.nav-close .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.site-nav__head :focus-visible {
  outline-color: var(--color-focus-on-brand);
}

.nav-list {
  padding: var(--space-2) var(--gutter) var(--space-7);
}

.nav-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
}

.nav-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 3.25rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-heading);
  font-size: var(--text-lg);
  font-weight: 600;
  text-align: left;
  text-decoration: none;
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  color: var(--color-primary);
}

.sub-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--color-primary);
}

.sub-toggle--label {
  justify-content: space-between;
  width: auto;
  height: auto;
  color: var(--color-heading);
}

.sub-toggle .icon {
  transition: transform var(--duration) var(--ease);
}

.sub-toggle[aria-expanded="true"] .icon {
  transform: rotate(180deg);
}

/* Sub-levels: accordions, closed until their li gets .is-open */
.js .nav-sub {
  display: none;
}

.js .is-open > .nav-sub {
  display: block;
}

.nav-sub {
  flex-basis: 100%;
  padding-bottom: var(--space-3);
}

.mega-col__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mega-heading {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--color-heading);
  font-weight: 600;
  text-decoration: none;
}

.nav-dropdown a,
.nav-sub--col a {
  display: block;
  padding: var(--space-2) 0 var(--space-2) var(--space-4);
  border-left: 2px solid var(--color-border);
  color: var(--color-text);
  text-decoration: none;
}

.nav-sub--col {
  margin-left: var(--space-2);
}

.mega-col + .mega-col {
  border-top: 1px solid var(--color-border);
}

.nav-sub a:hover,
.nav-sub a[aria-current="page"] {
  color: var(--color-primary);
  border-left-color: var(--color-primary);
}

/* ---- Navigation: desktop ---- */
@media (min-width: 960px) {
  :root {
    --topbar-h: 1.875rem;
  }

  /* The original header scrolls away with the page. */
  .site-header {
    position: relative;
    top: 0;
  }

  .topbar {
    font-size: 0.75rem;
  }

  .topbar__contact li:nth-child(2) span {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  .mainbar__inner {
    align-items: stretch;
    min-height: var(--mainbar-h);
  }

  .site-logo {
    align-self: center;
  }

  .site-logo img {
    width: 154px;
  }

  /* The bar keeps its height when compact: the header is sticky and in flow, so changing its
     height would pull the page up under the reader (a visible jump while scrolling). */
  .site-header.is-compact .site-logo img {
    width: 124px;
  }

  .nav-burger,
  .site-nav__head {
    display: none;
  }

  .js .site-nav,
  html:not(.js) .site-nav {
    display: flex;
    flex-basis: auto;
    background: none;
  }

  .site-nav {
    color: var(--color-on-brand);
  }

  .site-nav :focus-visible {
    outline-color: var(--color-focus-on-brand);
  }

  .site-nav .nav-sub :focus-visible {
    outline-color: var(--color-focus);
  }

  .site-nav > .nav-list {
    display: flex;
    align-items: stretch;
    gap: var(--space-1);
    padding: 0;
  }

  .nav-item {
    position: relative;
    flex-wrap: nowrap;
    border: 0;
  }

  /* The mega panel spans the container, not the item. */
  .nav-item.has-mega {
    position: static;
  }

  .nav-link {
    position: relative;
    flex: none;
    align-self: stretch;
    min-height: 0;
    padding-inline: var(--space-3);
    color: var(--color-on-brand);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    text-shadow: 0 1px 1px rgb(0 60 100 / 0.35);
  }

  .nav-link::after {
    content: "";
    position: absolute;
    left: var(--space-3);
    right: var(--space-3);
    bottom: 0.875rem;
    height: 2px;
    border-radius: 1px;
    background: currentColor;
    transform: scaleX(0);
    transition: transform var(--duration) var(--ease);
  }

  .nav-link:hover,
  .nav-link[aria-current="page"],
  .nav-item:hover > .nav-link {
    color: var(--color-on-brand);
  }

  .nav-link:hover::after,
  .nav-link[aria-current="page"]::after,
  .nav-item:hover > .nav-link::after,
  .nav-item.is-open > .nav-link::after {
    transform: scaleX(1);
  }

  .nav-item.has-sub > .nav-link:not(.sub-toggle) {
    padding-right: 0;
  }

  .sub-toggle {
    align-self: center;
    width: 1.75rem;
    height: 1.75rem;
    color: var(--color-on-brand);
  }

  .sub-toggle--label {
    align-self: stretch;
    width: auto;
    height: auto;
  }

  .sub-toggle .icon {
    width: 0.75rem;
    height: 0.75rem;
  }

  /* Panels: shown on hover, on keyboard focus (nav.js adds .is-open) and on toggle click. */
  .nav-sub,
  .js .nav-sub {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    display: block;
    min-width: 17rem;
    padding: var(--space-4) var(--space-2);
    border-top: 3px solid var(--color-primary-light);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    background: #fff;
    color: var(--color-text);
    box-shadow: var(--shadow-md);
    visibility: hidden;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), visibility 0s linear var(--duration);
  }

  .has-sub:hover:not(.is-dismissed) > .nav-sub,
  .has-sub.is-open > .nav-sub,
  html:not(.js) .has-sub:focus-within > .nav-sub {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition-delay: 0s;
  }

  .nav-dropdown a {
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius);
  }

  .nav-sub a:hover,
  .nav-sub a[aria-current="page"] {
    background: var(--color-bg-soft);
  }

  /* Mega panel: one column per category, product lists always visible. */
  .nav-mega,
  .js .nav-mega {
    left: var(--gutter);
    right: var(--gutter);
    padding: var(--space-6);
  }

  .mega-cols {
    display: grid;
    grid-template-columns: 1fr 1.6fr 1.2fr;
    gap: var(--space-6);
  }

  .mega-col + .mega-col {
    border-top: 0;
  }

  .mega-col__head {
    margin-bottom: var(--space-2);
    border-bottom: 2px solid var(--color-accent-implant);
  }

  .mega-heading {
    min-height: 2.25rem;
    color: var(--color-primary);
    font-size: var(--text-sm);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .mega-heading:hover {
    color: var(--color-primary-dark);
  }

  .sub-toggle--col {
    display: none;
  }

  .nav-sub.nav-sub--col,
  .js .nav-sub.nav-sub--col {
    position: static;
    display: block;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    visibility: inherit;
    opacity: 1;
    transform: none;
    transition: none;
  }

  .nav-sub--col a {
    padding: 0.3125rem var(--space-2);
    margin-inline: calc(-1 * var(--space-2));
    border: 0;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    line-height: 1.4;
  }

  /* The Biyomateryal dropdown carries the orange category accent. */
  .nav-dropdown,
  .js .nav-dropdown {
    border-top-color: var(--color-accent-bio);
  }
}

@media (min-width: 1200px) {
  .site-nav > .nav-list {
    gap: var(--space-2);
  }

  .nav-link {
    padding-inline: var(--space-4);
  }

  .nav-link::after {
    left: var(--space-4);
    right: var(--space-4);
  }
}

@media (min-width: 960px) {
  /* Links followed by a chevron toggle have no right padding; keep the underline under the text. */
  .nav-item.has-sub > .nav-link:not(.sub-toggle)::after {
    right: 0;
  }
}

/* Mobile panel: keep the menu items off the screen edge. */
@media (max-width: 959px) {
  .site-nav > .nav-list {
    padding-inline: var(--gutter);
  }
}
