/**
 * Walters Construction FL — Header Component
 *
 * Fixed-position site header with desktop dropdown navigation and
 * mobile hamburger overlay. Depends on styles/variables.css for brand tokens.
 *
 * Component-specific variables are declared here so the header can be
 * updated in isolation without touching the global design token file.
 */

/* ─────────────────────────────────────────────────────────────────────────────
   HEADER VARIABLES
   ───────────────────────────────────────────────────────────────────────────── */
:root {
  --header-height: 80px;
  --header-height-mobile: 64px;
  --header-bg: #ffffff;
  --header-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  --header-z-index: 1000;
  --color-walters-gold: #D4A84B;
  --nav-link-color: var(--color-primary, #02245e);
  --nav-link-hover-color: #D4A84B;
  --dropdown-bg: #ffffff;
  --dropdown-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  --transition-standard: 0.3s ease;
  --transition-fast: 0.15s ease;
}

/* ─────────────────────────────────────────────────────────────────────────────
   SCROLL PADDING — offsets anchor targets below the fixed header
   ───────────────────────────────────────────────────────────────────────────── */
html {
  scroll-padding-top: var(--header-height-mobile);
}

@media (min-width: 768px) {
  html {
    scroll-padding-top: var(--header-height);
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   HEADER CONTAINER
   ───────────────────────────────────────────────────────────────────────────── */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height-mobile);
  background-color: var(--header-bg);
  z-index: var(--header-z-index);
  transition: box-shadow var(--transition-standard);
}

/* Shadow appears only after the user scrolls down */
.site-header.is-scrolled {
  box-shadow: var(--header-shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 100%;
}

/* ─────────────────────────────────────────────────────────────────────────────
   LOGO
   ───────────────────────────────────────────────────────────────────────────── */
.header-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
  line-height: 0;
}

.header-logo img {
  height: 48px;
  width: auto;
  display: block;
}

/* ─────────────────────────────────────────────────────────────────────────────
   DESKTOP NAVIGATION — hidden on mobile, shown at 768px+
   ───────────────────────────────────────────────────────────────────────────── */
.main-nav {
  display: none;
}

.nav-list {
  display: flex;
  align-items: center;
  gap: 2rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  position: relative;
}

.nav-item > a,
.nav-item > .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--nav-link-color);
  text-decoration: none;
  font-family: var(--font-family-body, system-ui, sans-serif);
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 0.5rem 0;
  transition: color var(--transition-fast);
  white-space: nowrap;
}

.nav-item > a:hover,
.nav-item > a:focus-visible,
.nav-item--has-dropdown:hover > a,
.nav-item--has-dropdown:focus-within > a {
  color: var(--nav-link-hover-color);
  outline: none;
}

.nav-item > a:focus-visible {
  outline: 2px solid var(--color-walters-gold, #D4A84B);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   DROPDOWN CHEVRON ICON
   ───────────────────────────────────────────────────────────────────────────── */
.dropdown-chevron {
  display: inline-block;
  width: 10px;
  height: 6px;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.nav-item--has-dropdown:hover .dropdown-chevron,
.nav-item--has-dropdown:focus-within .dropdown-chevron {
  transform: rotate(180deg);
}

/* ─────────────────────────────────────────────────────────────────────────────
   DROPDOWN MENUS
   ───────────────────────────────────────────────────────────────────────────── */
.nav-item--has-dropdown {
  /* Bridge gap between nav item and dropdown so hover doesn't break */
  padding-bottom: 8px;
  margin-bottom: -8px;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0px);
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  min-width: 190px;
  background: var(--dropdown-bg);
  border-radius: 6px;
  box-shadow: var(--dropdown-shadow);
  padding: 0.375rem 0;
  list-style: none;
  margin: 0;
  /* Hidden by default */
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast),
    visibility var(--transition-fast);
  pointer-events: none;
  z-index: calc(var(--header-z-index) + 1);
}

/* Show on hover or keyboard focus-within */
.nav-item--has-dropdown:hover .dropdown-menu,
.nav-item--has-dropdown:focus-within .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.dropdown-menu li {
  list-style: none;
}

.dropdown-menu a {
  display: block;
  padding: 0.625rem 1.25rem;
  color: var(--nav-link-color);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 400;
  white-space: nowrap;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.dropdown-menu a:hover,
.dropdown-menu a:focus-visible {
  background-color: #f5f5f5;
  color: var(--nav-link-hover-color);
}

.dropdown-menu a:focus-visible {
  outline: 2px solid var(--color-walters-gold, #D4A84B);
  outline-offset: -2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   MOBILE MENU TOGGLE BUTTON
   ───────────────────────────────────────────────────────────────────────────── */
.mobile-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Minimum 44x44 touch target */
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--nav-link-color);
  border-radius: 4px;
  flex-shrink: 0;
}

.mobile-menu-toggle:focus-visible {
  outline: 2px solid var(--color-walters-gold, #D4A84B);
  outline-offset: 2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   HAMBURGER ICON — three lines that animate to × when open
   ───────────────────────────────────────────────────────────────────────────── */
.hamburger-icon {
  display: block;
  position: relative;
  width: 22px;
  height: 2px;
  background-color: currentColor;
  border-radius: 2px;
  transition: background-color var(--transition-standard);
}

.hamburger-icon::before,
.hamburger-icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: currentColor;
  border-radius: 2px;
  transition: transform var(--transition-standard), top var(--transition-standard);
}

.hamburger-icon::before { top: -7px; }
.hamburger-icon::after  { top:  7px; }

/* Transform to × when menu is open */
.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon {
  background-color: transparent;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon::before {
  top: 0;
  transform: rotate(45deg);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon::after {
  top: 0;
  transform: rotate(-45deg);
}

/* ─────────────────────────────────────────────────────────────────────────────
   MOBILE NAVIGATION OVERLAY
   ───────────────────────────────────────────────────────────────────────────── */
.mobile-nav-overlay {
  position: fixed;
  top: var(--header-height-mobile);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: calc(var(--header-z-index) - 1);
  visibility: hidden;
  pointer-events: none;
}

.mobile-nav-overlay.is-open {
  visibility: visible;
  pointer-events: auto;
}

/* Semi-transparent backdrop */
.mobile-nav-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity var(--transition-standard);
}

.mobile-nav-overlay.is-open .mobile-nav-backdrop {
  opacity: 1;
}

/* Slide-in navigation panel */
.mobile-nav {
  position: absolute;
  top: 0;
  right: 0;
  /* Clamp width: 320px or 85% of viewport */
  width: min(320px, 85vw);
  height: 100%;
  background-color: var(--header-bg);
  transform: translateX(100%);
  transition: transform var(--transition-standard);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-nav-overlay.is-open .mobile-nav {
  transform: translateX(0);
}

/* ─────────────────────────────────────────────────────────────────────────────
   MOBILE NAVIGATION LIST
   ───────────────────────────────────────────────────────────────────────────── */
.mobile-nav-list {
  list-style: none;
  margin: 0;
  padding: 1rem 0 2rem;
}

/* Divider line between top items */
.mobile-nav-item + .mobile-nav-item {
  border-top: 1px solid #f0f0f0;
}

/* Direct link items */
.mobile-nav-item > a {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.875rem 1.5rem;
  color: var(--nav-link-color);
  text-decoration: none;
  font-size: 1.0625rem;
  font-weight: 500;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.mobile-nav-item > a:hover,
.mobile-nav-item > a:focus-visible {
  background-color: #f5f5f5;
  color: var(--nav-link-hover-color);
}

.mobile-nav-item > a:focus-visible {
  outline: 2px solid var(--color-walters-gold, #D4A84B);
  outline-offset: -2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   MOBILE ACCORDION — expandable sub-menus
   ───────────────────────────────────────────────────────────────────────────── */
.accordion-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.875rem 1.5rem;
  color: var(--nav-link-color);
  font-size: 1.0625rem;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.accordion-toggle:hover,
.accordion-toggle:focus-visible {
  background-color: #f5f5f5;
  color: var(--nav-link-hover-color);
}

.accordion-toggle:focus-visible {
  outline: 2px solid var(--color-walters-gold, #D4A84B);
  outline-offset: -2px;
}

.accordion-chevron {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform var(--transition-standard);
}

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

/* Sub-menu content — height animated via max-height */
.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-standard);
  list-style: none;
  margin: 0;
  padding: 0;
  background-color: #fafafa;
}

.accordion-content.is-expanded {
  /* Set by JS to the scrollHeight value */
  max-height: 400px;
}

.accordion-content a {
  display: block;
  padding: 0.75rem 1.5rem 0.75rem 2.25rem;
  color: var(--nav-link-color);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 400;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.accordion-content a:hover,
.accordion-content a:focus-visible {
  color: var(--nav-link-hover-color);
  background-color: #f0f0f0;
}

.accordion-content a:focus-visible {
  outline: 2px solid var(--color-walters-gold, #D4A84B);
  outline-offset: -2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   MOBILE CTA — optional contact info in mobile nav footer
   ───────────────────────────────────────────────────────────────────────────── */
.mobile-nav-cta {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  margin-top: 0.5rem;
}

.mobile-nav-cta a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--nav-link-color);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9375rem;
}

.mobile-nav-cta a:hover {
  color: var(--nav-link-hover-color);
}

/* ─────────────────────────────────────────────────────────────────────────────
   DESKTOP BREAKPOINT — 768px and above
   ───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .site-header {
    height: var(--header-height);
  }

  .header-inner {
    padding: 0 1.5rem;
  }

  .header-logo img {
    height: 56px;
  }

  /* Show desktop nav */
  .main-nav {
    display: block;
  }

  /* Hide hamburger */
  .mobile-menu-toggle {
    display: none;
  }

  /* Hide mobile overlay on desktop */
  .mobile-nav-overlay {
    display: none;
  }
}

@media (min-width: 1024px) {
  .header-inner {
    padding: 0 2rem;
  }

  .nav-list {
    gap: 2.5rem;
  }
}
