/**
 * Post list: article cards from a GB Query Loop. Grid of cards, a vertical
 * list with the image on the left, or a horizontally scrolling row. The same
 * classes are meant for archive and taxonomy templates built as GP elements,
 * so listings look the same everywhere.
 *
 * globalClass: post-list   (container around the query loop) and
 *              post-item   (the post template container inside the loop)
 *
 * Variants (on .post-list):
 *   post-list--list       rows: image left (40%), text right, from 768px
 *   post-list--carousel   one scrolling row bleeding to the viewport edge
 *                         (cards carousel engine: cards.css + cards.js)
 *   post-list--compact    no image, title and meta only
 *   post-list--featured   the first item spans the row as a large lift
 *                         (image left, text right from 768px); only on the
 *                         first page (body:not(.paged)). Archive listing.
 *
 * Structure:
 *   .post-list.gb-container [.post-list--list]
 *     query-loop > grid (columns from GB) > .post-item.gb-container (post template)
 *       figure > img                 dynamic featured image (3:2 box)
 *       p.post-item-meta             date, category (dynamic)
 *       h3.post-item-title           dynamic title, linked to the post
 *       p.post-item-excerpt          dynamic excerpt
 *       a.gb-button.btn-no-bg.post-item-link   "Lue lisää", makes the card clickable
 *
 * Tuning: --post-item-ratio (3 / 2), --post-item-radius (12px)
 *
 * Chain animations: GB drops the attribute from the post template, so the
 * .post-list container animates once (chainAnimation on it).
 */

:root {
    --post-item-ratio: 3 / 2;
    --post-item-radius: 12px;
}

/* Loop container: the GB grid inside it does the columns */
.post-list .gb-grid-column {
    display: flex;
}

.post-list .gb-grid-column > .post-item {
    flex: 1 1 auto;
    width: 100%;
}

/* Item */
.post-item {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.post-item > * {
    margin: 0;
}

/* Image: the figure owns the box */
.post-item figure.gb-block-image {
    position: relative;
    aspect-ratio: var(--post-item-ratio);
    border-radius: var(--post-item-radius);
    overflow: hidden;
    margin-bottom: 8px;
}

.post-item figure.gb-block-image img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

/* Corner badge that slides in on hover: "click to open" */
.post-item figure.gb-block-image::after {
    content: '\2197';
    position: absolute;
    top: 12px;
    right: 12px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background-color: var(--bg-clr);
    color: var(--link-clr);
    display: grid;
    place-items: center;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    opacity: 0;
    transform: translate(8px, -8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.post-item-meta {
    font-size: 0.85rem;
    opacity: 0.8;
}

.post-item-title {
    font-size: var(--h4-size);
    transition: color 0.3s ease;
}

.post-item-title a {
    color: inherit;
    text-decoration: none;
}

.post-item-excerpt {
    font-size: 0.95rem;
}

/* Link at the bottom; the whole item becomes the click target */
.post-item-link {
    align-self: flex-start;
    margin-top: auto;
    padding-top: 8px;
}

.post-item a.post-item-link::before,
.post-item .post-item-link a::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
}

@media (hover: hover) {
    .post-item:hover figure.gb-block-image img {
        transform: scale(1.04);
    }

    .post-item:hover figure.gb-block-image::after {
        opacity: 1;
        transform: translate(0, 0);
    }

    .post-item:hover .post-item-title {
        color: var(--link-clr);
    }
}

/* Compact: no image */
.post-list--compact .post-item figure.gb-block-image,
.post-list--compact .post-item [data-type="generateblocks/image"] {
    display: none;
}

.post-list--compact .post-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--border-clr);
}

/* Carousel card width for the cards engine */
.post-list--carousel {
    --cards-card-width: min(78vw, 340px);
}

@media only screen and (min-width: 768px) {
    /* List: image left, text right */
    .post-list--list .post-item {
        flex-direction: row;
        gap: 24px;
        align-items: flex-start;
    }

    .post-list--list .post-item figure.gb-block-image,
    .post-list--list .post-item [data-type="generateblocks/image"] {
        flex: 0 0 40%;
        margin-bottom: 0;
    }

    .post-list--list .post-item > :not(figure):not([data-type="generateblocks/image"]) {
        flex-basis: auto;
    }

    .post-list--list .post-item-body {
        display: flex;
        flex-direction: column;
        gap: 8px;
        flex: 1 1 auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .post-item figure.gb-block-image img,
    .post-item figure.gb-block-image::after,
    .post-item-title {
        transition: none;
    }
}

/* ---------- Featured: the first item as a large lift on the first page ---------- */

@media only screen and (min-width: 768px) {
    body:not(.paged) .post-list--featured .gb-grid-wrapper > .gb-grid-column:first-child {
        width: 100%;
    }

    body:not(.paged) .post-list--featured .gb-grid-wrapper > .gb-grid-column:first-child > .post-item {
        display: grid;
        grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
        grid-template-rows: auto auto auto 1fr;
        column-gap: 40px;
        align-items: start;
        align-content: center;
    }

    body:not(.paged) .post-list--featured .gb-grid-wrapper > .gb-grid-column:first-child > .post-item > figure.gb-block-image {
        grid-column: 1;
        grid-row: 1 / span 4;
        margin: 0;
        align-self: stretch;
        aspect-ratio: auto;
        min-height: 320px;
    }

    body:not(.paged) .post-list--featured .gb-grid-wrapper > .gb-grid-column:first-child > .post-item > :not(figure) {
        grid-column: 2;
    }

    body:not(.paged) .post-list--featured .gb-grid-wrapper > .gb-grid-column:first-child > .post-item > .post-item-title {
        font-size: var(--h3-size);
    }

    body:not(.paged) .post-list--featured .gb-grid-wrapper > .gb-grid-column:first-child > .post-item > .post-item-link {
        margin-top: 8px;
    }
}
