/* Header mega menu (2026-09-27; reworked 2026-10-07, client point 4)
   Desktop: a card under its category link, as wide as its content, hanging
   from the link's left edge (right edge on the Arabic site) and kept inside
   the header row. mega-menu.js opens it (.is-open), places it and picks its
   shape: a plain list when no sub-category has sub-categories of its own
   (.mega-menu--list), otherwise a column per sub-category that has them
   (.mega-menu--grid), with the ones that have none stacked as a short list
   beside them (.mega-menu--mixed). Without the script, hover and keyboard
   focus open it.
   Phones: the same tree as an indented list, opened by the +/− button beside
   the link. Built from the shared $navCategories tree, so hidden categories
   never appear. */

.header-nav {
  position: relative;                      /* the panel anchors to this bar */
}

.nav-item {
  position: relative;                      /* the panel anchors to its own link */
  display: flex;
  align-items: center;
  min-width: 0;
}

.nav-item__row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

/* The +/− button is a phone control; desktop uses hover and keyboard focus. */
.nav-item__toggle {
  display: none;
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #1a1a1a;
  cursor: pointer;
  /* no double-tap-zoom gesture on this control: without it a second tap in
     quick succession is swallowed as part of a double tap and never opens
     or closes the list. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(225, 25, 35, 0.12);
}

.nav-item__plus,
.nav-item__plus::before {
  content: "";
  display: block;
  width: 13px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.nav-item__plus::before {
  transform: rotate(90deg);
  transition: transform 0.25s ease;
}

.nav-item__toggle[aria-expanded="true"] .nav-item__plus::before {
  transform: rotate(0deg);                 /* + becomes − */
}

.nav-item__toggle:focus-visible {
  outline: 2px solid var(--brand-red);
  outline-offset: 2px;
}

.mega-menu__inner {
  width: 100%;
  padding: 1.15rem 1.35rem 1.25rem;
  box-sizing: border-box;
}

.mega-menu__cols {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mega-menu__col {
  min-width: 0;
}

.header-nav .primary-nav .mega-menu__parent {
  display: block;
  white-space: normal;                     /* header.css forces nowrap + padding on nav links */
  padding: 0;
  margin-bottom: 0.45rem;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  line-height: 1.3;
  color: #1a1a1a;
  text-decoration: none;
}

/* :hover and :focus-visible in rules of their own: a browser without
   :focus-visible (Safari before 15.4) drops the whole rule it appears in */
.header-nav .primary-nav .mega-menu__parent:hover {
  color: var(--brand-red);
}

.header-nav .primary-nav .mega-menu__parent:focus-visible {
  color: var(--brand-red);
}

.mega-menu__list {
  margin: 0;
  padding: 0.15rem 0 0;
  list-style: none;
}

.header-nav .primary-nav .mega-menu__list a {
  display: block;
  padding: 0.17rem 0;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.38;
  color: #5f5b56;
  text-decoration: none;
  white-space: normal;
  transition: color 0.18s ease;
}

.header-nav .primary-nav .mega-menu__list a:hover {
  color: var(--brand-red);
}

.header-nav .primary-nav .mega-menu__list a:focus-visible {
  color: var(--brand-red);
}

/* header.css draws a full-width red bar under every nav link (a::after);
   inside the panel that bar spanned the whole column on hover. */
.header-nav .primary-nav .mega-menu a::after {
  content: none;
}

.header-nav .primary-nav .mega-menu__all {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1.05rem;
  padding: 0.85rem 0 0;
  border-top: 1px solid #f0ede9;
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--brand-red);
  text-decoration: none;
}

.header-nav .primary-nav .mega-menu__all:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.header-nav .primary-nav .mega-menu__all:focus-visible {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Desktop: a compact card under its own link ──────────────────── */
@media (min-width: 1101px) {
  .mega-menu {
    position: absolute;
    top: calc(100% - 0.35rem);             /* overlaps the link: no gap to cross */
    /* Set by mega-menu.js: --mega-shift how far the panel slides from the
       link's left edge (its right edge in Arabic) to stay inside the header
       row when the link sits near an end, --mega-max-w the row's width,
       --mega-max-h the room left below the bar. An offset, not a translate,
       so every browser keeps the panel inside the row. */
    left: var(--mega-shift, 0px);          /* browsers without logical insets; rtl.css mirrors it */
    inset-inline-start: var(--mega-shift, 0px);
    z-index: 40;
    width: max-content;
    min-width: 14rem;
    max-width: var(--mega-max-w, calc(100vw - 2.5rem));
    background: #fff;
    border: 1px solid #eceae6;
    border-top: 2px solid var(--brand-red);
    border-radius: 3px;
    box-shadow: 0 16px 34px rgba(26, 26, 26, 0.13), 0 2px 6px rgba(26, 26, 26, 0.05);
    opacity: 0;
    visibility: hidden;                    /* also hides it from screen readers */
    pointer-events: none;                  /* a closing panel never catches the pointer */
    transform: translateY(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
  }

  .mega-menu__inner {
    max-height: var(--mega-max-h, calc(100vh - 13rem));
    overflow-y: auto;
  }

  /* Only a panel taller than the room below the bar scrolls inside and keeps
     the wheel to itself (mega-menu.js); over one that fits, the wheel scrolls
     the page. */
  .mega-menu--scroll .mega-menu__inner {
    overscroll-behavior: contain;
  }

  .nav-item--mega.is-open .mega-menu,
  .nav-item--mega:not(.nav-item--js):hover .mega-menu,
  .nav-item--mega:not(.nav-item--js):focus-within .mega-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s;
  }

  /* moving from one category to the next swaps the panels at once */
  .mega-menu.mega-menu--instant {
    transition: none !important;
  }

  /* Columns: one per sub-category, as wide as its content, four to a row.
     Each spans a heading row and a list row shared with its neighbours, so
     the lists start on one line even when a long heading wraps. */
  .mega-menu__cols {
    display: grid;
    grid-template-columns: repeat(var(--mega-cols, 4), auto);
    justify-content: start;
    gap: 0 2.5rem;
  }

  .mega-menu__col {
    max-width: 15rem;
  }

  .mega-menu--grid .mega-menu__col {
    display: grid;
    grid-row: span 2;
    grid-template-rows: subgrid;
    align-content: start;
  }

  .mega-menu--grid:not(.mega-menu--mixed) .mega-menu__col:nth-child(n + 5) {
    margin-top: 1.4rem;                    /* a fifth sub-category starts a second row */
  }

  /* Mixed (mega-menu.js): the sub-categories without a sub-list of their own
     stack up as one short list in the column after the others, eight to a
     column, instead of standing as headings over empty columns. The grid
     has a row per stacked entry; each sub-list runs down from the second row,
     and the last row takes whatever the longest sub-list needs. */
  .mega-menu--mixed .mega-menu__cols {
    grid-auto-flow: column;
    grid-template-rows: var(--mega-rows, auto 1fr);
  }

  .mega-menu--mixed .mega-menu__col {
    grid-row: 1 / -1;
  }

  .mega-menu--mixed .mega-menu__col--leaf {
    display: block;
    grid-row: auto;
    order: 1;                              /* after the columns with sub-lists */
  }

  .header-nav .primary-nav .mega-menu--mixed .mega-menu__parent {
    margin: 0;
    padding: 0.42rem 0;                    /* headings line up with the stacked list */
  }

  @supports (grid-template-rows: subgrid) {
    .mega-menu--mixed .mega-menu__col > .mega-menu__list {
      grid-row: 2 / -1;
    }
  }

  /* a very long sub-list (mega-menu.js, when the row has room) reads as
     two short columns under its heading */
  .mega-menu__col--split {
    max-width: 32rem;
  }

  .mega-menu__col--split .mega-menu__list {
    column-count: 2;
    column-gap: 2rem;
  }

  .mega-menu__col--split .mega-menu__list > li {
    break-inside: avoid;
  }

  /* Plain list: sub-categories with nothing under them, one under another;
     mega-menu.js adds a column past eight */
  .mega-menu--list .mega-menu__cols {
    display: block;
    column-count: var(--mega-cols, 1);
    column-gap: 2.5rem;
  }

  .mega-menu--list .mega-menu__col {
    max-width: none;
    break-inside: avoid;
  }

  .header-nav .primary-nav .mega-menu--list .mega-menu__parent {
    margin: 0;
    padding: 0.42rem 0;
  }

  .header-nav .primary-nav .mega-menu--list .mega-menu__all {
    margin-top: 0.7rem;
    padding-top: 0.8rem;
  }

  /* keep the red underline lit while its panel is open */
  .header-nav .primary-nav .nav-item--mega.is-open > .nav-item__row > a::after,
  .header-nav .primary-nav .nav-item--mega:not(.nav-item--js):hover > .nav-item__row > a::after,
  .header-nav .primary-nav .nav-item--mega:not(.nav-item--js):focus-within > .nav-item__row > a::after {
    transform: scaleX(1);
  }

  .nav-item--mega.is-open > .nav-item__row > a,
  .nav-item--mega:not(.nav-item--js):hover > .nav-item__row > a,
  .nav-item--mega:not(.nav-item--js):focus-within > .nav-item__row > a {
    color: var(--brand-red);
  }
}

/* ── Phones / tablets: an indented list opened by the + button ───── */
@media (max-width: 1100px) {
  .nav-item {
    display: block;
  }

  .nav-item__row {
    justify-content: space-between;
    border-bottom: 1px solid #f2f0ec;
  }

  .nav-item__row a {
    flex: 1 1 auto;
    border-bottom: 0;                      /* the row carries the divider */
  }

  .nav-item__toggle {
    display: inline-flex;
  }

  .mega-menu {
    display: none;
    background: #fff;
    border-bottom: 1px solid #f2f0ec;
  }

  .nav-item--mega.is-open .mega-menu {
    display: block;
  }

  .mega-menu__inner {
    padding: 0.65rem 0 0.8rem;
  }

  .mega-menu__cols {
    /* one column on phones: the multi-column default would make the list
       wider than the screen and push the +/- button off the right edge */
    column-count: 1;
    display: block;
  }

  .mega-menu__col {
    margin-bottom: 0;
  }

  /* A sub-category with nothing under it reads as a plain row */
  .header-nav .primary-nav .mega-menu__col:has(> .mega-menu__parent:only-child) .mega-menu__parent {
    text-transform: none;
    letter-spacing: 0.01em;
    font-size: 0.875rem;
  }

  .mega-menu__col + .mega-menu__col {
    margin-top: 0.55rem;
    padding-top: 0.55rem;
    border-top: 1px solid #efece7;
  }

  .header-nav .primary-nav .mega-menu__parent {
    margin-bottom: 0.25rem;
    padding-left: 0.9rem;
    font-size: 0.75rem;
    min-height: 2rem;
    display: flex;
    align-items: center;
  }

  .mega-menu__list {
    border-top: 0;
    padding-top: 0;
  }

  .header-nav .primary-nav .mega-menu__list a {
    padding: 0.42rem 0 0.42rem 1.9rem;
    font-size: 0.875rem;
    min-height: 2.15rem;
    display: flex;
    align-items: center;
  }

  .header-nav .primary-nav .mega-menu__all {
    width: auto;
    margin: 0.55rem 0 0 0.9rem;
    padding-top: 0.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mega-menu,
  .nav-item__plus::before {
    transition: none !important;
  }
}
