/*
 * Filter Sidebar — lightweight editorial skin over WooCommerce Product Filters.
 *
 * WooCommerce owns the markup + behaviour (Interactivity API). This file only
 * re-skins it: no gray boxes, hairline dividers, brand checkboxes, a modern
 * range slider, muted counts. Rail is a 260px sticky column on desktop.
 *
 * Targets real WC classes (inspected from rendered DOM):
 *   .wc-block-product-filter-checkbox-list__{items,item,label,input,count,text}
 *   .wc-block-product-filter-price-slider__{content,range,left,right}
 *   .wc-block-product-filter-removable-chips__{item,label,remove}
 *
 * Tokens read: semantic.color.{text,brand,border,surface,input,button},
 *   semantic.radius.badge, semantic.typography.{body,display}, space.*.
 */

/* --- Rail ------------------------------------------------------------- */
.wpdl-filter-sidebar.wp-block-group {
  flex: 0 0 15rem;   /* 240px */
  inline-size: 15rem;
  margin-block: 0;
  position: sticky;
  top: var(--wp--custom--space--6);
  align-self: flex-start;
}

/* --- Filters wrapper -------------------------------------------------- */
.wpdl-filter-sidebar__filters {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Section title — Title Case, no divider lines; sections separated by space only */
.wpdl-filter-sidebar__title.wp-block-heading {
  font-family: var(--wp--custom--semantic--typography--body--font-family);
  font-size: 0.9375rem;   /* 15px */
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--wp--custom--semantic--color--text--primary);
  margin-block: var(--wp--custom--space--5) var(--wp--custom--space--2);
}

.wpdl-filter-sidebar__title.wp-block-heading:first-child {
  margin-block-start: 0;
}

/* --- Checkbox list (Category, Occasion, Color) ------------------------ */

/* WC wraps options in a <fieldset> with a default 2px browser border — kill
   the "gray box"; the list should read as bare rows. */
.wpdl-filter-sidebar fieldset {
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__items {
  display: flex;
  flex-direction: column;
  gap: var(--wp--custom--space--2);   /* ~row rhythm — tight */
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__item {
  min-block-size: auto;
  padding-block: 0;
}

/* Whole row is the click target; checkbox ↔ text tight; count pushed right. */
.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__label {
  inline-size: 100%;
  gap: var(--wp--custom--space--2);   /* checkbox ↔ text: 8px */
  align-items: center;
  cursor: pointer;
}

/* Custom checkbox — appearance:none box, brand fill + white tick when checked.
   Drops WC's faint ::before box + its own __mark. */
.wpdl-filter-sidebar input[type="checkbox"].wc-block-product-filter-checkbox-list__input {
  position: relative;
  appearance: none;
  opacity: 1;
  flex-shrink: 0;
  inline-size: 1.125rem;   /* 18px */
  block-size: 1.125rem;
  margin: 0;
  border: 1.5px solid var(--wp--custom--semantic--color--border--strong);
  border-radius: var(--wp--custom--radius--sm);
  background-color: var(--wp--custom--semantic--color--surface--primary);
  cursor: pointer;
  transition:
    background-color var(--wp--custom--duration--fast) var(--wp--custom--easing--default),
    border-color var(--wp--custom--duration--fast) var(--wp--custom--easing--default);
}

.wpdl-filter-sidebar input[type="checkbox"].wc-block-product-filter-checkbox-list__input:checked {
  background-color: var(--wp--custom--semantic--color--brand--primary);
  border-color: var(--wp--custom--semantic--color--brand--primary);
}

.wpdl-filter-sidebar input[type="checkbox"].wc-block-product-filter-checkbox-list__input:checked::after {
  content: "";
  position: absolute;
  inset-block-start: 0.13rem;
  inset-inline-start: 0.34rem;
  inline-size: 0.3rem;
  block-size: 0.55rem;
  border-inline-end: 2px solid var(--wp--custom--semantic--color--text--on-brand);
  border-block-end: 2px solid var(--wp--custom--semantic--color--text--on-brand);
  transform: rotate(45deg);
}

.wpdl-filter-sidebar input[type="checkbox"].wc-block-product-filter-checkbox-list__input:focus-visible {
  outline: 2px solid var(--wp--custom--semantic--color--focus--ring);
  outline-offset: 2px;
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__input-wrapper::before,
.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__mark {
  display: none;
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__input-wrapper {
  display: inline-flex;
  inline-size: auto;
}

/* Text + count share the row; count sits to the right, quieter. */
.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__text-wrapper {
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--wp--custom--space--3);
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__text {
  font-family: var(--wp--custom--semantic--typography--body--font-family);
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--wp--custom--semantic--color--text--primary);
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__count {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--wp--custom--semantic--color--text--secondary);
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__show-more-button {
  font-family: var(--wp--custom--semantic--typography--body--font-family);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--wp--custom--semantic--color--text--muted);
  margin-block-start: var(--wp--custom--space--2);
  cursor: pointer;
  transition: color var(--wp--custom--duration--base) var(--wp--custom--easing--default);
}

.wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__show-more-button:hover {
  color: var(--wp--custom--semantic--color--brand--primary);
}

/* --- Price slider — bare track + plain min/max labels (no boxy inputs) - */
.wpdl-filter-sidebar .wc-block-product-filter-price-slider {
  margin-block-start: var(--wp--custom--space--1);
}

.wpdl-filter-sidebar .wc-block-product-filter-price-slider__range {
  accent-color: var(--wp--custom--semantic--color--brand--primary);
  background-color: var(--wp--custom--semantic--color--border--base);
  border-radius: var(--wp--custom--radius--full);
  inline-size: auto;
  min-inline-size: 0;
  max-inline-size: 100%;
}

/* Selected range fills brand (WC defaults to ink — reads as a harsh black bar). */
.wpdl-filter-sidebar .wc-block-product-filter-price-slider__range .range-bar {
  background-image: linear-gradient(
    to right,
    rgb(0 0 0 / 0%) var(--low),
    var(--wp--custom--semantic--color--brand--primary) var(--low),
    var(--wp--custom--semantic--color--brand--primary) var(--high),
    rgb(0 0 0 / 0%) var(--high)
  );
  border-radius: var(--wp--custom--radius--full);
}

/* WC lays __content as a grid (slider row on top, min/middle/max below).
   The value inputs default to ~170px each, which blows the grid past the 240px
   rail and overflows the sidebar — pin everything to 100% and shrink the inputs. */
.wpdl-filter-sidebar .wc-block-product-filter-price-slider__content {
  box-sizing: border-box;   /* padding must eat into the 240px rail, not add to it */
  inline-size: 100%;
  max-inline-size: 100%;
  margin-block-start: var(--wp--custom--space--2);
  padding-inline: var(--wp--custom--space--3);   /* inset track from the rail edges */
  column-gap: var(--wp--custom--space--2);
  overflow: hidden;
}

.wpdl-filter-sidebar .wc-block-product-filter-price-slider__left,
.wpdl-filter-sidebar .wc-block-product-filter-price-slider__right {
  min-inline-size: 0;
}

.wpdl-filter-sidebar .wc-block-product-filter-price-slider__left input,
.wpdl-filter-sidebar .wc-block-product-filter-price-slider__right input {
  inline-size: 4rem;
  max-inline-size: 100%;
  min-inline-size: 0;
  font-family: var(--wp--custom--semantic--typography--body--font-family);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--wp--custom--semantic--color--text--primary);
  border: 0;
  background: transparent;
  padding: 0;
}

.wpdl-filter-sidebar .wc-block-product-filter-price-slider__right {
  text-align: end;
}

.wpdl-filter-sidebar .wc-block-product-filter-price-slider__right input {
  text-align: end;
}

/* --- Clear Filters (bottom, only when a filter is active) ------------- */
.wpdl-filter-sidebar__active {
  margin-block: var(--wp--custom--space--4) 0;
}

.wpdl-filter-sidebar__clear,
.wpdl-filter-sidebar__clear-btn {
  inline-size: 100%;
  margin: 0;
}

/* WC rewrites the inner <a> into a <button>; style it as a full-width outline. */
.wpdl-filter-sidebar__clear .wp-block-button__link {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 100%;
  min-block-size: 2.5rem;
  border: 1px solid var(--wp--custom--semantic--color--border--base);
  border-radius: var(--wp--custom--semantic--radius--btn);
  background: transparent;
  color: var(--wp--custom--semantic--color--text--primary);
  font-family: var(--wp--custom--semantic--typography--body--font-family);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    color var(--wp--custom--duration--base) var(--wp--custom--easing--default),
    border-color var(--wp--custom--duration--base) var(--wp--custom--easing--default);
}

.wpdl-filter-sidebar__clear .wp-block-button__link:hover {
  border-color: var(--wp--custom--semantic--color--brand--primary);
  color: var(--wp--custom--semantic--color--brand--primary);
  background: transparent;
}

/* --- Desktop: filters apply live on the inline rail; the WC "Apply" button
   is only meaningful inside the mobile overlay, so hide it here. --------- */
@media (width >= 64em) {
  .wpdl-filter-sidebar .wc-block-product-filters__apply {
    display: none;
  }
}

/* --- Tablet + mobile: off-canvas Filter drawer ----------------------- *
 * WC renders the filters inside a __overlay dialog + a __open-overlay button
 * and toggles .is-overlay-opened on the wrapper (Interactivity API). We drive
 * a left off-canvas drawer deterministically off that class. */
@media (width < 64em) {
  .wpdl-filter-sidebar.wp-block-group {
    position: static;
    flex: 0 0 auto;
    inline-size: 100%;
  }

  /* The WC overlay button is the trigger; our custom "Filter" head is redundant */
  .wpdl-filter-sidebar__head.wp-block-group {
    display: none;
  }

  /* Trigger — filled brand pill (per approved shop-archive design: the mobile
     Filter trigger reads as the primary action next to Sort). */
  .wpdl-filter-sidebar .wc-block-product-filters__open-overlay {
    display: inline-flex;
    align-items: center;
    gap: var(--wp--custom--space--2);
    min-block-size: 2.75rem;
    padding-block: var(--wp--custom--space--2);
    padding-inline: var(--wp--custom--space--5);
    border: 1px solid var(--wp--custom--semantic--color--button--primary--border);
    border-radius: var(--wp--custom--semantic--radius--badge);
    background-color: var(--wp--custom--semantic--color--button--primary--bg);
    color: var(--wp--custom--semantic--color--button--primary--text);
    font-family: var(--wp--custom--semantic--typography--body--font-family);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
  }

  /* Backdrop — hidden until opened */
  .wpdl-filter-sidebar .wc-block-product-filters__overlay {
    position: fixed;
    inset: 0;
    z-index: var(--wp--custom--z--overlay);
    background-color: var(--wp--custom--semantic--color--overlay--backdrop);
    visibility: hidden;
    opacity: 0;
    transition:
      opacity var(--wp--custom--duration--base) var(--wp--custom--easing--default),
      visibility 0s linear var(--wp--custom--duration--base);
  }

  .wpdl-filter-sidebar .wc-block-product-filters.is-overlay-opened .wc-block-product-filters__overlay {
    visibility: visible;
    opacity: 1;
    transition: opacity var(--wp--custom--duration--base) var(--wp--custom--easing--default);
  }

  /* Panel — slides in from the left */
  .wpdl-filter-sidebar .wc-block-product-filters__overlay-wrapper {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    inline-size: min(88%, 22rem);
    display: flex;
    flex-direction: column;
    background-color: var(--wp--custom--semantic--color--surface--primary);
    box-shadow: var(--wp--custom--semantic--shadow--modal);
    translate: -100% 0;
    transition: translate var(--wp--custom--duration--base) var(--wp--custom--easing--default);
  }

  .wpdl-filter-sidebar .wc-block-product-filters.is-overlay-opened .wc-block-product-filters__overlay-wrapper {
    translate: 0 0;
  }

  .wpdl-filter-sidebar .wc-block-product-filters__overlay-dialog {
    display: flex;
    flex-direction: column;
    block-size: 100%;
    overflow: hidden;
  }

  .wpdl-filter-sidebar .wc-block-product-filters__overlay-header {
    display: flex;
    justify-content: flex-end;
    padding: var(--wp--custom--space--5);
    border-block-end: 1px solid var(--wp--custom--semantic--color--divider--subtle);
  }

  .wpdl-filter-sidebar .wc-block-product-filters__close-overlay {
    display: inline-flex;
    align-items: center;
    gap: var(--wp--custom--space--1);
    background: none;
    border: none;
    color: var(--wp--custom--semantic--color--text--muted);
    font-family: var(--wp--custom--semantic--typography--body--font-family);
    font-size: 0.75rem;
    cursor: pointer;
  }

  .wpdl-filter-sidebar .wc-block-product-filters__overlay-content {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--wp--custom--space--5);
  }

  .wpdl-filter-sidebar .wc-block-product-filters__overlay-footer {
    padding: var(--wp--custom--space--5);
    border-block-start: 1px solid var(--wp--custom--semantic--color--divider--subtle);
  }

  .wpdl-filter-sidebar .wc-block-product-filters__apply {
    display: flex;
    align-items: center;
    justify-content: center;
    inline-size: 100%;
    min-block-size: 2.75rem;
    background-color: var(--wp--custom--semantic--color--button--primary--bg);
    color: var(--wp--custom--semantic--color--button--primary--text);
    border: none;
    border-radius: var(--wp--custom--semantic--radius--btn);
    font-family: var(--wp--custom--semantic--typography--body--font-family);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    cursor: pointer;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wpdl-filter-sidebar .wc-block-product-filter-checkbox-list__show-more-button,
  .wpdl-filter-sidebar__clear {
    transition: none;
  }
}
