.psaf-layout {
    --psaf-ink: #163248;
    --psaf-accent: #a50063;
    --psaf-border: #dce6eb;
    display: grid;
    grid-template-columns: minmax(200px, 230px) minmax(0, 1fr);
    align-items: start;
    gap: clamp(20px, 3vw, 38px);
    width: 100%;
    clear: both;
    margin-top: 24px;
    scroll-margin-top: 112px;
    color: var(--psaf-ink);
}

.psaf-sidebar,
.psaf-results {
    min-width: 0;
}

.psaf-form {
    background: #fff;
    border: 1px solid var(--psaf-border);
    border-radius: 16px;
    padding: 18px;
}

.psaf-form-heading,
.psaf-dialog-header {
    font-family: Montserrat, sans-serif;
    font-size: 20px;
    font-weight: 700;
}

.psaf-form-heading {
    margin-bottom: 8px;
}

.psaf-group {
    border-top: 1px solid var(--psaf-border);
    padding: 9px 0;
}

.psaf-group > summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 32px;
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.psaf-group > summary::-webkit-details-marker { display: none; }
.psaf-group > summary::after { content: '+'; color: var(--psaf-accent); font-size: 19px; font-weight: 400; }
.psaf-group[open] > summary::after { content: '−'; }

.psaf-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1px;
    padding: 3px 0 5px;
}

.psaf-choice {
    display: flex;
    align-items: center;
    min-height: 29px;
    gap: 7px;
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

.psaf-choice > span:last-child {
    min-width: 0;
    overflow-wrap: anywhere;
}

.psaf-choice > input[type=checkbox] {
    appearance: auto;
    width: 15px;
    height: 15px;
    flex: 0 0 15px;
    margin: 0;
    accent-color: var(--psaf-accent);
}

.psaf-swatch {
    width: 13px;
    height: 13px;
    flex: 0 0 13px;
    border-radius: 50%;
    border: 1px solid #16324842;
    background: var(--psaf-swatch);
}

.psaf-actions {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.psaf-actions button,
.psaf-mobile-trigger {
    min-height: 44px;
    width: 100%;
    padding: 9px 14px;
    border-radius: 9px;
    font: inherit;
    font-weight: 700;
}

.psaf-actions button {
    color: #fff;
    background: var(--psaf-accent);
    border: 1px solid var(--psaf-accent);
}

.psaf-actions a {
    justify-self: center;
    color: var(--psaf-accent);
    text-decoration: underline;
    font-size: 13px;
}

.psaf-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 16px;
}

.psaf-chips a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 4px 10px;
    border: 1px solid #efcfe1;
    border-radius: 24px;
    background: #fff2f8;
    color: var(--psaf-accent);
    font-size: 13px;
    font-weight: 700;
}

.psaf-layout :is(a, button, summary, input):focus-visible {
    outline: 2px solid var(--psaf-accent);
    outline-offset: 3px;
}

body.woocommerce .psaf-layout .psaf-results ul.products {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: clamp(12px, 2vw, 22px) !important;
    width: 100%;
}

body.woocommerce .psaf-layout .psaf-results ul.products::before,
body.woocommerce .psaf-layout .psaf-results ul.products::after { display: none !important; }

body.woocommerce .psaf-layout .psaf-results ul.products > * {
    width: 100% !important;
    min-width: 0;
    margin: 0 !important;
    float: none !important;
    box-sizing: border-box;
}

.psaf-results .woocommerce-sorting-wrapper > .row { margin-inline: 0; }
.psaf-results .woocommerce-sorting-wrapper > .row > div { padding-inline: 0; }
.psaf-results .woocommerce-ordering select { max-width: 100%; }
.psaf-mobile-trigger { display: none; }
.psaf-dialog:not([open]) { display: none; }

.psaf-dialog {
    width: min(100% - 24px, 430px);
    max-height: min(88vh, 740px);
    max-height: min(88dvh, 740px);
    padding: 0;
    border: 1px solid var(--psaf-border);
    border-radius: 16px;
    color: var(--psaf-ink);
    background: #fff;
}

.psaf-dialog::backdrop { background: #142a42a8; }
html:has(.psaf-dialog[open]) { overflow: hidden; }

.psaf-dialog-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px 10px 20px;
    background: #fff;
    border-bottom: 1px solid var(--psaf-border);
}

.psaf-dialog-header button {
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    color: var(--psaf-ink);
    background: #f2f6f8;
    font-size: 25px;
}

.psaf-dialog .psaf-form { border: 0; padding: 12px 20px 20px; }
.psaf-dialog .psaf-form-heading { display: none; }
.psaf-dialog .psaf-choice { min-height: 38px; font-size: 15px; }
.psaf-dialog .psaf-group > summary { min-height: 42px; }
.psaf-dialog .psaf-group:first-of-type { border-top: 0; }
.psaf-dialog .psaf-actions {
    position: sticky;
    bottom: 0;
    margin-bottom: -10px;
    padding: 10px 0;
    background: #fff;
}
.psaf-dialog [data-psaf-group="colore"] .psaf-options,
[data-psaf-group="taglia"] .psaf-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 1040px) {
    body.woocommerce .psaf-layout .psaf-results ul.products {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 760px) {
    .psaf-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 14px; }

    .psaf-layout[data-psaf-ready] .psaf-sidebar > .psaf-form { display: none; }
    .psaf-layout[data-psaf-ready] .psaf-mobile-trigger {
        display: inline-block;
        width: auto;
        color: var(--psaf-ink);
        background: #fff;
        border: 1px solid #bcced8;
    }

    .psaf-results .woocommerce-sorting-wrapper > .row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .psaf-results .woocommerce-sorting-wrapper > .row > div { width: auto; max-width: none; min-width: 0; }
    .psaf-results .woocommerce-result-count { font-size: 13px; margin: 0; }
    .psaf-results .woocommerce-ordering { max-width: 100%; margin: 0; }
    .psaf-results .woocommerce-ordering select { font-size: 13px; padding-inline: 6px 28px !important; text-overflow: ellipsis; }
}

@media (max-width: 360px) {
    .psaf-results .woocommerce-sorting-wrapper > .row { grid-template-columns: minmax(0, 1fr); }
}
