/* Count-aware Scan Card result layout.
   Keeps small result sets centered and removes the large empty result band. */

.results.show {
    min-height: 0 !important;
    padding-bottom: 0 !important;
}

.results.show .match-grid {
    width: 100%;
    margin-inline: auto;
    align-items: start;
}

/* Exactly one match: one centered result card. */
.results.show .match-grid:has(> .match:only-child) {
    grid-template-columns: minmax(0, 290px) !important;
    justify-content: center !important;
    max-width: 360px;
}

/* Exactly two matches: centered two-card row. */
.results.show .match-grid:has(> .match:nth-child(2):last-child) {
    grid-template-columns: repeat(2, minmax(0, 280px)) !important;
    justify-content: center !important;
    max-width: 590px;
}

/* Exactly three matches: centered three-card row. */
.results.show .match-grid:has(> .match:nth-child(3):last-child) {
    grid-template-columns: repeat(3, minmax(0, 270px)) !important;
    justify-content: center !important;
    max-width: 840px;
}

/* Keep the result heading/note visually tied to a small result set. */
.results.show:has(.match-grid > .match:only-child) .result-head,
.results.show:has(.match-grid > .match:only-child) .best {
    width: min(100%, 760px);
    margin-inline: auto;
}

.results.show:has(.match-grid > .match:nth-child(2):last-child) .result-head,
.results.show:has(.match-grid > .match:nth-child(2):last-child) .best {
    width: min(100%, 900px);
    margin-inline: auto;
}

.results.show:has(.match-grid > .match:nth-child(3):last-child) .result-head,
.results.show:has(.match-grid > .match:nth-child(3):last-child) .best {
    width: min(100%, 1040px);
    margin-inline: auto;
}

/* Once results exist, let the page end naturally after the cards instead of
   keeping a large empty band before the footer. */
.scan-main:has(.results.show) {
    padding-bottom: 34px !important;
}

.scan-shell:has(.results.show) + .ps-footer {
    margin-top: 26px !important;
}

/* Tablet: preserve the same 1 / 2 / 3 centered behavior. */
@media (max-width: 930px) {
    .results.show .match-grid:has(> .match:only-child) {
        grid-template-columns: minmax(0, 300px) !important;
    }

    .results.show .match-grid:has(> .match:nth-child(2):last-child) {
        grid-template-columns: repeat(2, minmax(0, 280px)) !important;
        max-width: 580px;
    }

    .results.show .match-grid:has(> .match:nth-child(3):last-child) {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        max-width: 820px;
    }
}

/* Mobile: every result count becomes a clean single-column list. */
@media (max-width: 620px) {
    .results.show .match-grid,
    .results.show .match-grid:has(> .match:only-child),
    .results.show .match-grid:has(> .match:nth-child(2):last-child),
    .results.show .match-grid:has(> .match:nth-child(3):last-child) {
        grid-template-columns: minmax(0, 1fr) !important;
        justify-content: stretch !important;
        max-width: 340px;
        margin-inline: auto;
        gap: 14px !important;
    }

    .results.show .result-head,
    .results.show .best {
        width: min(100%, 440px) !important;
        margin-inline: auto;
    }

    .scan-main:has(.results.show) {
        padding-bottom: 24px !important;
    }

    .scan-shell:has(.results.show) + .ps-footer {
        margin-top: 20px !important;
    }
}
