/**
 * Template Studio mega menu: structural SKELETON only.
 *
 * Split of responsibilities: this file owns layout, positioning and the
 * open/close mechanics, drawing every color, radius and duration from the
 * template's --ec-* tokens so any Studio template themes it automatically.
 * Template SKINS (each template's layout.css, "Megamenu skin" section)
 * restyle the same classes with theme character. WAM load order between
 * this file and a template's layout.css is not guaranteed, so selectors
 * here stay at single-class specificity: a skin rule at the same
 * specificity wins by source order when loaded after, and by nothing else.
 *
 * Containing block and stacking constraints:
 * - .ts-mega positions absolutely against .ts-header, so a non-sticky
 *   header must be position:relative (sticky headers already establish
 *   the containing block).
 * - z-index 960 sits above page content but below the cart drawer and
 *   off-canvas nav overlays.
 */

/* Absolute anchor for the panels; sticky headers are already positioned. */
.ts-header:not(.is-sticky) { position: relative; }

/* A mega item replaces the native mod_menu dropdown outright. */
.ts-header__nav li.ts-has-mega > ul.mod-menu__sub { display: none !important; }

/* -------------------------------------------------------------------- *
 * Toggle button (injected by megamenu.js after the item's anchor)
 * -------------------------------------------------------------------- */

.ts-mega-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin-left: 2px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    border-radius: 6px;
    transition: transform var(--ec-dur-1) var(--ec-ease), background var(--ec-dur-1) var(--ec-ease);
}

.ts-mega-toggle:hover { background: var(--ec-surface-2); }

.ts-mega-toggle svg {
    width: 14px;
    height: 14px;
    transition: transform var(--ec-dur-2) var(--ec-ease);
}

li.is-mega-open > .ts-mega-toggle svg { transform: rotate(180deg); }

/* -------------------------------------------------------------------- *
 * Nav item icons (prepended into the item anchor by megamenu.js)
 * -------------------------------------------------------------------- */

.ts-nav-icon {
    display: inline-flex;
    align-items: center;
    margin-inline-end: 7px;
}

.ts-nav-icon svg {
    width: 16px;
    height: 16px;
}

@media (max-width: 899.98px) {
    .ts-nav-icon svg {
        width: 18px;
        height: 18px;
    }
}

/* -------------------------------------------------------------------- *
 * Panel
 * -------------------------------------------------------------------- */

.ts-mega {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 960;
    background: var(--ec-surface);
    border-top: 1px solid var(--ec-border);
    border-bottom: 1px solid var(--ec-border);
    box-shadow: var(--ec-shadow);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity var(--ec-dur-2) var(--ec-ease), transform var(--ec-dur-2) var(--ec-ease),
                visibility 0s linear var(--ec-dur-2);
}

.ts-mega.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition-delay: 0s;
}

/* Pre-boot / no-JS state; megamenu.js removes the attribute once wired. */
.ts-mega[hidden] { display: none; }

/* Container width variant: a floating card centered under the header. */
.ts-mega[data-width="container"] {
    left: 50%;
    right: auto;
    width: min(var(--ec-cw), calc(100% - 2 * var(--ec-gut)));
    transform: translate(-50%, -6px);
    border: 1px solid var(--ec-border);
    border-radius: var(--ec-radius);
}

.ts-mega[data-width="container"].is-open { transform: translate(-50%, 0); }

/* -------------------------------------------------------------------- *
 * Grid
 * -------------------------------------------------------------------- */

.ts-mega__inner {
    display: grid;
    grid-template-columns: repeat(var(--ts-mega-cols, 3), minmax(0, 1fr));
    gap: clamp(24px, 3vw, 44px);
    max-width: var(--ec-cw);
    margin-inline: auto;
    padding: 30px var(--ec-gut) 34px;
}

/* minmax(0,1fr) + min-width:0 keep full-bleed media from overflowing. */
.ts-mega__col {
    grid-column: span var(--ts-mega-span, 1);
    min-width: 0;
}

/* -------------------------------------------------------------------- *
 * Block defaults (token-styled; template skins override by order)
 * -------------------------------------------------------------------- */

.ts-mega__title {
    margin: 0 0 14px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ec-fg-2);
}

.ts-mega__links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.ts-mega__links a {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    padding: 7px 10px;
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
}

.ts-mega__links a:hover { background: var(--ec-surface-2); }

.ts-mega__badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--ec-accent-soft);
    color: var(--ec-accent);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.ts-mega__group {
    margin-top: 14px;
    padding: 7px 10px 2px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ec-fg-2);
}

.ts-mega__cats {
    display: grid;
    /* --ts-mega-tile-cols (default 1) lays the tiles out in N columns so a
       collection list can wrap into a grid; set via the column's `columns`. */
    grid-template-columns: repeat(var(--ts-mega-tile-cols, 1), minmax(0, 1fr));
    grid-auto-rows: auto;
    gap: 6px;
}

.ts-mega__cat {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: calc(var(--ec-radius) / 2);
    color: inherit;
    text-decoration: none;
}

.ts-mega__cat:hover { background: var(--ec-surface-2); }

.ts-mega__cat-img,
.ts-mega__cat-ph {
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: calc(var(--ec-radius) / 2);
    border: 1px solid var(--ec-border);
    object-fit: cover;
}

.ts-mega__cat-ph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--ec-accent-soft);
    color: var(--ec-accent);
    font-family: var(--ec-font-display);
    font-size: 18px;
    font-weight: 600;
}

.ts-mega__cat-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ts-mega__cat-name {
    font-size: 14px;
    font-weight: 600;
}

.ts-mega__cat-count {
    font-size: 12px;
    color: var(--ec-fg-2);
}

.ts-mega__prods {
    display: grid;
    grid-template-columns: repeat(var(--ts-mega-tile-cols, 1), minmax(0, 1fr));
    grid-auto-rows: auto;
    gap: 6px;
}

.ts-mega__prod {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: calc(var(--ec-radius) / 2);
    color: inherit;
    text-decoration: none;
}

.ts-mega__prod:hover { background: var(--ec-surface-2); }

.ts-mega__prod-img,
.ts-mega__prod-ph {
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: calc(var(--ec-radius) / 2);
    border: 1px solid var(--ec-border);
    object-fit: cover;
}

.ts-mega__prod-ph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--ec-accent-soft);
    color: var(--ec-accent);
    font-family: var(--ec-font-display);
    font-size: 17px;
    font-weight: 600;
}

.ts-mega__prod-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ts-mega__prod-name {
    font-size: 14px;
    font-weight: 600;
}

.ts-mega__prod-price {
    font-size: 13px;
    font-weight: 600;
}

.ts-mega__banner {
    position: relative;
    display: flex;
    align-items: flex-end;
    min-height: 200px;
    border-radius: var(--ec-radius);
    overflow: hidden;
    color: #fff;
    text-decoration: none;
}

.ts-mega__banner-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ts-mega__banner-copy {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    padding: 44px 18px 16px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
    color: #fff;
}

.ts-mega__banner-eyebrow {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    opacity: 0.85;
}

.ts-mega__banner-title {
    font-family: var(--ec-font-display);
    font-size: 19px;
    font-weight: 600;
}

.ts-mega__html {
    font-size: 14px;
    color: var(--ec-fg-2);
}

/* .ts-mega__col--module gets no default chrome: the module owns its look. */

/* -------------------------------------------------------------------- *
 * Mobile: the panel moves into its nav item as an accordion
 * -------------------------------------------------------------------- */

@media (max-width: 899.98px) {
    .ts-mega {
        position: static;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: none;
        display: none;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    .ts-mega.is-open { display: block; }

    .ts-mega[data-width="container"] {
        left: auto;
        width: auto;
        transform: none;
        /* The desktop container variant's 0,2,0 border rule outranks the
           0,1,0 reset above, so clear it again at equal specificity. */
        border: 0;
        border-radius: 0;
    }

    .ts-mega__inner {
        display: flex;
        flex-direction: column;
        gap: 18px;
        padding: 6px 0 14px 12px;
        max-width: none;
    }

    .ts-mega__banner { min-height: 150px; }

    .ts-mega-toggle {
        width: 44px;
        height: 34px;
        margin-left: auto;
    }

    .ts-header__nav li.ts-has-mega {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
    }

    .ts-header__nav li.ts-has-mega > a { flex: 1; }

    .ts-header__nav li.ts-has-mega > .ts-mega { flex-basis: 100%; }

    /* On mobile the panel relocates INTO .ts-header__nav, where every
       template's drawer rules (.ts-header__nav a at 0,1,1 and stronger
       mobile variants) clobber the block anchors regardless of load
       order. Re-assert the block layout nav-scoped at 0,2,x. */
    .ts-header__nav a.ts-mega__cat,
    .ts-header__nav a.ts-mega__prod {
        display: flex;
        align-items: center;
        padding: 8px 10px;
    }

    .ts-header__nav a.ts-mega__banner {
        display: flex;
        align-items: flex-end;
        padding: 0;
    }

    .ts-header__nav .ts-mega__links a {
        display: block;
        padding: 7px 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ts-mega,
    .ts-mega-toggle svg { transition: none; }
}
