/* =============================================================
   barrio_white main navbar — three-level menu
   Desktop: mega-menu dropdown + level-3 floating popup
   Mobile (<992px): single-open accordion + drill-down to level-3
   ============================================================= */

:root {
  /* Desktop palette */
  --bw-mega-bg: #ffffff;
  --bw-mega-text: indianred;
  --bw-mega-text-muted: #666666;
  --bw-mega-border: #eaeaea;
  --bw-popup-bg: #ffffff;
  --bw-popup-fg: #1a1a1a;
  --bw-popup-fg-muted: #555555;
  --bw-popup-hover-bg: #2a2a2a;
  --bw-popup-hover-fg: #ffffff;

  /* News accent — applied to news titles and the "More news" CTA in the
     mega-menu banner. Distinguishes news links from L2 navigation items. */
  --bw-news-accent: #006e6d;

  /* Mobile palette */
  --bw-mobile-card-bg: #ffffff;
  --bw-mobile-card-fg: #000000;
  --bw-mobile-text-muted: #666666;
  --bw-mobile-card-radius: 12px;
  --bw-mobile-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --bw-mobile-card-gap: 10px;
  --bw-mobile-card-padding-y: 18px;
  --bw-mobile-card-padding-x: 20px;
  --bw-mobile-divider: #eeeeee;
  --bw-mobile-page-bg: #f5f6f8;
}

/* ----- Shared base ----- */
.bw-navbar {
  width: 100%;
  font-family: inherit;
}
.bw-navbar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.bw-navbar a {
  text-decoration: none;
  color: inherit;
}
.bw-navbar button {
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.bw-navbar [hidden] {
  display: none !important;
}
.bw-indicator {
  display: inline-block;
  line-height: 1;
}
.bw-navbar .bw-top-link:focus-visible,
.bw-navbar .bw-l2-link:focus-visible,
.bw-navbar .bw-l3-link:focus-visible,
.bw-navbar button:focus-visible {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
}

/* =============================================================
   Desktop layout (>= 992px)
   ============================================================= */
@media (min-width: 992px) {
  .bw-navbar {
    display: flex;
    align-items: center;
    background: var(--bw-mega-bg);
    padding: 0 20px;
    /* Positioning context for the full-width dropdown — the dropdown
       anchors to the navbar bounds rather than to the parent <li>, so it
       appears in the same place regardless of which top-level item opened
       it. */
    position: relative;
  }
  .bw-logo {
    flex: 0 0 auto;
    margin-right: 24px;
  }
  .bw-logo img {
    height: 54px;
    display: block;
  }
  .bw-menu {
    display: flex;
    align-items: stretch;
    flex: 1;
    justify-content: flex-end;
    gap: 18px;
  }
  .bw-top-item {
    /* No positioning context here — the dropdown anchors to .bw-navbar
       instead so it can span the full navbar width. */
    position: static;
    display: flex;
    align-items: flex-start;
  }
  /* Top-align the row's contents (link and toggle) so the + button lands
     at a consistent Y across primary items regardless of how many lines
     the link spans (a long description that wraps to 2 lines would
     otherwise lower the centre of that row). The toggle's margin-top
     below positions the + glyph at the title's vertical centre. */
  .bw-top-row {
    display: flex;
    align-items: flex-start;
    gap: 4px;
  }
  /* Note the .bw-navbar prefix: the colour rules need higher specificity
     than the shared .bw-navbar a { color: inherit } rule, which is
     (0,1,1). Prefixed selectors are (0,2,1) and win. */
  .bw-navbar .bw-top-link {
    padding: 18px 4px;
    color: var(--bw-mega-text);
    text-transform: uppercase;
    font-weight: 600;
    line-height: 1.15;
  }
  .bw-top-title {
    font-size:0.8em;
    display: block;
  }
  .bw-top-desc {
    display: block;
    color: var(--bw-mega-text-muted);
    font-size: 0.7em;
    font-weight: 400;
    text-transform: uppercase;
    margin-top: 2px;
  }
  /* Toggle button is visually hidden by default and revealed only when
     keyboard-focused. Mouse users open the mega-menu via hover, so the
     +/× button is informational for them; keyboard and screen-reader
     users still get the disclosure control via Tab.

     This is the standard .visually-hidden + :focus-visible pattern
     ("sr-only-focusable"). When focused the button re-enters the row's
     flex flow and reclaims its 28×28 size, causing a small one-step
     layout shift — intentional, it confirms focus has landed on a
     control. Required for WCAG-compliant disclosure widgets on a
     hover-driven mega-menu. */
  .bw-top-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .bw-top-toggle:focus-visible {
    /* Reveal the toggle with its original visible appearance. margin-top
       centres the + glyph on the title text's vertical centre so the
       focused button lands at a consistent Y across primary items.
       Calculation:
         - link padding-top:       18px  (from .bw-navbar .bw-top-link)
         - title line-height:    ~18.4px (0.9em * line-height 1.15)
         - title vertical centre: 18 + 18.4 / 2 = ~27.2px from row top
         - button centre when top-aligned: height / 2 = 14px
         - margin-top to align centres: 27.2 - 14 = ~13.2px → rounded to 12px
       Re-tune if you change .bw-top-link padding, .bw-top-title font-size,
       or the button height. */
    position: static;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 12px 0 0 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
  /* Desktop indicator: + closed, × open. */
  .bw-top-toggle .bw-indicator::before {
    content: '+';
    font-size: 22px;
    font-weight: 400;
    line-height: 2;
  }
  .bw-top-toggle[aria-expanded="true"] .bw-indicator::before {
    content: '×';
    font-size: 24px;
    line-height: 2;
  }

  /* Mega-menu dropdown — full-width, anchored to .bw-navbar so the
     position is identical regardless of which top-level item opened it.
     Banner left, L2 list right; widths split via the existing flex. */
  .bw-submenu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 0;
    background: var(--bw-mega-bg);
    border: 1px solid var(--bw-mega-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    padding: 24px;
    z-index: 100;
    display: flex;
    gap: 28px;
  }
  .bw-mega-banner {
    flex: 0 0 45%;
    border-right: 1px solid var(--bw-mega-border);
    padding-right: 20px;
    background-color: rgba(217, 202, 166, 0.17);
    background-image: url('/themes/custom/barrio_white/images/npm-pattern-white.png');
    background-position: bottom right;   /* anchor the pattern, matches original NPM */
    background-size: contain;            /* or specific px size */
    background-repeat: no-repeat;       /* prevent pattern from repeating */
  }
  .bw-mega-banner-title {
    font-size: 1.5em;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 3px;
  }

  .bw-mega-banner-desc {
    font-size: 1.3em;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 8px;
  }
  /* Brand line as a quiet footer at the bottom of the banner — divider above,
     small uppercase muted text. The dropdown is full-width so this is a
     subtle brand presence rather than a competing element. */

  .bw-mega-banner-heading {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--bw-mega-border);
    font-size: 0.75em;
    line-height: 1.1;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  /* News block inside the banner. Divider above separates from the banner
     header. Titles are deliberately quieter than L2 links so the nav list
     stays the dominant scan target. */
  .bw-mega-banner-news {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--bw-mega-border);
  }
  /* Both the <h3> and the <a> inside it are coloured; the <a> selector
     ensures the visible link text wins the cascade over .bw-navbar a. */
  .bw-navbar .bw-mega-banner-news .text-news-menu,
  .bw-navbar .bw-mega-banner-news .text-news-menu a {
    margin: 0 0 4px;
    font-size: 1em;
    font-weight: 500;
    text-transform: none;
    color: var(--bw-news-accent);
    line-height: 1.3;
  }
  .bw-mega-banner-news a:hover .text-news-menu,
  .bw-mega-banner-news .text-news-menu a:hover {
    text-decoration: underline;
  }
  .bw-mega-banner-news .text-news-excerpt {
    margin: 0 0 14px;
    font-size: 0.85em;
    color: var(--bw-mega-text-muted);
    line-height: 1.4;
  }
  /* CTA at the bottom of the view (typically rendered inside .view-footer
     or as a "more" link). Quieter than a navbar link — uppercase + arrow. */
  .bw-mega-banner-news .view-footer,
  .bw-mega-banner-news .more-link {
    margin-top: 8px;
  }
  .bw-navbar .bw-mega-banner-news .view-footer a,
  .bw-navbar .bw-mega-banner-news .more-link a {
    display: inline-block;
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bw-news-accent);
  }
  .bw-mega-banner-news .view-footer a::after,
  .bw-mega-banner-news .more-link a::after {
    content: ' →';
    margin-left: 2px;
  }
  .bw-mega-banner-news .view-footer a:hover,
  .bw-mega-banner-news .more-link a:hover {
    text-decoration: underline;
  }
  .bw-level-2-list {
    flex: 1;
  }
  .bw-l2-item {
    position: relative;
  }
  .bw-l2-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    gap: 8px;
  }
  .bw-navbar .bw-l2-link {
    flex: 1;
    color: var(--bw-mega-text);
    font-weight: 500;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .bw-l2-title {
    text-transform: capitalize;
    display: block;
  }
  .bw-l2-desc {
    display: block;
    text-transform: capitalize;
    font-size: 0.8em;
    font-weight: 400;
    color: var(--bw-mega-text-muted);
    line-height: 1.3;
  }
  .bw-l2-link:hover .bw-l2-title {
    text-decoration: underline;
  }
  .bw-l2-toggle {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .bw-l2-toggle .bw-indicator::before {
    content: '+';
    font-size: 18px;
  }
  .bw-l2-toggle[aria-expanded="true"] .bw-indicator::before {
    content: '×';
    font-size: 20px;
  }

  /* Level-3 floating popup */
  .bw-l3-panel {
    position: absolute;
    top: 0;
    left: 100%;
    min-width: 260px;
    background: var(--bw-popup-bg);
    color: var(--bw-popup-fg);
    z-index: 110;
    padding: 8px 0;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  }
  .bw-l3-back,
  .bw-l3-title {
    display: none;
  }
  .bw-navbar .bw-l3-link {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 24px;
    color: var(--bw-popup-fg);
    font-size: 0.95em;
  }
  .bw-l3-link-title {
    display: block;
  }
  .bw-l3-desc {
    display: block;
    font-size: 0.82em;
    font-weight: 400;
    color: var(--bw-popup-fg-muted);
    line-height: 1.3;
  }
  .bw-l3-link:hover {
    background: var(--bw-popup-hover-bg);
    color: var(--bw-popup-hover-fg);
  }
  .bw-l3-link:hover .bw-l3-desc {
    color: var(--bw-popup-hover-fg);
  }

  /* Active-trail styling — underline scoped to title only to keep the
     visual tidy when a description is present below. */
  .bw-top-item.is-active-trail > .bw-top-row > .bw-top-link .bw-top-title,
  .bw-l2-item.is-active-trail > .bw-l2-row > .bw-l2-link .bw-l2-title,
  .bw-l3-item.is-active-trail > .bw-l3-link .bw-l3-link-title {
    text-decoration: none;
    color: var(--bw-popup-fg);
  }

  /* Search — desktop renders the form inside a popup triggered by an icon
     button. .bw-search-card is positioned so its descendant popup can
     anchor below it, right-aligned. */
  .bw-search-card {
    margin-left: 16px;
    display: flex;
    align-items: center;
    position: relative;
  }
  .bw-navbar .bw-search-toggle {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--bw-mega-text);
    border-radius: 50%;
  }
  .bw-search-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
  }
  .bw-search-icon {
    display: block;
  }
  .bw-search-popup {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 320px;
    background: var(--bw-mega-bg);
    border: 1px solid var(--bw-mega-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    padding: 16px;
    z-index: 120;
  }
  .bw-search-card.is-open .bw-search-popup {
    display: block;
  }
  .bw-search-popup form,
  .bw-search-popup input[type="search"],
  .bw-search-popup input[type="text"] {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Parent-link row inside the mega-menu is a mobile affordance only — the
     desktop banner already exposes the parent link. Hide here. */
  .bw-l2-item.is-parent-link {
    display: none;
  }
}

/* =============================================================
   Mobile layout (< 992px)
   Single-open accordion cards + drill-down to level-3
   ============================================================= */
@media (max-width: 991.98px) {
  .bw-navbar {
    background: var(--bw-mobile-page-bg);
    padding: 12px 16px 24px;
  }
  .bw-logo {
    display: block;
    text-align: center;
    margin-bottom: 16px;
  }
  .bw-logo img {
    height: 36px;
    display: inline-block;
  }
  .bw-menu {
    display: flex;
    flex-direction: column;
    gap: var(--bw-mobile-card-gap);
  }
  /* Card-style top item */
  .bw-top-item {
    background: var(--bw-mobile-card-bg);
    color: var(--bw-mobile-card-fg);
    border-radius: var(--bw-mobile-card-radius);
    box-shadow: var(--bw-mobile-card-shadow);
    overflow: hidden;
  }
  .bw-top-row {
    display: flex;
    align-items: center;
    padding: var(--bw-mobile-card-padding-y) var(--bw-mobile-card-padding-x);
  }
  .bw-navbar .bw-top-link {
    flex: 1;
    color: var(--bw-mobile-card-fg);
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    line-height: 1.2;
  }
  .bw-top-title {
    display: inline;
  }
  .bw-top-desc {
    display: block;
    font-size: 1em;
    font-weight: 400;
    margin-top: 4px;
  }
  .bw-top-toggle {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
  }
  /* Mobile indicator: + closed, − open. */
  .bw-top-toggle .bw-indicator::before {
    content: '+';
    font-size: 26px;
    font-weight: 300;
    line-height: 1;
  }
  .bw-top-toggle[aria-expanded="true"] .bw-indicator::before {
    content: '−';
  }

  /* Inline submenu (accordion body) */
  .bw-submenu {
    padding: 0 var(--bw-mobile-card-padding-x) var(--bw-mobile-card-padding-y);
  }
  .bw-mega-banner {
    display: none;
  }
  .bw-level-2-list {
    border-top: 1px solid var(--bw-mobile-divider);
  }
  .bw-l2-item + .bw-l2-item {
    border-top: 1px solid var(--bw-mobile-divider);
  }
  /* Parent-link row: visually distinct so the user knows it goes to the
     top-level page itself, not to a child. */
  .bw-l2-item.is-parent-link .bw-l2-link {
    font-weight: 700;
    text-transform: uppercase;
  }
  .bw-l2-row {
    display: flex;
    align-items: center;
    padding: 14px 0;
    gap: 8px;
  }
  .bw-navbar .bw-l2-link {
    flex: 1;
    color: var(--bw-mobile-card-fg);
    font-weight: 500;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .bw-l2-title {
    display: block;
  }
  .bw-l2-desc {
    display: block;
    font-size: 0.85em;
    font-weight: 400;
    color: var(--bw-mobile-text-muted);
    line-height: 1.3;
  }
  .bw-l2-toggle {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /* Mobile L2 toggle: chevron-right to signal drill-down (not collapse). */
  .bw-l2-toggle .bw-indicator::before {
    content: '›';
    font-size: 22px;
    line-height: 1;
  }

  /* Drill-down panel: full-viewport overlay sliding in from the right. */
  .bw-l3-panel {
    position: fixed;
    inset: 0;
    background: var(--bw-mobile-page-bg);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 220ms ease;
    overflow-y: auto;
    padding: 16px 20px 32px;
  }
  .bw-l3-panel.is-active {
    transform: translateX(0);
  }
  .bw-navbar .bw-l3-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 18px;
    padding: 8px 0;
    color: var(--bw-mobile-card-fg);
    font-size: 1em;
  }
  .bw-l3-title {
    margin: 0 0 4px;
    font-size: 1.4em;
    font-weight: 700;
    text-transform: uppercase;
  }
  .bw-l3-title-desc {
    margin: 0 0 16px;
    font-size: 0.9em;
    color: var(--bw-mobile-text-muted);
    line-height: 1.35;
  }
  .bw-l3-list {
    background: var(--bw-mobile-card-bg);
    border-radius: var(--bw-mobile-card-radius);
    box-shadow: var(--bw-mobile-card-shadow);
    overflow: hidden;
  }
  .bw-l3-item + .bw-l3-item {
    border-top: 1px solid var(--bw-mobile-divider);
  }
  .bw-navbar .bw-l3-link {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px var(--bw-mobile-card-padding-x);
    color: var(--bw-mobile-card-fg);
    font-size: 0.95em;
  }
  .bw-l3-link-title {
    display: block;
  }
  .bw-l3-desc {
    display: block;
    font-size: 0.85em;
    font-weight: 400;
    color: var(--bw-mobile-text-muted);
    line-height: 1.3;
  }

  /* Search as final card. The desktop icon-toggle is hidden on mobile and
     the form (wrapped in .bw-search-popup) renders inline as the trailing
     full-width card. */
  .bw-search-card {
    background: var(--bw-mobile-card-bg);
    border-radius: var(--bw-mobile-card-radius);
    box-shadow: var(--bw-mobile-card-shadow);
    padding: var(--bw-mobile-card-padding-y) var(--bw-mobile-card-padding-x);
  }
  .bw-search-toggle {
    display: none;
  }
  .bw-search-popup {
    display: block;
  }

  /* When drilled, lock body scroll behind the overlay. */
  body.bw-drilled {
    overflow: hidden;
  }

  /* Active-trail styling — bolding scoped to title only so descriptions
     remain readable at normal weight. */
  .bw-top-item.is-active-trail > .bw-top-row > .bw-top-link .bw-top-title,
  .bw-l2-item.is-active-trail > .bw-l2-row > .bw-l2-link .bw-l2-title,
  .bw-l3-item.is-active-trail > .bw-l3-link .bw-l3-link-title {
    font-weight: 700;
  }
}
