/**
 * Shop filters (inc/shop-filters.php, inc/shop-filter-sliders.php,
 * assets/js/shop-filters.js).
 *
 * The left-hand panel on the shop and category pages, the applied-filter
 * chips above the grid, and the Weight and Price sliders. Moved out of
 * woocommerce.css, which had grown past 2,000 lines.
 *
 * Each group (Type, Purity, Weight, Price) is a fieldset whose legend is its
 * heading, underlined. The legend is floated so it lays out as a plain block
 * with the line beneath it; left to itself a legend sits on the fieldset's
 * top border, which drew the line out to its right instead.
 */

.shop-layout:has(> .shop-filters) {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    gap: var(--spacing-lg);
    align-items: start;
}

.shop-filters {
    position: sticky;
    top: var(--spacing-md);
}

.shop-filters__toggle {
    display: none;
}

.shop-filters__body {
    background-color: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--spacing-md);
    max-height: calc(100vh - 2 * var(--spacing-md));
    overflow-y: auto;
}

.shop-filters__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.shop-filters__title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.05rem;
    color: var(--color-primary);
}

/* Back arrow: undoes the last filter change (shop-filters.js). */
.shop-filters__back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: -6px -6px -6px 0;
    border-radius: 50%;
    color: var(--color-primary);
    transition: background-color 0.15s ease;
}

.shop-filters__back:hover,
.shop-filters__back:focus-visible {
    background-color: rgba(0, 0, 0, 0.06);
}

.shop-filters__back[hidden] {
    display: none;
}

.shop-filter-chips__clear {
    font-size: 0.85rem;
    color: var(--color-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.filter-group {
    border: 0;
    margin: 0;
    padding: var(--spacing-sm) 0;
    min-width: 0;
}

.filter-group:first-of-type {
    padding-top: 0;
}

.filter-group:last-of-type {
    padding-bottom: 0;
}

.filter-group__title {
    float: left;
    width: 100%;
    padding: 0 0 0.45rem;
    margin-bottom: 0.6rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text);
}

/* Everything in a group starts below its floated heading. */
.filter-group__title ~ * {
    clear: both;
}

.filter-group__unit {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--color-text-muted);
}

/* Gold / Silver headings inside Type on the shop page. */
.filter-subgroup__title {
    margin: 0.75rem 0 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.filter-group__title + .filter-subgroup__title {
    margin-top: 0;
}

.filter-options {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0.4rem;
    margin: 0 -0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--color-text);
    cursor: pointer;
    transition: var(--transition-fast);
}

.filter-option:hover {
    background-color: var(--color-primary-tint);
}

.filter-option input {
    flex: none;
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.filter-option__label {
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.filter-option__count {
    flex: none;
    font-size: 0.8rem;
    color: var(--color-text-subtle);
    font-variant-numeric: tabular-nums;
}

.filter-option input:checked ~ .filter-option__label {
    font-weight: 600;
    color: var(--color-primary);
}

/* "See more (4)" / "See less" under a long list (assets/js/shop-filters.js). */
.filter-more {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.35rem;
    padding: 0.2rem 0;
    border: 0;
    background: none;
    color: var(--color-primary);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.filter-more::after {
    content: '';
    width: 6px;
    height: 6px;
    margin-top: -3px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
}

.filter-more.is-open::after {
    margin-top: 3px;
    transform: rotate(-135deg);
}

.filter-more:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.filter-more:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Plain min / max boxes: what the sliders stand in for, shown without JS. */
.filter-range {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* display: flex above would otherwise beat the hidden attribute. */
.filter-range[hidden] {
    display: none;
}

.filter-range input {
    width: 100%;
    min-width: 0;
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--color-text);
    background-color: var(--color-white);
    -moz-appearance: textfield;
}

.filter-range input::-webkit-outer-spin-button,
.filter-range input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.filter-range input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-focus);
}

.filter-range__sep {
    color: var(--color-text-subtle);
}

.filter-range__go {
    flex: none;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background-color: var(--color-white);
    color: var(--color-primary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.filter-range__go:hover {
    background-color: var(--color-primary);
    color: var(--color-white);
}

/*
 * Weight and Price sliders: the range picked, and below it one bar with two
 * handles. Letting go of a handle applies it.
 *
 * Each slider is two range inputs laid over the same bar. The inputs ignore
 * the pointer and only their handles take it, so either handle can be
 * grabbed even though both inputs cover the whole bar. The coloured part
 * between the handles is a span the script positions.
 *
 * The inputs reach half a handle past each end of the bar. A native slider
 * keeps its handle inside the input, so this puts the handle's centre exactly
 * on the bar's ends, and the coloured part lines up with the handles.
 */
.filter-slider__value {
    margin: 0 0 0.6rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.filter-slider__bar {
    position: relative;
    height: 20px;
    /* Half a handle each side, so a handle at an end stays inside the panel. */
    margin: 0 9px 0.25rem;
}

.filter-slider__bar::before,
.filter-slider__fill {
    content: '';
    position: absolute;
    top: 50%;
    height: 4px;
    margin-top: -2px;
    border-radius: 2px;
}

.filter-slider__bar::before {
    left: 0;
    right: 0;
    background-color: var(--color-border);
}

.filter-slider__fill {
    background-color: var(--color-primary);
}

.filter-slider__thumb {
    position: absolute;
    top: 0;
    left: -9px;
    width: calc(100% + 18px);
    height: 20px;
    margin: 0;
    padding: 0;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
}

.filter-slider__thumb:focus {
    outline: none;
}

.filter-slider__thumb::-webkit-slider-runnable-track {
    height: 20px;
    background: none;
}

.filter-slider__thumb::-moz-range-track {
    background: none;
}

.filter-slider__thumb::-webkit-slider-thumb {
    -webkit-appearance: none;
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    border: 2px solid var(--color-primary);
    border-radius: 50%;
    background-color: var(--color-white);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    pointer-events: auto;
}

.filter-slider__thumb::-moz-range-thumb {
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-primary);
    border-radius: 50%;
    background-color: var(--color-white);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    pointer-events: auto;
}

.filter-slider__thumb:active::-webkit-slider-thumb {
    cursor: grabbing;
}

.filter-slider__thumb:active::-moz-range-thumb {
    cursor: grabbing;
}

.filter-slider__thumb:focus-visible::-webkit-slider-thumb {
    box-shadow: var(--shadow-focus);
}

.filter-slider__thumb:focus-visible::-moz-range-thumb {
    box-shadow: var(--shadow-focus);
}

.shop-filters__apply {
    width: 100%;
    margin-top: var(--spacing-sm);
}

/* Applied-filter chips above the grid */
.shop-filter-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: var(--spacing-md);
}

.shop-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--purple-200);
    border-radius: 999px;
    background-color: var(--color-primary-tint);
    color: var(--color-primary);
    font-size: 0.85rem;
    line-height: 1.2;
    transition: var(--transition-fast);
}

.shop-filter-chip:hover {
    border-color: var(--color-primary);
}

/* Narrow screens: the panel collapses behind a Filters button. */
@media (max-width: 991px) {
    .shop-layout:has(> .shop-filters) {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--spacing-sm);
    }

    .shop-filters {
        position: static;
    }

    .shop-filters__toggle {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.55rem 1rem;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-sm);
        background-color: var(--color-white);
        color: var(--color-text);
        font-family: var(--font-body);
        font-size: 0.9rem;
        font-weight: 600;
        cursor: pointer;
    }

    .shop-filters__dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background-color: var(--color-accent);
    }

    .shop-filters.js-ready:not(.is-open) .shop-filters__body {
        display: none;
    }

    .shop-filters.js-ready .shop-filters__body {
        margin-top: var(--spacing-xs);
        max-height: none;
    }
}
