/* =============================================================
   barrio_npm 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 */
  --np-mega-bg: #ffffff;
  --np-mega-text: indianred;
  --np-mega-text-muted: #666666;
  --np-mega-border: #eaeaea;
  --np-popup-bg: #ffffff;
  --np-popup-fg: #1a1a1a;
  --np-popup-fg-muted: #555555;
  --np-popup-hover-bg: #2a2a2a;
  --np-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. */
  --np-news-accent: #006e6d;

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

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

/* =============================================================
   Desktop layout (>= 992px)
   ============================================================= */
@media (min-width: 992px) {
  .np-navbar {
    display: flex;
    align-items: center;
    background: var(--np-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;
  }
  .np-logo {
    flex: 0 0 auto;
    margin-right: 24px;
  }
  .np-logo img {
    height: 54px;
    display: block;
  }
  .np-menu {
    display: flex;
    align-items: stretch;
    flex: 1;
    justify-content: flex-end;
    gap: 18px;
  }
  .np-top-item {
    /* No positioning context here — the dropdown anchors to .np-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. */
  .np-top-row {
    display: flex;
    align-items: flex-start;
    gap: 4px;
  }
  /* Note the .np-navbar prefix: the colour rules need higher specificity
     than the shared .np-navbar a { color: inherit } rule, which is
     (0,1,1). Prefixed selectors are (0,2,1) and win. */
  .np-navbar .np-top-link {
    padding: 18px 4px;
    color: var(--np-mega-text);
    text-transform: uppercase;
    font-weight: 600;
    line-height: 1.15;
  }
  .np-top-title {
    font-size:0.8em;
    display: block;
  }
  .np-top-desc {
    display: block;
    color: var(--np-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. */
  .np-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;
  }
  .np-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 .np-navbar .np-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 .np-top-link padding, .np-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. */
  .np-top-toggle .np-indicator::before {
    content: '+';
    font-size: 22px;
    font-weight: 400;
    line-height: 2;
  }
  .np-top-toggle[aria-expanded="true"] .np-indicator::before {
    content: '×';
    font-size: 24px;
    line-height: 2;
  }

  /* Mega-menu dropdown — full-width, anchored to .np-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. */
  .np-submenu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 0;
    background: var(--np-mega-bg);
    border: 1px solid var(--np-mega-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    padding: 24px;
    z-index: 100;
    display: flex;
    gap: 28px;
  }
  .np-mega-banner {
    flex: 0 0 45%;
    border-right: 1px solid var(--np-mega-border);
    padding-right: 20px;
    background-color: rgba(217, 202, 166, 0.17);
    background-image: url('/themes/custom/barrio_npm/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 */
  }
  .np-mega-banner-title {
    font-size: 1.5em;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 3px;
  }

  .np-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. */

  .np-mega-banner-heading {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--np-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. */
  .np-mega-banner-news {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--np-mega-border);
  }
  /* Both the <h3> and the <a> inside it are coloured; the <a> selector
     ensures the visible link text wins the cascade over .np-navbar a. */
  .np-navbar .np-mega-banner-news .text-news-menu,
  .np-navbar .np-mega-banner-news .text-news-menu a {
    margin: 0 0 4px;
    font-size: 1em;
    font-weight: 500;
    text-transform: none;
    color: var(--np-news-accent);
    line-height: 1.3;
  }
  .np-mega-banner-news a:hover .text-news-menu,
  .np-mega-banner-news .text-news-menu a:hover {
    text-decoration: underline;
  }
  .np-mega-banner-news .text-news-excerpt {
    margin: 0 0 14px;
    font-size: 0.85em;
    color: var(--np-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. */
  .np-mega-banner-news .view-footer,
  .np-mega-banner-news .more-link {
    margin-top: 8px;
  }
  .np-navbar .np-mega-banner-news .view-footer a,
  .np-navbar .np-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(--np-news-accent);
  }
  .np-mega-banner-news .view-footer a::after,
  .np-mega-banner-news .more-link a::after {
    content: ' →';
    margin-left: 2px;
  }
  .np-mega-banner-news .view-footer a:hover,
  .np-mega-banner-news .more-link a:hover {
    text-decoration: underline;
  }
  /* L2 list is the right ~55% of the mega-menu. Each L2 becomes its own
     column header; its L3 children render directly underneath it (no
     hover flyout). The auto-fit grid spreads columns evenly across the
     available width. */
  .np-level-2-list {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: 1.5rem;
    align-content: start;
  }
  .np-l2-item {
    /* No longer a popup-anchor; safe to drop position: relative. */
    position: static;
    display: block;
  }
  /* L2 row reads as a column heading: bottom border under the heading
     separates it visually from its L3 sub-items below. */
  .np-l2-row {
    display: flex;
    align-items: baseline;
    padding: 0 0 0.5rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--np-mega-border);
    gap: 8px;
  }
  .np-navbar .np-l2-link {
    flex: 1;
    color: var(--np-mega-text);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.95rem;
    line-height: 1.2;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .np-l2-title {
    display: block;
  }
  .np-l2-desc {
    display: block;
    text-transform: none;
    font-size: 0.7em;
    font-weight: 400;
    color: var(--np-mega-text-muted);
    line-height: 1.3;
    letter-spacing: 0;
  }
  .np-l2-link:hover .np-l2-title {
    text-decoration: underline;
  }
  /* L2 toggle hidden on desktop — its only role was the flyout trigger,
     which is gone. Mobile drilldown still uses it. */
  .np-l2-toggle {
    display: none;
  }

  /* L3 panel becomes a transparent inline container — no flyout
     positioning, no shadow, no background. Its <ul.np-l3-list> stacks
     vertically directly below its L2 heading. */
  .np-l3-panel {
    position: static;
    min-width: 0;
    background: transparent;
    color: var(--np-popup-fg);
    z-index: auto;
    padding: 0;
    box-shadow: none;
  }
  /* Override the HTML `hidden` attribute on desktop. Mobile JS toggles
     it for drilldown state; on desktop the panel is always rendered.
     !important is required to defeat the higher-priority
     `.np-navbar [hidden] { display: none !important }` rule at the top
     of this file, which the JS-toggled `hidden` attribute would otherwise
     trigger on every L3 panel by default. */
  .np-l3-panel[hidden] {
    display: block !important;
  }
  /* Mobile-only chrome — already hidden by the existing rule below; kept
     here for clarity. */
  .np-l3-back,
  .np-l3-title,
  .np-l3-title-desc {
    display: none;
  }
  .np-l3-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }
  /* L3 links — visually subordinate to L2 (smaller font, muted colour).
     Subtle underline-on-hover affordance instead of the flyout's dark
     reverse hover. */
  .np-navbar .np-l3-link {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0.25rem 0;
    color: var(--np-popup-fg-muted);
    font-size: 0.875em;
    background: transparent;
  }
  .np-navbar .np-l3-link:hover {
    color: var(--np-popup-fg);
    text-decoration: underline;
    background: transparent;
  }
  .np-l3-link-title {
    display: block;
  }
  .np-l3-desc {
    display: block;
    font-size: 0.82em;
    font-weight: 400;
    color: var(--np-popup-fg-muted);
    line-height: 1.3;
  }
  .np-l3-link:hover .np-l3-desc {
    color: var(--np-popup-fg);
  }

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

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

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

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

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

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

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

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