/**
 * Mobile sort modal: fix taps on sort options (iOS/WebKit + broken dialog animation).
 * Source of truth for this fix — loaded after dist/css/style.css.
 * Sass sources are not required to deploy this; push this file + functions.php enqueue only.
 */

/* Remove mistaken "exit" animation on the sort modal dialog */
.modal.shorting_model .modal-dialog {
  animation: none !important;
  opacity: 1 !important;
  bottom: 0 !important;
}

.shorting_model .modal-body .mobile-sorting-list li.filter-item {
  position: relative;
  min-height: 44px;
  padding: 5px 10px;
}

/* Invisible full-row hit target — override compiled display:none from main stylesheet */
.shorting_model .modal-body .mobile-sorting-list input[type="checkbox"] {
  display: block !important;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.shorting_model .modal-body .mobile-sorting-list label {
  position: relative;
  z-index: 0;
  display: block;
  pointer-events: none;
  touch-action: manipulation;
  transition: font-weight 0.15s ease, color 0.15s ease;
}

/*
 * Selected state: primary and "secondry" in theme variables share the same #2a445f,
 * so the original :checked+label color rule showed no visible change.
 */
.shorting_model .modal-body .mobile-sorting-list input[type="checkbox"]:checked + label {
  color: #2a445f !important;
  font-weight: 700 !important;
}

.shorting_model .modal-body .mobile-sorting-list li.filter-item:has(input:checked) {
  background-color: rgba(42, 68, 95, 0.1);
  border-radius: 8px;
  box-shadow: inset 3px 0 0 #ffd100;
  padding: 5px 10px;
}

/* JS-driven class — works in browsers where :has() is missing or unreliable */
.shorting_model .modal-body .mobile-sorting-list li.filter-item.sort-option--selected {
  background-color: #e8eef5 !important;
  border-radius: 8px;
  box-shadow: inset 4px 0 0 #ffd100;
}

/* ---------------------------------------------------------------------------
 * YITH AJAX Filters (mobile modal): panel must stack above Bootstrap backdrop
 * --------------------------------------------------------------------------- */
body.modal-open .modal-backdrop {
  z-index: 1040 !important;
}

body.modal-open .yith-wcan-filters.filters-modal,
body.modal-open .yith-wcan-filters.filters-modal.open,
body.modal-open .yith-wcan-filters.filters-modal.cst-open,
.yith-wcan-filters.filters-modal.open,
.yith-wcan-filters.filters-modal.cst-open,
/* Some presets omit .filters-modal on the root element */
body.modal-open .yith-wcan-filters.open,
body.modal-open .yith-wcan-filters.cst-open,
.yith-wcan-filters.open,
.yith-wcan-filters.cst-open {
  z-index: 106000 !important;
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  top: auto !important;
  max-height: 90vh !important;
  overflow-y: auto !important;
  visibility: visible !important;
  opacity: 1 !important;
  -webkit-overflow-scrolling: touch;
}

/* Mobile: hide panel after Close/backdrop — class-based so reopen is not blocked by inline display:none fights */
@media (max-width: 991px) {
  .yith-wcan-filters.adaptdev-yith-filters-mobile-closed {
    display: none !important;
  }

  /* Outer shell only — do not force .filter-items open (breaks YITH accordion/toggle JS). */
  .yith-wcan-filters.open .filters-container,
  .yith-wcan-filters.cst-open .filters-container {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
}

/*
 * Category templates: _products.scss sets .wp-block-column.category-left { display: none !important }
 * at max-width 767px. YITH markup sits in that column — ancestor display:none hides .filters-container.
 * body.adaptdev-yith-filter-mobile-active is set in theme-setup when the filter panel opens (≤767px).
 */
@media (max-width: 767px) {
  body.adaptdev-yith-filter-mobile-active .wp-block-column.category-left {
    display: block !important;
  }

  .wp-block-column.category-left:has(.yith-wcan-filters.open),
  .wp-block-column.category-left:has(.yith-wcan-filters.cst-open) {
    display: block !important;
  }
}

/* ---------------------------------------------------------------------------
 * YITH filter modal — layout (mobile): titles, lists, footer
 * wp_head sets p.filter-title { inline-block; margin auto; flex-basis 20% } which
 * breaks full-width modal rows; list bullets need resetting on .filter-items.
 * --------------------------------------------------------------------------- */
@media (max-width: 991px) {
  .yith-wcan-filters.open,
  .yith-wcan-filters.cst-open {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    overflow: hidden !important;
  }

  .yith-wcan-filters.open .filters-container,
  .yith-wcan-filters.cst-open .filters-container {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px 16px 8px !important;
    box-sizing: border-box !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Override theme wp_head rules for filter accordion titles */
  .yith-wcan-filters.open .yith-wcan-filter p.filter-title,
  .yith-wcan-filters.cst-open .yith-wcan-filter p.filter-title,
  .yith-wcan-filters.open .yith-wcan-filter h3,
  .yith-wcan-filters.cst-open .yith-wcan-filter h3 {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 12px 0 !important;
    flex-basis: auto !important;
    box-sizing: border-box !important;
    text-align: center !important;
  }

  .yith-wcan-filters.open .yith-wcan-filter,
  .yith-wcan-filters.cst-open .yith-wcan-filter {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box !important;
  }

  .yith-wcan-filters.open ul.filter-items,
  .yith-wcan-filters.cst-open ul.filter-items,
  .yith-wcan-filters.open .filter-items,
  .yith-wcan-filters.cst-open .filter-items {
    list-style: none !important;
    list-style-type: none !important;
    padding-left: 0 !important;
    margin: 0 !important;
  }

  .yith-wcan-filters.open .filter-items > li,
  .yith-wcan-filters.cst-open .filter-items > li,
  .yith-wcan-filters.open .filter-items li.filter-item,
  .yith-wcan-filters.cst-open .filter-items li.filter-item {
    list-style: none !important;
    margin-left: 0 !important;
  }

  /* Theme-injected CLOSE / APPLY — pin below scroll area, no overlap */
  .yith-wcan-filters.open .cate-apply-filter,
  .yith-wcan-filters.cst-open .cate-apply-filter {
    flex-shrink: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 14px 16px 18px !important;
    margin: 0 !important;
    border-top: 1px solid #e5e5e5 !important;
    background: #fff !important;
    height: auto !important;
  }

  .yith-wcan-filters.open .cate-apply-filter ul,
  .yith-wcan-filters.cst-open .cate-apply-filter ul {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 10px !important;
  }

  .yith-wcan-filters.open .cate-apply-filter li,
  .yith-wcan-filters.cst-open .cate-apply-filter li {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Sidebar wrapper padding can offset the fixed panel */
  body.adaptdev-yith-filter-mobile-active .wp-block-column.category-left .filter-option-area {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /*
   * YITH "Show results" (.main-modal-button) can render twice after selecting a term
   * (scroll area + sticky/footer). Hide duplicates — JS adds .adaptdev-yith-sr-hidden to earlier nodes.
   */
  .yith-wcan-filters.open .filters-container .main-modal-button.adaptdev-yith-sr-hidden,
  .yith-wcan-filters.cst-open .filters-container .main-modal-button.adaptdev-yith-sr-hidden {
    display: none !important;
  }

  /* Sibling duplicates: keep only the last button.main-modal-button among siblings */
  .yith-wcan-filters.open .filters-container button.main-modal-button:has(~ button.main-modal-button),
  .yith-wcan-filters.cst-open .filters-container button.main-modal-button:has(~ button.main-modal-button) {
    display: none !important;
  }
}
