.mg {
    --mg-brand: var(--main-color);
    --mg-ink: #1b1d21;
    --mg-muted: #71767e;
    --mg-line: #e6e8ec;
    --mg-soft: #f5f6f8;
    --mg-radius: 14px;
    font-family: inherit;
    color: var(--mg-ink);
    padding-top: 48px;
    padding-bottom: 40px;
}

.mg__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 14px;
    margin-bottom: 18px;
}

.mg__title {
    margin: 0;
    font-size: 22px;
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.mg__count {
    margin: 0;
    font-size: 14px;
    color: var(--mg-muted);
    white-space: nowrap;
}

.mg__panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 22px;
}

/* --- поиск --- */
.mg__search {
    position: relative;
    display: block;
}

.mg__search-icon {
    position: absolute;
    top: 50%;
    left: 16px;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    color: var(--mg-muted);
    pointer-events: none;
}

.mg__input {
    width: 100%;
    height: 52px;
    padding: 0 46px;
    border: 1px solid var(--mg-line);
    border-radius: var(--mg-radius);
    background: #fff;
    font: inherit;
    font-size: 15px;
    color: inherit;
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.mg__input::placeholder {
    color: var(--mg-muted);
}

.mg__input:hover {
    border-color: color-mix(in srgb, var(--mg-brand) 35%, var(--mg-line));
}

.mg__input:focus {
    outline: none;
    border-color: var(--mg-brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--mg-brand) 18%, transparent);
}

.mg__input::-webkit-search-cancel-button {
    display: none;
}

.mg__clear {
    position: absolute;
    top: 50%;
    right: 8px;
    display: none;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    transform: translateY(-50%);
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--mg-muted);
    cursor: pointer;
    transition:
        background-color 0.15s,
        color 0.15s;
}

.mg__clear:hover {
    background: var(--mg-soft);
    color: var(--mg-ink);
}

.mg__clear:focus-visible {
    outline: 2px solid var(--mg-brand);
    outline-offset: 2px;
}

.mg__clear svg {
    width: 14px;
    height: 14px;
}

.mg.is-searching .mg__clear {
    display: grid;
}

/* --- линейки: закреплённая «Всё» + слайдер --- */
.mg__tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.mg__slider {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.mg__track {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.mg__track::-webkit-scrollbar {
    display: none;
}

/* #fff — фон секции, поменяйте оба градиента, если блок стоит на сером */
.mg__slider::before,
.mg__slider::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 1;
    width: 56px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.mg__slider::before {
    left: 0;
    background: linear-gradient(90deg, #fff 20%, rgba(255, 255, 255, 0));
}

.mg__slider::after {
    right: 0;
    background: linear-gradient(270deg, #fff 20%, rgba(255, 255, 255, 0));
}

.mg__slider.is-scrollable:not(.is-start)::before,
.mg__slider.is-scrollable:not(.is-end)::after {
    opacity: 1;
}

.mg__nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: none;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    transform: translateY(-50%);
    border: 1px solid var(--mg-line);
    border-radius: 50%;
    background: #fff;
    color: var(--mg-ink);
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition:
        border-color 0.15s,
        color 0.15s;
}

.mg__nav:hover {
    border-color: var(--mg-brand);
    color: var(--mg-brand);
}

.mg__nav:focus-visible {
    outline: 2px solid var(--mg-brand);
    outline-offset: 2px;
}

.mg__nav svg {
    width: 14px;
    height: 14px;
}

.mg__nav--prev {
    left: 0;
}

.mg__nav--next {
    right: 0;
}

.mg__slider.is-scrollable:not(.is-start) .mg__nav--prev,
.mg__slider.is-scrollable:not(.is-end) .mg__nav--next {
    display: grid;
}

@media (hover: none) {
    .mg__nav {
        display: none !important;
    }

    .mg__slider::before,
    .mg__slider::after {
        width: 32px;
    }
}

.mg__tab {
    flex: 0 0 auto;
    padding: 9px 16px;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    background: #fff;
    font: inherit;
    font-size: 14px;
    line-height: 1.2;
    color: var(--mg-ink);
    white-space: nowrap;
    cursor: pointer;
    transition:
        border-color 0.15s,
        background-color 0.15s,
        color 0.15s;
}

.mg__tab:hover {
    border-color: color-mix(in srgb, var(--mg-brand) 45%, var(--mg-line));
}

.mg__tab:focus-visible {
    outline: 2px solid var(--mg-brand);
    outline-offset: 2px;
}

.mg__tab[aria-selected="true"] {
    border-color: var(--mg-brand);
    background: var(--mg-brand);
    color: #fff;
}

.mg__tab-num {
    margin-left: 6px;
    font-size: 12px;
    color: var(--mg-muted);
}

.mg__tab[aria-selected="true"] .mg__tab-num {
    color: color-mix(in srgb, #fff 75%, var(--mg-brand));
}

/* --- сетка моделей --- */
.mg__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.mg__item[hidden] {
    display: none;
}

/* Прячем «хвост» до инициализации JS, чтобы не было скачка высоты.
       Число должно совпадать с data-step + 1. */
.mg:not([data-mg-ready]) .mg__item:nth-child(n + 13) {
    display: none;
}

.mg__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 100%;
    padding: 14px 10px 16px;
    border: 1px solid var(--mg-line);
    border-radius: var(--mg-radius);
    background: #fff;
    font: inherit;
    color: inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition:
        border-color 0.15s,
        box-shadow 0.15s,
        transform 0.15s;
}

.mg__card:hover {
    border-color: color-mix(in srgb, var(--mg-brand) 55%, var(--mg-line));
    box-shadow: 0 6px 18px color-mix(in srgb, var(--mg-brand) 12%, transparent);
    transform: translateY(-2px);
}

.mg__card:focus-visible {
    outline: 2px solid var(--mg-brand);
    outline-offset: 2px;
}

.mg__pic {
    display: grid;
    place-items: center;
    width: 100%;
    aspect-ratio: 1/1;
    max-height: 120px;
    border-radius: 10px;
    background: var(--mg-soft);
    overflow: hidden;
}

.mg__img {
    width: auto;
    max-width: 76%;
    /* height: 100%;*/
    max-height: 96%;
    object-fit: contain;
}

.mg__name {
    font-size: 13px;
    line-height: 1.35;
    font-weight: 500;
    overflow-wrap: anywhere;
}

.mg__hl {
    padding: 0 1px;
    border-radius: 3px;
    background: color-mix(in srgb, var(--mg-brand) 22%, #fff);
    color: inherit;
}

/* --- «показать ещё» и пустое состояние --- */
.mg__more {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

.mg__more-btn {
    padding: 13px 30px;
    border: 1px solid var(--mg-brand);
    border-radius: 10px;
    background: var(--mg-brand);
    font: inherit;
    font-size: 15px;
    color: #fff;
    cursor: pointer;
    transition: background-color 0.15s;
}

.mg__more-btn:hover {
    background: color-mix(in srgb, var(--mg-brand) 85%, #000);
}

.mg__more-btn:focus-visible {
    outline: 2px solid var(--mg-brand);
    outline-offset: 3px;
}

.mg__empty {
    display: none;
    padding: 36px 20px;
    border: 1px dashed var(--mg-line);
    border-radius: var(--mg-radius);
    text-align: center;
}

.mg.is-empty .mg__empty {
    display: block;
}

.mg.is-empty .mg__grid,
.mg.is-empty .mg__more {
    display: none;
}

.mg__empty-title {
    margin: 0 0 6px;
    font-size: 17px;
    font-weight: 600;
}

.mg__empty-text {
    margin: 0 0 18px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--mg-muted);
}

.mg__empty-btn {
    padding: 12px 24px;
    border: 1px solid var(--mg-brand);
    border-radius: 10px;
    background: var(--mg-brand);
    font: inherit;
    font-size: 15px;
    color: #fff;
    cursor: pointer;
}

@media (min-width: 480px) {
    .mg__grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
    }

    .mg__title {
        font-size: 24px;
    }
}

@media (min-width: 768px) {
    .mg__grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .mg__panel {
        flex-direction: row-reverse;
        align-items: center;
        justify-content: space-between;
        gap: 20px;
    }

    .mg__tabs {
        flex: 1 1 auto;
    }

    .mg__search {
        flex: 0 0 300px;
    }

    /* линеек нет — поиск занимает всю строку */
    .mg__panel--solo .mg__search {
        flex: 1 1 auto;
    }

    .mg__title {
        font-size: 28px;
    }
}

@media (min-width: 1024px) {
    .mg__grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .mg__search {
        flex-basis: 340px;
    }

    .mg__panel--solo .mg__search {
        flex-basis: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mg * {
        transition: none !important;
    }

    .mg__track {
        scroll-behavior: auto;
    }
}
