/*
  ETECHTICS SOFTWARE SOLUTIONS — Navbar + Services Mega-Menu
  -------------------------------------------------------------
  Desktop: sticky white navbar, single dropdown (Services) as a
  two-column mega-menu (category rail + item pane).
  Mobile (<1024px): hamburger toggle opens a full-width drawer;
  Services becomes an inline accordion grouped by category.

  Depends on css/tokens.css.
*/

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-navbar);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--navbar-height);
  position: relative;
}

/* ---------------------------------------------------------------
   Logo (text placeholder — swap for the real logo asset once
   supplied; markup lives in one place, partials/navbar.html)
--------------------------------------------------------------- */
.navbar__logo {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.05;
  color: var(--color-navy);
  font-weight: var(--font-weight-black);
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}
.navbar__logo .navbar__logo-accent {
  color: var(--color-orange);
}
.navbar__logo .navbar__logo-sub {
  font-size: 0.6rem;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-muted);
}

/* ---------------------------------------------------------------
   Primary nav (desktop)
--------------------------------------------------------------- */
.navbar__primary {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

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

.navbar__link {
  display: inline-block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-body-text);
  padding: 0.6rem 0.1rem;
  border-bottom: 2px solid transparent;
}
.navbar__link:hover,
.navbar__link:focus-visible {
  color: var(--color-navy);
  text-decoration: none;
}
.navbar__link[aria-current="page"] {
  color: var(--color-navy);
  border-bottom-color: var(--color-orange);
}

.navbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------
   Services mega-menu trigger
--------------------------------------------------------------- */
.has-mega {
  position: relative;
  display: flex;
  align-items: center;
}

.mega-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  font: inherit;
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-body-text);
  cursor: pointer;
  padding: 0.6rem 0.1rem;
  border-bottom: 2px solid transparent;
}
.mega-trigger:hover,
.mega-trigger[aria-expanded="true"] {
  color: var(--color-navy);
}
.mega-trigger .mega-trigger__chevron {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}
.mega-trigger[aria-expanded="true"] .mega-trigger__chevron {
  transform: rotate(180deg);
}

/* ---------------------------------------------------------------
   Mega-menu panel (desktop)
--------------------------------------------------------------- */
.mega-panel {
  /* Fixed (not absolute) so it centers on the VIEWPORT, not on the
     narrow trigger button. Centering it on the trigger was overflowing
     the page at 1024–1280px viewports — confirmed with an automated
     check — because a 920px panel rarely fits centered on a point
     that sits left-of-center in the navbar. */
  position: fixed;
  top: var(--navbar-height);
  left: 50%;
  width: min(920px, calc(100vw - 2 * var(--container-gutter)));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: var(--z-mega-menu);
  display: grid;
  grid-template-columns: 230px 1fr;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 6px);
  transition: opacity var(--transition-base), transform var(--transition-base),
    visibility var(--transition-base);
}
.mega-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

.mega-panel__categories {
  list-style: none;
  margin: 0;
  padding: var(--space-2);
  background: var(--color-surface-alt);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.mega-panel__category-btn {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-body-text);
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: inset 3px 0 0 transparent;
}
.mega-panel__category-btn:hover,
.mega-panel__category-btn[aria-selected="true"] {
  background: var(--color-surface);
  color: var(--color-navy);
}
.mega-panel__category-btn[aria-selected="true"] {
  box-shadow: inset 3px 0 0 var(--color-orange);
}

.mega-panel__items {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3);
}
.mega-panel__items.is-active {
  display: grid;
}

.mega-panel__item a {
  display: block;
  padding: 0.5rem 0.6rem;
  margin: -0.5rem -0.6rem;
  border-radius: var(--radius-sm);
}
.mega-panel__item a:hover,
.mega-panel__item a:focus-visible {
  background: var(--color-surface-alt);
  text-decoration: none;
}
.mega-panel__item-title {
  display: block;
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-navy);
}
.mega-panel__item-desc {
  display: block;
  margin-top: 0.15rem;
  font-size: var(--font-size-xs);
  color: var(--color-muted);
  line-height: 1.45;
}

.mega-panel__footer-link {
  grid-column: 1 / -1;
  margin-top: 0.25rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--color-border);
}
.mega-panel__footer-link a {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  /* color-blue-600, not color-blue: see the comment on the base `a`
     rule in base.css — color-blue fails the 4.5:1 AA minimum at this
     text size. */
  color: var(--color-blue-600);
}

/* ---------------------------------------------------------------
   Mobile nav toggle
--------------------------------------------------------------- */
.navbar__toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}
.navbar__toggle-icon,
.navbar__toggle-icon::before,
.navbar__toggle-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--color-navy);
  border-radius: 1px;
  position: relative;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}
.navbar__toggle-icon::before {
  content: "";
  position: absolute;
  top: -6px;
}
.navbar__toggle-icon::after {
  content: "";
  position: absolute;
  top: 6px;
}
.navbar__toggle[aria-expanded="true"] .navbar__toggle-icon {
  background: transparent;
}
.navbar__toggle[aria-expanded="true"] .navbar__toggle-icon::before {
  top: 0;
  transform: rotate(45deg);
}
.navbar__toggle[aria-expanded="true"] .navbar__toggle-icon::after {
  top: 0;
  transform: rotate(-45deg);
}

/* ---------------------------------------------------------------
   Mobile drawer
--------------------------------------------------------------- */
.mobile-drawer {
  display: none;
  flex-direction: column;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  max-height: calc(100vh - var(--navbar-height));
  overflow-y: auto;
  padding: var(--space-2) var(--container-gutter) var(--space-3);
}
.mobile-drawer.is-open {
  display: flex;
}

.mobile-drawer__link,
.mobile-services-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  padding: 0.85rem 0.1rem;
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
  color: var(--color-body-text);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}
.mobile-drawer__link:hover {
  color: var(--color-navy);
  text-decoration: none;
}

.mobile-services-panel {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-2) 0 var(--space-3) var(--space-1);
  border-bottom: 1px solid var(--color-border);
}
.mobile-services-panel.is-open {
  display: flex;
}

.mobile-services-group__title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin: 0 0 0.5rem;
}
.mobile-services-group__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.mobile-services-group__list a {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-body-text);
}
.mobile-services-group__list a:hover {
  color: var(--color-navy);
}

.mobile-drawer__cta {
  margin-top: var(--space-3);
}

/* ---------------------------------------------------------------
   Breakpoint: at/below 1024px, switch to mobile nav.
   The cutoff is 1024px (not 1023px) because at exactly 1024px the
   full desktop row (8 nav links + Services trigger + Contact +
   CTA button) does not fit and overflows the viewport by ~83px —
   confirmed with an automated check across all required breakpoints.
   Desktop nav only renders once there is enough room, at 1025px+.
--------------------------------------------------------------- */
@media (max-width: 1024px) {
  .navbar__primary {
    display: none;
  }
  .navbar__toggle {
    display: inline-flex;
  }
}

@media (min-width: 1025px) {
  .mobile-drawer {
    display: none !important;
  }
}
