/*
 * Places Dropdown 1.2.0 — Portfolio Filter Gallery Premium.
 * Only galleries enhanced by our JS are affected.
 */
.pfg-gallery-wrapper.scf-places-enhanced {
  overflow: visible !important;
}

/* Desktop/tablet: keep the entire gallery filter menu in view while scrolling the gallery. */
.pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters {
  position: -webkit-sticky !important;
  position: sticky !important;
  top: 0;
  z-index: 990 !important;
  overflow: visible !important;
  background-color: #fff !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
}

/* WordPress toolbar: don't put the sticky bar underneath it. */
body.admin-bar .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters {
  top: 32px;
}
@media (max-width: 782px) {
  body.admin-bar .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters {
    top: 46px;
  }
}
@media (max-width: 600px) {
  body.admin-bar .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters {
    top: 0;
  }
}

/* Hide the entire filter bar while any detected image lightbox is open. */
.pfg-gallery-wrapper.scf-places-enhanced.scf-places-lightbox-open > .pfg-filters {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Keep the real filter buttons for the Portfolio Filter Gallery JS, but hide them visually. */
.pfg-gallery-wrapper.scf-places-enhanced .pfg-filters > .scf-places-original {
  display: none !important;
}

.pfg-gallery-wrapper.scf-places-enhanced .scf-places-dropdown {
  display: inline-flex;
  position: relative;
  align-self: center;
  vertical-align: middle;
  flex: 0 0 auto;
  z-index: 10;
  margin: 0;
  /* JS copies the other filter buttons' computed typography here. */
}

.pfg-gallery-wrapper.scf-places-enhanced .scf-places-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-sizing: border-box;
  list-style: none;
  cursor: pointer;
  padding: 9px 13px;
  background: transparent;
  color: #161616;
  border: 0;
  border-bottom: 2px solid transparent;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  white-space: nowrap;
  user-select: none;
}
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-toggle::-webkit-details-marker { display: none; }
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-toggle::marker { content: ''; }

.pfg-gallery-wrapper.scf-places-enhanced .scf-places-count {
  font: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  white-space: nowrap;
}

.pfg-gallery-wrapper.scf-places-enhanced .scf-places-chevron {
  display: inline-block;
  margin-left: 2px;
  font-size: .8em;
  transition: transform 160ms ease;
}
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-dropdown[open] .scf-places-chevron {
  transform: rotate(180deg);
}
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-dropdown--active .scf-places-toggle,
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-dropdown[open] .scf-places-toggle {
  color: #70120c;
  border-bottom-color: #70120c;
}

.pfg-gallery-wrapper.scf-places-enhanced .scf-places-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 9999;
  box-sizing: border-box;
  width: max-content;
  min-width: 210px;
  max-width: min(300px, calc(100vw - 32px));
  max-height: min(420px, 62vh);
  overflow: auto;
  padding: 6px 0;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .09);
  border-radius: 4px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .15);
}
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-option {
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 9px 16px;
  border: 0;
  background: transparent;
  color: #161616;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-option:hover,
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-option:focus-visible {
  background: #f3f3f3;
}
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-option--active {
  color: #70120c;
  font-weight: 700;
  background: #f9f0ef;
}
.pfg-gallery-wrapper.scf-places-enhanced .scf-places-toggle:focus-visible {
  outline: 2px solid #70120c;
  outline-offset: 2px;
}


/*
 * Mobile (< 782px): precisely six visible filters form two rows of three.
 * The grid and its dropdown remain in normal document flow: NOT sticky/fixed.
 * If more than six top-level filters are added later, the grid grows naturally
 * instead of hiding them.
 */
@media (max-width: 781px) {
  .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters {
    position: static !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    grid-auto-flow: row !important;
    grid-template-rows: repeat(2, auto);
    gap: 0 4px !important;
    align-items: stretch !important;
    justify-items: stretch !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 5px 0 !important;
    margin: 0 0 12px !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    box-shadow: none !important;
    z-index: 10 !important;
  }

  /* The parent dropdown and the five original visible filters share each cell. */
  .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters > button.pfg-filter:not(.scf-places-original),
  .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters > .scf-places-dropdown {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    align-self: stretch !important;
    justify-self: stretch !important;
  }

  .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters > button.pfg-filter:not(.scf-places-original) {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-wrap: wrap !important;
    min-height: 44px !important;
    padding: 8px 3px !important;
    text-align: center !important;
    white-space: normal !important;
    overflow-wrap: break-word !important;
    line-height: 1.3 !important;
  }

  .pfg-gallery-wrapper.scf-places-enhanced > .pfg-filters > .scf-places-dropdown {
    display: flex !important;
    position: relative !important;
    flex: auto !important;
  }

  .pfg-gallery-wrapper.scf-places-enhanced .scf-places-toggle {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 44px !important;
    padding: 8px 3px !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-content: center !important;
    text-align: center !important;
    white-space: normal !important;
    gap: 2px 4px !important;
    line-height: 1.3 !important;
  }

  .pfg-gallery-wrapper.scf-places-enhanced .scf-places-menu {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: max-content !important;
    min-width: 200px !important;
    max-width: calc(100vw - 24px) !important;
    max-height: 55vh !important;
    text-align: left !important;
  }

  /* In mobile, Places remains legible even when the count wraps. */
  .pfg-gallery-wrapper.scf-places-enhanced .scf-places-count,
  .pfg-gallery-wrapper.scf-places-enhanced .pfg-filter-count {
    white-space: nowrap !important;
  }
}
