/* Modern 2025 styles for filter block */
.filter-block {
  max-width: 300px;
  padding: 18px;
  border-radius: 14px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.72),
    rgba(250, 250, 250, 0.6)
  );
  box-shadow:
    0 8px 24px rgba(16, 24, 40, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(20, 28, 48, 0.06);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  /* only animate shadow to avoid layout shift when hovering */
  transition: box-shadow 220ms ease;
}
.filter-block:hover {
  box-shadow: 0 12px 36px rgba(16, 24, 40, 0.1);
}

.filter-block .filter-section {
  margin-bottom: 18px;
}

.filter-block .filter-header-title {
  font-size: 15px;
  margin: 0 0 12px;
  color: #0f1724; /* deep slate */
  font-weight: 600;
  letter-spacing: -0.01em;
}

.filter-section .section-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-section .section-header .subtitle {
  color: #6b7280;
  font-size: 12px;
}

.filter-values {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* When a values list has more than 11 options, limit height and allow scroll */
.filter-values.scrollable {
  max-height: 260px; /* ~11 items at 22-24px each plus gaps */
  overflow-y: auto;
  padding-right: 6px; /* space for scrollbar */
}

/* Nice inertial scrolling on touch devices */
.filter-values.scrollable {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.filter-values.scrollable::-webkit-scrollbar {
  width: 8px;
}
.filter-values.scrollable::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 6px;
}
.filter-values.scrollable::-webkit-scrollbar-track {
  background: transparent;
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #111827;
}
.filter-option label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

/* Modern checkbox using accent-color when supported, fallback styles */
.filter-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #d9a180;
  border-radius: 4px;
  cursor: pointer;
}
.filter-option .cnt {
  color: #9ca3af;
  font-size: 12px;
  margin-left: auto;
  padding: 4px 8px;
}

.filter-price .price-row {
  display: flex;
  gap: 10px;
}
.filter-price input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 36, 0.06);
  background: rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  max-width: 100px;
}
.filter-price input[type="number"]:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(11, 116, 222, 0.08);
  border-color: #0b74de;
}

.filter-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}
.filters-reset,
.filters-apply {
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  border: none;
}
.filters-reset {
  background: transparent;
  color: #374151;
  border: 1px solid rgba(15, 23, 36, 0.06);
}
.filters-reset:hover {
  background: rgba(15, 23, 36, 0.02);
}
.filters-apply {
  background: linear-gradient(90deg, #f6e4d7, #edd0bd);
  border: 1px solid #d6ab8c;
  color: #6a4330;
  box-shadow:
    0 2px 0 #d6ab8c,
    0 6px 14px rgba(214, 171, 140, 0.24);
  transition:
    background 320ms cubic-bezier(0.2, 0.9, 0.2, 1),
    transform 180ms ease,
    box-shadow 220ms ease;
}
.filters-apply:hover {
  transform: translateY(-1px);
  background: linear-gradient(90deg, #f8e9de, #f1d8c7);
  box-shadow:
    0 2px 0 #cf9f7d,
    0 9px 18px rgba(214, 171, 140, 0.3);
}
.filters-apply:focus {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(216, 160, 126, 0.3),
    0 2px 0 #cf9f7d,
    0 9px 18px rgba(214, 171, 140, 0.3);
}
.filters-apply:active {
  transform: translateY(1px);
}

/* small counter badge for overall results */
.filters-count {
  display: inline-block;
  font-size: 13px;
  color: #0b1220;
  padding: 4px 8px;
  margin-left: 8px;
}

/* Make block full-width on small screens */
@media (max-width: 640px) {
  .filter-block {
    max-width: 100%;
    padding: 14px;
  }
  .filter-actions {
    flex-direction: row;
    justify-content: space-between;
  }
}

/* Accessibility focus states */
.filter-option input[type="checkbox"]:focus {
  outline: 3px solid rgba(11, 116, 222, 0.12);
  outline-offset: 2px;
}
.filters-apply:focus {
  box-shadow:
    0 0 0 3px rgba(216, 160, 126, 0.3),
    0 2px 0 #cf9f7d,
    0 9px 18px rgba(214, 171, 140, 0.3);
}

/* Subtle divider */
.filter-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    rgba(15, 23, 36, 0.03),
    rgba(15, 23, 36, 0.02)
  );
  margin: 12px -18px;
}

/* Toggle button for mobile filters */
.filter-toggle-btn {
  display: none; /* shown only on small screens */
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid #e1e4e8; /* match sorting */
  background: #fff; /* match sorting */
  color: #1f2328; /* match sorting */
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03); /* subtle like sorting */
}
.filter-toggle-btn:hover {
  border-color: #c9d1d9;
  background: #f1f5f9;
}

/* Collapsed state: hide the form and keep a compact header area */
.filter-block.collapsed .filters-form {
  display: none;
}
.filter-block .filters-form {
  transition: max-height 240ms ease;
}

@media (max-width: 735px) {
  .filter-toggle-btn {
    display: inline-flex;
    width: auto;
    justify-content: center;
    max-width: 159px;
    width: 159px;
  }
  .filter-block {
    padding: 12px;
  }
}

/* Prevent flash-of-overlay on initial page load on mobile:
   hide the filter block until JS signals it's ready. This avoids the
   fixed overlay appearing briefly before the script collapses it. */
@media (max-width: 735px) {
  .filter-block {
    visibility: hidden;
    opacity: 0;
  }
  body.filters-js-ready .filter-block {
    visibility: visible;
    opacity: 1;
  }
}

/* When expanded (not .collapsed) on small screens show as an overlay above products */
@media (max-width: 735px) {
  .filter-block:not(.collapsed) {
    position: fixed;
    left: 12px;
    right: 12px;
    top: 12px;
    bottom: 12px; /* cover viewport with small margins to capture scroll */
    z-index: 1200;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(16, 24, 40, 0.2);
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.96),
      rgba(250, 250, 250, 0.94)
    );
    backdrop-filter: blur(6px) saturate(120%);
    -webkit-backdrop-filter: blur(6px) saturate(120%);
    max-height: none;
    overflow: hidden; /* prevent double scrollbars; inner form will scroll */
  }
  /* ensure the toggle button remains visible at the top of the overlay */
  .filter-block:not(.collapsed) .filter-toggle-btn {
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
  /* collapsed state: make container minimal like sorting control */
  .filter-block.collapsed {
    background: transparent;
    box-shadow: none;
    border: none;
    padding: 0;
    max-width: 159px;
  }
}

/* Mobile filter list heights by viewport height */
@media (max-width: 735px) and (min-height: 841px) {
  .filter-block:not(.collapsed) .filters-form {
    height: 635px;
    overflow: auto;
  }
}
@media (max-width: 735px) and (min-height: 651px) and (max-height: 840px) {
  .filter-block:not(.collapsed) .filters-form {
    height: 450px;
    overflow: auto;
  }
}
@media (max-width: 735px) and (min-height: 551px) and (max-height: 650px) {
  .filter-block:not(.collapsed) .filters-form {
    height: 350px;
    overflow: auto;
  }
}
@media (max-width: 735px) and (max-height: 550px) {
  .filter-block:not(.collapsed) .filters-form {
    height: 305px;
    overflow: auto;
  }
}

/* Prefer flexible max-height scrolling for the inner form to fit any device height */
@media (max-width: 735px) {
  .filter-block:not(.collapsed) .filters-form {
    height: calc(100% - 44px); /* leave space for sticky toggle header approx */
    max-height: none !important;
    overflow: auto;
    -webkit-overflow-scrolling: touch; /* smooth touch scroll */
  }
}

/* Lock background scroll when filters overlay is open */
body.filters-open {
  overflow: hidden;
}

/* Optional dim backdrop behind overlay (non-interactive) */
body.filters-open::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 36, 0.28);
  z-index: 1100; /* below overlay z-index 1200 */
  pointer-events: none;
}

/* Preserve layout space when mobile filter overlay is opened.
   The filter block becomes position:fixed (removed from flow) which can
   collapse the aside and shift content; add a pseudo-element to the
   filters column to keep its height while overlay is active. */
@media (max-width: 735px) {
  body.filters-open .filters-column::after {
    content: "";
    display: block;
    height: 48px; /* approximate height of the collapsed toggle header */
    width: 100%;
  }
}

@media (min-width: 736px) and (max-width: 1085px) {
  .filter-block {
    max-width: 197px;
  }
  .filter-price input[type="number"] {
    max-width: 70px;
  }
  .filters-reset,
  .filters-apply {
    font-size: 12px;
    padding: 4px 5px;
  }
}

/* Very small screens: smaller filter button */
@media (min-width: 320px) and (max-width: 368px) {
  .filter-toggle-btn {
    padding: 6px 8px;
    font-size: 12px;
    gap: 6px;
    max-width: 137px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
