/* ECS shared nav — one stylesheet, one source of truth.
 * Pairs with nav.html (markup) and nav.js (behavior).
 * Loaded on every page after components.css.
 *
 * Architecture: nav.js replaces #ecs-nav-root with <aside.ecs-utility>
 * + <nav.ecs-nav> as direct body siblings. That makes <body> the
 * containing block for the sticky <nav>, so it pins for the full page. */

/* ---------- Anti-FOUC skeleton ----
 * #ecs-nav-root reserves vertical space before nav.js runs.
 * Two-stop gradient mirrors the rendered chrome (forest then cream).
 * --------------------------------- */
#ecs-nav-root {
  min-height: 125px;  /* utility 52 + nav 72 + border 1 */
  background: linear-gradient(
    to bottom,
    var(--c-emerald-900) 0,
    var(--c-emerald-900) 52px,
    var(--bg-page) 52px,
    var(--bg-page) 125px
  );
}
@media (max-width: 768px) {
  #ecs-nav-root {
    min-height: 60px;  /* utility hidden on mobile */
    background: var(--bg-page);
  }
}

/* Skip link */
.ecs-nav__skip {
  position: absolute;
  left: -9999px;
  top: 0;
}
.ecs-nav__skip:focus {
  left: 0; top: 0;
  z-index: 100;
  padding: var(--space-3) var(--space-4);
  background: var(--c-ink-900);
  color: var(--c-cream-50);
  text-decoration: none;
}

/* ---------- Tier 1 — utility bar ----
 * Dark green ground; owns the brand wordmark (white) and the
 * conversion CTAs (Get in touch / Book an Audit) on the right.
 * Document-flow (static) — scrolls away naturally.
 * Hidden on mobile.
 * ---------------------------------- */
.ecs-utility {
  background: var(--c-emerald-900);
  color: var(--c-cream-50);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.ecs-utility__inner {
  max-width: var(--container-wide);
  margin: 0 auto;
  padding: 0 var(--gutter);
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
}
.ecs-utility__brand {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.35rem, 1.8vw, 1.7rem);
  letter-spacing: -0.012em;
  line-height: 1;
  color: var(--c-cream-50);
  text-decoration: none;
  white-space: nowrap;
  font-variation-settings: "opsz" 60;
  transition: color var(--dur-fast) var(--ease-out);
}
.ecs-utility__brand:hover,
.ecs-utility__brand:focus-visible { color: var(--c-emerald-100); }
.ecs-utility__actions {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}
.ecs-utility__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--c-cream-50);
  text-decoration: none;
  padding: var(--space-2) 0;
  transition: color var(--dur-fast) var(--ease-out);
}
.ecs-utility__item:hover,
.ecs-utility__item:focus-visible { color: var(--c-emerald-100); }
/* Hairline between the two actions so they read as separate affordances */
.ecs-utility__item + .ecs-utility__item {
  border-left: 1px solid rgba(251, 248, 243, 0.25);
  padding-left: var(--space-6);
}
.ecs-utility__icon {
  width: 14px; height: 14px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Tier 2 — main nav (sticky) ----
 * Direct child of <body> after injection. Sticky works because
 * <body> is its containing block and extends the full page.
 * ----------------------------------------- */
.ecs-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-page);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}
body.ecs-nav-stuck .ecs-nav {
  border-bottom-color: var(--border-soft);
  box-shadow: var(--shadow-sm);
}

/* Grid scaffolding — identical on every page.
 * 1fr | auto | 1fr — center column auto-sizes, flanking 1fr columns
 * guarantee the link cluster is mathematically centered regardless
 * of brand-slot width. */
.ecs-nav__inner {
  max-width: var(--container-wide);
  margin: 0 auto;
  padding: var(--space-4) var(--gutter);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-5);
  min-height: 72px;
  transition: min-height var(--dur-base) var(--ease-out),
              padding var(--dur-base) var(--ease-out);
}
body.ecs-nav-stuck .ecs-nav__inner {
  min-height: 56px;
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}

/* ---------- Brand slot — ECS monogram only ----
 * The full wordmark lives in the utility bar. On desktop the
 * monogram is invisible until the nav sticks (the wordmark above
 * is still on screen); it fades in as the utility bar scrolls away.
 * visibility keeps the hidden link out of the accessibility tree
 * and tab order; it flips at the transition boundary.
 * ---------------------------------------------- */
.ecs-nav__brand {
  grid-column: 1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-base) var(--ease-out),
              visibility var(--dur-base) var(--ease-out);
}
body.ecs-nav-stuck .ecs-nav__brand {
  opacity: 1;
  visibility: visible;
}
.ecs-nav__brand-mono {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-md);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--c-emerald-700);
  line-height: 1;
}
/* ---------- Centered links — col 2 ---------- */
.ecs-nav__links {
  grid-column: 2;
  justify-self: center;
  display: flex;
  gap: var(--space-6);
  align-items: center;
}
.ecs-nav__links a {
  position: relative;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--c-ink-900);
  text-decoration: none;
  letter-spacing: 0.01em;
  padding: var(--space-2) 0;
  transition: color var(--dur-fast) var(--ease-out);
}
.ecs-nav__links a::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  bottom: -2px;
  height: 1px;
  background: var(--c-emerald-700);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--dur-base) var(--ease-out);
}
.ecs-nav__links a:hover { color: var(--c-emerald-700); }
.ecs-nav__links a:hover::after { transform: scaleX(0.5); }
.ecs-nav__links a[aria-current="page"] { color: var(--c-emerald-700); }
.ecs-nav__links a[aria-current="page"]::after { transform: scaleX(1); }

/* Phone CTA — desktop hides it (mobile overlay only) */
.ecs-nav__phone { display: none; }

/* ---------- Book an Audit pill (col 3) ----
 * Hidden on desktop — the CTA lives in the utility bar there.
 * Shown on mobile, where the utility bar is gone. Pill styling
 * sits here so the mobile block only flips display.
 * ------------------------------------------ */
.ecs-nav__cta {
  display: none;
  grid-column: 3;
  justify-self: end;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--c-emerald-700);
  color: var(--c-cream-50);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  min-height: 36px;
  transition: background var(--dur-fast) var(--ease-out);
}
.ecs-nav__cta:hover,
.ecs-nav__cta:focus-visible { background: var(--c-emerald-900); }

.ecs-nav__toggle { display: none; }

/* ---------- Mobile (≤768px) ----
 * Utility bar (and the wordmark in it) gone.
 * ECS monogram always visible.
 * Row: hamburger | ECS | Book pill.
 * Must match nav.js matchMedia('(min-width: 769px)').
 * --------------------------------- */
@media (max-width: 768px) {
  .ecs-utility { display: none; }

  .ecs-nav__inner {
    padding: var(--space-3) var(--gutter);
    gap: var(--space-3);
    min-height: 56px;
  }
  body.ecs-nav-stuck .ecs-nav__inner {
    min-height: 56px;
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
  }

  /* Hamburger — col 1.
   * grid-row: 1 on all three row items: the toggle comes after the
   * CTA in DOM order, and auto-placement would push it to row 2. */
  .ecs-nav__toggle {
    display: inline-flex;
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--c-ink-900);
    border-radius: var(--radius-pill);
    color: var(--c-ink-900);
    cursor: pointer;
  }

  /* Brand — col 2: monogram always visible (no utility wordmark here) */
  .ecs-nav__brand {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    opacity: 1;
    visibility: visible;
  }

  /* Book an Audit pill — col 3 (pill styling in base rule above) */
  .ecs-nav__cta {
    display: inline-flex;
    grid-row: 1;
  }

  /* Overlay menu.
   * justify/align-self: stretch override the desktop centering —
   * grid self-alignment applies even to fixed-position children,
   * and "center" would shrink the overlay to content width. */
  .ecs-nav__links {
    display: none;
    position: fixed;
    inset: 0;
    justify-self: stretch;
    align-self: stretch;
    z-index: 60;
    background: var(--bg-page);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    margin: 0;
    padding: calc(56px + var(--space-7)) var(--gutter) var(--space-7);
    overflow-y: auto;
  }
  body.ecs-nav-open .ecs-nav__links { display: flex; }
  body.ecs-nav-open { overflow: hidden; }

  .ecs-nav__links a {
    font-family: var(--font-display);
    font-size: var(--fs-2xl);
    font-weight: 500;
    line-height: 1.1;
    color: var(--c-ink-900);
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
  }
  .ecs-nav__links a::after { display: none; }
  .ecs-nav__links a[aria-current="page"] { color: var(--c-emerald-700); }

  .ecs-nav__phone {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: auto;
    padding-top: var(--space-6) !important;
    border-bottom: none !important;
    font-family: var(--font-body) !important;
    font-size: var(--fs-md) !important;
    font-weight: 600 !important;
    color: var(--c-emerald-700) !important;
    text-decoration: none;
  }
  .ecs-nav__phone svg { width: 22px; height: 22px; flex-shrink: 0; }

  /* Hamburger → X */
  .ecs-nav__bars,
  .ecs-nav__bars::before,
  .ecs-nav__bars::after {
    content: "";
    display: block;
    width: 18px; height: 2px;
    background: currentColor;
    border-radius: 1px;
    transition: transform var(--dur-fast) var(--ease-out),
                opacity var(--dur-fast) var(--ease-out);
  }
  .ecs-nav__bars { position: relative; }
  .ecs-nav__bars::before { position: absolute; top: -6px; left: 0; }
  .ecs-nav__bars::after  { position: absolute; top:  6px; left: 0; }

  /* Keep the full bar row (toggle, monogram, Book pill) above the
     overlay while open so the header stays intact */
  body.ecs-nav-open .ecs-nav__toggle { z-index: 70; }
  body.ecs-nav-open .ecs-nav__brand { position: relative; z-index: 70; }
  body.ecs-nav-open .ecs-nav__cta { position: relative; z-index: 70; }
  body.ecs-nav-open .ecs-nav__bars { background: transparent; }
  body.ecs-nav-open .ecs-nav__bars::before { transform: translateY(6px) rotate(45deg); }
  body.ecs-nav-open .ecs-nav__bars::after  { transform: translateY(-6px) rotate(-45deg); }
}

/* Honor reduced motion: snap, don't crossfade */
@media (prefers-reduced-motion: reduce) {
  .ecs-nav__brand,
  .ecs-nav,
  .ecs-nav__inner { transition: none !important; }
}
