/* Mobile filter panel (search.php + category.php).

   Deliberately does not duplicate any filter markup or logic - the
   ".rld-filter-panel" element wrapped around each page's existing
   includes/search_sidebar.php / includes/category_sidebar.php include
   IS the sidebar. On desktop none of the rules below apply (everything
   here is scoped inside the max-width query) so the sidebar renders
   exactly as it always has. Below 767.98px - the same breakpoint
   styles/mycss.css already uses to hide .mobile-bottom-nav on desktop -
   that same element becomes a bottom sheet toggled by the new
   "Filters" button, and the header/body/footer chrome around it
   (added directly in search.php/category.php, not in the shared
   sidebar partials) becomes visible. Checkbox/select state lives in
   the untouched DOM the whole time, so opening/closing the sheet can
   never lose or reset a selection - only CSS visibility changes. */

.rld-mobile-filter-bar {
  display: none;
}

.rld-filter-panel-header,
.rld-filter-panel-footer {
  display: none;
}

.rld-filter-backdrop {
  display: none;
}

@media (max-width: 767.98px) {

  .rld-mobile-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
  }

  .rld-filters-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--light-bg);
    border: 1.5px solid var(--brand-green);
    color: var(--brand-green);
    font-weight: 600;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 8px;
    line-height: 1;
  }

  .rld-filters-btn:active {
    background: var(--light-surface);
  }

  html.dark .rld-filters-btn {
    background: var(--dark-surface);
    border-color: var(--brand-green-bright);
    color: var(--brand-green-bright);
  }

  html.dark .rld-filters-btn:active {
    background: var(--dark-surface-alt);
  }

  .rld-filter-count {
    background: var(--brand-green);
    color: #fff;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
  }

  html.dark .rld-filter-count {
    background: var(--brand-green-bright);
    color: #06210a;
  }

  /* Backdrop */

  .rld-filter-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .rld-filter-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  /* Sheet - this IS the existing sidebar column (.col-lg-3...), just
     repositioned; its own filter cards are untouched. */

  .rld-filter-panel {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    max-width: 100%;
    width: 100%;
    max-height: 85vh;
    background: var(--light-bg);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.28);
    z-index: 2001;
    transform: translateY(105%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
  }

  html.dark .rld-filter-panel {
    background: var(--dark-surface);
  }

  .rld-filter-panel.is-open {
    transform: translateY(0);
  }

  .rld-filter-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--light-border);
    flex: none;
  }

  html.dark .rld-filter-panel-header {
    border-color: var(--dark-border);
  }

  .rld-filter-panel-header h4 {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
    color: var(--light-text);
  }

  html.dark .rld-filter-panel-header h4 {
    color: var(--dark-text);
  }

  .rld-filter-panel-close {
    background: transparent;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--light-text-muted);
    padding: 4px 8px;
  }

  html.dark .rld-filter-panel-close {
    color: var(--dark-text-muted);
  }

  .rld-filter-panel-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px calc(14px + var(--mobile-bottom-nav-height, 65px));
    flex: 1 1 auto;
  }

  /* Touch-friendly tweak to the existing checkbox rows rendered by
     search_sidebar.php/category_sidebar.php - spacing only, the
     checkboxes/labels themselves are unchanged. */
  .rld-filter-panel-body .nav-item.checkbox label {
    display: flex;
    align-items: center;
    min-height: 34px;
    font-size: 15px;
  }

  .rld-filter-panel-body .card {
    margin-bottom: 14px;
  }

  .rld-filter-panel-footer {
    display: flex;
    gap: 10px;
    padding: 12px 16px calc(12px + var(--mobile-bottom-nav-height, 65px));
    border-top: 1px solid var(--light-border);
    flex: none;
    background: var(--light-bg);
  }

  html.dark .rld-filter-panel-footer {
    border-color: var(--dark-border);
    background: var(--dark-surface);
  }

  .rld-filter-clear-all-btn {
    flex: 1;
    background: transparent;
    border: 1.5px solid var(--light-border);
    color: var(--light-text);
    font-weight: 600;
    font-size: 14px;
    padding: 12px;
    border-radius: 8px;
  }

  html.dark .rld-filter-clear-all-btn {
    border-color: var(--dark-border);
    color: var(--dark-text);
  }

  .rld-filter-apply-btn {
    flex: 2;
    background: var(--brand-green);
    border: 1.5px solid var(--brand-green);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    padding: 12px;
    border-radius: 8px;
  }

  html.dark .rld-filter-apply-btn {
    background: var(--brand-green-bright);
    border-color: var(--brand-green-bright);
    color: #06210a;
  }

  body.rld-filter-open-lock {
    overflow: hidden;
  }

}
