/**
 * Filterable Animals — browse grid module with filters, search, sort.
 * Auto-enqueued by get_module() when the module is used on any page.
 */

.module.filterable-animals.loading {
	pointer-events: none;
}

body:has(.module.filterable-animals.loading)::after {
	background: var(--pitty-off-white);
	content: '';
	height: 100dvh;
	left: 0;
	opacity: .6;
	position: fixed;
	top: 0;
	width: 100vw;
	z-index: 4;
}

.module.filterable-animals.loading [jx-form-results] {
	opacity: .3;
	transition: opacity .2s ease;
}

.module.filterable-animals > .container > .heading-2 {
	margin-bottom: var(--text-spacing-large);
}

.animals-browse-filters {
	align-items: flex-start;
	display: flex;
	gap: var(--text-spacing-xxsmall);
}

/* More Filters accordion — always open on desktop, collapsible on mobile */

.animals-browse-more-filters {
	display: contents;
}

.animals-browse-more-filters > summary {
	display: none;
}

.animals-browse-more-filters-inner {
	display: flex;
	flex-wrap: wrap;
	gap: var(--text-spacing-xxsmall);
}

.animals-browse-filters select {
	flex: 1;
	font-size: calc(14rem / 16);
	min-width: 140px;
}

/*** Search ***/

.animals-browse-search {
	min-width: 200px;
	order: -1;
	position: relative;
}

.animals-browse-search input {
	font-size: calc(14rem / 16);
	padding-left: var(--text-spacing-large);
	padding-right: var(--text-spacing-xsmall);
	width: 100%;
}

.animals-browse-search-btn {
	align-items: center;
	background: none;
	border: none;
	color: var(--grayhound);
	cursor: pointer;
	display: flex;
	font-size: calc(14rem / 16);
	justify-content: center;
	line-height: 1;
	padding: 0;
	position: absolute;
	left: var(--text-spacing-xsmall);
	top: calc(50% + 1px);
	transform: translateY(-50%);
}

.animals-browse-search-btn:hover {
	color: var(--retriever-black);
}

.animals-browse-search-btn svg {
	height: 13px;
	width: 13px;
}

/*** Clear Filters ***/

.animals-browse-clear {
}

.animals-browse-clear[hidden] {
	display: none;
}

.animals-browse-results-bar {
	align-items: center;
	border-bottom: none;
	display: flex;
	justify-content: space-between;
	margin-top: var(--text-spacing-large);
	padding-bottom: var(--text-spacing-xsmall);
}

.animals-browse-count {
	align-items: baseline;
	display: flex;
	font-size: calc(15rem / 16);
	gap: var(--text-spacing-xsmall);
	margin: 0;
}

.animals-browse-count:has([jx-form-results-count]:empty) {
	opacity: 0;
}

.animals-browse-grid {
	list-style: none;
	margin: 0;
	padding: 0;
}

.animals-browse-grid [jx-form-results-items] {
	column-gap: var(--text-spacing-large);
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	list-style: none;
	margin: 0;
	padding: var(--text-spacing-xsmall) 0 0;
	row-gap: var(--text-spacing-large);
}

/*** No Results ***/

.animals-browse-grid [jx-form-no-results] {
	color: var(--grayhound);
	padding: var(--module-spacing-medium) 0;
	text-align: center;
}

/*** Load More ***/

.animals-browse-grid [jx-form-pagination] {
	display: block;
	margin-left: auto;
	margin-right: auto;
	margin-top: var(--text-spacing-xxlarge);
	width: fit-content;
}

.animals-browse-grid [jx-form-pagination].load-more-complete {
	display: none;
}

/*
 * ====================================================================== *
 * MQ <=1200px — Laptop
 * ====================================================================== *
 */

@media only screen and (max-width: calc(1200rem / 16)) {

	.animals-browse-grid [jx-form-results-items] {
		grid-template-columns: repeat(3, 1fr);
	}

}

/*
 * ====================================================================== *
 * MQ <=950px — Tablet
 * ====================================================================== *
 */

@media only screen and (max-width: calc(950rem / 16)) {

	.animals-browse-filters {
		align-items: center;
		gap: var(--text-spacing-xxsmall);
		position: relative;
	}

	.animals-browse-search {
		flex: none;
		min-width: 0;
		width: 320px;
	}

	.animals-browse-more-filters {
		margin-left: auto;
	}

	.animals-browse-results-bar {
		margin-top: var(--text-spacing-xsmall);
	}

	/* More Filters accordion — collapsible on tablet and below.
	   The <details> has `open` in HTML so desktop display:contents works.
	   On tablet/mobile we remove `open` via JS so it starts collapsed. */

	.animals-browse-more-filters {
		display: block;
		flex-shrink: 0;
	}

	.animals-browse-more-filters > summary {
		border-radius: var(--border-radius-normal);
		color: var(--russian-blue);
		cursor: pointer;
		display: block;
		font-size: calc(15rem / 16);
		font-weight: 600;
		letter-spacing: 0.2px;
		line-height: calc(20 / 15);
		list-style: none;
		margin-right: calc(-1 * var(--text-spacing-small));
		padding: var(--text-spacing-xsmall) var(--text-spacing-small) var(--text-spacing-xsmall) var(--text-spacing-small);
	}

	.animals-browse-more-filters[open] > summary {
		background: var(--appaloosa-beige);
	}

	.animals-browse-more-filters > summary::-webkit-details-marker {
		display: none;
	}

	.animals-browse-more-filters > summary::after {
		content: ' +';
	}

	.animals-browse-more-filters[open] > summary::after {
		content: ' −';
	}

	.animals-browse-more-filters-inner {
		background: var(--appaloosa-beige);
		border-radius: var(--border-radius-normal);
		display: flex;
		flex-direction: column;
		gap: var(--text-spacing-xsmall);
		left: calc(-1 * var(--text-spacing-small));
		padding: var(--text-spacing-small);
		position: absolute;
		top: calc(100% + var(--text-spacing-xxsmall));
		width: calc(100% + (var(--text-spacing-small) * 2));
		z-index: 3;
	}

	.animals-browse-filters select {
		width: 100%;
	}

	.animals-browse-grid [jx-form-results-items] {
		gap: var(--text-spacing-large) var(--text-spacing-xsmall);
		grid-template-columns: repeat(2, 1fr);
	}

}

/*
 * ====================================================================== *
 * MQ <=650px — Mobile
 * ====================================================================== *
 */

@media only screen and (max-width: calc(650rem / 16)) {

	.animals-browse-filters {
		flex-direction: column;
	}

	.animals-browse-search {
		flex: none;
		width: 100%;
	}

	.animals-browse-more-filters {
		align-self: flex-start;
		margin-left: 0;
		width: auto;
	}

	.animals-browse-more-filters > summary {
		border-radius: 0;
		margin: 0 var(--viewport-edge);
		padding: var(--text-spacing-small) var(--container-outer-padding) var(--text-spacing-xsmall);
	}

	.animals-browse-more-filters-inner {
		background: var(--appaloosa-beige);
		border-radius: 0;
		gap: var(--text-spacing-xxsmall);
		left: auto;
		margin: 0 var(--viewport-edge);
		padding: 0 var(--container-outer-padding) var(--text-spacing-small);
		position: static;
		top: auto;
		width: var(--viewport-full);
		z-index: auto;
	}

	.animals-browse-grid [jx-form-results-items] {
		gap: var(--text-spacing-large) var(--text-spacing-xsmall);
	}

	/*** Card — mobile tweaks ***/

	/* Tighter gap between image and text on mobile */

	.animals-browse-grid .card.animal .card-link {
		gap: var(--text-spacing-xsmall);
	}

	/* Only reserve the "badge" row when the card has a foster-badge, otherwise
	   the empty row contributes an extra gap between media and text. */

	.animals-browse-grid .card.animal .card-link:has(.foster-badge) {
		grid-template-areas:
			"media"
			"badge"
			"text";
		grid-template-rows: auto auto 1fr;
	}

	/* Location pill: bottom-left of image, icon hidden for space */

	.animals-browse-grid .card.animal .media .pill.location i,
	.animals-browse-grid .card.animal .media .pill.location svg {
		display: none;
	}

	.animals-browse-grid .card.animal .media .pill {
		bottom: var(--text-spacing-xxsmall);
		top: auto;
	}

	/* Foster badge flows into its own row between image and text. Negative
	   margin-top tightens the gap below the image without shrinking the gap
	   to the text below. */

	.animals-browse-grid .card.animal .foster-badge {
		align-self: start;
		grid-area: badge;
		justify-self: start;
		margin: calc(-1 * var(--text-spacing-xxsmall)) 0 0;
	}

	/* In-foster sticker stays overlaid bottom-right; just smaller on the
	   tighter 2-col mobile grid. */

	.animals-browse-grid .card.animal .in-foster-badge {
		font-size: calc(10rem / 16);
		width: 72px;
	}

}
