/* Витрина: YooAI Category — сетка каталога (не путать с header mega-menu) */
/* Сетка: flex + wrap; --yooai-cat-cols — макс. в ряд; --yooai-cat-item-min — когда сужаться нельзя, перенос */
.yooai-cat {
    --yooai-cat-cols: 4;
    --yooai-cat-gap-x: var(--yooai-cat-gap-x-d, 40px);
    --yooai-cat-gap-y: var(--yooai-cat-gap-x-d, 40px);
    --yooai-cat-item-min: var(--yooai-cat-item-min-d, 220px);
    --yooai-cat-pad-y: var(--yooai-cat-pad-y-d, 20px);
    --yooai-cat-pad-x: var(--yooai-cat-pad-x-d, 16px);
    --yooai-cat-thumb-w: 58px;
    --yooai-cat-thumb-h: 58px;
    --yooai-cat-name: #0f172a;
    --yooai-cat-child: #334155;
    --yooai-cat-child-hover: #0f172a;
    --yooai-cat-accent: #2563eb;
    --yooai-cat-more: #64748b;
    --yooai-cat-section-title: 28px;
    --yooai-cat-head-gap: 28px;
    /* head + grid в одной колонке, оба по левому краю блока */
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: var(--yooai-cat-pad-y) var(--yooai-cat-pad-x);
    box-sizing: border-box;
    font-family: inherit;
    color: var(--yooai-cat-name);
    text-align: left;
}

.yooai-cat__head {
    width: 100%;
    align-self: stretch;
    margin: 0 0 var(--yooai-cat-head-gap);
    text-align: left;
}

.yooai-cat__title {
    margin: 0;
    font-size: var(--yooai-cat-section-title);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--yooai-cat-name);
    text-align: left;
}

.yooai-cat__grid {
    --yooai-cat-slot: calc((100% - (var(--yooai-cat-cols) - 1) * var(--yooai-cat-gap-x)) / var(--yooai-cat-cols));
    --yooai-cat-col: max(var(--yooai-cat-item-min), var(--yooai-cat-slot));
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-start;
    align-content: flex-start;
    gap: var(--yooai-cat-gap-y) var(--yooai-cat-gap-x);
    margin: 0;
    width: 100%;
}

.yooai-cat__item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-sizing: border-box;
    /* flex-grow: 0 — последний ряд не растягивается, колонки остаются друг под другом */
    flex: 0 0 var(--yooai-cat-col);
    width: var(--yooai-cat-col);
    max-width: min(100%, var(--yooai-cat-col));
    min-width: 0;
    min-height: 0;
}

.yooai-cat--img-top .yooai-cat__item {
    flex-direction: column;
    gap: 10px;
}

.yooai-cat__icon {
    flex: 0 0 auto;
    display: block;
    line-height: 0;
}

.yooai-cat__icon img {
    display: block;
    width: var(--yooai-cat-thumb-w);
    height: var(--yooai-cat-thumb-h);
    object-fit: cover;
    border-radius: 8px;
}

.yooai-cat__body {
    min-width: 0;
    flex: 1 1 auto;
}

.yooai-cat__name {
    display: inline-block;
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--yooai-cat-name);
    text-decoration: none;
    overflow-wrap: break-word;
    word-break: normal;
    hyphens: manual;
}

.yooai-cat__name:hover {
    color: var(--yooai-cat-accent);
}

.yooai-cat__children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.yooai-cat__children li {
    margin: 0 0 5px;
}

.yooai-cat__children a {
    font-size: 15px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--yooai-cat-child);
    text-decoration: none;
    overflow-wrap: break-word;
    word-break: normal;
}

.yooai-cat__children a:hover {
    color: var(--yooai-cat-child-hover);
    text-decoration: underline;
}

.yooai-cat__more {
    display: inline-block;
    margin-top: 8px;
    font-size: 14px;
    color: var(--yooai-cat-more);
    text-decoration: none;
}

.yooai-cat__more:hover {
    color: var(--yooai-cat-child-hover);
    text-decoration: underline;
}

/* Телефон: мин. ширина, отступы и зазор — из мобильных полей админки */
@media (max-width: 767px) {
    .yooai-cat {
        --yooai-cat-item-min: var(--yooai-cat-item-min-m, 180px);
        --yooai-cat-gap-x: var(--yooai-cat-gap-x-m, 16px);
        --yooai-cat-gap-y: var(--yooai-cat-gap-x-m, 16px);
        --yooai-cat-pad-y: var(--yooai-cat-pad-y-m, 12px);
        --yooai-cat-pad-x: var(--yooai-cat-pad-x-m, 0px);
    }

    /* Горизонтальный скролл: один ряд, свайп (класс с админки, по умолчанию вкл.) */
    .yooai-cat-shell > .yooai-cat-cw > .yooai-cat.yooai-cat--m-scroll {
        width: 100%;
        max-width: 100%;
        align-self: stretch;
    }

    .yooai-cat--m-scroll .yooai-cat__grid {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        scroll-snap-type: x proximity;
        width: 100%;
        max-width: 100%;
        padding-bottom: 14px;
    }

    .yooai-cat--m-scroll .yooai-cat__item {
        flex: 0 0 var(--yooai-cat-item-min);
        width: var(--yooai-cat-item-min);
        max-width: none;
        scroll-snap-align: start;
    }
}

@media (max-width: 575px) {
    .yooai-cat {
        --yooai-cat-section-title: 22px;
        --yooai-cat-head-gap: 18px;
    }

    .yooai-cat__item {
        gap: 8px;
    }

    .yooai-cat__icon img {
        width: min(var(--yooai-cat-thumb-w), 48px);
        height: min(var(--yooai-cat-thumb-h), 48px);
    }

    .yooai-cat__name {
        font-size: 16px;
        margin-bottom: 6px;
    }

    .yooai-cat__children a {
        font-size: 13px;
        line-height: 1.35;
    }

    .yooai-cat__children li {
        margin-bottom: 3px;
    }

    .yooai-cat__more {
        font-size: 13px;
        margin-top: 6px;
    }
}

/* Ширина блока: внешний потолок из админки, а внутри .yooai-cat сжимается под влезшие колонки и центрируется */
.yooai-cat-shell {
    position: relative;
    width: 100%;
    clear: both;
    box-sizing: border-box;
}

.yooai-cat-shell > .yooai-cat-cw {
    container-type: inline-size;
    container-name: yooai-cat;
    display: block;
    width: 100%;
    max-width: none;
    margin-left: auto;
    margin-right: auto;
    padding-left: 15px;
    padding-right: 15px;
    float: none;
    box-sizing: border-box;
}

/*
 * Когда все N колонок помещаются — блок растягивается на 100% контейнера (до 1440px из админки),
 * а колонки делят эту ширину поровну. Когда все N не влезают (планшет/мобила) — сжимается под
 * влезшие колонки и встаёт по центру.
 */
.yooai-cat-shell > .yooai-cat-cw > .yooai-cat {
    --yooai-cat-inner: calc(100cqi - (var(--yooai-cat-pad-x) * 2));
    --yooai-cat-slot-full: calc((var(--yooai-cat-inner) - (var(--yooai-cat-cols) - 1) * var(--yooai-cat-gap-x)) / var(--yooai-cat-cols));
    --yooai-cat-eff-item: max(var(--yooai-cat-item-min), var(--yooai-cat-slot-full));
    --yooai-cat-step: calc(var(--yooai-cat-eff-item) + var(--yooai-cat-gap-x));
    --yooai-cat-fit: max(
        var(--yooai-cat-eff-item),
        calc(round(down, calc(var(--yooai-cat-inner) + var(--yooai-cat-gap-x)), var(--yooai-cat-step)) - var(--yooai-cat-gap-x))
    );
    --yooai-cat-cap: calc((var(--yooai-cat-cols) * var(--yooai-cat-step)) - var(--yooai-cat-gap-x));
    width: min(100%, calc(min(var(--yooai-cat-fit), var(--yooai-cat-cap)) + (var(--yooai-cat-pad-x) * 2)));
}

.yooai-cat-shell > .yooai-cat-cw-m-boxed {
    max-width: var(--yoo-cat-wrap-max-m, 100%);
}

.yooai-cat-shell > .yooai-cat-cw-m-full {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    padding-left: 15px;
    padding-right: 15px;
}

@media (min-width: 768px) {
    .yooai-cat-shell > .yooai-cat-cw-d-container {
        width: 100%;
        max-width: none;
        margin-left: auto;
        margin-right: auto;
    }

    .yooai-cat-shell > .yooai-cat-cw-d-boxed {
        width: 100%;
        max-width: var(--yoo-cat-wrap-max-d, 1320px);
    }

    .yooai-cat-shell > .yooai-cat-cw-d-full {
        width: 100vw;
        max-width: 100vw;
        margin-left: calc(50% - 50vw);
        margin-right: calc(50% - 50vw);
        padding-left: 15px;
        padding-right: 15px;
    }
}
