/* ==========================================================================
   Section: header — topnav + middlenav + bottomnav + megamenus + mobile menu
   Sticky header; topnav collapses on scroll (168px → 128px on desktop).
   ========================================================================== */

.x-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--white);
  display: block;
}

/* ---------- TopNav (desktop) ---------- */
.x-header__topnav {
  background: var(--green-dark);
  height: var(--header-topbar-h);
  max-height: var(--header-topbar-h);
  position: relative;
  z-index: 10;
  overflow: hidden;
  transition: max-height .3s ease, opacity .25s ease;
}
.x-header.is-scrolled .x-header__topnav { max-height: 0; opacity: 0; }
.x-header__topnav-inner {
  max-width: var(--container-nav);
  margin: 0 auto;
  padding: 0 16px;
  height: var(--header-topbar-h);
  display: flex;
  justify-content: space-between;
  align-items: stretch;
}
.x-header__segments { display: flex; align-items: stretch; margin: 0; padding: 0; list-style: none; }
.x-header__segments li { display: flex; }
.x-header__segment {
  display: flex;
  align-items: center;
  height: var(--header-topbar-h);
  padding: 0 16px;
  font-size: 13px;
  font-weight: var(--fw-medium);
  color: var(--white);
}
.x-header__segment--active { background: rgba(255, 255, 255, .4); }
.x-header__services { display: flex; align-items: center; margin: 0; padding: 0; list-style: none; }
.x-header__services li { position: relative; display: list-item; }
.x-header__service {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--header-topbar-h);
  padding: 0 14px;
  font-size: 13px;
  font-weight: var(--fw-medium);
  color: rgba(255, 255, 255, .75);
  transition: color .15s ease;
}
.x-header__service:hover { color: var(--white); }
.x-header__services-sep { width: 1px; height: 16px; background: var(--white); margin: 0 12px; align-self: center; }

/* ---------- Mobile top bar ---------- */
.x-header__mobilebar {
  display: none;
  background: var(--green-dark);
  height: var(--header-topbar-h);
  max-height: var(--header-topbar-h);
  overflow: hidden;
  transition: max-height .3s ease, opacity .25s ease;
  padding: 0 16px;
  justify-content: space-between;
  align-items: stretch;
  position: relative;
  z-index: 10;
}
.x-header.is-scrolled .x-header__mobilebar { max-height: 0; opacity: 0; }
.x-header__mobilebar-segments { display: flex; margin: 0; padding: 0; list-style: none; }
.x-header__mobilebar-more { display: flex; align-items: center; position: relative; }
.x-header__mobilebar-more-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: background-color .15s ease;
}
.x-header__mobilebar-more-btn:hover { background: rgba(255, 255, 255, .15); }
.x-header__mobilesheet {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--green-dark);
  border-radius: 0 0 12px 12px;
  padding: 8px 0;
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
  z-index: 50;
}
.x-header__mobilesheet.is-open { opacity: 1; visibility: visible; transform: translateY(0); }
.x-header__mobilesheet ul { margin: 0; padding: 0; list-style: none; }
.x-header__mobilesheet .x-header__service { height: 40px; }
.x-header__mobilesheet-sep { height: 1px; background: rgba(255, 255, 255, .35); margin: 4px 12px; }

/* ---------- MiddleNav ---------- */
.x-header__middlenav {
  background: var(--white);
  height: var(--header-middle-h);
  position: relative;
  z-index: 2; /* stays visible above the mobile menu overlay */
  display: block;
}
.x-header__middlenav-inner {
  max-width: var(--container-nav);
  margin: 0 auto;
  padding: 0 16px;
  height: calc(var(--header-middle-h) - 1px);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.x-header__logo { display: flex; align-items: center; height: 33px; width: 110.28px; }
.x-header__logo-picture { display: block; height: 33px; }
.x-header__logo img { display: block; height: 33px; width: auto; max-width: none; }
.x-header__actions { display: flex; align-items: center; gap: 12px; height: 40px; }
.x-header__search-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--green);
  font-size: 14px;
  font-weight: var(--fw-regular);
  transition: color .15s, background-color .15s, border-color .15s;
}
.x-header__search-btn:hover { background: var(--green-tint-06); }
.x-header__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 9.5px 16px;
  border-radius: var(--r-pill);
  font-size: 14px;
  font-weight: var(--fw-medium);
  line-height: 21px;
  letter-spacing: -.01em;
  text-decoration: none;
  transition: color .15s, background-color .15s, border-color .15s;
  white-space: nowrap;
}
.x-header__btn--outline {
  background: var(--green-tint-12);
  color: var(--green-dark);
  border: 1px solid transparent;
}
.x-header__btn--outline:hover {
  background: var(--green-tint-06);
  color: var(--green-darker);
  border-color: var(--green-darker);
}
.x-header__btn--primary { background: var(--green); color: var(--white); }
.x-header__btn--primary:hover { background: var(--green-hover); }
.x-header__hamburger {
  display: none;
  width: 40px;
  height: 40px;
  padding: 8px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
}
.x-header__hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--gray-hamb);
  border-radius: 2px;
  transition: transform .25s ease, opacity .2s ease;
}
.x-header.is-menu-open .x-header__hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.x-header.is-menu-open .x-header__hamburger span:nth-child(2) { opacity: 0; }
.x-header.is-menu-open .x-header__hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- BottomNav (desktop) ---------- */
.x-header__bottomnav {
  background: var(--white);
  height: var(--header-bottom-h);
  display: block;
  box-shadow: 0 1px 0 rgba(27, 48, 82, .08);
}
.x-header__bottomnav-inner {
  max-width: var(--container-nav);
  margin: 0 auto;
  padding: 0 16px;
  height: calc(var(--header-bottom-h) - 1px);
  display: flex;
  align-items: stretch;
  position: relative;
}
.x-header__nav-items {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0;
  list-style: none;
  width: 100%;
}
.x-header__nav-li { position: relative; display: flex; align-items: center; height: 55px; }
.x-header__nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 55px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: var(--fw-semibold);
  line-height: 21px;
  letter-spacing: -.01em;
  color: var(--gray-nav);
  text-decoration: none;
  transition: color .15s, background-color .15s, border-color .15s;
}
.x-header__nav-item:hover { color: var(--ink-2); }
.x-header__nav-li.is-open .x-header__nav-item { color: var(--green-dark); }
.x-header__underline {
  position: absolute;
  top: 53px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--green);
  transition: left .25s ease, width .25s ease, opacity .2s ease;
  opacity: 0;
  pointer-events: none;
}
.x-header__underline.is-visible { opacity: 1; }

/* ---------- Megamenu ---------- */
.x-megamenu {
  position: fixed;
  left: 0;
  right: 0;
  top: 168px;
  background: var(--white);
  border-radius: 0 0 12px 12px;
  padding: 8px 0 0;
  z-index: var(--z-megamenu);
  box-shadow: 0 24px 48px rgba(27, 48, 82, .12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity .25s ease, transform .25s ease, visibility .25s;
}
.x-header.is-scrolled .x-megamenu { top: 128px; }
.x-megamenu.is-open { opacity: 1; visibility: visible; transform: translateY(0); }
.x-megamenu__closebar { display: flex; justify-content: flex-end; height: 33px; max-width: var(--container-nav); margin: 0 auto; padding: 0 16px; }
.x-megamenu__close { display: flex; align-items: center; justify-content: center; width: 33px; height: 33px; color: var(--gray-nav); }
.x-megamenu__inner {
  max-width: var(--container-nav);
  margin: 0 auto;
  padding: 12px 24px 24px;
  display: flex;
  gap: 24px;
}
.x-megamenu__columns { display: flex; gap: 48px; flex: 1; }
.x-megamenu__group { display: flex; flex-direction: column; min-width: 220px; }
.x-megamenu__group-title {
  font-size: 13px;
  font-weight: var(--fw-semibold);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--gray-muted);
  margin: 0 0 12px;
}
.x-megamenu__quick { display: flex; flex-direction: column; min-width: 240px; }
.x-megamenu__link,
.x-megamenu__quicklink {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  font-size: 14px;
  font-weight: var(--fw-regular);
  color: var(--ink);
  text-decoration: none;
  transition: color .15s ease;
}
.x-megamenu__link:hover,
.x-megamenu__quicklink:hover { color: var(--green-dark); }
.x-megamenu__link img,
.x-megamenu__quicklink img { flex: 0 0 14px; }
.x-megamenu__quicklink { font-weight: var(--fw-medium); color: var(--green-dark); }
.x-megamenu__campaign { width: 300px; flex: 0 0 300px; display: flex; flex-direction: column; gap: 8px; }
.x-megamenu__campaign-img { border-radius: 12px; overflow: hidden; }
.x-megamenu__campaign-img img { width: 100%; height: auto; display: block; object-fit: cover; }
.x-megamenu__campaign-title { font-size: 18px; font-weight: var(--fw-semibold); color: var(--ink); margin: 8px 0 0; }
.x-megamenu__campaign-text { font-size: 14px; color: var(--gray-text); margin: 0; }
.x-megamenu__campaign-cta { font-size: 14px; font-weight: var(--fw-semibold); color: var(--green-dark); text-decoration: underline; }
.x-header__screen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  /* The header (sticky, z-index:900) creates a stacking context; z-index:-1 keeps
     the overlay above page content but BEHIND the header's own children, so it
     never steals hover from the nav items (would cause an open/close loop). */
  z-index: -1;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s ease, visibility .25s;
}
.x-header__screen-overlay.is-visible { opacity: 1; visibility: visible; }

/* ---------- Mobile menu ---------- */
.x-header__mobilemenu {
  position: fixed;
  inset: 0;
  top: 0;
  background: var(--bg-gray);
  z-index: 1;
  padding-top: var(--header-middle-h);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-100%);
  transition: transform .3s ease, opacity .3s ease, visibility .3s;
  overflow-y: auto;
  display: none;
}
.x-header.is-menu-open .x-header__mobilemenu { opacity: 1; visibility: visible; transform: translateX(0); }
/* When the mobile menu is open, the green mobile bar collapses (matches live) */
.x-header.is-menu-open .x-header__mobilebar { max-height: 0; opacity: 0; }
.x-header__mobilemenu-body { padding: 16px; }
.x-header__mobilemenu-searchwrap { margin-bottom: 16px; }
.x-header__mobilemenu-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border-radius: var(--r-pill);
  padding: 12px 16px;
  box-shadow: var(--shadow-card-dark);
}
.x-header__mobilemenu-search input {
  border: 0;
  outline: 0;
  background: transparent;
  flex: 1;
  font-size: 16px;
  color: var(--ink);
}
.x-header__mobilemenu-search input::placeholder { color: var(--gray-muted); }
.x-header__mobilemenu-card {
  background: var(--white);
  border-radius: var(--r-card);
  padding: 8px 16px;
  box-shadow: var(--shadow-card-dark);
}
.x-header__mrow {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px 0;
  font-size: 16px;
  font-weight: var(--fw-medium);
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--gray-border);
  text-align: left;
}
.x-header__mrow span { flex: 1; }
.x-header__mrow-chevron { transition: transform .25s ease; }
.x-header__mrow[aria-expanded="true"] .x-header__mrow-chevron { transform: rotate(90deg); }
.x-header__mdrawer {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease;
  border-bottom: 1px solid var(--gray-border);
}
.x-header__mdrawer.is-open { max-height: 640px; }
.x-header__mlink {
  display: block;
  padding: 10px 0 10px 36px;
  font-size: 15px;
  color: var(--gray-text);
  text-decoration: none;
}
.x-header__mlink:hover { color: var(--green-dark); }
.x-header__mlink--accent { color: var(--green-dark); font-weight: var(--fw-medium); }

/* ---------- Search modal ---------- */
.x-header__searchmodal { position: fixed; inset: 0; z-index: var(--z-modal); display: none; }
.x-header__searchmodal.is-open { display: block; }
.x-header__searchmodal-overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); }
.x-header__searchmodal-panel {
  position: relative;
  background: var(--white);
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 32px 32px;
  border-radius: 0 0 24px 24px;
}
.x-header__searchmodal-top { display: flex; align-items: center; gap: 24px; }
.x-header__searchmodal-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  height: 56px;
  border: 1px solid var(--lime);
  border-radius: var(--r-pill);
  padding: 0 24px;
}
.x-header__searchmodal-form input { border: 0; outline: 0; flex: 1; font-size: 16px; color: var(--ink); background: transparent; }
.x-header__searchmodal-close {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: var(--fw-medium);
  color: var(--green-dark);
}
.x-header__searchmodal-title { font-size: 18px; font-weight: var(--fw-semibold); color: var(--green-dark); margin: 24px 0 8px; }
.x-header__searchmodal-list { list-style: none; margin: 0; padding: 0; }
.x-header__searchmodal-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  font-size: 16px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--gray-border);
  transition: color .15s ease;
}
.x-header__searchmodal-list li:last-child a { border-bottom: 0; }
.x-header__searchmodal-list a:hover { color: var(--green-dark); }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
  .x-header__topnav, .x-header__bottomnav { display: none; }
  .x-header__mobilebar { display: flex; }
  .x-header__hamburger { display: flex; }
  .x-header__mobilemenu { display: block; }
  .x-header__search-trigger { display: none; }
}
@media (max-width: 767px) {
  .x-header__middlenav-inner { padding: 0 16px; }
  .x-header__logo { width: 33px; overflow: hidden; }
  .x-header__btn { padding: 9.5px 12px; font-size: 13px; }
  .x-header__actions { gap: 8px; }
}
