/**
 * Page layout on procedure categories that list patients (body.pgsa-layout).
 * Depends on base.css and on the design tokens defined in cards.css.
 */

body.pgsa-layout {
    background: var(--pgsa-bg);
    overflow-x: clip;
}

/* The gallery plugin's header wrapper is left empty (except for the explicit content warning) */
body.pgsa-layout .photo-gallery-header-wrapper:not(:has(*)) { display: none; }

/* Explicit content warning (the gallery plugin's overlay and script), sized to the layout */
body.pgsa-layout .photogallery_taxonomy__procedure-explicit-message {
    z-index: 10000;
    flex-wrap: wrap;
    gap: 12px 16px;
    align-content: center;
    padding: 0 16px;
    box-sizing: border-box;
    text-align: center;
}
body.pgsa-layout .photogallery_taxonomy__procedure-explicit-message__text {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: normal;
    text-transform: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}
body.pgsa-layout .photogallery_taxonomy__procedure-explicit-message__button {
    margin: 0;
    padding: 10px 24px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #fff;
    background: var(--pgsa-accent);
    border: 0;
    border-radius: 0;
    cursor: pointer;
    transition: opacity .2s ease;
}
body.pgsa-layout .photogallery_taxonomy__procedure-explicit-message__button:hover { opacity: .85; }

/* Refine results */
.pgsa-refine {
    background: var(--pgsa-surface);
    padding: 16px 0;
    border-bottom: 1px solid #ebe9e4;
}
.pgsa-refine__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.pgsa-refine__label {
    font-size: 11px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--pgsa-muted);
}
.pgsa-refine__fields { display: flex; flex-wrap: wrap; gap: 8px; }
.pgsa-refine__fields select {
    min-width: 180px;
    height: 44px;
    padding: 0 12px;
    font-size: 13px;
    color: var(--pgsa-text);
    background-color: var(--pgsa-surface);
    border: 1px solid var(--pgsa-border);
    border-radius: 0;
}
.pgsa-refine__fields .pgsa-button { height: 44px; padding: 0 40px; }

/* Visible labels, toggle bar, sheet header and backdrop are only shown on phones */
.pgsa-refine__field-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.pgsa-refine__toggle,
.pgsa-refine__head,
.pgsa-refine__backdrop { display: none; }
.pgsa-refine__icon,
.pgsa-refine__chevron { flex: none; }

/* Patient grid spacing */
body.pgsa-layout #pgsa-container {
    padding: 80px 24px 0;
    box-sizing: border-box;
}

/* Pagination (replaces the gallery plugin's one) */
body.pgsa-layout .archive-pagination { display: none; }
.pgsa-pagination { padding-top: 56px; padding-bottom: 72px; }
.pgsa-pagination ul {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}
/* paginate_links() also gives the <ul> the "page-numbers" class, so only target the links */
.pgsa-pagination li > .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    box-sizing: border-box;
    font-size: 13px;
    color: var(--pgsa-text);
    text-decoration: none;
    background: var(--pgsa-surface);
    border: 1px solid var(--pgsa-border);
}
.pgsa-pagination li > .page-numbers.current {
    background: var(--pgsa-dark);
    border-color: var(--pgsa-dark);
    color: #fff;
}

/* Procedure CTA */
.pgsa-cta { background: var(--pgsa-surface); padding: 72px 0; }
.pgsa-cta__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
}
.pgsa-cta__title { font-size: clamp(26px, 3vw, 36px); max-width: 560px; }
.pgsa-cta__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; }

/* Disclaimer */
.pgsa-disclaimer { background: var(--pgsa-surface); padding: 28px 0; }
.pgsa-disclaimer p { margin: 0 auto; text-align: center; font-size: 12px; color: var(--pgsa-muted); }

/* Responsive */
@media (max-width: 900px) {
    .pgsa-refine__fields,
    .pgsa-refine__field,
    .pgsa-refine__fields select,
    .pgsa-refine__fields .pgsa-button { width: 100%; }
}

@media (max-width: 640px) {
    body.pgsa-layout #pgsa-container { padding: 48px 16px 0; }
    .pgsa-cta__actions { flex-direction: column; align-items: stretch; width: 100%; }

    /* Refine results: fixed bar at the bottom that opens a bottom sheet */
    body.pgsa-layout { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
    html.pgsa-refine-locked,
    html.pgsa-refine-locked body { overflow: hidden; }

    .pgsa-refine {
        width: auto;
        margin: 0;
        padding: 0;
        background: none;
        border: 0;
    }
    .pgsa-refine__label { display: none; }

    /* White strip with a shadow; ::before draws the inner bordered box */
    .pgsa-refine__toggle {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9997;
        display: flex;
        align-items: center;
        gap: 12px;
        margin: 0;
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
        box-sizing: border-box;
        border: 0;
        border-radius: 0;
        background: var(--pgsa-surface);
        box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
        color: var(--pgsa-text);
        font: inherit;
        text-align: left;
        cursor: pointer;
    }
    .pgsa-refine__toggle::before {
        content: "";
        position: absolute;
        top: 16px;
        left: 16px;
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        border: 1px solid var(--pgsa-border);
        pointer-events: none;
    }
    .pgsa-refine__toggle > * { position: relative; }
    .pgsa-refine__toggle .pgsa-refine__icon { margin-left: 16px; }
    .pgsa-refine__toggle .pgsa-refine__chevron { margin-right: 16px; }
    .pgsa-refine__toggle-label {
        padding: 15px 0;
        font-size: 13px;
        letter-spacing: .08em;
        text-transform: uppercase;
    }
    .pgsa-refine__summary {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 13px;
        color: var(--pgsa-muted);
    }

    .pgsa-refine__inner {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: 0;
        max-width: none;
        max-height: 90vh;
        overflow-y: auto;
        padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
        background: var(--pgsa-surface);
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        visibility: hidden;
        transition: transform .3s ease, visibility 0s linear .3s;
    }
    .pgsa-refine.is-open .pgsa-refine__inner {
        transform: none;
        visibility: visible;
        transition: transform .3s ease;
    }

    .pgsa-refine__head {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
    }
    .pgsa-refine__handle {
        flex-basis: 100%;
        height: 4px;
        margin-bottom: 20px;
    }
    .pgsa-refine__handle::before {
        content: "";
        display: block;
        width: 36px;
        height: 4px;
        margin: 0 auto;
        border-radius: 2px;
        background: var(--pgsa-border);
    }
    .pgsa-refine__title {
        display: flex;
        align-items: center;
        gap: 12px;
        font-size: 13px;
        letter-spacing: .08em;
        text-transform: uppercase;
        color: var(--pgsa-text);
    }
    .pgsa-refine__close {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 4px 0;
        border: 0;
        background: none;
        font: inherit;
        font-size: 13px;
        color: var(--pgsa-muted);
        cursor: pointer;
    }
    .pgsa-refine__close .pgsa-refine__chevron { transform: rotate(180deg); }

    .pgsa-refine__fields { gap: 16px; }
    .pgsa-refine__field-label {
        position: static;
        display: block;
        width: auto;
        height: auto;
        margin: 0 0 8px;
        overflow: visible;
        clip: auto;
        white-space: normal;
        font-size: 11px;
        letter-spacing: .1em;
        text-transform: uppercase;
        color: var(--pgsa-muted);
    }
    .pgsa-refine__fields select { height: 50px; font-size: 15px; }
    .pgsa-refine__fields .pgsa-button { height: 50px; margin-top: 0; }

    .pgsa-refine__backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 9998;
        background: rgba(0, 0, 0, .45);
        opacity: 0;
        visibility: hidden;
        transition: opacity .3s ease, visibility 0s linear .3s;
    }
    .pgsa-refine.is-open .pgsa-refine__backdrop {
        opacity: 1;
        visibility: visible;
        transition: opacity .3s ease;
    }
}

@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
    .pgsa-refine__inner,
    .pgsa-refine__backdrop { transition: none !important; }
}
