/*
 * «Кнопка каталога» (shop.catalog in the header builder, CatalogMenuHook):
 * the button, and its panel as a mega menu, a dropdown or picture tiles.
 * Below 64rem the panel is a full-screen sheet, one level at a time.
 * Colours and radii come from the theme's tokens, so it looks native in any
 * theme.
 */
.shop-cmenu,
.shop-cmenu__panel {
    --cmenu-surface: var(--c-surface, #fff);
    --cmenu-text: var(--c-text, #14171f);
    --cmenu-muted: var(--c-text-muted, #6b7280);
    --cmenu-line: var(--c-border, rgb(20 23 31 / 0.1));
    --cmenu-accent: var(--c-accent, var(--c-primary, #2563eb));
    --cmenu-hover: color-mix(in srgb, var(--cmenu-accent) 9%, var(--cmenu-surface));
    --cmenu-radius: var(--r-md, 12px);
}
.shop-cmenu {
    position: relative;
    display: inline-flex;
}

/* --- the button -------------------------------------------------------------------- */

.shop-cmenu__btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0 1.1rem;
    border: 1.5px solid transparent;
    border-radius: var(--r-pill, 999px);
    font: inherit;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.shop-cmenu__btn--primary { background: var(--cmenu-accent); color: var(--c-on-accent, #fff); }
.shop-cmenu__btn--primary:hover { background: color-mix(in srgb, var(--cmenu-accent) 88%, #000); }
.shop-cmenu__btn--ghost { border-color: currentColor; color: inherit; background: transparent; }
.shop-cmenu__btn--ghost:hover { background: var(--cmenu-hover); color: var(--cmenu-accent); }
.shop-cmenu__btn--plain { padding-inline: 0.5rem; color: inherit; background: transparent; }
.shop-cmenu__btn--plain:hover { color: var(--cmenu-accent); }
.shop-cmenu__btn:focus-visible { outline: 3px solid var(--c-mark, var(--cmenu-accent)); outline-offset: 2px; }

.shop-cmenu__icon { width: 1.15rem; height: 1.15rem; flex: none; fill: currentColor; stroke: none; }
.shop-cmenu__icon--lines,
.shop-cmenu__icon--close { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.shop-cmenu__btn .shop-cmenu__icon--close { display: none; }
.shop-cmenu.is-open .shop-cmenu__btn .shop-cmenu__icon:not(.shop-cmenu__icon--close) { display: none; }
.shop-cmenu.is-open .shop-cmenu__btn .shop-cmenu__icon--close { display: block; }

/* --- the panel ---------------------------------------------------------------------- */

.shop-cmenu__panel {
    position: fixed;
    z-index: 900;
    color: var(--cmenu-text);
    background: var(--cmenu-surface);
    box-shadow: 0 24px 60px -24px rgb(10 12 20 / 0.35), 0 2px 6px rgb(10 12 20 / 0.06);
}
.shop-cmenu__panel[hidden] { display: none; }
.shop-cmenu__panel a { color: inherit; text-decoration: none; }
.shop-cmenu__panel a:hover { color: var(--cmenu-accent); }
.shop-cmenu__panel a:focus-visible,
.shop-cmenu__panel button:focus-visible { outline: 2px solid var(--cmenu-accent); outline-offset: 2px; border-radius: 6px; }
.shop-cmenu__img-ph { display: inline-block; border-radius: 6px; background: color-mix(in srgb, var(--cmenu-accent) 8%, var(--cmenu-surface)); }
.shop-cmenu__count { margin-inline-start: 0.4rem; font-size: 0.78em; font-weight: 500; color: var(--cmenu-muted); }
.shop-cmenu__chev { width: 1rem; height: 1rem; margin-inline-start: auto; flex: none; color: var(--cmenu-muted); }
.shop-cmenu__sheet-head { display: none; }
.shop-cmenu__all {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.9rem 1.5rem;
    border-top: 1px solid var(--cmenu-line);
    font-weight: 600;
    color: var(--cmenu-accent) !important;
}
.shop-cmenu__all .cms-icon { width: 1rem; height: 1rem; }
.shop-cmenu__panel .shop-cmenu__links { margin: 0.35rem 0 0; padding: 0; list-style: none; display: grid; gap: 0.3rem; font-size: 0.92rem; }
.shop-cmenu__links a { color: var(--cmenu-muted); }
.shop-cmenu__more { font-weight: 600; color: var(--cmenu-accent) !important; }

/* Desktop: the mega menu spans the window under the header; the dropdown
   and the tiles hang from the button. */
@media (min-width: 64rem) {
    .shop-cmenu__panel--mega {
        left: 0;
        right: 0;
        top: var(--cmenu-top, 4.5rem);
        max-height: calc(100vh - var(--cmenu-top, 4.5rem) - 1rem);
        overflow: auto;
        border-top: 1px solid var(--cmenu-line);
    }
    .shop-cmenu__panel--tiles { max-height: calc(100vh - var(--cmenu-top, 4.5rem) - 1rem); overflow: auto; }
    .shop-cmenu__panel--dropdown,
    .shop-cmenu__panel--tiles {
        top: var(--cmenu-top, 4.5rem);
        left: var(--cmenu-left, 1rem);
        border-radius: var(--cmenu-radius);
        border: 1px solid var(--cmenu-line);
    }

    /* Mega: the top categories, and the one pointed at in columns. */
    .shop-cmenu__mega {
        display: grid;
        grid-template-columns: minmax(15rem, 18rem) 1fr;
        max-width: var(--w-wide, 82rem);
        margin-inline: auto;
        min-height: 22rem;
    }
    .shop-cmenu__panel .shop-cmenu__roots { margin: 0; padding: 0.75rem; list-style: none; border-inline-end: 1px solid var(--cmenu-line); }
    .shop-cmenu__root-link {
        display: flex;
        align-items: center;
        gap: 0.7rem;
        padding: 0.6rem 0.75rem;
        border-radius: 10px;
        font-weight: 500;
    }
    .shop-cmenu__root.is-active > .shop-cmenu__root-link { background: var(--cmenu-hover); color: var(--cmenu-accent); }
    .shop-cmenu__root-img { width: 2rem; height: 2rem; object-fit: contain; border-radius: 6px; flex: none; }
    .shop-cmenu__panes { padding: 1.5rem 2rem 2rem; }
    .shop-cmenu__pane { display: none; }
    .shop-cmenu__pane.is-active { display: block; }
    .shop-cmenu__pane-head { margin-block-end: 1.25rem; }
    .shop-cmenu__back { display: none; }
    .shop-cmenu__pane-title { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 1.35rem; font-weight: 700; }
    .shop-cmenu__pane-title .cms-icon { width: 1.1rem; height: 1.1rem; }
    .shop-cmenu__cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 1.5rem 2rem; }
    .shop-cmenu__col-title { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; }
    .shop-cmenu__col-img { width: 2.5rem; height: 2.5rem; object-fit: contain; border-radius: 8px; flex: none; }

    /* Dropdown: a column (scrolling when long), the subcategories beside
       the panel — not inside the scrolling list, which would clip them;
       on the left when the button sits by the right edge («is-flip»). */
    .shop-cmenu__panel--dropdown { display: flex; flex-direction: column; }
    .shop-cmenu__panel .shop-cmenu__list {
        width: 17rem;
        max-height: calc(100vh - var(--cmenu-top, 4.5rem) - 4.5rem);
        margin: 0;
        padding: 0.5rem;
        overflow: auto;
        list-style: none;
    }
    .shop-cmenu__item { position: static; }
    .shop-cmenu__item-link { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.75rem; border-radius: 8px; font-weight: 500; }
    .shop-cmenu__item:hover > .shop-cmenu__item-link,
    .shop-cmenu__item:focus-within > .shop-cmenu__item-link { background: var(--cmenu-hover); color: var(--cmenu-accent); }
    .shop-cmenu__panel .shop-cmenu__sub {
        position: absolute;
        top: 0;
        left: calc(100% + 0.4rem);
        max-height: 100%;
        overflow: auto;
        display: none;
        width: 17rem;
        margin: 0;
        padding: 0.5rem;
        list-style: none;
        background: var(--cmenu-surface);
        border: 1px solid var(--cmenu-line);
        border-radius: var(--cmenu-radius);
        box-shadow: 0 24px 60px -24px rgb(10 12 20 / 0.35);
    }
    .shop-cmenu__panel.is-flip .shop-cmenu__sub { left: auto; right: calc(100% + 0.4rem); }
    .shop-cmenu__item:hover > .shop-cmenu__sub,
    .shop-cmenu__item:focus-within > .shop-cmenu__sub { display: block; }
    /* A bridge over the gap, so the pointer reaches the subcategories. */
    .shop-cmenu__item:hover > .shop-cmenu__sub::before { content: ""; position: absolute; inset: 0 100% 0 -0.6rem; }
    .shop-cmenu__panel.is-flip .shop-cmenu__item:hover > .shop-cmenu__sub::before { inset: 0 -0.6rem 0 100%; }
    .shop-cmenu__sub-link,
    .shop-cmenu__sub .shop-cmenu__more { display: block; padding: 0.45rem 0.75rem; border-radius: 8px; }
    .shop-cmenu__sub-link:hover { background: var(--cmenu-hover); }

    /* Tiles. */
    .shop-cmenu__panel .shop-cmenu__tiles {
        display: grid;
        grid-template-columns: repeat(4, 11rem);
        gap: 1rem;
        margin: 0;
        padding: 1.25rem;
        list-style: none;
    }
}

/* Tiles, everywhere. */
.shop-cmenu__panel .shop-cmenu__tiles { list-style: none; }
.shop-cmenu__tile-link { display: grid; gap: 0.5rem; font-weight: 600; }
.shop-cmenu__tile-media {
    display: grid;
    place-items: center;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: var(--cmenu-radius);
    background: color-mix(in srgb, var(--cmenu-accent) 6%, var(--cmenu-surface));
}
.shop-cmenu__tile-img { width: 100%; height: 100%; object-fit: contain; padding: 0.5rem; transition: transform 0.3s; }
.shop-cmenu__tile-link:hover .shop-cmenu__tile-img { transform: scale(1.05); }
.shop-cmenu__tile-ph { font-size: 2rem; font-weight: 700; color: var(--cmenu-accent); }

/* --- phones and tablets: a full-screen sheet, one level at a time ------------------- */

@media (max-width: 63.99rem) {
    .shop-cmenu__btn .shop-cmenu__label { display: none; }
    .shop-cmenu__btn { padding: 0 0.85rem; }
    .shop-cmenu__panel {
        inset: 0;
        display: flex;
        flex-direction: column;
        overflow: auto;
        overscroll-behavior: contain;
    }
    .shop-cmenu__panel[hidden] { display: none; }
    .shop-cmenu__sheet-head {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        background: var(--cmenu-surface);
        border-bottom: 1px solid var(--cmenu-line);
    }
    .shop-cmenu__sheet-title { font-size: 1.15rem; font-weight: 700; }
    .shop-cmenu__close { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border: 0; border-radius: 50%; background: var(--cmenu-hover); color: inherit; cursor: pointer; }
    .shop-cmenu__close .shop-cmenu__icon { display: block; }

    .shop-cmenu__panel .shop-cmenu__roots,
    .shop-cmenu__panel .shop-cmenu__list { margin: 0; padding: 0.5rem 0; list-style: none; }
    .shop-cmenu__root-link,
    .shop-cmenu__item-link {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        min-height: 3.25rem;
        padding: 0.5rem 1rem;
        border-bottom: 1px solid var(--cmenu-line);
        font-weight: 500;
    }
    .shop-cmenu__root-img { width: 2.25rem; height: 2.25rem; object-fit: contain; flex: none; }

    /* Mega on a phone: the roots; a tapped one opens its own page of subcategories. */
    .shop-cmenu__panes { display: contents; }
    .shop-cmenu__pane { display: none; }
    .shop-cmenu__panel.is-drilled .shop-cmenu__roots { display: none; }
    .shop-cmenu__panel.is-drilled .shop-cmenu__pane.is-shown { display: block; }
    .shop-cmenu__pane-head { padding: 0.5rem 1rem 0.75rem; border-bottom: 1px solid var(--cmenu-line); }
    .shop-cmenu__back { display: inline-flex; align-items: center; gap: 0.3rem; min-height: 2.75rem; padding: 0; border: 0; background: none; color: var(--cmenu-muted); font: inherit; cursor: pointer; }
    .shop-cmenu__back .cms-icon { width: 1rem; height: 1rem; }
    .shop-cmenu__pane-title { display: flex; align-items: center; gap: 0.4rem; font-size: 1.2rem; font-weight: 700; }
    .shop-cmenu__pane-title .cms-icon { width: 1rem; height: 1rem; }
    .shop-cmenu__cols { display: grid; gap: 0; }
    .shop-cmenu__col { padding: 0.85rem 1rem; border-bottom: 1px solid var(--cmenu-line); }
    .shop-cmenu__col-title { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; }
    .shop-cmenu__col-img { width: 2rem; height: 2rem; object-fit: contain; flex: none; }

    /* Dropdown on a phone: an accordion. */
    .shop-cmenu__panel .shop-cmenu__sub { display: none; margin: 0; padding: 0.25rem 0 0.5rem 1rem; list-style: none; }
    .shop-cmenu__item.is-open > .shop-cmenu__sub { display: block; }
    .shop-cmenu__item.is-open > .shop-cmenu__item-link .shop-cmenu__chev { transform: rotate(90deg); }
    .shop-cmenu__sub-link,
    .shop-cmenu__sub .shop-cmenu__more { display: block; padding: 0.6rem 1rem; }

    .shop-cmenu__panel .shop-cmenu__tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; margin: 0; padding: 1rem; }
    .shop-cmenu__all { margin-top: auto; }
}

@media (prefers-reduced-motion: reduce) {
    .shop-cmenu__tile-img { transition: none; }
}
