/* ==========================================================================
   CIR Product Filter — Styles
   Cast Iron Radiator Company — slide-out filter drawer for category pages.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design tokens
   -------------------------------------------------------------------------- */
/* Plugin relies on theme :root variables from main.css.
   Fallbacks only for standalone testing. */

/* --------------------------------------------------------------------------
   Layout: drawer + content side-by-side
   -------------------------------------------------------------------------- */
.cir-filter-layout {
  display: flex;
  overflow: hidden;
}

/* Reduce count bar gap when filter layout follows */
.count-bar:has(+ .cir-filter-layout),
.count-bar:has(+ #cirFilterPills + .cir-filter-layout),
.count-bar:has(+ #cirFilterPills) {
  margin-bottom: 12px;
}

.cir-filter-drawer {
  width: 0;
  min-width: 0;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  border-right: 0px solid var(--cir-border);
  background: var(--cir-white);
  display: flex;
  flex-direction: column;
  padding-top: 8px;
  will-change: width, min-width;
  contain: layout style;
}

.cir-filter-drawer.active {
  width: 340px;
  min-width: 340px;
  border-right-width: 1px;
  overflow: visible;
  align-self: flex-start;
  position: sticky;
  top: 0;
}

.cir-filter-drawer.active > .cir-drawer-section:first-child .cir-drawer-label {
  margin-top: 0;
}

/* Lock children to their final rendered width so they don't reflow as the
   drawer animates open. The drawer's overflow:hidden clips them during the
   slide; once the drawer reaches 340px the clipping stops. No text re-wrap,
   no layout shift. */
.cir-filter-drawer > .cir-drawer-section,
.cir-filter-drawer > .cir-drawer-footer {
  width: 316px;
  flex-shrink: 0;
  box-sizing: border-box;
}


.cir-filter-content {
  flex: 1;
  min-width: 0;
  contain: layout style;
}

/* --------------------------------------------------------------------------
   Hide original content when JS-filtered results are showing
   -------------------------------------------------------------------------- */
.cir-filter-content.filtered .product-grid,
.cir-filter-content.filtered .cir-pagination {
  display: none;
}

/* Add left padding to content when drawer is open */
.cir-filter-drawer.active ~ .cir-filter-content {
  padding-left: 24px;
}

/* Grid columns: 3 when drawer is open */
.cir-filter-drawer.active ~ .cir-filter-content .product-grid,
.cir-filter-drawer.active ~ .cir-filter-content #cirFilterResults {
  grid-template-columns: repeat(3, 1fr);
}

/* Filter results grid */
#cirFilterResults {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

#cirFilterResults:empty {
  display: none;
}

/* --------------------------------------------------------------------------
   Filter button (in count bar)
   -------------------------------------------------------------------------- */
.cir-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 170px;
  padding: 10px 18px;
  border: 1px solid var(--cir-input-border);
  background: transparent;
  cursor: pointer;
  font-family: var(--cir-font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--cir-text);
  transition: border-color 0.2s, color 0.2s;
  line-height: 1;
}

.cir-filter-btn:hover {
  border-color: var(--cir-burgundy);
  color: var(--cir-burgundy);
}

.cir-filter-btn svg {
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Drawer header
   -------------------------------------------------------------------------- */
.cir-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--cir-border);
}

.cir-drawer-title {
  font-family: var(--cir-font-heading);
  font-size: 22px;
  font-weight: 600;
  color: var(--cir-text);
  margin: 0;
}

.cir-drawer-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cir-drawer-close:hover svg path {
  stroke: var(--cir-burgundy);
}

/* --------------------------------------------------------------------------
   Drawer sections
   -------------------------------------------------------------------------- */
.cir-drawer-section {
  padding: 20px 0 20px 0;
  border-bottom: 1px solid var(--cir-border);
  margin-right: 24px;
}

.cir-drawer-section:first-child {
  padding-top: 0;
}

.cir-drawer-label {
  display: block;
  font-family: var(--cir-font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--cir-gold);
  text-transform: uppercase;
  margin-bottom: 14px;
}

.cir-drawer-sublabel {
  display: block;
  font-family: var(--cir-font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--cir-text-secondary);
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* --------------------------------------------------------------------------
   Sort dropdown
   -------------------------------------------------------------------------- */
.cir-sort-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--cir-input-border);
  border-radius: 0;
  background: var(--cir-white);
  font-family: var(--cir-font-body);
  font-size: 13px;
  color: var(--cir-text);
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%232D2D2D' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.cir-sort-select:focus {
  outline: none;
  border-color: var(--cir-burgundy);
}

/* --------------------------------------------------------------------------
   Style pills
   -------------------------------------------------------------------------- */
.cir-style-pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.cir-style-pill {
  padding: 9px 8px;
  border: 1px solid var(--cir-input-border);
  background: transparent;
  font-family: var(--cir-font-body);
  font-size: 12px;
  color: var(--cir-text);
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cir-style-pill:hover:not(.active) {
  border-color: var(--cir-burgundy);
  color: var(--cir-burgundy);
}

.cir-style-pill.active {
  background: var(--cir-burgundy);
  border-color: var(--cir-burgundy);
  color: #fff;
}

.cir-style-pill.active:hover {
  background: var(--cir-burgundy);
  color: #fff;
}

.cir-loading-hint {
  font-family: var(--cir-font-body);
  font-size: 12px;
  color: var(--cir-text-secondary);
  margin: 0;
}

/* --------------------------------------------------------------------------
   Range group (inputs + slider)
   -------------------------------------------------------------------------- */
.cir-range-group {
  margin-bottom: 4px;
}

.cir-range-inputs {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.cir-range-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  border: 1px solid var(--cir-input-border);
  padding: 0 14px;
  background: var(--cir-white);
}

.cir-range-input-wrap:focus-within {
  border-color: var(--cir-burgundy);
}

.cir-range-prefix,
.cir-range-suffix {
  font-family: var(--cir-font-body);
  font-size: 13px;
  color: var(--cir-text-secondary);
  flex-shrink: 0;
}

.cir-range-input {
  width: 100%;
  padding: 10px 0;
  border: none;
  outline: none;
  font-family: var(--cir-font-body);
  font-size: 13px;
  color: var(--cir-text);
  background: transparent;
  -moz-appearance: textfield;
}

.cir-range-input::-webkit-outer-spin-button,
.cir-range-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cir-range-to {
  font-family: var(--cir-font-body);
  font-size: 12px;
  color: var(--cir-text-secondary);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Dual-thumb range slider
   -------------------------------------------------------------------------- */
.cir-range-slider {
  position: relative;
  width: 100%;
  height: 14px;
  display: flex;
  align-items: center;
}

.cir-range-track {
  position: relative;
  width: 100%;
  height: 4px;
  background: var(--cir-border);
  border-radius: 2px;
}

.cir-range-fill {
  position: absolute;
  height: 4px;
  background: var(--cir-burgundy);
  border-radius: 2px;
  top: 0;
  left: 0;
  right: 0;
}

/* Both range inputs overlay the track */
.cir-range-slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: transparent;
  pointer-events: none;
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  margin: 0;
  padding: 0;
  z-index: 1;
}

/* Webkit thumb */
.cir-range-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cir-burgundy);
  border: 2px solid var(--cir-burgundy);
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Firefox thumb */
.cir-range-slider input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cir-burgundy);
  border: 2px solid var(--cir-burgundy);
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Firefox track (hide default) */
.cir-range-slider input[type="range"]::-moz-range-track {
  background: transparent;
  border: none;
  height: 4px;
}

/* Focus styles */
.cir-range-slider input[type="range"]:focus {
  outline: none;
}

.cir-range-slider input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(131, 46, 49, 0.2);
}

.cir-range-slider input[type="range"]:focus::-moz-range-thumb {
  box-shadow: 0 0 0 3px rgba(131, 46, 49, 0.2);
}

/* --------------------------------------------------------------------------
   Quick presets (height)
   -------------------------------------------------------------------------- */
.cir-preset-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.cir-preset-btn {
  padding: 6px 12px;
  background: rgba(131, 46, 49, 0.08);
  border: none;
  font-family: var(--cir-font-body);
  font-size: 11px;
  color: var(--cir-burgundy);
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}

.cir-preset-btn:hover {
  background: rgba(131, 46, 49, 0.15);
}

.cir-preset-btn.active {
  background: var(--cir-burgundy);
  color: var(--cir-white);
}

/* --------------------------------------------------------------------------
   Collapsible section (Width & Depth)
   -------------------------------------------------------------------------- */
.cir-collapsible-toggle {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cir-chevron {
  font-size: 10px;
  color: var(--cir-text-secondary);
  transition: transform 0.2s ease;
}

.cir-collapsible-body {
  padding-top: 14px;
}

/* --------------------------------------------------------------------------
   Drawer footer
   -------------------------------------------------------------------------- */
.cir-drawer-footer {
  padding: 20px 0 20px 0;
  margin-right: 24px;
  margin-top: auto;
  border-top: 1px solid var(--cir-border);
}

.cir-drawer-count {
  font-family: var(--cir-font-body);
  font-size: 13px;
  color: var(--cir-text-secondary);
  margin: 0 0 14px 0;
  text-align: center;
}

.cir-btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--cir-burgundy);
  border: none;
  color: var(--cir-white);
  font-family: var(--cir-font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
  margin-bottom: 8px;
}

.cir-btn-primary:hover {
  background: #6B2225;
}

.cir-btn-outline {
  display: block;
  width: 100%;
  padding: 14px;
  background: transparent;
  border: 1px solid var(--cir-input-border);
  color: #5A5549;
  font-family: var(--cir-font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cir-btn-outline:hover {
  border-color: var(--cir-burgundy);
  color: var(--cir-burgundy);
}

/* --------------------------------------------------------------------------
   Active filter pills (below count bar)
   -------------------------------------------------------------------------- */
/* Filter pills now sit inside the count bar */
#cirFilterPills {
  display: none;
}

.cir-active-pills-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  margin: 0 16px;
}

.cir-active-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px 5px 10px;
  background: rgba(131, 46, 49, 0.06);
  border: 1px solid rgba(131, 46, 49, 0.15);
  color: var(--cir-burgundy);
  font-family: var(--cir-font-body);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}

.cir-active-pill button {
  background: none;
  border: none;
  color: var(--cir-burgundy);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  opacity: 0.4;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
}

.cir-active-pill button:hover {
  opacity: 1;
}

.cir-clear-all-inline {
  font-family: var(--cir-font-body);
  font-size: 11px;
  color: var(--cir-text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s;
}

.cir-clear-all-inline:hover {
  color: var(--cir-burgundy);
}

/* Heat output pills (BTU/Watts) — matches product page .pill--highlight */
.height-pill--heat {
  background: rgba(131, 46, 49, 0.08) !important;
  color: var(--cir-burgundy) !important;
  border-color: transparent !important;
}

/* --------------------------------------------------------------------------
   Clear link (next to count text when filters active)
   -------------------------------------------------------------------------- */
.cir-clear-link {
  font-family: var(--cir-font-body);
  font-size: 12px;
  color: var(--cir-burgundy);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  white-space: nowrap;
  flex-shrink: 0;
}

.cir-clear-link:hover {
  color: #6B2225;
}

/* --------------------------------------------------------------------------
   No results message
   -------------------------------------------------------------------------- */
.cir-no-results {
  grid-column: 1 / -1;
  padding: 60px 20px;
  text-align: center;
}

.cir-no-results p {
  font-family: var(--cir-font-body);
  font-size: 15px;
  color: var(--cir-text-secondary);
  margin: 0;
}

/* --------------------------------------------------------------------------
   Skeleton loading state
   -------------------------------------------------------------------------- */
.cir-skeleton-card {
  display: flex;
  flex-direction: column;
}

.cir-skeleton-img {
  width: 100%;
  padding-bottom: 100%;
  background: linear-gradient(90deg, #D8D0C6 25%, #FDFAF7 50%, #D8D0C6 75%);
  background-size: 200% 100%;
  animation: cir-skeleton-pulse 1.5s ease-in-out infinite;
}

.cir-skeleton-text {
  height: 14px;
  margin-top: 12px;
  background: linear-gradient(90deg, #D8D0C6 25%, #FDFAF7 50%, #D8D0C6 75%);
  background-size: 200% 100%;
  animation: cir-skeleton-pulse 1.5s ease-in-out infinite;
  width: 80%;
}

.cir-skeleton-text.short {
  width: 50%;
  margin-top: 8px;
}

@keyframes cir-skeleton-pulse {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* --------------------------------------------------------------------------
   Count bar
   -------------------------------------------------------------------------- */
#cirFilterCount {
  font-family: var(--cir-font-body);
  font-size: 14px;
  color: var(--cir-text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Mobile header (hidden on desktop)
   -------------------------------------------------------------------------- */
.cir-drawer-mobile-header {
  display: none;
}

/* Body scroll lock when mobile filter is open */
body.cir-filter-open {
  overflow: hidden;
}

/* Backdrop */
.cir-filter-backdrop {
  display: none;
}

/* Show Results button (hidden on desktop, visible via footer on mobile) */
#cirShowResults {
  display: none;
}

/* --------------------------------------------------------------------------
   Responsive: full-screen filter overlay on mobile
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .cir-filter-btn {
    min-width: 0;
    padding: 8px 14px;
    font-size: 12px;
  }

  .cir-filter-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100% !important;
    min-width: 100% !important;
    height: 100%;
    z-index: 9999;
    border-right: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 20px;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }

  .cir-filter-drawer.active {
    width: 100% !important;
    min-width: 100% !important;
    transform: translateY(0);
    overflow-y: auto;
    position: fixed;
    border-right: none;
    align-self: auto;
    top: 0;
  }

  /* 16px inputs to prevent iOS zoom */
  .cir-range-input,
  .cir-sort-select {
    font-size: 16px;
  }

  /* Match prefix/suffix to input size */
  .cir-range-prefix,
  .cir-range-suffix {
    font-size: 16px;
  }

  /* Slider thumbs on mobile: 20px visible, 44px touch target */
  .cir-range-slider {
    height: 44px;
    touch-action: none;
    padding: 0 6px;
  }

  .cir-range-slider input[type="range"] {
    height: 44px;
  }

  .cir-range-slider input[type="range"]::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    -webkit-tap-highlight-color: transparent;
  }

  .cir-range-slider input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }

  /* Remove sticky hover on style pills */
  .cir-style-pill:hover:not(.active) {
    border-color: var(--cir-input-border);
    color: var(--cir-text);
  }

  /* Hide inline pills on mobile — use count badge on button instead */
  .cir-active-pills-inline {
    display: none !important;
  }

  .cir-filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 50%;
    background: var(--cir-burgundy);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    margin-left: 4px;
  }

  .cir-filter-drawer > .cir-drawer-section,
  .cir-filter-drawer > .cir-drawer-footer {
    width: 100%;
  }

  .cir-drawer-section {
    margin-right: 0;
  }

  .cir-filter-drawer.active .cir-drawer-footer {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 -20px;
    background: var(--cir-white);
    padding: 16px 20px;
    border-top: 1px solid var(--cir-border);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    width: calc(100% + 40px) !important;
    box-sizing: border-box;
  }

  .cir-filter-drawer:not(.active) .cir-drawer-footer {
    display: none;
  }

  .cir-filter-drawer.active .cir-drawer-footer .cir-drawer-count {
    display: none;
  }

  .cir-filter-drawer.active .cir-drawer-footer .cir-btn-primary,
  .cir-filter-drawer.active .cir-drawer-footer .cir-btn-outline {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    padding: 14px 0;
    font-size: 14px;
    text-align: center;
    margin: 0;
    border: 1px solid;
    box-sizing: border-box;
  }

  .cir-filter-drawer.active .cir-drawer-footer .cir-btn-primary {
    border-color: var(--cir-burgundy);
  }

  /* Content padding not needed on mobile (drawer is overlay) */
  .cir-filter-drawer.active ~ .cir-filter-content {
    padding-left: 0;
  }

  /* Keep 2-col grid on mobile */
  .cir-filter-drawer.active ~ .cir-filter-content .product-grid,
  .cir-filter-drawer.active ~ .cir-filter-content #cirFilterResults {
    grid-template-columns: repeat(2, 1fr);
  }

  #cirFilterResults {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  /* Style pills: 3 columns on mobile */
  .cir-style-pills {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Mobile drawer header — sticky at top */
  .cir-drawer-mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 16px;
    border-bottom: 1px solid var(--cir-border);
    position: sticky;
    top: 0;
    background: var(--cir-white);
    z-index: 10;
    margin: 0 -20px;
    padding-left: 20px;
    padding-right: 20px;
  }

  .cir-drawer-mobile-title {
    font-family: var(--cir-font-heading);
    font-size: 20px;
    font-weight: 600;
    color: var(--cir-text);
  }

  .cir-drawer-mobile-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cir-text);
  }

  /* Backdrop */
  .cir-filter-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
  }

  /* Show Results button */
  #cirShowResults {
    display: block;
  }

  /* Style pills: collapsed state */
  .cir-style-pills.collapsed .cir-style-pill:nth-child(n+7) {
    display: none;
  }

  .cir-style-pills-toggle {
    display: block;
    background: none;
    border: none;
    font-family: var(--cir-font-body);
    font-size: 12px;
    color: var(--cir-burgundy);
    cursor: pointer;
    padding: 8px 0 0;
    text-decoration: underline;
  }
}

@media (max-width: 480px) {
  #cirFilterResults {
    grid-template-columns: 1fr;
  }
}
