/**
 * Pixelated Orange - Search
 * Structural styles. Styling custom properties (--po-search-*) are set inline
 * from ACF settings by po_search_css_vars() in includes/po-search-enqueue.php,
 * scoped to .po-search. Fallback values below are only used before that inline
 * block loads / if ACF is inactive.
 */

:root {
	--po-search-border-color: #e2e2e2;
	--po-search-bg: #ffffff;
	--po-search-radius: 6px;
}

.po-search {
	position: relative;
	width: 100%;
	max-width: var(--po-search-max-width, 480px);
}

/* Set on <body> by po-search.js (setResultsHidden()) whenever any search
   box's results panel is visible - the panel overlays the page, so the
   page's own scrollbar behind it let the page scroll underneath while the
   panel stayed put. */
body.po-search-scroll-lock {
	overflow: hidden;
}

/* When attached to a nav menu, don't let it stretch to the menu's text width */
.po-search-menu-item {
	list-style: none;
	max-width: 260px;
}

.po-search-menu-item .po-search {
	max-width: 100%;
}

.po-search__form {
	display: block;
}

.po-search__input {
	width: 100%;
	box-sizing: border-box;
	padding: 0.6em 0.9em;
	border: 1px solid var(--po-search-border-color);
	border-radius: var(--po-search-radius);
	font-size: 1em;
}

.po-search__results {
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	/* Higher than the mega menu plugin's expanded panel (z-index: 2000 in
	   pixelated-orange-mega-menu/assets/css/mega-menu.css), so results
	   render on top of an open mega menu instead of underneath it. */
	z-index: 2100;
	margin-top: 0.4em;
	max-height: var(--po-search-max-height, 400px);
	overflow-y: auto;
	overflow-x: hidden;
	background: var(--po-search-bg);
	border: 1px solid var(--po-search-border-color);
	border-radius: var(--po-search-radius);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
	padding: 0.75em;
}

.po-search__results[hidden] {
	display: none;
}

/* Slide-out panel */
.po-search-wrapper {
	display: inline-block;
}

.po-search__trigger {
	cursor: pointer;
	background: none;
	border: 1px solid var(--po-search-border-color);
	border-radius: var(--po-search-radius);
	padding: 0.5em 1em;
	font-size: 1em;
}

.po-search__overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.4);
	z-index: 2098;
}

.po-search__overlay[hidden] {
	display: none;
}

.po-search--slideout {
	position: fixed;
	top: 0;
	bottom: 0;
	z-index: 2099;
	width: min(90vw, var(--po-search-max-width, 480px));
	max-width: none;
	background: var(--po-search-bg);
	padding: 1.25em;
	box-shadow: 0 0 32px rgba(0, 0, 0, 0.2);
	overflow-y: auto;
	transition: transform 0.25s ease;
}

.po-search--slideout.po-search--side-right {
	right: 0;
	transform: translateX(100%);
}

.po-search--slideout.po-search--side-left {
	left: 0;
	transform: translateX(-100%);
}

.po-search--slideout.is-open {
	transform: translateX(0);
}

.po-search--slideout .po-search__results {
	position: static;
	margin-top: 0.75em;
	box-shadow: none;
}

.po-search__section + .po-search__section {
	margin-top: 1em;
	padding-top: 1em;
	border-top: 1px solid var(--po-search-border-color);
}

/* Brands / Categories / the actual matched items, each its own labeled
   block within a section - divided the same way sections themselves are,
   just a step down in the hierarchy. */
.po-search__group + .po-search__group {
	margin-top: 0.85em;
	padding-top: 0.85em;
	border-top: 1px dashed var(--po-search-border-color);
}

.po-search__section-title {
	margin: 0 0 0.5em;
	font-size: 0.85em;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	opacity: 0.6;
}

/*
 * This list can render inside very different surrounding contexts - a
 * shortcode dropped into normal page content, or auto-insert placing the
 * exact same markup inside the theme's <header>. A dark header nav commonly
 * sets `color: #fff` (or similar) broadly via `header a` / `header *`
 * selectors, which cascades straight through since CSS inheritance doesn't
 * care where in the DOM an element sits. The old `color: var(--po-search-
 * cat-btn-color, inherit)` fallback meant that if the inline custom
 * property block wasn't picked up for any reason, the pill's text quietly
 * inherited that white nav color while sitting on its own light background
 * - readable in page content (default dark text), invisible in a header
 * (white-on-near-white). Explicit, non-inherited fallback colors plus
 * !important on the properties that actually make it legible fixes that
 * regardless of what the surrounding theme does.
 */
.po-search__categories {
	list-style: none !important;
	margin: 0 0 0.75em !important;
	padding: 0 !important;
	display: flex !important;
	flex-wrap: wrap;
	gap: 0.4em;
}

.po-search__category a {
	display: inline-block;
	padding: var(--po-search-cat-btn-padding, 5px);
	border-radius: var(--po-search-cat-btn-radius, 999px);
	background: var(--po-search-cat-btn-bg, #f0f0f0) !important;
	color: var(--po-search-cat-btn-color, #1a1a1a) !important;
	font-size: 0.85em;
	text-decoration: none !important;
	white-space: nowrap;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.po-search__category a:hover,
.po-search__category a:focus {
	background: var(--po-search-cat-btn-bg-hover, var(--po-search-cat-btn-bg, #f0f0f0)) !important;
	color: var(--po-search-cat-btn-color-hover, var(--po-search-cat-btn-color, #1a1a1a)) !important;
}

/* Item layouts */
.po-search__items--rows {
	display: flex;
	flex-direction: column;
	gap: 0.5em;
}

.po-search__items--grid {
	display: grid;
	grid-template-columns: repeat(var(--po-search-grid-columns, 2), 1fr);
	gap: var(--po-search-grid-gap, 0.75em);
}

@media (max-width: 600px) {
	.po-search__items--grid {
		grid-template-columns: repeat(var(--po-search-grid-columns-mobile, 1), 1fr);
	}
}

.po-search__card {
	display: flex;
	align-items: center;
	gap: 0.6em;
}

/*
 * The card itself is a plain <div> so the add-to-cart <button> can sit
 * alongside the link without nesting an interactive element inside another.
 * `display: contents` makes this anchor invisible to layout - its children
 * (image/body) become direct flex items of .po-search__card, exactly as if
 * the card were still one big <a> wrapping everything.
 */
.po-search__card-link {
	display: contents;
	text-decoration: none;
	color: inherit;
}

.po-search__items--rows .po-search__card {
	padding: var(--po-search-row-padding, 0);
}

.po-search__items--grid .po-search__card {
	flex-direction: column;
	align-items: flex-start;
	text-align: var(--po-search-grid-align, left);
	gap: var(--po-search-grid-padding, 0.6em);
}

.po-search__items--grid .po-search__card-body {
	gap: var(--po-search-grid-padding, 0.6em);
	width: 100%;
}

.po-search__card-image {
	flex: 0 0 auto;
	display: block;
	width: var(--po-search-row-image-size, 20%);
	overflow: hidden;
	border-radius: var(--po-search-image-radius, 4px);
}

.po-search__items--grid .po-search__card-image {
	width: 100%;
	height: auto;
	aspect-ratio: 1 / 1;
}

.po-search__card-image img {
	width: 100%;
	height: auto;
	object-fit: cover;
	display: block;
}

.po-search__card-body {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

/* Category/brand line shown above the title - separate from, and not
   styled like, the .po-search__category term-match pills below (those
   are for when the search TERM itself matches a category/brand name,
   linking through to that archive; this is per-product metadata). */
.po-search__card-category {
	display: block;
	font-size: var(--po-search-catbrand-size, 0.8em);
	font-weight: var(--po-search-catbrand-weight, 400);
	text-transform: var(--po-search-catbrand-transform, none);
	color: var(--po-search-catbrand-color, #222222);
	transition: color 0.15s ease;
}

.po-search__card:hover .po-search__card-category,
.po-search__card:focus-within .po-search__card-category {
	color: var(--po-search-catbrand-color-hover, var(--po-search-catbrand-color, #222222));
}

.po-search__card-title {
	font-weight: var(--po-search-title-weight, 600);
	font-size: var(--po-search-title-size, 1em);
	text-transform: var(--po-search-title-transform, none);
	line-height: 1.3;
	color: var(--po-search-title-color, #222222);
	transition: color 0.15s ease;
}

.po-search__card:hover .po-search__card-title,
.po-search__card:focus-within .po-search__card-title {
	color: var(--po-search-title-color-hover, var(--po-search-title-color, #222222));
}

.po-search__card-price {
	font-size: 0.9em;
	color: var(--po-search-price-color, inherit);
}

.po-search__card-subtitle {
	font-size: var(--po-search-subtitle-size, 0.85em);
	font-weight: var(--po-search-subtitle-weight, 400);
	text-transform: var(--po-search-subtitle-transform, none);
	color: var(--po-search-subtitle-color, #222222);
	transition: color 0.15s ease;
}

.po-search__card:hover .po-search__card-subtitle,
.po-search__card:focus-within .po-search__card-subtitle {
	color: var(--po-search-subtitle-color-hover, var(--po-search-subtitle-color, #222222));
}

.po-search__card-subtitle-item {
	display: block;
}

.po-search__card-atc {
	display: inline-block;
	align-self: flex-start;
	cursor: pointer;
	text-align: center;
	text-decoration: none;
	font-size: 0.85em;
	font-weight: var(--po-search-atc-btn-font-weight, 400);
	text-transform: var(--po-search-atc-btn-text-transform, none);
	padding: var(--po-search-atc-btn-padding, 6px);
	border-radius: var(--po-search-atc-btn-radius, 4px);
	border-width: var(--po-search-atc-btn-border-width, 0px);
	border-style: solid;
	border-color: var(--po-search-atc-btn-border-colour, transparent);
	background: var(--po-search-atc-btn-bg, #000000);
	color: var(--po-search-atc-btn-color, #ffffff);
	transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.po-search__card-atc:hover,
.po-search__card-atc:focus {
	background: var(--po-search-atc-btn-bg-hover, var(--po-search-atc-btn-bg, #000000));
	color: var(--po-search-atc-btn-color-hover, var(--po-search-atc-btn-color, #ffffff));
	border-color: var(--po-search-atc-btn-border-colour-hover, var(--po-search-atc-btn-border-colour, transparent));
}

.po-search__card-atc:disabled {
	opacity: 0.6;
	cursor: default;
}

.po-search__items--grid .po-search__card-atc {
	align-self: stretch;
}

.po-search__card-excerpt {
	font-size: 0.85em;
	color: var(--po-search-excerpt-color, inherit);
	line-height: 1.4;
}

.po-search__empty {
	margin: 0;
	opacity: 0.6;
	font-size: 0.9em;
}

/* Quicklinks row rendered under the search field */
.po-search__quicklinks {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5em;
	margin-top: 0.6em;
	font-size: 0.85em;
}

.po-search__quicklinks-label {
	font-weight: 700;
	text-transform: uppercase;
}

/* Styled with the same custom properties as .po-search__category a
   (Category Button Settings tab), so quicklinks match whatever button
   look is already configured rather than needing their own styling
   fields. */
.po-search__quicklinks-link {
	display: inline-block;
	padding: var(--po-search-cat-btn-padding, 5px);
	border-radius: var(--po-search-cat-btn-radius, 999px);
	background: var(--po-search-cat-btn-bg, #f0f0f0) !important;
	color: var(--po-search-cat-btn-color, #1a1a1a) !important;
	font-size: 0.85em;
	text-decoration: none !important;
	white-space: nowrap;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.po-search__quicklinks-link:hover,
.po-search__quicklinks-link:focus {
	background: var(--po-search-cat-btn-bg-hover, var(--po-search-cat-btn-bg, #f0f0f0)) !important;
	color: var(--po-search-cat-btn-color-hover, var(--po-search-cat-btn-color, #1a1a1a)) !important;
}
