/* ==========================================================================
   Astra theme overrides — THE ONLY FILE ALLOWED TO TARGET ASTRA CLASSES

   Everything here touches .ast-*, .site-*, .entry-* or Astra's menu markup.
   Keeping it isolated means that when a rule fights the theme, there is
   exactly one file to look in.

   Because the child stylesheet is enqueued AFTER the parent, most of these
   need no !important. Where one is genuinely required (Astra ships an inline
   dynamic style block with high specificity), it is commented with why.
   ========================================================================== */

/* --- Content width release ---------------------------------------------
   Old CSS did this with `body.page-id-73` and 12 !important declarations.
   Now it is a body class added by functions.php whenever the template opts
   in, so it works for every review/compare page without editing CSS.
   ------------------------------------------------------------------------ */
.bma-fullwidth .site-content .ast-container {
  max-width: 100%;
  padding-inline: 0;
}

.bma-fullwidth #primary,
.bma-fullwidth .content-area,
.bma-fullwidth .entry-content {
  max-width: none;
  width: 100%;
  margin: 0;
  padding-inline: 0;
  background: transparent;
}

.bma-fullwidth .site-content,
.bma-fullwidth #page {
  background: var(--bma-cream);
}

/* Gutenberg wraps Custom HTML in .wp-block-html; let our own bleed classes
   through it rather than forcing every block full width. */
.bma-fullwidth .entry-content > .wp-block-html { padding: 0; }

/* NOTE: an earlier version hid .entry-header here. That was wrong for Phase 1,
   which must be a visual no-op — it silently removed the post title and byline
   from every review.

   The duplicate title is still worth addressing (the hero already carries its
   own heading, so the page renders two), but hiding an H1 with display:none is
   the wrong fix: it keeps the heading in the DOM where Google discounts it, and
   removes the byline, which is an E-E-A-T signal on review content.

   Decide it properly in Phase 2 — most likely by removing the duplicate from
   the hero markup rather than hiding the theme's real title. */

/* --- Desktop header menu ------------------------------------------------ */
.ast-header-menu > .menu-item > a { color: rgba(255, 255, 255, 0.85); }
.ast-header-menu > .menu-item > a:hover { color: #fff; }

.ast-desktop .main-header-menu .sub-menu .menu-item > .menu-link,
.ast-header-menu .sub-menu .menu-item > a,
.ast-desktop .ast-mega-menu-enabled .sub-menu .menu-item > .menu-link {
  color: var(--bma-navy);
  background: var(--bma-white);
}

.ast-desktop .main-header-menu .sub-menu .menu-item:hover > .menu-link,
.ast-header-menu .sub-menu .menu-item:hover > a {
  color: var(--bma-gold);
  background: #F5EFE0;
}

/* --- Mobile mega menu grid — REMOVED -----------------------------------
   The two-column button grid lived here. The mobile menu now drills down one
   level at a time (see below), so a grid of buttons inside an accordion has
   nothing left to do.

   A copy of these rules also sits in legacy-additional.css with !important on
   every property, and that file loads last. It only bites while a menu item
   still carries the `mega-grid-menu` CSS class — remove the class in
   Appearance → Menus and the old grid stops applying anywhere.
   ------------------------------------------------------------------------ */

/* --- Menu ---------------------------------------------------------------
   Fed by inc/menu.php: the score comes from data/scores.json and the accent
   colour from a small inline block, so the menu cannot drift from the pages
   it links to.

   Desktop and mobile want different shapes from the same menu. Desktop is
   fine as a flat bar — Reviews, Guides, Comparisons, Deals, Quiz — and the
   "Mattresses" wrapper only pushed every dropdown a level deeper until the
   third-level flyouts ran off the right of the screen. Mobile is the opposite:
   43 items need grouping. So the wrapper exists in the menu and is dissolved
   on desktop.
   ------------------------------------------------------------------------ */

.bma-menu-icon {
  flex-shrink: 0;
  margin-right: 11px;
  color: var(--bma-gold);
  vertical-align: -3px;
}

/*
 * On the navy header bar the icons need the lighter gold — #B8860B against
 * #1B2A4A is close enough in value to read as muddy brown, which is why they
 * looked wrong on desktop and right on the white mobile drawer.
 * --bma-gold-light exists in tokens.css for exactly this: gold on dark.
 */
.ast-header-menu > .menu-item > .menu-link .bma-menu-icon,
.ast-header-menu > .menu-item > a .bma-menu-icon,
.main-header-menu > .menu-item > .menu-link .bma-menu-icon {
  color: var(--bma-gold-light);
}

/* Inside a dropdown the background is white again, so the darker gold returns. */
.sub-menu .bma-menu-icon { color: var(--bma-gold); }

.bma-menu-score {
  margin-left: auto;
  padding-left: 8px;
  font-size: 11.5px;
  font-weight: var(--bma-w-body-med);
  color: #8A8375;
  font-variant-numeric: tabular-nums;
}

/* ----- Desktop ---------------------------------------------------------
   The "#" groups are removed in inc/menu.php before Astra renders this menu,
   so the bar is flat and every dropdown behaves as it always has. The
   display:contents version that used to live here made the whole menu
   invisible — see the note in menu.php.
   ------------------------------------------------------------------------ */

@media (min-width: 992px) {
  /*
   * A dropdown was reading as one solid block of text. These give each row an
   * edge to sit on: a hairline between rows, the brand's own colour down the
   * left of a review row, and the score set apart from the name.
   */
  /*
   * !important throughout. Astra ships a dynamic style block in the head that
   * sets borders on submenu links with enough specificity to win, which is why
   * the first attempt drew no lines at all — every dropdown still read as one
   * unbroken block of text.
   */
  .ast-desktop .main-header-menu .sub-menu > li > .menu-link,
  .ast-header-menu .sub-menu > li > a {
    display: flex !important;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #E5DDD0 !important;
    border-left: 3px solid transparent !important;
  }

  .ast-desktop .main-header-menu .sub-menu > li:last-child > .menu-link,
  .ast-header-menu .sub-menu > li:last-child > a {
    border-bottom: 0 !important;
  }

  .ast-desktop .main-header-menu .sub-menu > li.bma-menu-brand > .menu-link,
  .ast-header-menu .sub-menu > li.bma-menu-brand > a {
    border-left-color: var(--bma-menu-accent, transparent) !important;
  }

  /* A flyout is a level of its own, so it gets a rule of its own to sit
     against rather than blending into the panel that opened it. */
  .ast-desktop .main-header-menu .sub-menu .sub-menu {
    border-left: 2px solid var(--bma-gold);
  }

  /*
   * The Reviews dropdown goes two-up. Twelve brands in a single column runs
   * past the bottom of the viewport, so the last few are unreachable without
   * scrolling a menu that closes when the pointer leaves it.
   *
   * :has() rather than a class, because the class would have to go on the <ul>
   * and WordPress's nav_menu_submenu_css_class filter is handed no item to
   * decide from. If :has() is unsupported the dropdown simply stays one column,
   * which is where it is today.
   */
  .ast-desktop .main-header-menu .sub-menu:has(> li.bma-menu-brand),
  .ast-header-menu .sub-menu:has(> li.bma-menu-brand) {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    width: 480px !important;
    max-width: calc(100vw - 40px);
  }

  /* The line down the middle, and no stray line under the last row of each. */
  .ast-desktop .main-header-menu .sub-menu:has(> li.bma-menu-brand) > li:nth-child(odd) > .menu-link,
  .ast-header-menu .sub-menu:has(> li.bma-menu-brand) > li:nth-child(odd) > a {
    border-right: 1px solid #E5DDD0 !important;
  }
}

/* ----- Mobile: one level at a time -------------------------------------- */

@media (max-width: 991px) {
  /*
   * No panel show/hide rules here on purpose. menu.js sets display inline,
   * because a stylesheet rule has to out-specify both Astra and the !important
   * copies in legacy-additional.css — and the first attempt lost that fight,
   * which emptied the menu on every tap.
   *
   * Everything below is deliberately heavy-handed with !important. Menu rules
   * reach this drawer from at least three places outside this file — Astra,
   * legacy-additional.css, and the site's own Additional CSS, which is where
   * the stray "&gt;" before every row comes from. Rather than out-specify each
   * of them one at a time, the drawer states its own appearance outright.
   */

  /*
   * Astra puts two arrows inside every <a>: an .ast-icon on leaf rows and a
   * .dropdown-menu-toggle (role="button") on rows with children. menu.js
   * removes both from the DOM; these rules are the belt to that braces, for the
   * moment before the script runs and for anything Astra re-renders later.
   */
  .bma-drill .menu-link::before { content: none !important; }

  .bma-drill .ast-icon,
  .bma-drill .dropdown-menu-toggle,
  .bma-drill .ast-header-navigation-arrow,
  .bma-drill .ast-menu-toggle {
    display: none !important;
  }

  /* ----- The bar ----- */

  .bma-drill-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 18px;
    background: var(--bma-navy);
    border: 0;
  }

  .bma-drill-bar[hidden] { display: none; }

  .bma-drill-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px 5px 8px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 20px;
    background: none;
    color: var(--bma-gold-light);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
  }

  .bma-drill-title {
    font-family: 'Playfair Display', serif;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
  }

  /* ----- The rows ----- */

  /*
   * One continuous list, not a stack of cards. The card treatment is what made
   * the levels read as unrelated fragments: rounded boxes with gaps between
   * them look like separate things, and at three levels deep nothing said which
   * list you were in.
   */
  .bma-drill .menu-item > .menu-link {
    display: flex !important;
    align-items: center;
    justify-content: flex-start !important;
    gap: 11px;
    padding: 15px 18px !important;
    margin: 0 !important;
    background: transparent !important;
    border: 0 !important;
    border-bottom: 1px solid #EFE9DE !important;
    border-radius: 0 !important;
    font-family: 'DM Sans', sans-serif !important;
    font-size: 14.5px !important;
    font-weight: 500 !important;
    text-align: left !important;
    color: var(--bma-navy) !important;
    /* Every row the same height whether or not it carries an icon — an icon on
       one row and none on the next was making single items look oversized. */
    min-height: 54px !important;
    line-height: 1.35 !important;
  }

  .bma-drill .menu-item > .menu-link:hover,
  .bma-drill .menu-item > .menu-link:focus {
    background: var(--bma-cream) !important;
  }

  .bma-drill .sub-menu {
    background: var(--bma-white) !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
  }

  .bma-drill .sub-menu > li { margin: 0 !important; padding: 0 !important; }

  /* A row that opens a level gets one chevron, right-aligned and quiet. Leaf
     rows get none, so the two are told apart before they are tapped. */
  .bma-drill .menu-item-has-children > .menu-link::after {
    content: "";
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    margin-left: auto;
    border-right: 1.5px solid #C4BCAD;
    border-bottom: 1.5px solid #C4BCAD;
    transform: rotate(-45deg);
  }

  /* ----- Brand rows ----- */

  .bma-drill .bma-menu-brand > .menu-link {
    border-left: 3px solid var(--bma-menu-accent, transparent) !important;
    padding-left: 13px !important;
    padding-right: 12px !important;
  }

  /*
   * Two-up brand panel. menu.js applies both the class and `display: grid` —
   * it has to set display inline, and an inline !important cannot be overruled
   * from here, so a grid rule in this file would never take.
   *
   * The background stays white: an earlier version tinted it the same colour as
   * the row dividers, which made every line between brands disappear.
   */
  .bma-drill .bma-panel-grid {
    grid-template-columns: 1fr 1fr;
    background: var(--bma-white) !important;
  }

  .bma-drill .bma-panel-grid > li { min-width: 0; }

  .bma-drill .bma-panel-grid > li > .menu-link {
    min-height: 60px !important;
    padding-left: 11px !important;
    padding-right: 10px !important;
    font-size: 13.5px !important;
  }

  /* The line down the middle of the two columns. */
  .bma-drill .bma-panel-grid > li:nth-child(odd) > .menu-link {
    border-right: 1px solid #E5DDD0 !important;
  }

  .bma-drill .bma-panel-grid .bma-menu-score { font-size: 12px; }

  .bma-menu-score {
    margin-left: auto;
    font-size: 12.5px;
    font-weight: 400;
    color: #9A9285;
    font-variant-numeric: tabular-nums;
  }

  /* A brand row ends in its score, so the chevron would be a second thing
     competing for the same corner. Brands are leaves anyway. */
  .bma-drill .bma-menu-brand > .menu-link::after { content: none !important; }

  .bma-drill .bma-menu-icon { margin-right: 0; }
}
