/* ==========================================================================
   GNC SG — Mega Menu (TB Mega Menu)

   Restyles the markup produced by the tb_megamenu module. The module's own
   CSS (Bootstrap 2 grid + default skin + Font Awesome CDN) is stripped in
   gnc_sg_library_info_alter(), so everything the menu needs lives here.

   Markup shape:
     .tb-megamenu
       .tb-megamenu-button            <- mobile toggle (module JS)
       .nav-collapse
         ul.tb-megamenu-nav.level-0
           li.tb-megamenu-item.level-1.dropdown[.open]
             a.dropdown-toggle
             .tb-megamenu-submenu     <- full-width panel
               .mega-dropdown-inner
                 .mega-dropdown-container   (theme override)
                   .mega-menu__label
                   .tb-megamenu-row
                     .tb-megamenu-column.span{1..12}
   ========================================================================== */

.tb-megamenu {
  height: 100%;
}

/*
 * The module's menuResponsive() writes inline `height: 0; overflow: hidden`
 * onto .nav-collapse below 980px so that its own hamburger can toggle it.
 * This theme uses its own header hamburger and drawer instead, so take the
 * wrapper out of the box tree entirely — that neutralises the inline styles
 * without an !important arms race, and lets the menu items become direct
 * flex children of .site-header__nav.
 */
.tb-megamenu > .nav-collapse {
  display: contents;
}

/* --------------------------------------------------------------------------
   Top-level bar
   -------------------------------------------------------------------------- */

.tb-megamenu-nav.level-0 {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  height: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tb-megamenu-item.level-1 {
  display: flex;
  align-items: center;
  height: 100%;
  /* The panel is positioned against .site-header, not against the item. */
  position: static;
}

/*
 * Top-level links. Per the designs these are sentence case (not uppercase)
 * and carry a red underline on hover/focus/open only — there is no persistent
 * active-trail underline.
 */
.tb-megamenu-item.level-1 > a,
.tb-megamenu-item.level-1 > span {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0;
  color: var(--color-primary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  text-transform: none;
  letter-spacing: 0;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  background: none;
  cursor: pointer;
  transition: border-color var(--transition-base);
}

.tb-megamenu-item.level-1 > a:hover,
.tb-megamenu-item.level-1 > a:focus-visible,
.tb-megamenu-item.level-1.open > a {
  border-bottom-color: var(--color-primary);
  text-decoration: none;
}

/* The module can emit a caret span; the designs have no arrows. */
.tb-megamenu .caret {
  display: none;
}

/* --------------------------------------------------------------------------
   Dropdown panel — full viewport width, flush under the header
   -------------------------------------------------------------------------- */

.tb-megamenu-submenu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  background-color: var(--color-white);
  border: 0;
  border-top: 1px solid var(--color-border-light);
  border-radius: 0;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
}

.tb-megamenu-item.level-1.open > .tb-megamenu-submenu {
  display: block;
}

.mega-dropdown-inner {
  width: 100%;
}

/* Aligns panel content with the header's container grid. */
.mega-dropdown-container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-8) var(--container-padding) var(--space-10);
}

/* Panel heading: "SHOP BY GOAL" / "CATEGORIES" / "LEARN". */
.mega-menu__label {
  margin-bottom: var(--space-5);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* --------------------------------------------------------------------------
   Rows and columns — 12-column grid driven by the module's span* classes
   -------------------------------------------------------------------------- */

.tb-megamenu-row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0 var(--space-6);
}

.tb-megamenu-column {
  min-width: 0;
}

.tb-megamenu-column.span1  { grid-column: span 1; }
.tb-megamenu-column.span2  { grid-column: span 2; }
.tb-megamenu-column.span3  { grid-column: span 3; }
.tb-megamenu-column.span4  { grid-column: span 4; }
.tb-megamenu-column.span5  { grid-column: span 5; }
.tb-megamenu-column.span6  { grid-column: span 6; }
.tb-megamenu-column.span7  { grid-column: span 7; }
.tb-megamenu-column.span8  { grid-column: span 8; }
.tb-megamenu-column.span9  { grid-column: span 9; }
.tb-megamenu-column.span10 { grid-column: span 10; }
.tb-megamenu-column.span11 { grid-column: span 11; }
.tb-megamenu-column.span12 { grid-column: span 12; }

/* --------------------------------------------------------------------------
   Second-level links
   -------------------------------------------------------------------------- */

.tb-megamenu-subnav {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tb-megamenu-item.level-2 {
  display: block;
}

.tb-megamenu-item.level-2 > a,
.tb-megamenu-item.level-2 > span {
  display: block;
  padding: var(--space-2) 0;
  color: var(--color-text);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: 1.6;
  text-decoration: none;
  transition: color var(--transition-fast);
}

.tb-megamenu-item.level-2 > a:hover,
.tb-megamenu-item.level-2 > a:focus-visible {
  color: var(--color-primary);
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   Learn panel — "Latest Articles" block column
   -------------------------------------------------------------------------- */

.mega-col--articles .block > h2,
.mega-col--articles .block-title,
.mega-col--articles .tb-block .block-inner h2 {
  margin: 0 0 var(--space-5);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mega-menu__articles-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-6);
}

/* The unformatted-rows wrapper sits between the grid and the cards. */
.mega-menu__articles-grid > .views-row,
.mega-menu__articles-grid .views-view-unformatted {
  display: contents;
}

.mega-col--articles .article-card__image {
  display: block;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* The field template wraps the image in an extra div. */
.mega-col--articles .article-card__image > * {
  display: block;
  height: 100%;
}

.mega-col--articles .article-card__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mega-col--articles .article-card__body {
  padding: var(--space-3) 0 0;
}

/* The designs show title + "Read article" only — no teaser text. */
.mega-col--articles .article-card__excerpt {
  display: none;
}

.mega-col--articles .article-card__title {
  margin: 0 0 var(--space-2);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-bold);
  line-height: 1.35;
}

.mega-col--articles .article-card__title a {
  color: var(--color-text);
  text-decoration: none;
}

.mega-col--articles .article-card__title a:hover {
  color: var(--color-primary);
}

/* --------------------------------------------------------------------------
   Mobile — the panel becomes an inline accordion inside the drawer
   -------------------------------------------------------------------------- */

/* The module's own hamburger is redundant: the theme header has one. */
.tb-megamenu-button {
  display: none;
}

@media (max-width: 767px) {
  .tb-megamenu-nav.level-0 {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    height: auto;
  }

  .tb-megamenu-item.level-1 {
    display: block;
    height: auto;
    border-bottom: 1px solid var(--color-border-light);
  }

  /* Top-level row: label left, chevron right. Regular weight, not bold —
     the drawer rows in menu.png read as body text. */
  .tb-megamenu-item.level-1 > a,
  .tb-megamenu-item.level-1 > span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: 48px;
    height: auto;
    padding: var(--space-3) var(--space-4);
    border-bottom: 0;
    font-weight: var(--font-weight-normal);
    font-size: var(--font-size-base);
    color: var(--color-text);
  }

  /* Chevron, on parents only. "Stores" has no children and no chevron. */
  .tb-megamenu-item.level-1.has-children > a::after,
  .tb-megamenu-item.level-1.has-children > span::after {
    content: '';
    flex: none;
    width: 20px;
    height: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%239E9E9E' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    transition: transform var(--transition-base);
  }

  .tb-megamenu-item.level-1.is-open > a::after,
  .tb-megamenu-item.level-1.is-open > span::after {
    transform: rotate(180deg);
  }

  /* Collapsed by default; JS opens one at a time. */
  .tb-megamenu-submenu {
    position: static;
    width: auto;
    box-shadow: none;
    border-top: 0;
    display: none;
  }

  .tb-megamenu-item.level-1.is-open > .tb-megamenu-submenu {
    display: block;
  }

  /* The child list runs straight from the parent row to the section's closing
     divider — in the mocks the children fill that space exactly, with no
     padding of their own. */
  .mega-dropdown-container {
    padding: 0;
  }

  .mega-menu__label {
    display: none;
  }

  .tb-megamenu-row {
    display: block;
  }

  .tb-megamenu-column {
    grid-column: auto;
  }

  /* Child links: a 32px row, indented to 24px and muted. Measured off
     "Shop by Goal.png", where the eleven children sit on an even 32px rhythm
     (text baselines at y=115, 147, 179 … 435) and start at x=25. */
  .tb-megamenu-item.level-2 > a {
    display: block;
    padding: 6px var(--space-4) 6px var(--space-6);
    font-size: var(--font-size-sm);
    line-height: 20px;
    color: var(--color-text-muted);
    font-weight: var(--font-weight-normal);
  }

  /* No rules between children — the only divider is the one closing the whole
     section, which the level-1 item's own border draws. */
  .tb-megamenu-item.level-2 {
    border: 0;
  }

  .mega-col--articles {
    display: none;
  }
}
