/**
 * category-price-filter.css
 *
 * TOC:
 * - container and toggle styles
 * - filter panel layout
 * - range and numeric input styles
 * - action buttons
 * - responsive tweaks
 */

/* Root remains layout container only, so closed state keeps compact width. */
.category-price-filter {
  margin: 16px 0 24px;
  position: static;
  overflow: visible;
}

/* Align compact filter at left and sorting control at far right. */
.category-price-controls-row {
  margin: 16px 0 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
  position: relative;
  z-index: 20;
}

/* Keep filter margins neutral inside two-column controls row. */
.category-price-controls-row .category-price-filter {
  margin: 0;
  flex: 0 0 auto;
}

/* Keep toggle compact: width follows label + chevron only. */
.category-price-filter__toggle {
  width: auto;
  min-width: 0;
  border: 1px solid #e2e4ea;
  border-radius: 10px;
  background: #fff;
  color: #394554;
  font-size: 15px;
  font-family: 'TikTok Sans', sans-serif;
  text-align: left;
  padding: 10px 12px;
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}

/* Keep filter label truncation behavior same as sorting label. */
.category-price-filter__toggle-label {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Rotate visual indicator when filter panel is open. */
.category-price-filter__toggle.is-open .category-price-filter__arrow {
  transform: rotate(180deg);
}

/* Animate icon rotation to make state transition obvious. */
.category-price-filter__arrow {
  transition: transform 0.2s ease;
  font-size: 14px;
  line-height: 1;
}

/* Keep chevron icon visually aligned with toggle text baseline. */
.category-price-filter__arrow i {
  display: block;
}

/* Expanded block opens separately and keeps full content width. */
.category-price-filter__panel {
  margin-top: 0;
  padding: 14px 16px 16px;
  border: 1px solid #e2e4ea;
  border-radius: 10px;
  background: #fff;
  transform-origin: top right;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 10px);
  z-index: 35;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.16);
}

/* Preload state warms slider layout before first visible open. */
.category-price-filter__panel.is-preload {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px) scale(0.98);
}

/* Genie-like reveal: panel expands with slight squeeze and fade. */
.category-price-filter__panel.is-opening {
  animation: categoryFilterGenieOpen 0.38s cubic-bezier(0.22, 0.74, 0.21, 1) forwards;
}

/* Reverse genie collapse before hidden state is applied by JS. */
.category-price-filter__panel.is-closing {
  animation: categoryFilterGenieClose 0.3s cubic-bezier(0.6, 0.02, 0.95, 0.38) forwards;
}

@keyframes categoryFilterGenieOpen {
  0% {
    opacity: 0;
    transform: translateY(-14px) scaleX(0.92) scaleY(0.14);
    filter: blur(3px);
  }
  45% {
    opacity: 1;
    transform: translateY(0) scaleX(1.02) scaleY(1.04);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scaleX(1) scaleY(1);
    filter: blur(0);
  }
}

@keyframes categoryFilterGenieClose {
  0% {
    opacity: 1;
    transform: translateY(0) scaleX(1) scaleY(1);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-16px) scaleX(0.9) scaleY(0.08);
    filter: blur(2px);
  }
}

/* Keep active badge near compact toggle and not full-row stretched. */
.category-price-filter__active-row {
  padding: 10px 0 0;
}

/* Sort control uses details/summary to avoid extra JavaScript complexity. */
.category-sort-control {
  position: relative;
  flex: 0 0 auto;
}

/* Hide default disclosure marker for custom icon-based summary. */
.category-sort-control summary {
  list-style: none;
}

.category-sort-control summary::-webkit-details-marker {
  display: none;
}

/* Compact icon button with label near right page edge. */
.category-sort-control__summary {
  width: auto;
  border: 1px solid #e2e4ea;
  border-radius: 10px;
  background: #fff;
  color: #394554;
  font-family: 'TikTok Sans', sans-serif;
  font-size: 15px;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  justify-content: space-between;
}

/* Keep text short but readable for active sort mode. */
.category-sort-control__label {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Rotate caret when dropdown is opened. */
.category-sort-control.is-open .category-sort-control__caret {
  transform: rotate(180deg);
}

.category-sort-control__caret {
  transition: transform 0.2s ease;
}

/* Dropdown menu floats under summary and stays visually separated. */
.category-sort-control__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 0;
  background: #fff;
  border: 1px solid #e2e4ea;
  border-radius: 10px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  padding: 6px;
  z-index: 30;
  width: max-content;
  max-width: min(92vw, 340px);
  transform-origin: top right;
}

/* Smooth menu appearance keeps list from popping abruptly. */
.category-sort-control__menu.is-opening {
  animation: categorySortMenuOpen 0.26s cubic-bezier(0.22, 0.74, 0.21, 1) forwards;
}

/* Reverse animation before hidden is applied by script. */
.category-sort-control__menu.is-closing {
  animation: categorySortMenuClose 0.2s cubic-bezier(0.6, 0.02, 0.95, 0.38) forwards;
}

@keyframes categorySortMenuOpen {
  0% {
    opacity: 0;
    transform: translateY(-8px) scale(0.94);
    filter: blur(1px);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes categorySortMenuClose {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-8px) scale(0.94);
    filter: blur(1px);
  }
}

/* Every sorting option line includes icon + text and active highlight. */
.category-sort-control__item {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #334155;
  font-family: 'TikTok Sans', sans-serif;
  font-size: 15px;
  border-radius: 8px;
  padding: 8px 10px;
  white-space: nowrap;
}

.category-sort-control__item:hover {
  background: #f8f2fb;
  color: #b64072;
}

.category-sort-control__item.is-active {
  background: #fbe5ee;
  color: #a53561;
}

/* Make active filter badge obvious and clickable for instant reset. */
.category-price-filter__active-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fbe5ee;
  border: 1px solid #eb9fba;
  color: #a53561;
  font-family: 'TikTok Sans', sans-serif;
  font-size: 14px;
  line-height: 1;
  text-decoration: none;
}

/* Keep close icon compact and readable on all breakpoints. */
.category-price-filter__active-close {
  font-size: 16px;
  line-height: 1;
}

/* Use a responsive two-column layout for min/max number fields. */
.category-price-filter__values {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

/* Group label and input vertically for clear form semantics. */
.category-price-filter__label {
  display: grid;
  gap: 6px;
  color: #495056;
  font-family: 'TikTok Sans', sans-serif;
  font-size: 15px;
}

/* Keep numeric inputs touch-friendly and visually consistent with theme forms. */
.category-price-filter__number {
  width: 100%;
  min-height: 40px;
  border: 1px solid #c9cfda;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 16px;
  font-family: 'TikTok Sans', sans-serif;
  color: #2f3a45;
}

/* Place range inputs in a compact vertical stack for precise dragging. */
.category-price-filter__ranges {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

/* Reserve space for Ion.RangeSlider and keep layout stable. */
.category-price-filter__ranges {
  padding: 8px 28px 6px;
}

/* Allow badges above handles to render outside plugin internals without clipping. */
.category-price-filter .irs {
  overflow: visible;
}

/* Build pink-themed slider track close to requested visual reference. */
.category-price-filter .irs--flat .irs-line {
  top: 28px;
  height: 8px;
  background-color: #efe7f2;
  border-radius: 999px;
}

/* Highlight active interval with brand accent. */
.category-price-filter .irs--flat .irs-bar {
  top: 28px;
  height: 8px;
  background: linear-gradient(90deg, #d65982, #e57ca0);
}

/* Style slider handles with white core and pink border. */
.category-price-filter .irs--flat .irs-handle {
  top: 19px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid #d65982;
  background: #fff;
  box-shadow: 0 2px 8px rgba(214, 89, 130, 0.25);
}

/* Hide default small marker inside handle to match clean style. */
.category-price-filter .irs--flat .irs-handle > i:first-child {
  display: none;
}

/* Keep min/max labels subtle and readable on light background. */
.category-price-filter .irs--flat .irs-min,
.category-price-filter .irs--flat .irs-max {
  top: 0;
  color: #8c97a5;
  background: #f6f7fa;
  border-radius: 6px;
  padding: 2px 6px;
}

/* Emphasize selected values like badges above thumbs. */
.category-price-filter .irs--flat .irs-from,
.category-price-filter .irs--flat .irs-to,
.category-price-filter .irs--flat .irs-single {
  top: -16px;
  background-color: #d65982;
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 14px;
}

/* Match value pointer color to selected value badge. */
.category-price-filter .irs--flat .irs-from:before,
.category-price-filter .irs--flat .irs-to:before,
.category-price-filter .irs--flat .irs-single:before {
  border-top-color: #d65982;
}

/* Align action controls and keep clear visual hierarchy between apply/reset. */
.category-price-filter__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Primary submit button mirrors existing pink action buttons in theme. */
.category-price-filter__apply {
  border: 1px solid #d65982;
  border-radius: 6px;
  background: #d65982;
  color: #fff;
  font-family: 'TikTok Sans', sans-serif;
  font-size: 15px;
  text-transform: uppercase;
  min-height: 38px;
  padding: 7px 16px;
  cursor: pointer;
  transition: 0.2s;
}

/* Keep hover behavior consistent with buy buttons. */
.category-price-filter__apply:hover {
  background: #fff;
  color: #d65982;
}

/* Reset link stays secondary but clearly actionable. */
.category-price-filter__reset {
  color: #3a93c4;
  text-decoration: none;
  font-family: 'TikTok Sans', sans-serif;
  font-size: 15px;
  order: 1;
}

/* Keep submit button on the far right for desktop ergonomics. */
.category-price-filter__apply {
  order: 2;
}

/* Keep controls in one horizontal row on mobile as requested. */
@media (max-width: 767px) {
  .category-price-filter {
    margin-top: 10px;
  }

  .category-price-controls-row {
    align-items: flex-start;
    gap: 8px;
    overflow: visible;
  }

  .category-price-controls-row .category-price-filter {
    flex: 0 0 auto;
  }

  /* Keep mobile toggle compact but avoid too narrow touch target. */
  .category-price-filter__toggle {
    min-width: 0;
  }

  .category-price-filter__values {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Keep actions aligned to the right on mobile, same as desktop UX. */
  .category-price-filter__actions {
    justify-content: flex-end;
  }

  /* Give slider a bit more width on phones by reducing side paddings. */
  .category-price-filter__ranges {
    padding-left: 18px;
    padding-right: 18px;
  }

  /* Keep sorting dropdown visible and aligned inside viewport on phones. */
  .category-sort-control__menu {
    right: 0;
    left: auto;
    max-width: calc(100vw - 20px);
  }
}

/* Tiny screens: keep sorting trigger icon-only. */
@media (max-width: 470px) {
  .category-sort-control__label {
    display: none;
  }

  .category-sort-control__summary {
    min-width: 0;
    padding-left: 10px;
    padding-right: 10px;
    gap: 8px;
  }
}

/* Rounded refresh parity with main theme. */
.category-price-filter__toggle,
.category-price-filter__panel,
.category-price-filter__active-badge,
.category-price-filter__apply,
.category-sort-control__summary,
.category-sort-control__menu,
.category-sort-control__item {
  border-radius: 12px;
}
