/* ==========================================================================
   MAGNET4WATER NAV COMPONENT — PREMIUM FINAL
   Robust, fully scoped, compact one-column dropdowns.
   ========================================================================== */

/* === STICKY-NAV PREREQUISITE ============================================
   Many docs/platform pages set `overflow-x: hidden` on <html>/<body>
   (via the `overflow` shorthand) to suppress a horizontal scrollbar.
   That ALSO turns those elements into scroll containers, which silently
   disables `position: sticky` on the nav inside them — the nav scrolls
   away. Switching the horizontal clipping to `overflow-x: clip` still
   prevents sideways scrolling but does NOT create a scroll container, so
   sticky works again. Vertical scrolling is untouched. */
html:not(#__never__),
html:not(#__never__) body:not(#__never__) {
  overflow-x: clip !important;
}

#m4w-nav-root,
#m4w-nav-root * {
  box-sizing: border-box;
}

#m4w-nav-root {
  position: relative;
  z-index: 10000;
  width: 100%;
  font-family: "DM Sans", "IBM Plex Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* === STICKY NAV (single source of truth) =================================
   Pin the nav to the top on every page that loads this file. Some external
   /docs/platform pages carry an INLINED copy of an older nav-override block
   (html body … {width/min-height …}) that sets no position, so nothing
   pinned the nav and it scrolled away. This rule matches that same
   `html body` specificity AND uses !important so it wins over those inlined
   blocks — without enumerating per page.

   The homepage immersive hero pins the nav itself with
   `position:fixed !important` on `body.m4w-nav-over-hero #m4w-nav-root`
   (in index.html). We EXCLUDE that state here so the hero overlay is
   untouched; only non-hero pages get sticky. */
html body:not(.m4w-nav-over-hero) #m4w-nav-root,
html body:not(.m4w-nav-over-hero) #m4w-nav[data-m4w-nav],
html body:not(.m4w-nav-over-hero) [data-m4w-nav] {
  position: sticky !important;
  top: 0 !important;
  z-index: 10000 !important;
}

#m4w-nav-root a,
#m4w-nav-root button {
  font-family: inherit;
}

#m4w-nav-root a {
  text-decoration: none;
}

/* -------------------------
   GLOBAL NAV ROW
------------------------- */
#m4w-nav-root .m4w-nav {
  width: 100%;
  height: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid rgba(148,163,184,.18);
  backdrop-filter: blur(12px);
}

#m4w-nav-root .m4w-nav-wrap {
  width: 100%;
  max-width: 1320px;
  height: 64px;
  min-height: 64px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 28px;
  flex-wrap: nowrap !important;
}

#m4w-nav-root .m4w-brand {
  flex: 0 0 auto;
  height: 64px;
  display: inline-flex;
  align-items: center;
  color: #0e7490;
  font-size: 15.5px;
  line-height: 1;
  font-weight: 950;
  letter-spacing: .055em;
  text-transform: uppercase;
  white-space: nowrap;
}

#m4w-nav-root .m4w-nav-links {
  flex: 0 1 auto;
  margin-left: auto;
  height: 64px;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end;
  gap: 22px;
  flex-wrap: nowrap !important;
  white-space: nowrap;
  overflow: visible;
}

#m4w-nav-root .m4w-dropdown {
  position: relative;
  height: 64px;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

/* Reset button styling — tabs are text, not buttons */
#m4w-nav-root .m4w-nav-link {
  appearance: none !important;
  -webkit-appearance: none !important;
  border: 0 !important;
  outline: 0;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 !important;

  height: 64px;
  display: inline-flex;
  align-items: center;
  color: #263449;
  font-size: 14.5px;
  line-height: 1;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .075em;
  cursor: pointer;
  white-space: nowrap;
  transition: color .16s ease, transform .16s ease;
}

#m4w-nav-root a.m4w-nav-link {
  text-decoration: none;
}

#m4w-nav-root .m4w-nav-link:hover,
#m4w-nav-root .m4w-dropdown.open > .m4w-nav-link {
  color: #0e7490;
  transform: translateY(-1px);
}

/* -------------------------
   DROPDOWN PANELS
------------------------- */
#m4w-nav-root .m4w-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 258px;
  min-width: 258px;
  max-width: 258px;
  padding: 7px;
  display: block !important;
  border-radius: 14px;
  background: rgba(255,255,255,.985);
  border: 1px solid rgba(148,163,184,.22);
  box-shadow: 0 16px 42px rgba(15,23,42,.14);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px) scale(.985);
  transition: opacity .16s ease, transform .16s ease, visibility .16s ease;
  z-index: 10001;
}

/* Keep right-side dropdowns on-screen */
#m4w-nav-root .m4w-dropdown:nth-last-child(-n+2) .m4w-dropdown-menu {
  left: auto;
  right: 0;
}

#m4w-nav-root .m4w-dropdown.open > .m4w-dropdown-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Optional divider item */
#m4w-nav-root .m4w-menu-divider {
  height: 1px;
  margin: 5px 4px;
  background: rgba(148,163,184,.18);
}

/* Menu items */
#m4w-nav-root .m4w-dropdown-item {
  width: 100%;
  border-radius: 9px;
  margin: 0;
  color: #1f2d3d;
}

#m4w-nav-root .m4w-dropdown-item + .m4w-dropdown-item {
  margin-top: 2px;
}

#m4w-nav-root a.m4w-dropdown-item {
  display: block;
  padding: 7px 9px;
  line-height: 1.15;
  transition: background .14s ease, color .14s ease;
}

#m4w-nav-root a.m4w-dropdown-item:hover {
  background: linear-gradient(135deg, rgba(14,116,144,.07), rgba(37,99,235,.045));
}

#m4w-nav-root .m4w-dropdown-item strong {
  display: block;
  color: #1f2d3d;
  font-size: 11.5px;
  line-height: 1.1;
  font-weight: 950;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#m4w-nav-root .m4w-dropdown-item span {
  display: block;
  margin-top: 2px;
  color: #667085;
  font-size: 10.7px;
  line-height: 1.15;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Higher-priority top item in Docs */
#m4w-nav-root .m4w-dropdown-item.m4w-featured {
  background: rgba(14,116,144,.055);
}

#m4w-nav-root .m4w-dropdown-item.m4w-featured:hover {
  background: rgba(14,116,144,.09);
}

/* Platforms: dual-action row */
#m4w-nav-root .m4w-dropdown-item.m4w-dual {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 8px;
  padding: 6px 6px 6px 9px;
  transition: background .14s ease;
}

#m4w-nav-root .m4w-dropdown-item.m4w-dual:hover {
  background: linear-gradient(135deg, rgba(14,116,144,.075), rgba(37,99,235,.045));
}

#m4w-nav-root .m4w-item-main {
  min-width: 0;
  display: block;
  color: inherit;
  line-height: 1.1;
}

#m4w-nav-root .m4w-item-main strong,
#m4w-nav-root .m4w-item-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#m4w-nav-root .m4w-item-launch {
  justify-self: end;
  align-self: center;
  min-width: 64px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-left: 1px solid rgba(148,163,184,.30);
  border-radius: 999px;
  color: #0e7490;
  background: rgba(14,116,144,.04);
  font-size: 10px;
  line-height: 1;
  font-weight: 950;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background .14s ease, color .14s ease, transform .14s ease;
}

#m4w-nav-root .m4w-item-launch:hover {
  background: rgba(14,116,144,.12);
  color: #075985;
  transform: translateX(1px);
}

/* -------------------------
   LOCAL PLATFORM ROW
------------------------- */
#m4w-nav-root .m4w-platform-nav {
  width: 100%;
  height: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  background: #f8fafc;
  border-bottom: 1px solid rgba(148,163,184,.14);
}

#m4w-nav-root .m4w-platform-wrap {
  width: 100%;
  max-width: 1320px;
  height: 24px;
  min-height: 24px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end;
  gap: 13px;
  flex-wrap: nowrap !important;
  overflow: hidden;
}

#m4w-nav-root .m4w-platform-label {
  flex: 0 0 auto;
  color: #0e7490;
  font-size: 10.5px;
  line-height: 1;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: .12em;
  white-space: nowrap;
}

#m4w-nav-root .m4w-platform-label::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 12px;
  margin-left: 12px;
  vertical-align: -2px;
  background: rgba(148,163,184,.45);
}

#m4w-nav-root .m4w-platform-links {
  display: flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-wrap: nowrap !important;
  overflow-x: auto;
  scrollbar-width: none;
}

#m4w-nav-root .m4w-platform-links::-webkit-scrollbar {
  display: none;
}

#m4w-nav-root .m4w-platform-links a {
  flex: 0 0 auto;
  color: #475569;
  font-size: 10.8px;
  line-height: 1;
  font-weight: 750;
  white-space: nowrap;
  transition: color .14s ease;
}

#m4w-nav-root .m4w-platform-links a:hover {
  color: #0e7490;
}

/* -------------------------
   RESPONSIVE
------------------------- */
@media (max-width: 860px) {
  #m4w-nav-root .m4w-nav {
    height: auto;
    min-height: 46px;
  }

  #m4w-nav-root .m4w-nav-wrap {
    height: auto;
    min-height: 46px;
    padding: 8px 18px;
    gap: 10px;
    flex-wrap: wrap !important;
  }

  #m4w-nav-root .m4w-nav-links {
    width: 100%;
    height: auto;
    justify-content: flex-start;
    gap: 14px;
    flex-wrap: wrap !important;
  }

  #m4w-nav-root .m4w-dropdown {
    height: 30px;
  }

  #m4w-nav-root .m4w-nav-link {
    height: 30px;
    font-size: 12.5px;
  }

  #m4w-nav-root .m4w-dropdown-menu {
    left: 0;
    right: auto;
    width: min(258px, calc(100vw - 36px));
    min-width: min(258px, calc(100vw - 36px));
    max-width: min(258px, calc(100vw - 36px));
  }

  #m4w-nav-root .m4w-platform-wrap {
    justify-content: flex-start;
    padding: 0 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #m4w-nav-root *,
  #m4w-nav-root *::before,
  #m4w-nav-root *::after {
    transition: none !important;
    transform: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   SINGLE SOURCE OF TRUTH — NAV HEIGHT LOCK  (2026-05-29)
   ───────────────────────────────────────────────────────────────────────
   Every page must render the SAME 64px nav (the "agriculture" look),
   regardless of what else the page loads. Pages were drifting to 40 / 65 /
   72 / 99px due to four different causes (page box-sizing, an explicit
   height:72 on one page, 28px header padding on the homepage, content-box
   padding). This block overrides ALL of them:

     • high specificity (html body #m4w-nav-root …) + !important beats
       page-level rules, even !important ones at lower specificity
     • explicit height + min + max pins the row exactly to 64
     • padding-top/bottom:0 neutralises the homepage's 14px+14px padding
     • box-sizing:border-box makes it independent of the page's box model

   Desktop only (≥861px). Mobile (≤860px) keeps its own auto-height wrap.
   UNIFIED: every page — including the homepage in both immersive states — is
   pinned to 64. (The dark→white switch timing must therefore NOT depend on
   navHeight; that is handled in index.html's scroll script by comparing the
   hero to a fixed point, not to navHeight — see that file.)
   ═══════════════════════════════════════════════════════════════════════ */
@media (min-width: 861px) {
  html body #m4w-nav-root .m4w-nav,
  html body #m4w-nav-root header.m4w-nav {
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    box-sizing: border-box !important;
  }
  html body #m4w-nav-root .m4w-nav-wrap {
    height: 64px !important;
    min-height: 64px !important;
    max-height: 64px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    box-sizing: border-box !important;
  }
  html body #m4w-nav-root .m4w-brand,
  html body #m4w-nav-root .m4w-nav-links,
  html body #m4w-nav-root .m4w-dropdown,
  html body #m4w-nav-root .m4w-nav-link:not(.m4w-signup-btn):not(.m4w-launch-btn) {
    height: 64px !important;
  }
  /* Pill buttons (Sign Up / Launch) must NOT stretch to the 64px row — they
     size to their own content (padding) and centre vertically in the row.
     Without this they inherit the 64px nav-link height and look too tall. */
  html body #m4w-nav-root .m4w-nav-link.m4w-signup-btn,
  html body #m4w-nav-root .m4w-nav-link.m4w-launch-btn {
    height: auto !important;
    min-height: 0 !important;
    align-self: center !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   SINGLE SOURCE OF TRUTH — NAV WIDTH (BOX TO 1200) — EXTERNAL PAGES  (2026-05-29)
   ───────────────────────────────────────────────────────────────────────
   Every page (homepage included) boxes the nav to the 1200px page column and
   centres it. This lives HERE (the one file every page loads) so it can't
   drift — change 1200 in ONE place to change it site-wide.

   WHY THE :not(#__a__)… HACK: the homepage's inline CSS locks #m4w-nav-root
   to width:100vw with a high-specificity selector (≈4 IDs) + !important. A
   plain rule can't beat it, which is why the homepage kept reverting to
   full-width. The five :not(#never) clauses raise THIS rule's specificity
   above each page's own width rules. ONLY the immersive over-hero state (dark
   nav over the hero) is excluded, so it stays full-width edge to edge — do NOT
   touch the hero. EVERY other state boxes to 1200: external pages AND the
   homepage's scrolled light nav (over-content). That keeps the light nav 1200
   on all pages, the hero full-width.
   (#__a__…#__e__ are IDs that never exist, so they don't change what matches.)
   ═══════════════════════════════════════════════════════════════════════ */
html body:not(.m4w-nav-over-hero) #m4w-nav:not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__),
html body:not(.m4w-nav-over-hero) [data-m4w-nav]:not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__),
html body:not(.m4w-nav-over-hero) #m4w-nav-root:not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__),
html body:not(.m4w-nav-over-hero) #m4w-nav-root .m4w-nav:not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__),
html body:not(.m4w-nav-over-hero) header.m4w-nav:not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__) {
  width: 100% !important;
  max-width: 1200px !important;
  left: 0 !important;
  right: 0 !important;
  margin-left: auto !important;
  margin-right: auto !important;
  transform: none !important;
}

/* ───────────────────────────────────────────────────────────────────────
   (Immersive dark band removed 2026-05-29.)
   It caused a black flash on homepage load: the page ships with
   m4w-nav-over-hero in the body markup, so the dark band painted instantly,
   then the page's JS settled to m4w-nav-over-content (white nav) and the band
   faded out — that gap was the flash. The homepage rests as a white nav on a
   light background, so the boxed-1200 gutters simply show the light page
   background; no dark band is needed. Removing it eliminates the flash.
   ─────────────────────────────────────────────────────────────────────── */

/* ═══════════════════════════════════════════════════════════════════════
   SINGLE SOURCE OF TRUTH — EXTERNAL PAGE BACKGROUND  (2026-05-29)
   ───────────────────────────────────────────────────────────────────────
   On external pages, confine the blue page card (#dceaf2) to the 1200px
   column and make the area beyond it (the gutter) off-white (#f5f9fb), so
   the blue no longer spans the full viewport. This mirrors the agriculture
   page's own rule (main{max-width:1200;background:#dceaf2;overflow:hidden})
   — now applied to ALL external pages from this one file.

   Used to live in m4w-shared-overrides.css, which only some pages loaded —
   that's why the blue kept going full-viewport on pages that didn't load it.
   Lives HERE now (the file every page loads) so it can't drift.

   HOMEPAGE SAFE: targets <main> that is NOT #m4w-main, and .m4w-doc-standalone.
   The homepage's <main id="m4w-main"> matches neither, so its hero/background
   are untouched. The :not(#__never__) clauses only raise specificity so this
   wins over each page's own background; they never change what matches.
   Colours: change #dceaf2 (card) / #f5f9fb (gutter) HERE to retune site-wide.
   ═══════════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════════════
   ★ FINAL SAY — PAGE WIDTH ENFORCEMENT (MUST REMAIN THE LAST BLOCK) ★
   ───────────────────────────────────────────────────────────────────────
   One rule, every external page, no per-page wrapper knowledge required.

   "External page" = any page WITHOUT the homepage's #m4w-main element. That
   signal is universal: only the homepage has a real <main id="m4w-main">; the
   string "m4w-main.css" in other pages is just the stylesheet name and does
   NOT match :has(#m4w-main). So the homepage is always excluded and untouched.

   THREE guarantees, in order:
   1. GUTTER  — the body is forced off-white, so no page's own full-viewport
      blue body can ever span the screen, whatever its markup.
   2. WIDTH   — every top-level content block (anything that is a direct child
      of body and is NOT the nav / header / footer / script / style) is clamped
      to max-width:1200 and centred. This is wrapper-NAME-agnostic: it catches
      <main>, .m4w-doc-standalone, #page, or any future wrapper automatically.
   3. CARD    — the blue page colour (#dceaf2) is painted on those same content
      blocks, so the blue is the 1200 card and the gutter beyond it is off-white.

   To retune site-wide, change 1200 / #dceaf2 / #f5f9fb HERE — nowhere else.
   This block is intentionally LAST so nothing downstream can override it.
   ═══════════════════════════════════════════════════════════════════════ */

/* 1. GUTTER: external body is off-white */
html body:not(:has(#m4w-main)) {
  background: #f5f9fb !important;
}

/* 2 + 3. WIDTH + CARD: clamp & colour every top-level content block.
   Excludes the nav, header bar, footer, scripts and styles by tag/id. */
html body:not(:has(#m4w-main)) > *:not(#m4w-nav):not(#m4w-nav-root):not(header):not(footer):not(script):not(style):not(noscript):not([id*="nav"]):not(.topbar):not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__) {
  width: 100% !important;
  max-width: 1200px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  background: #dceaf2 !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}

/* Also catch the named doc wrappers if they sit nested rather than as a direct
   child of body (belt-and-braces; same 1200 blue card). */
html body:not(:has(#m4w-main)) .m4w-doc-standalone:not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__),
html body:not(:has(#m4w-main)) #page:not(#__a__):not(#__b__):not(#__c__):not(#__d__):not(#__e__) {
  width: 100% !important;
  max-width: 1200px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  background: #dceaf2 !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}


/* ═══════════════════════════════════════════════════════════════════════
   SINGLE SOURCE OF TRUTH — SECONDARY IN-PAGE NAV BAR → BOX TO 1200
   ───────────────────────────────────────────────────────────────────────
   Some doc pages (e.g. the StormNET/ConduitNET Cost Model) render a SECOND
   sticky bar of section-jump anchor links. On the deployed pages this bar is
   markup:  <header class="top"> … </header>  (a sticky <header>, full-viewport
   width by default). Older copies used class "topbar" / ".topbar-in", so we
   match BOTH names. To stay CONSISTENT WITH THE MAIN NAV ABOVE — which boxes
   the whole bar to 1200 and centres it — cap the whole secondary bar to 1200
   too, centred. Scoped to a STICKY <header> so the generic ".top" class can't
   accidentally box unrelated elements. Change 1200 here to move both bars. */
html body header.top,
html body header.topbar,
html body .topbar {
  width: 100% !important;
  max-width: 1200px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  box-sizing: border-box !important;
  /* Pinned just under the main nav (which is sticky at z-index 10000). The
     page's own rule left this bar at z-index ~10, so page content with a
     higher z-index scrolled OVER it — looking like it vanished on scroll.
     Raise it above page content but below the main nav + its dropdowns. */
  z-index: 9990 !important;
}
/* Inner content wrappers (whatever they're named) align to the same 1200. */
html body header.top > *,
html body header.topbar .topbar-in,
html body .topbar .topbar-in {
  max-width: 1200px !important;
  margin-left: auto !important;
  margin-right: auto !important;
}
