/**
 * WP Search with Algolia - Product search modal overlay.
 *
 * The modal mirrors the search page DOM (#ais-wrapper.algolia-search-shell) so
 * the result cards, pagination and category pills inherit the exact same look
 * defined in css/algolia-instantsearch.css. This file only styles the modal
 * chrome (backdrop, centred panel, animation, close button, scroll area).
 */

.algolia-psm-modal,
.algolia-psm-modal * {
	box-sizing: border-box;
}

.algolia-psm-modal {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 8vh 1rem 1rem;
	background: rgba(23, 21, 17, 0.55);
	-webkit-backdrop-filter: blur(3px);
	backdrop-filter: blur(3px);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.22s ease, visibility 0.22s ease;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.algolia-psm-modal.is-open {
	opacity: 1;
	visibility: visible;
}

.algolia-psm-modal__panel {
	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 1080px;
	max-height: 86vh;
	margin: auto;
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 30px 80px rgba(15, 23, 42, 0.32);
	transform: translateY(-14px) scale(0.985);
	opacity: 0;
	transition: transform 0.24s ease, opacity 0.24s ease;
}

.algolia-psm-modal.is-open .algolia-psm-modal__panel {
	transform: translateY(0) scale(1);
	opacity: 1;
}

.algolia-psm-modal__close {
	position: absolute;
	top: 1.85rem;
	right: 1.5rem;
	z-index: 5;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.4rem;
	height: 2.4rem;
	padding: 0;
	border: 0;
	border-radius: 999px;
	background: rgba(15, 23, 42, 0.06);
	color: #4d4334;
	cursor: pointer;
	line-height: 0;
	transition: background 0.18s ease, color 0.18s ease;
}

.algolia-psm-modal__close:hover,
.algolia-psm-modal__close:focus-visible {
	background: var(--algolia-accent, #776330);
	color: #fff;
	outline: none;
}

.algolia-psm-modal__close svg {
	width: 1.05rem;
	height: 1.05rem;
	fill: currentColor;
}

.algolia-psm-modal__body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 1.6rem 1.6rem 1.2rem;
}

/* Re-fit the search-page shell so it sits flush inside the modal. */
.algolia-psm-modal #ais-wrapper.algolia-search-shell {
	padding: 0;
}

.algolia-psm-modal .algolia-search-box-wrapper {
	position: sticky;
	top: -1.6rem;
	z-index: 4;
	margin: -1.6rem -1.6rem 0.9rem;
	/* Extra right padding keeps the search field clear of the close button. */
	padding: 1.6rem 4.75rem 0.85rem 1.6rem;
	background: #fff;
	border-bottom: 1px solid #efe7da;
	border-radius: 16px 16px 0 0;
}

/* The base stylesheet positions the icon for a wrapper with no padding. Inside
   the modal the wrapper is padded, so the icon must be offset by that padding,
   otherwise it sits outside the search field. */
.algolia-psm-modal .algolia-search-box-wrapper .search-icon {
	left: calc(1.6rem + 0.95rem);
	top: calc(1.6rem + 0.95rem);
}

/* Empty helper rows should not add vertical gaps to the grid. */
.algolia-psm-modal #algolia-stats:empty,
.algolia-psm-modal #algolia-powered-by:empty {
	display: none;
}

/* The category pills only carry meaning once a query is running, so keep them
   hidden (instead of showing a row of "(0)" counts) until the search starts. */
.algolia-psm-modal:not(.is-searching) #algolia-category-pills {
	display: none;
}

/* Stack the result cards a touch tighter inside the narrower modal column. */
@media (min-width: 768px) {
	.algolia-psm-modal #ais-wrapper.algolia-search-results--product #algolia-hits .search-li {
		flex: 0 0 25%;
		max-width: 25%;
		padding-bottom: 0.7rem;
	}
}

@media (min-width: 1200px) {
	.algolia-psm-modal #ais-wrapper.algolia-search-results--product #algolia-hits .search-li {
		flex: 0 0 20%;
		max-width: 20%;
	}
}

.algolia-psm-modal #algolia-stats .shop-title {
	margin: 0;
	padding-top: 0.75rem !important;
	padding-bottom: 0.65rem !important;
	font-size: 1.9rem !important;
	line-height: 1.15;
}

.algolia-psm-modal__hint {
	margin: 0;
	padding: 3rem 1rem 3.25rem;
	color: var(--algolia-muted, #5f6b7a);
	font-size: 1.02rem;
	line-height: 1.5;
	text-align: center;
}

/* "View all results" button shown beneath the top results. */
.algolia-psm-modal__more {
	display: none;
	margin: 1.75rem 0 0.5rem;
	text-align: center;
}

.algolia-psm-modal__more-link,
.algolia-psm-modal__more-link:visited {
	display: inline-block;
	padding: 0.8rem 2.1rem;
	border-radius: 999px;
	background: var(--algolia-accent, #776330);
	/* Force white text so it stays readable on the accent background even when
	   the active theme styles anchor colours. */
	color: #fff !important;
	font-size: 1rem;
	font-weight: 600;
	text-decoration: none;
	transition: background 0.18s ease, transform 0.18s ease;
}

.algolia-psm-modal__more-link:hover,
.algolia-psm-modal__more-link:focus-visible {
	background: #5f4d25;
	color: #fff !important;
	text-decoration: none;
	transform: translateY(-1px);
	outline: none;
}

/* Keep the selected category pill's label white on its accent background. */
.algolia-psm-modal .algolia-pill.is-selected,
.algolia-psm-modal .algolia-pill.is-selected .algolia-pill__count {
	color: #fff !important;
}

/* Add-to-basket toast, pinned to the bottom of the panel so it stays in view
   regardless of how far the results list has been scrolled. */
.algolia-psm-modal__toast {
	position: absolute;
	left: 50%;
	bottom: 1.25rem;
	z-index: 20;
	width: min(440px, calc(100% - 2.5rem));
	transform: translateX(-50%);
	pointer-events: none;
}

.algolia-psm-modal__toast:empty {
	display: none;
}

.algolia-psm-modal__toast .woocommerce-notices-wrapper > *,
.algolia-psm-modal__toast .woocommerce-message,
.algolia-psm-modal__toast .woocommerce-error,
.algolia-psm-modal__toast .woocommerce-info {
	pointer-events: auto;
	margin: 0;
	padding: 0.9rem 1.15rem;
	border-radius: 12px;
	box-shadow: 0 16px 40px rgba(15, 23, 42, 0.25);
	animation: algolia-psm-toast-in 0.22s ease;
}

@keyframes algolia-psm-toast-in {
	from {
		opacity: 0;
		transform: translateY(12px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@media (max-width: 767px) {
	.algolia-psm-modal {
		padding: 0;
		background: rgba(23, 21, 17, 0.65);
	}

	.algolia-psm-modal__panel {
		max-width: none;
		max-height: 100%;
		min-height: 100%;
		margin: 0;
		border-radius: 0;
	}

	.algolia-psm-modal__body {
		padding: 1.1rem 1rem 1rem;
	}

	.algolia-psm-modal .algolia-search-box-wrapper {
		top: -1.1rem;
		margin: -1.1rem -1rem 1.1rem;
		padding: 1.1rem 3.75rem 0.9rem 1rem;
		border-radius: 0;
	}

	.algolia-psm-modal #algolia-stats .shop-title {
		padding-top: 0.45rem !important;
		padding-bottom: 0.45rem !important;
		font-size: 1.35rem !important;
	}

	.algolia-psm-modal .algolia-search-box-wrapper .search-icon {
		left: calc(1rem + 0.95rem);
		top: calc(1.1rem + 0.95rem);
	}

	.algolia-psm-modal__close {
		top: 1.25rem;
		right: 0.85rem;
	}
}

/* Prevent the page behind the modal from scrolling while it is open. */
body.algolia-psm-open {
	overflow: hidden;
}
