/* WordPress reserves .search-results for body_class(). Give the theme-owned
 * result list a distinct component root. Keep the scope class-only and the
 * internal selectors low-specificity; no element prefix or exclusion limit
 * is needed to prevent the WordPress body collision. */
@scope (.bpv-search-results) {
    :scope {
        margin: 2rem 0;
        padding: 0;
        list-style: none;
        border-block-start: 1px solid var(--bpv-ui-divider);
    }

    li,
    li + li {
        margin: 0;
        padding-block: 1rem;
        border-block-end: 1px solid var(--bpv-ui-divider);
    }

    h2 {
        display: flex;
        justify-content: space-between;
        margin: 0;
        font-size: 1.15rem;
    }

    .bpv-search-results__access {
        display: inline-block;
        align-self: flex-start;
        margin-inline-start: 0.5rem;
        padding: 0.125rem 0.375rem;
        border: 1px solid var(--bpv-ui-control-border);
        background: var(--bpv-ui-subtle-bg);
        color: var(--bpv-ui-muted);
        font-size: 0.75em;
        font-weight: 600;
        line-height: 1.4;
        vertical-align: baseline;
        white-space: nowrap;
    }

    @media (forced-colors: active) {
        .bpv-search-results__access {
            border-color: CanvasText;
            background: Canvas;
            color: CanvasText;
        }
    }
}

/* Proposal 32: one pagination DOM, three named grid areas.
 * Mobile: page numbers in the top row with space-between spacing, actions below.
 * At 30rem: previous / centered numbers / next in one row.
 * A narrow content column (e.g. beside the sidebar) uses the mobile layout
 * without duplicating anchors or relying on JavaScript.
 */
.bpv-search-pagination {
    margin-block-start: 2rem;
    container-type: inline-size;
}

.bpv-search-pagination__layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
        "pages pages"
        "previous next";
    align-items: center;
    row-gap: 0.75rem;
}

.bpv-search-pagination__previous {
    grid-area: previous;
    justify-self: start;
}

.bpv-search-pagination__pages {
    grid-area: pages;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-inline-size: 0;
}

.bpv-search-pagination__next {
    grid-area: next;
    justify-self: end;
}

/* Extra neighbours are rendered only once but shown when space allows.
 * Compact ellipses describe gaps after those neighbours are hidden. */
.bpv-search-pagination__optional,
.bpv-search-pagination__regular-dot {
    display: none;
}

.bpv-search-pagination__compact-dot {
    display: inline-flex;
}

.bpv-search-pagination .page-numbers {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    min-inline-size: 44px;
    min-block-size: 44px;
    padding-inline: 0.4rem;
    text-align: center;
}

.bpv-search-pagination .page-numbers.current {
    border: 1px solid var(--bpv-ui-control-border);
    background: var(--bpv-ui-subtle-bg);
    color: var(--bpv-ui-text);
    font-weight: 700;
}

.bpv-search-pagination .page-numbers.dots {
    min-inline-size: 1rem;
    padding-inline: 0;
    color: var(--bpv-ui-muted);
}

.bpv-search-pagination__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-block-size: 44px;
    white-space: nowrap;
}

/* Retain the agreed 30rem viewport switch. The component-width fallback
 * below handles large sidebars and enlarged text independently. */
@media (min-width: 30rem) {
    .bpv-search-pagination__layout {
        grid-template-columns: minmax(0, 1fr) max-content minmax(0, 1fr);
        grid-template-areas: "previous pages next";
        column-gap: 0.25rem;
        row-gap: 0;
    }

    .bpv-search-pagination__pages {
        justify-content: center;
        gap: 0.25rem;
    }
}

@media (min-width: 30rem) {
    @container (max-width: 25rem) {
        .bpv-search-pagination__layout {
            grid-template-columns: repeat(2, minmax(0, 1fr));
            grid-template-areas:
                "pages pages"
                "previous next";
            row-gap: 0.75rem;
        }

        .bpv-search-pagination__pages {
            justify-content: space-between;
            gap: 0.5rem;
        }
    }
}

/* Up to six result pages fit their full native WordPress number sequence
 * in an 18rem-wide content area (288px at the default root font size),
 * including 44px targets, 0.5rem gaps and the ellipsis. Keep the compact
 * fallback below this real component-width threshold (e.g. increased text).
 * More than six pages retain the conservative 34rem threshold below.
 * This is one DOM sequence; optional neighbours are never duplicated. */
@container (min-width: 18rem) {
    .bpv-search-pagination--up-to-six .bpv-search-pagination__optional,
    .bpv-search-pagination--up-to-six .bpv-search-pagination__regular-dot {
        display: inline-flex;
    }

    .bpv-search-pagination--up-to-six .page-numbers.bpv-search-pagination__compact-dot {
        display: none;
    }
}

/* Larger result sets retain their safety margin until there is enough
 * width for a full five-number sequence with longer decimal labels. */
@container (min-width: 34rem) {
    .bpv-search-pagination__optional,
.bpv-search-pagination__regular-dot {
        display: inline-flex;
    }

    /* Override the more specific shared .page-numbers display declaration. */
    .bpv-search-pagination .page-numbers.bpv-search-pagination__compact-dot {
        display: none;
    }
}

@media (forced-colors: active) {
    .bpv-search-pagination .page-numbers.current {
        border-color: CanvasText;
        background: Canvas;
        color: CanvasText;
    }
}
