/* ==========================================================================
   header-menu.css — Site navigation header (BEM)
   ========================================================================== */

/* --- Block: header-menu ------------------------------------------------- */
.header-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  width: 100%;
  padding: var(--space-md) 0;
  background-color: transparent;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  background-color: rgba(12, 41, 111, 0.15);
  transition: background-color var(--transition-base),
              padding var(--transition-base),
              box-shadow var(--transition-base);
}

/* --- State: scrolled --------------------------------------------------- */
.header-menu--scrolled {
  background-color: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-md);
  padding: 0.5rem 0;
}

/* --- Container --------------------------------------------------------- */
.header-menu__container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--container-padding);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

/* --- Brand / Logo ------------------------------------------------------ */
.header-menu__brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  z-index: 1002;
}

.header-menu__logo {
  height: 38px;
  width: auto;
  transition: height var(--transition-base), filter var(--transition-base);
  filter: brightness(0) invert(1);

  @media (min-width: 768px) {
    height: 56px;
  }
}

.header-menu--scrolled .header-menu__logo {
  height: 38px;
  filter: none;

  @media (min-width: 768px) {
    height: 56px;
  }
}

/* --- Navigation -------------------------------------------------------- */
.header-menu__nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.header-menu__list {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.header-menu__item {
  position: relative;
}

/* Extra hover area below dropdown trigger to bridge the gap to the submenu */
.header-menu__item--dropdown {
  padding-bottom: 0.5rem;
  margin-bottom: -0.5rem;
}

.header-menu__link {
  display: inline-block;
  padding: 0.5rem 0;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--color-text-on-dark);
  transition: color var(--transition-base);
  position: relative;
}

.header-menu--scrolled .header-menu__link {
  color: var(--color-secondary);
}

.header-menu__link:hover {
  color: var(--color-primary-light);
}

.header-menu--scrolled .header-menu__link:hover {
  color: var(--color-primary);
}

/* Active link underline ------------------------------------------------- */
.header-menu__link--active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  background-color: var(--color-primary);
  border-radius: 2px;
}

.header-menu:not(.header-menu--scrolled) .header-menu__link--active::after {
  background-color: var(--color-primary-light);
}

/* --- CTA --------------------------------------------------------------- */
.header-menu__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-text-on-dark);
  background-color: var(--color-primary);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  box-shadow: 0 2px 8px rgba(10, 128, 69, 0.3);
  white-space: nowrap;
}

.header-menu__cta:hover {
  background-color: var(--color-primary-dark);
  color: var(--color-text-on-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(10, 128, 69, 0.4);
}

/* --- Mobile toggle ----------------------------------------------------- */
.header-menu__toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  z-index: 1002;
  background: transparent;
  border: none;
  cursor: pointer;
}

.header-menu__toggle-bar {
  display: block;
  width: 100%;
  height: 2px;
  background-color: var(--color-text-on-dark);
  border-radius: 2px;
  transition: transform var(--transition-base),
              opacity var(--transition-base),
              background-color var(--transition-base);
  transform-origin: center;
}

.header-menu--scrolled .header-menu__toggle-bar {
  background-color: var(--color-secondary);
}

.header-menu__toggle--active .header-menu__toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.header-menu__toggle--active .header-menu__toggle-bar:nth-child(2) {
  opacity: 0;
}
.header-menu__toggle--active .header-menu__toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* --- Dropdown chevron --------------------------------------------------- */
.header-menu__link--has-dropdown {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}

.header-menu__chevron {
  width: 12px;
  height: 12px;
  transition: transform var(--transition-base);
}

.header-menu__item--open .header-menu__chevron {
  transform: rotate(180deg);
}

/* --- Submenu (desktop dropdown) ---------------------------------------- */
.header-menu__submenu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  min-width: 220px;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease,
              transform 0.2s ease,
              visibility 0.2s ease;
  z-index: 1001;
  list-style: none;
}

/* Invisible bridge between the trigger and the submenu to prevent
   the hover from being lost when the cursor crosses the gap. */
.header-menu__submenu::before {
  content: "";
  position: absolute;
  top: -0.75rem;
  left: 0;
  right: 0;
  height: 0.75rem;
  background: transparent;
}

.header-menu__item--dropdown:hover .header-menu__submenu,
.header-menu__item--open .header-menu__submenu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.header-menu__subitem--all {
  border-top: 1px solid var(--color-border);
  margin-top: 0.3rem;
  padding-top: 0.3rem;
}

.header-menu__sublink {
  display: block;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  color: var(--color-secondary);
  transition: background-color var(--transition-base),
              color var(--transition-base);
}

.header-menu__sublink:hover {
  background-color: var(--color-bg-alt);
  color: var(--color-primary);
}

.header-menu__sublink--all {
  color: var(--color-primary);
  font-weight: 600;
}

/* --- Responsive: mobile ------------------------------------------------ */
/* --- Responsive: mobile ------------------------------------------------ */
@media (max-width: 900px) {
  .header-menu__toggle {
    display: flex;
  }

  .header-menu__nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    padding: 5rem var(--container-padding) var(--space-lg);
    background-color: var(--color-bg);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .header-menu__nav--open {
    transform: translateX(0);
  }

  .header-menu__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
  }

  .header-menu__item {
    width: 100%;
    border-bottom: 1px solid var(--color-border);
  }

  /* Mobile: undo desktop hover-bridge so it doesn't break the layout */
  .header-menu__item--dropdown {
    padding-bottom: 0;
    margin-bottom: 0;
  }

  .header-menu__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 1rem 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-secondary);
  }

  .header-menu:not(.header-menu--scrolled) .header-menu__link {
    color: var(--color-secondary);
  }

  .header-menu__link--active::after {
    display: none;
  }

  .header-menu__link--active {
    color: var(--color-primary);
  }

  /* Chevron rotates more naturally in accordion context */
  .header-menu__chevron {
    width: 16px;
    height: 16px;
    color: var(--color-text-muted);
    transition: transform 0.25s ease;
  }

  .header-menu__cta {
    width: 100%;
    padding: 1rem 1.25rem;
    font-size: 1rem;
    text-align: center;
    justify-content: center;
    margin-top: var(--space-md);
  }

  .header-menu--mobile-open .header-menu__toggle-bar {
    background-color: var(--color-secondary);
  }

  .header-menu--mobile-open .header-menu__logo {
    filter: none;
  }

  /* ---------- Mobile dropdown → accordion ---------- */

  /* Override ALL desktop transforms and positioning */
  .header-menu__submenu {
    position: static !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    box-shadow: none;
    border: none;
    background-color: var(--color-bg-alt);
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    min-width: 0;
    border-radius: 0;
    width: 100%;
  }

  /* Hide the desktop hover-bridge on mobile */
  .header-menu__submenu::before {
    display: none;
  }

  .header-menu__item--dropdown.header-menu__item--open .header-menu__submenu {
    max-height: 500px;
    padding: 0.5rem 0;
  }

  .header-menu__subitem {
    width: 100%;
  }

  .header-menu__sublink {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2rem;
    font-size: 0.95rem;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    background-color: transparent;
  }

  .header-menu__sublink:last-child {
    border-bottom: none;
  }

  .header-menu__sublink:hover,
  .header-menu__sublink:active {
    background-color: rgba(0, 119, 212, 0.06);
    color: var(--color-primary);
  }

  /* Prevent hover-open on touch devices */
  .header-menu__item--dropdown:hover .header-menu__submenu {
    max-height: 0;
    padding: 0;
  }

  .header-menu__item--dropdown.header-menu__item--open:hover .header-menu__submenu {
    max-height: 500px;
    padding: 0.5rem 0;
  }
}
