﻿.card-section {
    --card-section-gap: var(--space-medium);
    --card-section-padding: var(--space-medium-xl);
    --card-section-padding-tablet: var(--space-medium);
    --card-section-padding-mobile: var(--space-small);
    position: relative;
    inline-size: 100%;
    min-inline-size: 0;
}

.card-section__content {
    inline-size: 100%;
    min-inline-size: 0;
}

.card-section__header {
    inline-size: 100%;
    margin-block-end: var(--space-medium-xl);
    text-align: center;
}

    .card-section__header > :first-child {
        margin-block-start: 0;
    }

    .card-section__header > :last-child {
        margin-block-end: 0;
    }

.card-section__border {
    inline-size: 100%;
    padding: var(--card-section-padding);
    border: 1px solid var(--card-surface-border);
    background-color: var(--card-surface-background);
}

.card-section__items {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    align-items: stretch;
    gap: var(--card-section-gap);
    inline-size: 100%;
    min-inline-size: 0;
    margin: 0;
    padding: 0;
}

    .card-section__items > * {
        display: flex;
        min-inline-size: 0;
        max-inline-size: 100%;
        margin: 0;
        padding: 0;
    }

        .card-section__items > * > * {
            display: flex;
            flex: 1 1 auto;
            inline-size: 100%;
            min-inline-size: 0;
            max-inline-size: 100%;
        }

            .card-section__items > * > * > * {
                min-inline-size: 0;
                max-inline-size: 100%;
            }

.card-section--icon-callouts,
.card-section--content-cards,
.card-section--image-callouts {
    background-color: var(--card-surface-background);
}
    /* Content Cards - max 4 per row */
    .card-section--content-cards
    .card-section__items > * {
        grid-column: auto / span 3;
    }

    /* Icon Callout Cards - max 4 per row */
    .card-section--icon-callouts
    .card-section__items > * {
        grid-column: auto / span 3;
    }

    /* Image Callout Cards - max 3 per row */
    .card-section--image-callouts
    .card-section__items > * {
        grid-column: auto / span 4;
    }


/* Exactly one card - center at one-third width */
.card-section__items > :only-child {
    grid-column: 5 / span 4;
}


/* Exactly two cards - center at one-third width each */
.card-section__items > :first-child:nth-last-child(2) {
    grid-column: 3 / span 4;
}

.card-section__items > :last-child:nth-child(2) {
    grid-column: 7 / span 4;
}

/* Exactly three content or icon cards - center as three equal columns */
.card-section--content-cards
.card-section__items > :first-child:nth-last-child(3),
.card-section--content-cards
.card-section__items > :first-child:nth-last-child(3) ~ *,
.card-section--icon-callouts
.card-section__items > :first-child:nth-last-child(3),
.card-section--icon-callouts
.card-section__items > :first-child:nth-last-child(3) ~ * {
    grid-column: auto / span 4;
}

.card-section--content-cards
.content-card,
.card-section--icon-callouts
.icon-callout-card,
.card-section--image-callouts
.image-callout-card {
    display: flex;
    flex: 1 1 auto;
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
    block-size: 100%;
}

/* Two-card text measures */
.card-section--content-cards
.card-section__items:has( > :first-child:nth-last-child(2) )
.content-card__content {
    inline-size: 100%;
    max-inline-size: 40ch;
    margin-inline: auto;
}

.card-section--content-cards
.card-section__items:has( > :first-child:nth-last-child(2) )
.content-card__heading {
    max-inline-size: 28ch;
}

.card-section--icon-callouts
.card-section__items:has( > :first-child:nth-last-child(2) )
.icon-callout-card__heading {
    max-inline-size: 24ch;
    margin-inline: auto;
}

.card-section--icon-callouts
.card-section__items:has( > :first-child:nth-last-child(2) )
.icon-callout-card__text {
    inline-size: 100%;
    max-inline-size: 24ch;
    margin-inline: auto;
}


/* Mobile Reset */

@media (max-width: 767.98px) {
    .card-section--content-cards
    .content-card__content,
    .card-section--content-cards
    .content-card__heading,
    .card-section--icon-callouts
    .icon-callout-card__heading,
    .card-section--icon-callouts
    .icon-callout-card__text {
        max-inline-size: none;
    }
}


/* Sitefinity Page-Editor Safety */
.sfPageEditor .card-section,
.sfPageEditor .card-section .container,
.sfPageEditor .card-section__items,
.sfPageEditor .card-section__items > *,
.sfPageEditor .card-section__items > * > *,
.sfPageEditor .card-section__items > * > * > *,
.sfPageEditor .content-card,
.sfPageEditor .icon-callout-card,
.sfPageEditor .image-callout-card {
    overflow: visible;
}
    .sfPageEditor
    .card-section__items > * {
        position: relative;
        z-index: 0;
    }
        .sfPageEditor
        .card-section__items > *:hover,
        .sfPageEditor
        .card-section__items > *:focus-within {
            z-index: 10;
        }


/* Tablet */
@media (max-width: 991.98px) {
    .card-section {
        --card-section-gap: var(--space-small);
    }

    .card-section__header {
        margin-block-end: var(--space-medium);
    }

    .card-section__border {
        padding: var(--card-section-padding-tablet);
    }

    /* All card types use two columns on tablet */
    .card-section--content-cards
    .card-section__items > *,
    .card-section--icon-callouts
    .card-section__items > *,
    .card-section--image-callouts
    .card-section__items > * {
        grid-column: auto / span 6;
    }

    .card-section__items > :only-child {
        grid-column: 4 / span 6;
    }

    .card-section__items > :first-child:nth-last-child(2),
    .card-section__items > :last-child:nth-child(2) {
        grid-column: auto / span 6;
    }

    .card-section__items > :last-child:nth-child(odd) {
        grid-column: 4 / span 6;
    }
}


/* MOBILE */
@media (max-width: 767.98px) {
    .card-section {
        --card-section-gap: 1rem;
    }

    .card-section__header {
        margin-block-end: var(--space-small);
    }

    .card-section__border {
        padding: var(--card-section-padding-mobile);
    }

    /* Use one explicit Grid column on mobile */
    .card-section__items {
        grid-template-columns: minmax(0, 1fr);
        align-items: start;
    }

    /* Default mobile placement for every card type */
    .card-section--content-cards
    .card-section__items > *,
    .card-section--icon-callouts
    .card-section__items > *,
    .card-section--image-callouts
    .card-section__items > * {
        grid-column: 1 / -1;
    }

    /* Reset the higher-specificity one-card and two-card desktop placement rules */
    .card-section__items > :only-child,
    .card-section__items > :first-child:nth-last-child(2),
    .card-section__items > :last-child:nth-child(2),
    .card-section__items > :last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    /* Reset the higher-specificity exact-three rules */
    .card-section--content-cards
    .card-section__items > :first-child:nth-last-child(3),
    .card-section--content-cards
    .card-section__items > :first-child:nth-last-child(3) ~ *,
    .card-section--icon-callouts
    .card-section__items > :first-child:nth-last-child(3),
    .card-section--icon-callouts
    .card-section__items > :first-child:nth-last-child(3) ~ * {
        grid-column: 1 / -1;
    }

    /* Icon callouts can continue spanning four tracks and remain in one row on mobile */
    .card-section--content-cards
    .card-section__items > :first-child:nth-last-child(3),
    .card-section--content-cards
    .card-section__items > :first-child:nth-last-child(3) ~ *,
    .card-section--icon-callouts
    .card-section__items > :first-child:nth-last-child(3),
    .card-section--icon-callouts
    .card-section__items > :first-child:nth-last-child(3) ~ * {
        grid-column: 1 / -1;
    }

    /* Cards grow naturally on mobile instead of matching the tallest card from the row */
    .card-section--content-cards
    .content-card,
    .card-section--icon-callouts
    .icon-callout-card,
    .card-section--image-callouts
    .image-callout-card {
        block-size: auto;
        min-block-size: 0;
    }

    /* Reset the higher-specificity two-card text measures */
    .card-section--content-cards
    .content-card__content,
    .card-section--content-cards
    .content-card__heading,
    .card-section--icon-callouts
    .icon-callout-card__heading,
    .card-section--icon-callouts
    .icon-callout-card__text {
        max-inline-size: none;
    }
}