/* Shared rows for product tiles, including carousels and catalog grids. */
:is(.product-item, .product-item-sm):has(> .title):has(> .price) {
    --tile-price-height: 72px;
    --tile-details-height: 0px;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 63px var(--tile-price-height) var(--tile-details-height) 44px auto;
    align-content: start;
    height: auto !important;
    padding-bottom: 8px !important;
}

:is(.product-item, .product-item-sm):has(> .title):has(> .price):has(> .article, > .bt-small) {
    --tile-details-height: 42px;
}

:is(.product-item, .product-item-sm) > .img { grid-row: 1; }
:is(.product-item, .product-item-sm) > .title {
    grid-row: 2;
    height: 63px !important;
    min-height: 63px !important;
    margin-block: 0 !important;
    overflow-wrap: anywhere;
}

:is(.product-item, .product-item-sm) > .title.sl-title-overflow::after {
    right: 0;
    width: min(45%, 70px);
}

:is(.product-item, .product-item-sm) > .price,
:is(.product-item, .product-item-sm) > .price:has(> .new) {
    grid-row: 3;
    align-self: start;
    display: block !important;
    height: var(--tile-price-height) !important;
    min-height: 0 !important;
    margin-block: 0 !important;
    padding-block: 8px 0 !important;
    line-height: 1.25 !important;
}

/* Keep the old price and discount close to the current price within the reserved row. */
:is(.product-item, .product-item-sm) > .price > .new {
    padding-bottom: 0 !important;
}

:is(.product-item, .product-item-sm) > .price:has(> .new) > .old-line {
    margin-top: -2px !important;
}

:is(.product-item, .product-item-sm) > .article {
    grid-row: 4;
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 2px 5px 0 !important;
    line-height: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

:is(.product-item, .product-item-sm) > .sl-card-rating-row {
    grid-row: 5;
    align-self: start;
    align-content: start;
    margin: 0 !important;
    padding: 2px 3px 0;
}

:is(.product-item, .product-item-sm) > .bt-small {
    grid-row: 6;
    position: static !important;
    display: grid !important;
    grid-template-rows: 27px 45px;
    justify-items: center;
    align-items: center;
    margin: 0 !important;
}

:is(.product-item, .product-item-sm) > .bt-small > .open-oneclick {
    grid-row: 1;
    margin: 0 !important;
    line-height: 1.2 !important;
    max-width: 100%;
}

:is(.product-item, .product-item-sm) > .bt-small > .js-add-cart {
    grid-row: 2;
    display: block;
    box-sizing: border-box;
    height: 45px !important;
    line-height: 45px !important;
    margin: 0 auto !important;
}

@media (max-width: 640px) {
    :is(.product-item, .product-item-sm):has(> .title):has(> .price) {
        --tile-price-height: 64px;
    }
}


/* Keep taller source images from stretching a row on narrow screens. */
:is(.product-item, .product-item-sm):has(> .title):has(> .price) {
    --tile-image-height: 240px;
}

:is(.product-item, .product-item-sm) > .img > a {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    height: var(--tile-image-height) !important;
}

:is(.product-item, .product-item-sm) > .img > a > img {
    max-height: var(--tile-image-height);
    object-fit: contain;
}

@media (min-width: 817px) and (max-width: 916px), (max-width: 516px) {
    :is(.product-item, .product-item-sm):has(> .title):has(> .price) {
        --tile-image-height: 200px;
    }
}

@media (max-width: 416px) {
    :is(.product-item, .product-item-sm):has(> .title):has(> .price) {
        --tile-image-height: 160px;
    }
}

@media (max-width: 366px) {
    :is(.product-item, .product-item-sm):has(> .title):has(> .price) {
        --tile-image-height: 130px;
    }
}

:is(#product-hits-block, #product-new-block) .product-item {
    --tile-image-height: 200px;
}

@media (max-width: 767px) {
    :is(#product-hits-block, #product-new-block) .product-item {
        --tile-image-height: 160px;
    }
}


/* Keep supplier discount prices legible in the catalog and product view. */
:is(.product-item, .product-item-sm):has(> .item_info:is([data-item-brand="Аргента"], [data-item-brand="Мстерский Ювелир"]))
    > .price:has(> .old-line) > .new,
.product-detail:is([data-item-brand="Аргента"], [data-item-brand="Мстерский Ювелир"])
    .price:has(> .old) > .new {
    color: #333;
    font-weight: 600;
}

:is(.product-item, .product-item-sm):has(> .item_info:is([data-item-brand="Аргента"], [data-item-brand="Мстерский Ювелир"]))
    > .price > .old-line > .old,
.product-detail:is([data-item-brand="Аргента"], [data-item-brand="Мстерский Ювелир"])
    .price > .old > .level {
    color: #5e5360;
    text-decoration: line-through;
    text-decoration-thickness: 1.4px;
}

:is(.product-item, .product-item-sm):has(> .item_info:is([data-item-brand="Аргента"], [data-item-brand="Мстерский Ювелир"]))
    > .price > .old-line > .old {
    font-size: 14px;
}

@media (max-width: 640px) {
    :is(.product-item, .product-item-sm):has(> .item_info:is([data-item-brand="Аргента"], [data-item-brand="Мстерский Ювелир"]))
        > .price > .old-line > .old {
        font-size: 13px;
    }
}
