/**
 * Archive layout with filters (inc/Filters.php, js/blog/filters.js).
 *
 * Desktop: the filters in an aside, the articles/products beside it.
 * Phones and tablets: a floating "Filters" button opens the same aside as a
 * modal sheet. Without JavaScript the filters simply sit above the results.
 * Tokens only (css/core/tokens.css).
 */

/* Layout ----------------------------------------------------------------- */
.archive-layout {
    margin-top: var(--spacing-lg);
}

.archive-results {
    min-width: 0;
}

@media (min-width: 961px) {
    .archive-layout.has-filters {
        display: grid;
        grid-template-columns: minmax(230px, 270px) minmax(0, 1fr);
        gap: var(--spacing-xl);
        align-items: start;
    }

    /* The panel scrolls with the page, at its full height: no inner scroll
       box (a second scrollbar beside the page's), and no sticky position
       (a tall panel would hide its lower filters while stuck). */
    .archive-filters {
        position: static;
    }

    /* Products have less room beside the filters: let the grid choose. */
    .archive-layout.has-filters ul.products {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card-min)), 1fr));
    }
}

/* The aside ------------------------------------------------------------- */
.archive-filters {
    padding: var(--spacing-md) var(--spacing-lg) var(--spacing-lg);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
}

.archive-filters__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.archive-filters__title {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    margin: 0;
    font-size: var(--font-size-large);
    color: var(--text-color);
}

.archive-filters__close {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    box-shadow: none;
}

.archive-filters__close[hidden] {
    display: none;
}

.archive-filters .widget {
    margin: 0;
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
    transform: none;
}

.filter-panel__count {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--filled-bg);
    color: var(--filled-text);
    font-size: 12px;
    font-weight: 600;
}

.filter-panel__count[hidden] {
    display: none;
}

/* Form: one column in the aside ---------------------------------------- */
.filter-panel__form,
.product-filters {
    display: grid;
    gap: var(--spacing-md);
}

.filter-panel__field,
.filter-panel__group,
.product-filters__group {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.filter-panel__row {
    display: grid;
    gap: var(--spacing-md);
}

.filter-panel__field label,
.filter-panel__group legend,
.product-filters__group legend {
    padding: 0;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: var(--font-size-small);
    color: var(--text-color);
}

.filter-panel__field input,
.filter-panel__field select {
    width: 100%;
    min-height: 42px;
}

.filter-panel__option,
.product-filters__option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    color: var(--text-color);
}

.filter-panel__option input,
.product-filters__option input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--filled-bg);
}

.filter-panel__n,
.product-filters__count {
    margin-inline-start: auto;
    color: var(--text-muted, var(--text-color));
    font-size: var(--font-size-small);
}

.product-filters__price {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
}

.product-filters__price label {
    display: grid;
    gap: 2px;
    font-size: var(--font-size-small);
}

.product-filters__price input {
    width: 100%;
    max-width: none;
    min-height: 42px;
}

/* Topic chips */
.filter-panel__group--chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter-panel__group--chips legend {
    width: 100%;
}

.filter-panel__chip {
    position: relative;
}

.filter-panel__chip input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.filter-panel__chip span {
    display: inline-block;
    padding: 4px 12px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--card-bg);
    color: var(--text-color);
    font-size: var(--font-size-small);
}

.filter-panel__chip input:hover + span {
    border-color: var(--focus-color);
    background: var(--hover-surface);
    color: var(--hover-text);
}

.filter-panel__chip input:checked + span {
    background: var(--filled-bg);
    border-color: var(--filled-bg);
    color: var(--filled-text);
}

.filter-panel__chip input:focus-visible + span {
    outline: var(--focus-ring-width) solid var(--focus-color);
    outline-offset: var(--focus-ring-offset);
}

.filter-panel__actions,
.product-filters__actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin: 0;
}

.filter-panel__actions .cta-btn-primary,
.product-filters__actions .cta-btn-primary {
    flex: 1 1 auto;
}

/* While results are being fetched: the results fade and a round spinner
   turns in the middle of the grid (kept on screen for long lists). The fade
   is on the children, so the spinner itself stays at full strength. */
.archive-results {
    position: relative;
}

.archive-results > * {
    transition: opacity 0.15s;
}

.archive-results[aria-busy="true"] > * {
    opacity: 0.45;
}

.archive-results[aria-busy="true"]::after {
    content: "";
    position: absolute;
    z-index: 5;
    top: min(50%, 40vh);
    left: 50%;
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border: 4px solid color-mix(in srgb, var(--filled-bg) 22%, transparent);
    border-top-color: var(--filled-bg);
    border-radius: 50%;
    background: var(--card-bg);
    box-shadow: 0 0 0 6px var(--card-bg), 0 6px 20px rgba(0, 0, 0, 0.15);
    animation: tarjava-theme-spin 0.8s linear infinite;
    pointer-events: none;
}

@keyframes tarjava-theme-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .archive-results > * {
        transition: none;
    }

    /* Still shown, turning slowly — a static ring would not say "working". */
    .archive-results[aria-busy="true"]::after {
        animation-duration: 2.4s;
    }
}

/* Floating "Filters" button (created by js/blog/filters.js) ------------------ */
.filters-fab {
    display: none;
}

.filters-backdrop[hidden] {
    display: none;
}

/* Small screens: FAB + modal sheet ------------------------------------------
   Keyed to html.js (set in <head> before the first paint), not to the class the
   deferred script adds: the panel used to render inline above the results and
   then vanish into the sheet, pushing the page up (layout shift 0.4–0.5 on
   phones). Without JavaScript the filters stay inline. */
@media (max-width: 960px) {
    html.js .archive-layout .archive-filters {
        display: none;
    }

    html.js .archive-layout .archive-filters.is-open {
        display: block;
        position: fixed;
        z-index: 100003;
        inset: auto 0 0 0;
        max-height: min(85vh, 720px);
        overflow-y: auto;
        overscroll-behavior: contain;
        border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
        padding-bottom: calc(var(--spacing-lg) + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.25);
    }

    .archive-filters.is-open .archive-filters__header {
        position: sticky;
        top: calc(var(--spacing-md) * -1);
        z-index: 1;
        margin: calc(var(--spacing-md) * -1) calc(var(--spacing-lg) * -1) var(--spacing-md);
        padding: var(--spacing-md) var(--spacing-lg) var(--spacing-sm);
        background: var(--card-bg);
    }

    .filters-backdrop {
        position: fixed;
        inset: 0;
        z-index: 100002;
        background: rgba(0, 0, 0, 0.5);
    }

    .filters-fab.is-enhanced {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        z-index: 100001;
        right: var(--spacing-md);
        bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
        min-height: 52px;
        padding: 0 20px;
        border: 0;
        border-radius: 999px;
        background: var(--filled-bg);
        color: var(--filled-text);
        font-weight: 600;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
        cursor: pointer;
    }

    [dir="rtl"] .filters-fab.is-enhanced {
        right: auto;
        left: var(--spacing-md);
    }

    .filters-fab.is-enhanced:hover,
    .filters-fab.is-enhanced:focus-visible {
        background: var(--filled-bg-hover);
        color: var(--filled-text);
    }

    .filters-fab.is-enhanced:focus-visible {
        outline: var(--focus-ring-width) solid var(--focus-color);
        outline-offset: 3px;
    }

    .filters-fab .filter-panel__count {
        background: var(--filled-text);
        color: var(--filled-bg);
    }

    body.filters-open {
        overflow: hidden;
    }

    /* Keep the FAB clear of the store's toast. */
    body:has(.shop-toast.is-visible) .filters-fab.is-enhanced {
        bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    }
}

/* The widget wrapper inside the aside is not a second card (the theme's and
   WooCommerce's .widget styles are more specific than a plain reset). */
body .archive-filters .widget,
body .archive-filters .archive-filters__widget,
.woocommerce .archive-filters .widget {
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

/* Result count and sort order share one row above the products. */
body.woocommerce .archive-results > .woocommerce-result-count {
    float: left;
    margin: 10px 0 var(--spacing-md);
}

body.woocommerce .archive-results > .woocommerce-ordering {
    float: right;
    clear: none;
    width: auto;
    display: block;
    margin: 0 0 var(--spacing-md);
}

.archive-results > .woocommerce-ordering select {
    width: auto;
    min-width: 200px;
}

[dir="rtl"] .woocommerce .archive-results > .woocommerce-result-count {
    float: right;
}

[dir="rtl"] .woocommerce .archive-results > .woocommerce-ordering {
    float: left;
}

.archive-results > ul.products,
.archive-results > .woocommerce-info,
.archive-results > .woocommerce-no-products-found {
    clear: both;
}

/* Older product-filter rules in shop-extras.css load later: restate the
   aside layout with enough weight. */
body .archive-filters .product-filters,
body .archive-filters .product-filters__group {
    margin: 0;
    padding: 0;
}

body .archive-filters .product-filters__price input {
    width: 100%;
    max-width: none;
}


/* Category, tag, author and date cards: the meta line (author, date,
   reading time) at the bottom of the card. */
.post-grid > li > .post-card__inner > .post-card__content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

.post-grid > li > .post-card__inner > .post-card__content > .post-card__meta {
    margin-top: auto;
}

/* The shop's <main> had its own max-width and padding on top of the
   container's, so products got 30px less than the blog. The container alone
   sets the width, as on every other page. */
body.woocommerce .site-main.woocommerce-main {
    max-width: none;
    padding-inline: 0;
}


/* With live filtering there is no apply button ("Clear all" stays). */
.has-live-filters .filter-panel__actions .cta-btn-primary,
.has-live-filters .product-filters__actions .cta-btn-primary {
    display: none;
}

.has-live-filters .filter-panel__actions,
.has-live-filters .product-filters__actions {
    justify-content: flex-end;
}

/* Long term lists (roadmap 29): extras hidden until "Show all", except a
   ticked one. Without JavaScript every term shows. */
fieldset.is-collapsed .is-extra:not(:has(input:checked)) {
    display: none;
}

.filter-panel__more {
    justify-self: start;
    margin-top: 4px;
    padding: 2px 0;
    border: 0;
    background: none;
    color: var(--link-color, var(--focus-color));
    font-size: var(--font-size-small);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    box-shadow: none;
}

.filter-panel__more:hover,
.filter-panel__more:focus-visible {
    color: var(--hover-text);
}

/* Active filters as chips above the results (roadmap 35) -------------- */
.filter-chips {
    margin: 0 0 var(--spacing-md);
}

.filter-chips__list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.filter-chips__chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 4px 10px 4px 12px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--card-bg);
    color: var(--text-color);
    font-size: var(--font-size-small);
    text-decoration: none;
}

.filter-chips__chip:hover,
.filter-chips__chip:focus-visible {
    background: var(--hover-surface);
    color: var(--hover-text);
    border-color: var(--focus-color);
}

.filter-chips__clear {
    margin-inline-start: 4px;
    font-size: var(--font-size-small);
}

/* Terms that would give no results with the other filters (roadmap 36). */
.filter-panel__option:has([data-zero]):not(:has(input:checked)),
.product-filters__option:has([data-zero]):not(:has(input:checked)) {
    opacity: 0.6;
}

/* Price slider (roadmap 37) -------------------------------------------- */
.price-slider {
    --lo: 0%;
    --hi: 100%;
    position: relative;
    height: 28px;
    margin-top: 8px;
}

.price-slider[hidden] {
    display: none;
}

.price-slider::before {
    content: "";
    position: absolute;
    inset-inline: 0;
    top: 12px;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--border-color) var(--lo), var(--filled-bg) var(--lo), var(--filled-bg) var(--hi), var(--border-color) var(--hi));
}

[dir="rtl"] .price-slider::before {
    background: linear-gradient(to left, var(--border-color) var(--lo), var(--filled-bg) var(--lo), var(--filled-bg) var(--hi), var(--border-color) var(--hi));
}

.price-slider__range {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 28px;
    margin: 0;
    background: none;
    pointer-events: none;
    appearance: none;
}

.price-slider__range::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    border: 3px solid var(--card-bg);
    border-radius: 50%;
    background: var(--filled-bg);
    box-shadow: 0 0 0 1px var(--filled-bg);
    pointer-events: auto;
    cursor: grab;
    appearance: none;
}

.price-slider__range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: 3px solid var(--card-bg);
    border-radius: 50%;
    background: var(--filled-bg);
    pointer-events: auto;
    cursor: grab;
}

.price-slider__range::-webkit-slider-runnable-track,
.price-slider__range::-moz-range-track {
    background: none;
}

/* The theme's form-field look (border, padding, background) must not reach
   the slider's inputs: each would draw a box over the other's handle. */
.product-filters .price-slider__range,
.filter-panel__form .price-slider__range {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    min-height: 0;
    outline: none;
}

.price-slider__range:focus-visible::-webkit-slider-thumb {
    outline: var(--focus-ring-width, 2px) solid var(--focus-color);
    outline-offset: 2px;
}

/* The price fields are text boxes in the shop's number format (1,200.00),
   so there are no browser up/down arrows to hide. */
.product-filters__price input[data-price-field] {
    font-variant-numeric: tabular-nums;
}
