.gallery-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--pst-color-surface);
  border: 1px solid var(--pst-color-border);
  border-radius: 0.5rem;
}

/* Cards' thumbnails loading in can grow the carousel's height after the page
   settles, and scroll anchoring would silently re-scroll to compensate. */
.sd-cards-carousel {
  overflow-anchor: none;
}

/* Shared sizing/typography for every toolbar control, so the search box,
   facet dropdowns, and clear button all render at the same height - inputs
   and buttons don't inherit font from the page by default. */
#gallery-search,
.facet-toggle,
#filter-clear {
  box-sizing: border-box;
  height: 2.15rem;
  padding: 0 0.6rem;
  border-radius: 0.35rem;
  border: 1px solid var(--pst-color-border);
  background: var(--pst-color-background);
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  line-height: 2.05rem;
}

#gallery-search {
  min-width: 14rem;
}

.facet-dropdown {
  position: relative;
  font-size: 0.85rem;
}

.facet-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 8rem;
  font-weight: 600;
  cursor: pointer;
}

.facet-toggle::after {
  content: "\25BE";
  margin-left: auto;
  opacity: 0.6;
}

.facet-toggle-count {
  color: var(--pst-color-primary);
}

.facet-panel {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 12rem;
  max-height: 16rem;
  overflow-y: auto;
  padding: 0.5rem;
  background: var(--pst-color-background);
  border: 1px solid var(--pst-color-border);
  border-radius: 0.35rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.facet-panel[hidden] {
  display: none;
}

.facet-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0.3rem;
  border-radius: 0.25rem;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 400;
  /* Skips mobile's tap-delay, which can otherwise land a fast tap's synthetic click on whatever ended up under it after the grid reflows. */
  touch-action: manipulation;
}

.facet-option:hover {
  background: var(--pst-color-surface);
}

.facet-option input {
  margin: 0;
  cursor: pointer;
  accent-color: var(--pst-color-primary);
}

#filter-clear {
  background: transparent;
  cursor: pointer;
}

#filter-clear:hover {
  background: var(--pst-color-surface);
}

.gallery-filter-count {
  margin-left: auto;
  font-size: 0.85rem;
  opacity: 0.75;
  align-self: center;
}

.gallery-card.gallery-hidden {
  display: none !important;
}

/* Right-aligns a value that's wrapped onto its own line (space-between has nothing to push against there). */
.gallery-card .field-value-primary {
  margin-left: auto;
}

/* Stacks the bar and both nav slots in one shared area, so the buttons can be positioned from the bar's own box (see .gallery-nav-button). */
.gallery-toolbar-wrap {
  display: grid;
  margin-bottom: 1rem;
}

.gallery-toolbar-wrap > * {
  grid-area: 1 / 1;
}

.gallery-nav-slot {
  position: relative; /* containing block for .gallery-nav-button's absolute positioning */
  z-index: 5;
  pointer-events: none; /* let clicks fall through to the bar/dropdowns beneath; the button re-enables its own */
}

/* top: 100% = the slot's own bottom edge (always the bar's), so the fixed offset below it lands on the card header band. */
.gallery-nav-button {
  position: absolute;
  top: calc(100% + 54px);
  transform: translateY(-50%);
  pointer-events: auto;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--pst-color-border);
  background: var(--pst-color-surface);
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  opacity: 0.85;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.gallery-nav-button:hover:not(:disabled) {
  opacity: 1;
}

.gallery-nav-button:disabled {
  opacity: 0.25;
  cursor: default;
}

#gallery-prev {
  left: 0.5rem;
}

#gallery-next {
  right: 0.5rem;
}
