/* Webworks Filter Grid and Filter. UIkit draws the controls (checkboxes,
   radios, buttons, subnav, tabs, dropdowns, selects, inputs, search) in the
   site's style; this file only lays them out and adds what UIkit has no
   component for: the toggle switch, the two-handled range slider, counts
   and chips. Colours come from currentColor, so light and dark sections
   both work. Logical properties keep right-to-left pages right.

   Custom properties, for your own CSS:
   --ww-filter-gap            space between filters
   --ww-filter-option-gap     space between a filter's options
   --ww-filter-count-color    colour of the counts
   --ww-filter-chip-radius    corners of the applied-filter chips
   --ww-filter-accent         the switch's and slider's colour (by default
                              the theme's primary colour, from UIkit's
                              uk-text-primary on the parts, so it follows
                              the style and dark sections with no script)
   --ww-filter-switch-on      the switch's colour when on, if different */

.ww-filter {
    --ww-filter-gap: 30px;
    --ww-filter-option-gap: 4px;
}
.ww-filter-gap-small { --ww-filter-gap: 15px; }
.ww-filter-gap-medium { --ww-filter-gap: 40px; }
.ww-filter-gap-large { --ww-filter-gap: 70px; }

.ww-filter-facets {
    display: flex;
    flex-direction: column;
    gap: var(--ww-filter-gap);
}
.ww-filter-row .ww-filter-facets {
    flex-flow: row wrap;
    align-items: center;
    column-gap: calc(var(--ww-filter-gap) * 0.66);
    row-gap: 15px;
}
.ww-filter-align-center .ww-filter-facets { justify-content: center; }
.ww-filter-align-right .ww-filter-facets { justify-content: flex-end; }
.ww-filter-align-between .ww-filter-facets { justify-content: space-between; }
.ww-filter-facet[hidden], .ww-filter [hidden] { display: none !important; }
.ww-filter-hint { margin: 0 0 15px; }
.ww-filter-warning { margin: 0 0 15px; }

/* Groups: a fieldset and its label */
.ww-filter-group { border: 0; margin: 0; padding: 0; min-width: 0; }
.ww-filter-legend { display: block; margin: 0 0 10px; padding: 0; }
.ww-filter-legend.uk-h5, .ww-filter-legend.uk-h6 { margin-top: 0; }
.ww-filter-row .ww-filter-legend:not(.uk-hidden-visually) { margin-bottom: 6px; }
.ww-filter-label-plain { font-weight: inherit; }
/* UIkit's "* + ul" margin would push Subnav and Tab lists down after the
   legend, even a hidden one, so they sat lower than the other facets in a row */
.ww-filter-options { margin-top: 0; }

/* Folding a group away (the disclosure pattern) */
.ww-filter-fold {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    inline-size: 100%;
    min-block-size: 24px;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    text-align: start;
    cursor: pointer;
}
.ww-filter-fold-icon { transition: transform 0.2s ease; flex: none; }
.ww-filter-fold[aria-expanded="false"] .ww-filter-fold-icon { transform: rotate(-90deg); }
[dir="rtl"] .ww-filter-fold[aria-expanded="false"] .ww-filter-fold-icon { transform: rotate(90deg); }

/* Checkbox and radio lists */
.ww-filter-list { display: flex; flex-direction: column; align-items: flex-start; gap: var(--ww-filter-option-gap); }
.ww-filter-option { display: inline-flex; align-items: center; gap: 0.5em; min-block-size: 24px; cursor: pointer; }
.ww-filter-option > input { flex: none; margin: 0; }
.ww-filter-count { font-size: 0.875em; color: var(--ww-filter-count-color, inherit); white-space: nowrap; }
.ww-filter-disabled { opacity: 0.5; cursor: default; }
.ww-filter-more { margin-top: 6px; min-block-size: 24px; text-align: start; }

/* Buttons */
.ww-filter-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.ww-filter-button .ww-filter-count { margin-inline-start: 0.35em; }
.ww-filter-button[disabled] { opacity: 0.5; }

/* Subnav and tabs: UIkit's, with links acting as buttons */
.ww-filter-link { cursor: pointer; min-block-size: 24px; }
/* Minimum sizes include the padding on every platform: YOOtheme's Joomla stylesheet sets
   border-box on elements without uk- classes, its WordPress one doesn't */
.ww-filter-link, .ww-filter-option, .ww-filter-more, .ww-filter-switch, .ww-filter-chip, .ww-filter-result-count, .ww-filter-clear { box-sizing: border-box; }
.ww-filter-link .ww-filter-count { margin-inline-start: 0.35em; font-size: 0.9em; }
.ww-filter-link[aria-disabled="true"] { cursor: default; }
.uk-subnav.ww-filter-options { margin-bottom: 0; }

/* Dropdown */
.ww-filter-dropdown { position: relative; display: inline-block; }
.ww-filter-dropdown-toggle { display: inline-flex; align-items: center; gap: 8px; }
.ww-filter-badge { margin: 0; }
.ww-filter-drop { min-inline-size: 220px; }
.ww-filter-select, .ww-filter-sort { display: flex; flex-direction: column; }
.ww-filter-row .ww-filter-sort, .ww-filter-row .ww-filter-select { flex-direction: row; align-items: center; gap: 10px; }
.ww-filter-row .ww-filter-sort .ww-filter-legend, .ww-filter-row .ww-filter-select .ww-filter-legend { margin: 0; white-space: nowrap; }
.ww-filter-row .ww-filter-sort .uk-select, .ww-filter-row .ww-filter-select .uk-select { inline-size: auto; min-inline-size: 160px; }

/* Toggle switch: UIkit has no switch, so this is ours, built on a real
   checkbox (role="switch") that stays focusable and announced. */
.ww-filter-switch { position: relative; display: inline-flex; align-items: center; gap: 0.6em; min-block-size: 24px; cursor: pointer; }
.ww-filter-switch-input { position: absolute; inset-inline-start: 0; inline-size: 40px; block-size: 24px; margin: 0; opacity: 0; cursor: inherit; }
.ww-filter-switch-track {
    position: relative;
    flex: none;
    inline-size: 40px;
    block-size: 24px;
    border-radius: 12px;
    background: color-mix(in srgb, currentColor 30%, transparent);
}
/* The "on" colour: a part with UIkit's uk-text-primary, so currentColor is the
   theme's primary colour in this style and section. It fades in (opacity only)
   and carries the focus ring, which stays visible while the switch is off.
   The thumb is its ::after, so it can read that colour (below). */
.ww-filter-switch-on {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    --ww-filter-switch-fill: var(--ww-filter-switch-on, var(--ww-filter-accent, currentColor));
}
.ww-filter-switch-on::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--ww-filter-switch-fill);
    opacity: 0;
    transition: opacity 0.2s ease;
}
.ww-filter-switch-on::after {
    content: "";
    position: absolute;
    inset-block-start: 3px;
    inset-inline-start: 3px;
    inline-size: 18px;
    block-size: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}
.ww-filter-switch-input:checked + .ww-filter-switch-track .ww-filter-switch-on::before { opacity: 1; }
.ww-filter-switch-input:checked + .ww-filter-switch-track .ww-filter-switch-on::after { transform: translateX(16px); }
[dir="rtl"] .ww-filter-switch-input:checked + .ww-filter-switch-track .ww-filter-switch-on::after { transform: translateX(-16px); }
.ww-filter-switch-input:focus-visible + .ww-filter-switch-track .ww-filter-switch-on { outline: 2px solid var(--ww-filter-switch-fill); outline-offset: 2px; }
/* In a dark (inverse) section UIkit makes the primary colour light, white in
   its default style, so a white thumb would vanish into the switched-on
   track. So when the track's colour is light, the thumb goes dark instead; for
   any other track it stays white. It reads the colour the track really has
   (UIkit's inverse colours, the style's own, or --ww-filter-switch-on), so it
   is right in every kind of dark section, nested ones included, with no list
   of section classes to keep up with. Browsers without relative colours keep
   the white thumb, and so do those that can't start a relative colour from
   currentColor (the default fill), hence the test with it. */
@supports (color: oklch(from currentColor l c h)) {
    .ww-filter-switch-input:checked + .ww-filter-switch-track .ww-filter-switch-on::after {
        background: oklch(from var(--ww-filter-switch-fill) clamp(0.25, calc((0.7 - l) * 100), 1) 0 0);
    }
}

/* Range: two number boxes always, and optionally a slider with two
   handles: two native range inputs on one track (UIkit has a range style
   but not two handles on one track). */
.ww-filter-range-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ww-filter-range-label { display: block; margin-bottom: 4px; font-size: 0.875em; line-height: 24px; }
.ww-filter-row .ww-filter-range { min-inline-size: 240px; }
.ww-filter-slider {
    position: relative;
    block-size: 24px;
    margin: 0 0 10px;
}
.ww-filter-slider::before, .ww-filter-slider-fill {
    content: "";
    position: absolute;
    inset-block-start: 10px;
    block-size: 4px;
    border-radius: 2px;
}
.ww-filter-slider::before { inset-inline: 0; background: color-mix(in srgb, currentColor 20%, transparent); }
/* The chosen part of the track, and (below) the handles, take the theme's
   primary colour from uk-text-primary on them: currentColor */
.ww-filter-slider-fill { inset-inline-start: var(--ww-filter-from); inset-inline-end: calc(100% - var(--ww-filter-to)); background: var(--ww-filter-accent, currentColor); }
.ww-filter-slider-input {
    position: absolute;
    inset: 0;
    z-index: 1;
    inline-size: 100%;
    block-size: 24px;
    margin: 0;
    background: none;
    pointer-events: none;
    appearance: none;
    -webkit-appearance: none;
}
.ww-filter-slider-input::-webkit-slider-runnable-track { background: none; block-size: 24px; }
.ww-filter-slider-input::-moz-range-track { background: none; }
.ww-filter-slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    inline-size: 24px;
    block-size: 24px;
    border-radius: 50%;
    border: 2px solid var(--ww-filter-accent, currentColor);
    background: var(--ww-filter-accent, currentColor);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    cursor: grab;
}
.ww-filter-slider-input::-moz-range-thumb {
    box-sizing: border-box;
    inline-size: 24px;
    block-size: 24px;
    border-radius: 50%;
    border: 2px solid var(--ww-filter-accent, currentColor);
    background: var(--ww-filter-accent, currentColor);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    cursor: grab;
}
.ww-filter-slider-input:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--ww-filter-accent, currentColor); outline-offset: 2px; }
.ww-filter-slider-input:focus-visible::-moz-range-thumb { outline: 2px solid var(--ww-filter-accent, currentColor); outline-offset: 2px; }

/* Search */
.ww-filter-search .uk-search { display: block; }
.ww-filter-row .ww-filter-search { min-inline-size: 220px; }

/* Applied filters: theme buttons, with a remove icon */
.ww-filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ww-filter-chip { display: inline-flex; align-items: center; gap: 0.4em; min-block-size: 24px; border-radius: var(--ww-filter-chip-radius, 500px); }
.ww-filter-chip-name { opacity: 0.8; }
/* UIkit fills the icon in later: its size is kept from the start so chips don't grow and wrap */
.ww-filter-chip-x { flex: none; display: inline-flex; inline-size: 14px; block-size: 14px; }
.ww-filter-chip-x > svg { inline-size: 14px; block-size: 14px; }

.ww-filter-result-count { min-block-size: 24px; }
.ww-filter-clear { min-block-size: 24px; }

/* Apply: "Show 12 results" and "Clear all" */
.ww-filter-apply { display: flex; flex-wrap: wrap; gap: 10px; margin-top: var(--ww-filter-gap); }
.ww-filter-apply-button { flex: 1 1 auto; }
/* In an off-canvas panel it stays at the bottom while the filters scroll */
.uk-offcanvas-bar .ww-filter-apply {
    position: sticky;
    inset-block-end: 0;
    z-index: 1;
    margin-inline: -20px;
    padding: 15px 20px;
    background: var(--ww-filter-bar-bg, inherit);
}
.ww-filter-trigger-count { white-space: nowrap; }

/* Reduced motion: the fold arrow, the switch and its colour change at once.
   (The script's own item movement skips the same visitors.) */
@media (prefers-reduced-motion: reduce) {
    .ww-filter-fold-icon, .ww-filter-switch-on::after, .ww-filter-switch-on::before { transition: none; }
}

/* The grid */
.ww-filter-item[hidden] { display: none !important; }
/* Numbered pages (pagination.php), the Filter Grid's and the Data Table's:
   UIkit's pagination with buttons, which need the browser's button look taken off */
:is(.ww-filter-grid-pagination, .ww-data-table-pagination) button {
    min-width: 24px;
    min-height: 24px;
    margin: 0;
    border: 0;
    background: none;
    font: inherit;
    cursor: pointer;
}
/* Items outside the current page (pagination.php); filtered-out items have the hidden attribute */
.ww-filter-item.ww-filter-grid-off-page { display: none !important; }
.ww-filter-items:focus { outline: none; }
/* Printing: every item of the current filter, without the page controls */
@media print {
    .ww-filter-item.ww-filter-grid-off-page { display: block !important; }
    .ww-filter-grid :is(.ww-filter-grid-pagination, .ww-filter-grid-more) { display: none !important; }
}
