/*
 * Product grid columns: 2 on phones, 3 from 768px, 4 from 992px,
 * 5 from 1200px.
 */
.p2p-product-grid,
.product-cell-gallery {
    --product-grid-columns: 2;

    display: grid;
    grid-template-columns: repeat(var(--product-grid-columns), minmax(0, 1fr));
    grid-auto-rows: 1fr;
    gap: var(--product-cell-gap);
}

@media (min-width: 768px) {
    .p2p-product-grid,
    .product-cell-gallery {
        --product-grid-columns: 3;
    }
}

@media (min-width: 992px) {
    .p2p-product-grid,
    .product-cell-gallery {
        --product-grid-columns: 4;
    }
}

@media (min-width: 1200px) {
    .p2p-product-grid,
    .product-cell-gallery {
        --product-grid-columns: 5;
    }
}

.p2p-product-cell {
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    min-width: 0;
    height: 100%;

    border: 1px solid rgba(0, 0, 0, 0.26);

    [p2p-modal-trigger] {
        cursor: pointer;
    }

    /*
     * Rows: square image / title / price + cart.
     * The image is always square and the title row takes the spare
     * height, so in every grid row the titles start, and the prices
     * and buttons sit, at the same height.
     */
    .product-cell-container {
        display: grid;
        flex: 1;
        min-height: 0;
        padding: 1rem 0.75rem;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
        "image"
        "title"
        "checkout";
        gap: 0.5rem;

        >.product-cell-image-container {
            grid-area: image;
            aspect-ratio: 1 / 1;
            min-width: 0;
            overflow: hidden;

            > a {
                display: block;
                width: 100%;
                height: 100%;
            }

            img {
                display: block;
                width: 100%;
                height: 100%;
                object-fit: contain;
                background-color: white;
            }
        }

        >.product-cell-title-container {
            grid-area: title;
            align-self: start;
            min-width: 0;

            > a {
                text-decoration: none;
            }

            .product-cell-title {
                padding: 0;
                margin: 0;
                font-family: var(--font-opensans);

                /* At most two lines each, so titles stay compact. */
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                line-clamp: 2;
                overflow: hidden;
            }

            .product-cell-title-big {
                font-size: 1rem;
                font-weight: bold;
            }

            .product-cell-title-small {
                font-size: 0.8rem;
            }
        }

        >.product-cell-checkout-container {
            grid-area: checkout;
            align-self: end;
            display: flex;
            flex-flow: row nowrap;
            justify-content: space-between;
            align-items: center;
            gap: 0.5rem;

            > .product-cell-price {
                flex: 1 1 auto;
                min-width: 0;

                .p2p-price-tag {
                    align-items: flex-start;
                    margin: 0;
                }
            }

            > .product-cell-cart-btn {
                flex: 0 0 auto;
            }
        }
    }
}

/*
 * Below 768px: price on its own line, add to cart on a full-width
 * row beneath.
 */
@media (max-width: 767.98px) {

    .p2p-product-cell {

        .product-cell-container {
            padding: 0.75rem 0.5rem;
        }

        .product-cell-container > .product-cell-title-container .product-cell-title-big {
            font-size: 0.9rem;
        }

        .product-cell-container > .product-cell-checkout-container {
            flex-direction: column;
            align-items: stretch;

            > .product-cell-cart-btn {
                display: flex;
                justify-content: flex-start;
            }

            .p2p-price-tag {
                margin: 0;
                width: 100%;
            }
        }
    }
}


/*
 * Placeholder cards while products load (filter-products.js,
 * showPlaceholders). Same layout as a real card, with a soft shimmer.
 */
.p2p-product-cell--placeholder {
    pointer-events: none;

    .product-cell-container > .product-cell-image-container,
    .p2p-skeleton-line,
    .p2p-skeleton-button {
        background: linear-gradient(90deg, #eee 0%, #f6f6f6 40%, #eee 80%) 0 0 / 200% 100%;
        animation: p2p-skeleton-shimmer 1.2s ease-in-out infinite;
        border-radius: 4px;
    }

    .product-cell-title-container {
        display: flex;
        flex-direction: column;
        gap: 0.4rem;
    }

    .p2p-skeleton-line {
        display: block;
        height: 0.9rem;
        width: 90%;
    }

    .p2p-skeleton-line--short {
        width: 55%;
    }

    .p2p-skeleton-line--price {
        width: 40%;
        height: 1.1rem;
    }

    .p2p-skeleton-button {
        display: block;
        width: 5.9rem;
        height: 2.25rem;
        border-radius: 6px;
    }
}

@keyframes p2p-skeleton-shimmer {
    from {
        background-position: 100% 0;
    }
    to {
        background-position: -100% 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .p2p-product-cell--placeholder * {
        animation: none !important;
    }
}
