/* ═══════════════════════════════════════════════════════════════════════════
   Filter sidebar — all filter UI styles.

   BEM:
     .filter-form          — top-level form
     .filter-accordion     — one collapsible filter group (<details>)
     .filter-accordion__head  — the <summary> trigger row
     .filter-accordion__title — section name ("GARMENT TYPE")
     .filter-accordion__clear — "Clear" link
     .filter-accordion__chevron — ▼ icon
     .filter-accordion__body  — collapsible content
     .filter-list          — <ul> of radio / checkbox items
     .filter-item          — individual label row (radio or checkbox)
     .filter-item__input   — the actual input (sr-only visually)
     .filter-item__icon    — optional 18px icon beside label
     .filter-item__label   — text
     .filter-swatch        — compact color / pattern swatch
     .filter-swatch__input — sr-only input
     .filter-swatch__dot   — colored circle or pattern preview
     .filter-swatch__name  — text label below dot
*/

/* ═══════════════════════════════════════════════════════════════════════════
   Mobile Filter Panel
   ═══════════════════════════════════════════════════════════════════════════

   BEM:
     .filter-panel          — fixed full-screen overlay wrapper
     .filter-panel__backdrop — dimmed background, tap to close
     .filter-panel__sheet   — the visible panel
     .filter-panel__head    — title row + close button
     .filter-panel__body    — scrollable filter form area
     .filter-panel__footer  — sticky Clear + Apply row

   Mobile  ≤639px : bottom sheet — slides up, rounded top corners
   Tablet  ≥640px : right panel  — slides in from right
*/

/* ─── Panel overlay ──────────────────────────────────────────────────────── */

.filter-panel {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;

    /* Mobile: align sheet to bottom */
    align-items: flex-end;
    justify-content: stretch;
}

@media (min-width: 640px) {
    .filter-panel {
        align-items: stretch;
        justify-content: flex-end;
    }
}

/* ─── Backdrop ───────────────────────────────────────────────────────────── */

.filter-panel__backdrop {
    position: fixed;
    inset: 0;
    background-color: var(--overlay-panel);
    cursor: pointer;
}

/* ─── Sheet ──────────────────────────────────────────────────────────────── */

.filter-panel__sheet {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    box-shadow: var(--shadow-lg);

    /* Mobile: full-width bottom sheet, 92vh max */
    width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-top: 1px solid var(--border-light);
}

@media (min-width: 640px) {
    .filter-panel__sheet {
        /* Tablet: right panel */
        width: 360px;
        max-height: 100%;
        border-radius: 0;
        border-top: none;
        border-left: 1px solid var(--border-light);
    }
}

/* ─── Header ─────────────────────────────────────────────────────────────── */

.filter-panel__head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.filter-panel__title {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.1;
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
}

/* Active filter count badge beside the title */
.filter-panel__active-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-1);
    background-color: var(--accent-gold);
    color: var(--bg-primary);
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1;
}

/* Close button — 44×44 touch target */
.filter-panel__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    margin-right: calc(-1 * var(--space-2));
    transition:
        color            var(--duration-fast) var(--ease),
        background-color var(--duration-fast) var(--ease);
}

.filter-panel__close:hover {
    color: var(--text-primary);
    background-color: var(--surface-hover);
}

.filter-panel__close:focus-visible {
    outline: 2px solid var(--accent-gold);
    outline-offset: 2px;
}

/* ─── Scrollable body ────────────────────────────────────────────────────── */

.filter-panel__body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 var(--space-5);
    /* Smooth momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-medium) transparent;
}

/* Increase touch targets for all filter items inside the panel */
.filter-panel__body .filter-item {
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
}

.filter-panel__body .filter-accordion__toggle {
    min-height: 48px;
    padding: var(--space-3) 0;
}

/* Slightly larger swatches on mobile for easier tapping */
.filter-panel__body .filter-swatch__dot {
    width: 34px;
    height: 34px;
}

/* Swatch grid — 4 columns within the narrower panel padding context */
.filter-panel__body .filter-swatches {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* ─── Sticky footer ──────────────────────────────────────────────────────── */

.filter-panel__footer {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-light);
    background-color: var(--bg-secondary);
    flex-shrink: 0;
}

.filter-panel__clear {
    flex: 0 0 auto;
}

.filter-panel__apply {
    flex: 1;
    justify-content: center;
}

/* ─── Transitions — bottom sheet on mobile, right panel on tablet ─────────── */

/* Mobile: slide up from bottom */
.filter-panel--enter .filter-panel__backdrop,
.filter-panel--leave .filter-panel__backdrop {
    transition: opacity var(--duration-slow) var(--ease);
}

.filter-panel--enter-start .filter-panel__backdrop,
.filter-panel--leave-end   .filter-panel__backdrop { opacity: 0; }

.filter-panel--enter-end   .filter-panel__backdrop,
.filter-panel--leave-start .filter-panel__backdrop { opacity: 1; }

.filter-panel--enter .filter-panel__sheet,
.filter-panel--leave .filter-panel__sheet {
    transition: transform var(--duration-slow) var(--ease-out);
}

.filter-panel--enter-start .filter-panel__sheet,
.filter-panel--leave-end   .filter-panel__sheet {
    transform: translateY(100%);
}

.filter-panel--enter-end   .filter-panel__sheet,
.filter-panel--leave-start .filter-panel__sheet {
    transform: translateY(0);
}

/* Tablet+: slide in from right */
@media (min-width: 640px) {
    .filter-panel--enter-start .filter-panel__sheet,
    .filter-panel--leave-end   .filter-panel__sheet {
        transform: translateX(100%);
    }

    .filter-panel--enter-end   .filter-panel__sheet,
    .filter-panel--leave-start .filter-panel__sheet {
        transform: translateX(0);
    }
}

/* ─── Mobile panel loading skeleton ─────────────────────────────────────── */
/* Shown while HTMX fetches the filter form on first drawer open.            */

.filter-panel__skeleton {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4) 0;
}

.filter-panel__skeleton-row {
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--surface-hover) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: filter-shimmer 1.4s ease infinite;
}

@keyframes filter-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .filter-panel__skeleton-row { animation: none; }
}

/* ─── Form shell ─────────────────────────────────────────────────────────── */

.filter-form__actions {
    padding-top: var(--space-5);
    padding-bottom: var(--space-3);
}

.filter-form .btn {
    width: 100%;
    justify-content: center;
}

/* ─── Accordion ──────────────────────────────────────────────────────────── */

.filter-accordion {
    border-bottom: 1px solid var(--border-light);
}

.filter-accordion__head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Toggle button — the clickable expand/collapse control */
.filter-accordion__toggle {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4) 0;
    background: none;
    border: none;
    cursor: pointer;
    user-select: none;
    text-align: left;
    color: inherit;
    min-width: 0;
}

.filter-accordion__toggle:focus-visible {
    outline: 2px solid var(--accent-gold);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.filter-accordion__title {
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.filter-accordion__clear {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: color var(--duration-fast) var(--ease);
    position: relative;
    z-index: var(--z-raised);
}

.filter-accordion__clear:hover       { color: var(--accent-gold); }
.filter-accordion__clear:focus-visible {
    outline: 2px solid var(--accent-gold);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.filter-accordion__chevron {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform var(--duration-base) var(--ease);
    margin-left: auto;
}

.filter-accordion__chevron--open {
    transform: rotate(180deg);
}

.filter-accordion__body {
    padding-top: var(--space-2);
    padding-bottom: var(--space-5);
    overflow: hidden;   /* prevents any child from creating horizontal scroll */
}

.filter-accordion__empty {
    font-size: var(--text-sm);
    color: var(--text-muted);
    padding: var(--space-1) 0;
    list-style: none;
}

/* ─── Radio / Checkbox list ──────────────────────────────────────────────── */

.filter-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;   /* consistent rhythm between items */
}

.filter-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease);
}

.filter-item:hover       { background-color: var(--surface-hover); }
.filter-item--active     { background-color: var(--surface-hover); }

/* Hidden native input — WCAG clip technique */
.filter-item__input {
    appearance: none;
    -webkit-appearance: none;
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    margin: 0;
    padding: 0;
}

/* ─── Unified control indicator drawn via ::before ───────────────────────── */
/*
   Radio  — circle, filled gold with white inner dot when checked.
   Checkbox — rounded-sm square, filled gold with white checkmark when checked.
   Same size, border weight, color, and transitions for both.
*/

.filter-item::before {
    content: '';
    display: block;
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    border: 1.5px solid var(--border-medium);
    border-radius: var(--radius-full);          /* radio: circle */
    background-color: var(--bg-secondary);
    transition:
        border-color     var(--duration-fast) var(--ease),
        background-color var(--duration-fast) var(--ease),
        box-shadow       var(--duration-fast) var(--ease);
}

/* Checkbox modifier: square corners */
.filter-item:has([type="checkbox"])::before {
    border-radius: var(--radius-sm);
}

/* Checked state — shared gold fill */
.filter-item--active::before {
    background-color: var(--accent-gold);
    border-color: var(--accent-gold);
}

/* Checkbox checked: white SVG checkmark */
.filter-item:has([type="checkbox"]).filter-item--active::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 9px;
}

/* Radio checked: white inner dot via inset box-shadow */
.filter-item:has([type="radio"]).filter-item--active::before {
    box-shadow: inset 0 0 0 3px var(--bg-secondary);
}

/* Hover — subtly brighten the ring */
.filter-item:hover::before {
    border-color: var(--accent-gold);
}

/* Focus ring via :has() — keyboard navigation */
.filter-item:has(.filter-item__input:focus-visible) {
    outline: 2px solid var(--accent-gold);
    outline-offset: 2px;
}

.filter-item__label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.4;
    transition: color var(--duration-fast) var(--ease);
}

.filter-item--active .filter-item__label {
    color: var(--text-primary);
    font-weight: 500;
}

.filter-item:hover .filter-item__label {
    color: var(--text-primary);
}

/* ─── SR-ONLY input pattern — used by swatch inputs ─────────────────────── */

.filter-swatch__input {
    -webkit-appearance: none;
    appearance: none;
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    margin: 0;
    padding: 0;
}

/* ─── Color / Pattern swatch grid ────────────────────────────────────────── */

.filter-swatches {
    display: grid;
    /* 4 columns with minmax(0,1fr) prevents grid blowout.
       Each swatch gets equal space; names truncate via ellipsis if too long. */
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-4) var(--space-2);
    min-width: 0;       /* allows grid to shrink below content min-width */
    overflow: hidden;   /* belt-and-suspenders: contain any child overflow */
}

.filter-swatch {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    cursor: pointer;
    transition: opacity var(--duration-fast) var(--ease);
}

.filter-swatch:hover { opacity: 0.80; }

.filter-swatch--active { opacity: 1; }

.filter-swatch__dot {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background-color: var(--bg-tertiary);
    border: 1.5px solid var(--border-light);
    display: block;
    transition:
        box-shadow   var(--duration-fast) var(--ease),
        border-color var(--duration-fast) var(--ease);
}

/* Active ring: white gap + gold border */
.filter-swatch--active .filter-swatch__dot {
    border-color: transparent;
    box-shadow:
        0 0 0 2px var(--bg-primary),
        0 0 0 4px var(--accent-gold);
}

/* Focus ring */
.filter-swatch:has(.filter-swatch__input:focus-visible) .filter-swatch__dot {
    outline: 2px solid var(--accent-gold);
    outline-offset: 3px;
}

.filter-swatch__name {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
    transition: color var(--duration-fast) var(--ease);
}

.filter-swatch--active .filter-swatch__name {
    color: var(--text-primary);
}

/* ─── CSS TEXTILE PATTERNS — applied to .filter-swatch__dot ─────────────── */
/* Same visual patterns as before, now on 30px circular swatch dots.         */

[data-pattern] .filter-swatch__dot {
    border-radius: var(--radius-sm);
}

[data-pattern="plain"] .filter-swatch__dot {
    background-color: var(--bg-tertiary);
    background-image: repeating-linear-gradient(
        90deg, transparent 0, transparent 3px,
        var(--border-medium) 3px, var(--border-medium) 4px
    );
}

[data-pattern="herringbone"] .filter-swatch__dot {
    background-color: var(--bg-tertiary);
    background-image:
        repeating-linear-gradient(45deg,  var(--border-medium) 0, var(--border-medium) 1px, transparent 1px, transparent 4px),
        repeating-linear-gradient(-45deg, var(--border-medium) 0, var(--border-medium) 1px, transparent 1px, transparent 4px);
}

[data-pattern="pinstripe"] .filter-swatch__dot {
    background-color: var(--bg-tertiary);
    background-image: repeating-linear-gradient(
        90deg, var(--border-medium) 0, var(--border-medium) 1px,
        transparent 1px, transparent 8px
    );
}

[data-pattern="windowpane"] .filter-swatch__dot {
    background-color: var(--bg-tertiary);
    background-image:
        linear-gradient(var(--border-medium) 1px, transparent 1px),
        linear-gradient(90deg, var(--border-medium) 1px, transparent 1px);
    background-size: 10px 10px;
}

[data-pattern="glen-check"] .filter-swatch__dot {
    background-color: var(--bg-tertiary);
    background-image:
        repeating-linear-gradient(45deg,  var(--border-light)  0, var(--border-light)  1px, transparent 1px, transparent 8px),
        repeating-linear-gradient(-45deg, var(--border-light)  0, var(--border-light)  1px, transparent 1px, transparent 8px),
        repeating-linear-gradient(0deg,   var(--border-medium) 0, var(--border-medium) 1px, transparent 1px, transparent 16px),
        repeating-linear-gradient(90deg,  var(--border-medium) 0, var(--border-medium) 1px, transparent 1px, transparent 16px);
}

[data-pattern="prince-of-wales"] .filter-swatch__dot {
    background-color: var(--bg-tertiary);
    background-image:
        repeating-linear-gradient(45deg,  var(--border-medium) 0, var(--border-medium) 1px, transparent 1px, transparent 4px),
        repeating-linear-gradient(-45deg, var(--border-light)  0, var(--border-light)  1px, transparent 1px, transparent 4px),
        repeating-linear-gradient(0deg,   var(--border-medium) 0, var(--border-medium) 1px, transparent 1px, transparent 8px);
}

[data-pattern="birdseye"] .filter-swatch__dot {
    background-color: var(--bg-tertiary);
    background-image: radial-gradient(circle, var(--border-medium) 1.5px, transparent 1.5px);
    background-size: 6px 6px;
}
