/* ======================================================================
   Rally Mega Store — Desktop header & megamenu v3
   Loaded globally from _partials/head.tpl (media: min-width 992px).
   Fixes the submenu overflow, unifies the dark/orange identity and adds
   a usable sticky bar (logo + search + cart stay reachable).
   ====================================================================== */

:root {
  --rms-h-ink: #ffffff;
  --rms-h-bg: #111315;
  --rms-h-bg-soft: #17191c;
  --rms-h-line: rgba(255, 255, 255, .1);
  --rms-h-accent: #fc4c01;
  --rms-h-accent-soft: rgba(252, 76, 1, .14);
  --rms-h-muted: #a9aeb1;
}

/* ----------------------------------------------------------------------
   1. Submenu geometry — the actual bug fix
   The panel used to be `position:absolute; width:100%` with `left:auto`,
   so it started under its own tab and ran 500px past the viewport,
   clipping the third column. It is now pinned to the header container.
   ---------------------------------------------------------------------- */
@media (min-width: 992px) {
  #desktop-header .col-header-menu { position: static; }
  #iqitmegamenu-wrapper,
  #iqitmegamenu-wrapper .container-iqitmegamenu,
  #iqitmegamenu-horizontal,
  #cbp-hrmenu,
  #cbp-hrmenu > ul,
  #cbp-hrmenu > ul > li { position: static; }

  /* The panel anchors on #desktop-header-container (position:relative). */
  #desktop-header .cbp-hrmenu .cbp-hrsub {
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    top: 100%;
  }

  /* Sticky state: the wrapper becomes the positioned ancestor. */
  #iqitmegamenu-wrapper.stuck { position: fixed; }
  #iqitmegamenu-wrapper.stuck .cbp-hrsub { top: 100%; }

  /* ------------------------------------------------------------------
     2. Panel surface
     ------------------------------------------------------------------ */
  #desktop-header .cbp-hrmenu .cbp-hrsub-inner {
    background: linear-gradient(180deg, #17191c 0%, #101214 100%);
    border: 0;
    border-top: 2px solid var(--rms-h-accent);
    box-shadow: 0 26px 60px rgba(0, 0, 0, .55);
    padding: 0;
  }
  /* Warehouse adds a 20px bottom margin on the last row of the panel. */
  #desktop-header .cbp-hrmenu .cbp-hrsub-inner > .row:last-child,
  #desktop-header .cbp-hrmenu .iqitmegamenu-submenu-container > .row:last-child { margin-bottom: 0; }
  #desktop-header .cbp-hrmenu .cbp-menu-column,
  #desktop-header .cbp-hrmenu .cbp-menu-column-inner { padding-bottom: 0; }
  #desktop-header .cbp-hrmenu .cbp-hrsub-inner > .container,
  #desktop-header .cbp-hrmenu .iqitmegamenu-submenu-container {
    margin: 0 auto;
    max-width: 1440px;
    padding-left: 24px;
    padding-right: 24px;
    width: 100%;
  }

  /* Entry motion — the module toggles .cbp-hropen on the tab. */
  #desktop-header .cbp-hrmenu .cbp-hrsub-inner {
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity .18s ease, transform .22s cubic-bezier(.16, 1, .3, 1);
  }
  #desktop-header .cbp-hrmenu .cbp-hropen .cbp-hrsub-inner,
  #desktop-header .cbp-hrmenu li:hover > .cbp-hrsub > .cbp-hrsub-inner {
    opacity: 1;
    transform: translateY(0);
  }

  /* ------------------------------------------------------------------
     3. Category tiles inside the panel
     ------------------------------------------------------------------ */
  #desktop-header .jj-sub-menu {
    padding: 20px 0 22px;
  }
  /* The three source <ul> columns are flattened into one grid so every tile
     shares the same row height instead of stretching to fill its column. */
  #desktop-header .jj-sub-menu-grid {
    align-items: start;
    display: grid;
    gap: 10px 14px;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    padding: 0;
  }
  #desktop-header .jj-sub-menu-column {
    align-content: start;
    display: grid;
    gap: 10px;
    grid-auto-rows: 58px;
    margin: 0;
    padding: 0;
  }
  #desktop-header .jj-sub-menu-item,
  #desktop-header #sub-menu-produits .jj-sub-menu-item {
    background: rgba(255, 255, 255, .045);
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.2;
    margin: 0;
    padding: 0;
    transition: background-color .16s ease, border-color .16s ease, transform .16s ease;
  }
  #desktop-header .jj-sub-menu-item a {
    align-items: center;
    color: #fff !important;
    display: flex;
    font-weight: 600;
    gap: 12px;
    letter-spacing: .01em;
    height: 100%;
    padding: 10px 16px;
    text-decoration: none;
  }
  #desktop-header .jj-sub-menu-item .sub_cat_thumb {
    filter: brightness(0) invert(1);
    flex: 0 0 34px;
    height: 34px;
    margin: 0;
    object-fit: contain;
    opacity: .82;
    transition: opacity .16s ease, filter .16s ease;
    width: 34px;
  }
  #desktop-header .jj-sub-menu-item:hover,
  #desktop-header .jj-sub-menu-item:focus-within {
    background: rgba(252, 76, 1, .12);
    border-color: rgba(252, 76, 1, .55);
    transform: translateY(-2px);
  }
  #desktop-header .jj-sub-menu-item:hover a,
  #desktop-header .jj-sub-menu-item:focus-within a { color: #fff !important; }
  #desktop-header .jj-sub-menu-item:hover .sub_cat_thumb { opacity: 1; }
  #desktop-header .jj-sub-menu-item a:focus-visible { border-radius: 10px; outline: 2px solid var(--rms-h-accent); outline-offset: 2px; }

  /* Native megamenu category links (non-HTML columns) share the tile look. */
  /* Even vertical rhythm: Warehouse spaces the bootstrap columns, the tiles
     carry the spacing instead so every row lands on the same grid. */
  #desktop-header .cbp-hrmenu .cbp-menu-column { margin-bottom: 0; }
  #desktop-header .cbp-hrmenu .cbp-categories-row { margin-bottom: 0; }
  #desktop-header .cbp-menu-column-inner .cbp-category-link-w {
    background-color: rgba(255, 255, 255, .045) !important;
    border: 1px solid rgba(255, 255, 255, .09) !important;
    border-radius: 10px !important;
    font-size: 14px !important;
    line-height: 48px !important;
    margin-bottom: 10px !important;
    padding-left: 16px !important;
    transition: background-color .16s ease, border-color .16s ease;
  }
  #desktop-header .cbp-menu-column-inner .cbp-category-link-w:hover {
    background-color: rgba(252, 76, 1, .12) !important;
    border-color: rgba(252, 76, 1, .55) !important;
  }

  /* ------------------------------------------------------------------
     4. Brands panel — logo grid on a light surface
     ------------------------------------------------------------------ */
  /* Keep the dark panel; the logos read as bright chips against it. */
  #desktop-header .cbp-manufacturers {
    display: grid !important;
    gap: 8px;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    list-style: none;
    margin: 0 !important;
    max-height: min(58vh, 460px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 6px 22px 0 !important;
  }
  #desktop-header .cbp-manufacturers > li {
    flex: none !important;
    margin: 0 !important;
    max-width: none !important;
    padding: 0 !important;
    width: auto !important;
  }
  #desktop-header .cbp-manufacturers > li > a {
    align-items: center;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 8px;
    display: flex !important;
    height: 62px;
    justify-content: center;
    padding: 8px;
    transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
    width: 100% !important;
  }
  #desktop-header .cbp-manufacturers > li > a:hover {
    border-color: var(--rms-h-accent);
    box-shadow: 0 10px 22px rgba(0, 0, 0, .35);
    transform: translateY(-2px);
  }
  #desktop-header .cbp-manufacturers img {
    height: auto !important;
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
    width: auto !important;
  }
  #desktop-header #cbp-hrmenu-tab-3 .cbp-menu-column-inner { position: relative; }
  #desktop-header #cbp-hrmenu-tab-3 .cbp-menu-column-inner::after {
    background: linear-gradient(180deg, rgba(16, 18, 20, 0), #101214 90%);
    bottom: 0;
    content: "";
    height: 42px;
    left: 0;
    pointer-events: none;
    position: absolute;
    right: 0;
  }
  #desktop-header .cbp-manufacturers::-webkit-scrollbar { width: 8px; }
  #desktop-header .cbp-manufacturers::-webkit-scrollbar-track { background: rgba(255, 255, 255, .05); border-radius: 8px; }
  #desktop-header .cbp-manufacturers::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .22); border-radius: 8px; }

  /* ------------------------------------------------------------------
     5. Top-level links — clearer affordance
     ------------------------------------------------------------------ */
  #desktop-header .cbp-hrmenu > ul > li > a.nav-link {
    position: relative;
    transition: color .16s ease;
  }
  #desktop-header .cbp-hrmenu > ul > li > a.nav-link::after {
    background: var(--rms-h-accent);
    border-radius: 2px;
    bottom: 6px;
    content: "";
    height: 2px;
    left: 50%;
    position: absolute;
    transform: translateX(-50%) scaleX(0);
    transform-origin: center;
    transition: transform .2s cubic-bezier(.16, 1, .3, 1);
    width: calc(100% - 32px);
  }
  #desktop-header .cbp-hrmenu > ul > li:hover > a.nav-link::after,
  #desktop-header .cbp-hrmenu > ul > li.cbp-hropen > a.nav-link::after { transform: translateX(-50%) scaleX(1); }
  /* Warehouse paints the open tab with a light background; keep it dark and
     let the orange underline carry the state instead. */
  #desktop-header .cbp-hrmenu > ul > li.cbp-hropen > a.nav-link,
  #desktop-header .cbp-hrmenu > ul > li:hover > a.nav-link {
    background: transparent !important;
    color: #fff !important;
  }
  #desktop-header .cbp-hrmenu > ul > li.cbp-hropen > a.nav-link .cbp-tab-title,
  #desktop-header .cbp-hrmenu > ul > li:hover > a.nav-link .cbp-tab-title { color: #fff !important; }
  #desktop-header .cbp-hrmenu .cbp-submenu-aindicator { transition: transform .2s ease; }
  #desktop-header .cbp-hrmenu > ul > li:hover .cbp-submenu-aindicator,
  #desktop-header .cbp-hrmenu > ul > li.cbp-hropen .cbp-submenu-aindicator { transform: rotate(180deg); }
  #desktop-header .cbp-hrmenu > ul > li > a.nav-link:focus-visible { outline: 2px solid var(--rms-h-accent); outline-offset: -4px; }

  /* ------------------------------------------------------------------
     6. Header action buttons (search / account / cart)
     ------------------------------------------------------------------ */
  #desktop-header .col-header-right .row > div > a,
  #desktop-header .col-header-right .row > div > button,
  #desktop-header #header-search-btn > a,
  #desktop-header #header-search-btn > button {
    border-radius: 8px;
    transition: background-color .16s ease, color .16s ease;
  }
  #desktop-header .col-header-right a:hover,
  #desktop-header .col-header-right button:hover { background-color: var(--rms-h-accent-soft); }
  #desktop-header .col-header-right .cart-products-count {
    background: var(--rms-h-accent);
    border-radius: 999px;
    color: #fff;
    font-weight: 800;
  }

  /* ------------------------------------------------------------------
     7. Sticky bar — logo + actions cloned in by header-rms-v3.js
     ------------------------------------------------------------------ */
  #iqitmegamenu-wrapper.stuck {
    background: rgba(15, 17, 19, .96) !important;
    backdrop-filter: saturate(140%) blur(8px);
    border-bottom: 1px solid rgba(252, 76, 1, .3);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  }
  #iqitmegamenu-wrapper.stuck .container-iqitmegamenu {
    align-items: center;
    display: flex;
    gap: 18px;
    max-width: 1440px;
    min-height: 56px;
  }
  #iqitmegamenu-wrapper.stuck #cbp-hrmenu > ul { justify-content: center; }
  #iqitmegamenu-wrapper.stuck #iqitmegamenu-horizontal { flex: 1 1 auto; min-width: 0; }

  .rms-stuck-logo {
    align-items: center;
    display: none;
    flex: 0 0 auto;
    line-height: 0;
    order: -1;
  }
  #iqitmegamenu-wrapper.stuck .rms-stuck-logo { display: flex; }
  .rms-stuck-logo img { height: auto; max-height: 24px; width: auto; }

  .rms-stuck-actions {
    align-items: center;
    display: none;
    flex: 0 0 auto;
    gap: 4px;
    order: 3;
  }
  #iqitmegamenu-wrapper.stuck .rms-stuck-actions { display: flex; }
  .rms-stuck-actions button {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    height: 38px;
    justify-content: center;
    padding: 0;
    position: relative;
    transition: background-color .16s ease, color .16s ease;
    width: 38px;
  }
  .rms-stuck-actions button:hover { background: var(--rms-h-accent-soft); color: var(--rms-h-accent); }
  .rms-stuck-actions button:focus-visible { outline: 2px solid var(--rms-h-accent); outline-offset: 2px; }
  .rms-stuck-actions .fa { font-size: 17px; }
  .rms-stuck-actions .rms-stuck-count {
    background: var(--rms-h-accent);
    border-radius: 999px;
    color: #fff;
    font-family: Arial, sans-serif;
    font-size: 10px;
    font-weight: 800;
    line-height: 16px;
    min-width: 16px;
    padding: 0 3px;
    position: absolute;
    right: -2px;
    text-align: center;
    top: 0;
  }
  .rms-stuck-count:empty,
  .rms-stuck-count[data-empty="1"] { display: none; }

  /* "See every brand" link appended by header-rms-v3.js */
  .rms-mm-allbrands {
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, .12);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin: 0;
    padding: 12px 0 16px;
    position: relative;
    z-index: 1;
  }
  .rms-mm-allbrands a {
    align-items: center;
    color: #fff !important;
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    gap: 8px;
    letter-spacing: .1em;
    text-decoration: none;
    text-transform: uppercase;
  }
  .rms-mm-allbrands a::after {
    background: var(--rms-h-accent);
    content: "";
    display: block;
    height: 2px;
    transition: width .2s ease;
    width: 22px;
  }
  .rms-mm-allbrands a:hover { color: var(--rms-h-accent) !important; }
  .rms-mm-allbrands a:hover::after { width: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  #desktop-header .cbp-hrmenu .cbp-hrsub-inner,
  #desktop-header .jj-sub-menu-item,
  #desktop-header .cbp-hrmenu > ul > li > a.nav-link::after { transition: none !important; }
}
