/**
 * Persian Search X — front-end styles (RTL-first, dark-mode aware).
 */

/* Dimming overlay (Digikala style). z-index kept BELOW the host theme's
   own header (which is its own stacking context, e.g. z-index: 100 on
   ghataatmobile.com's header) -- a z-index here higher than the
   header's traps the header (and this widget's own dropdown, whose
   z-index:9999 only matters *inside* that header context) underneath
   the overlay, which then silently swallows every click on the
   results. Any value below the header's own z-index still sits above
   ordinary (z-index:auto) page content, which is all the dimming
   needs to cover. */
.psx-overlay {
	position: fixed;
	inset: 0;
	background: rgba( 16, 24, 40, 0.45 );
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease, visibility 0.2s ease;
	z-index: 50;
}

.psx-overlay.is-visible {
	opacity: 1;
	visibility: visible;
}

.psx-search {
	position: relative;
	width: 100%;
	max-width: 560px;
	direction: rtl;
	font-family: inherit;
	z-index: 1;
}

.psx-search.is-active {
	z-index: 9999;
}

/* Input field */
.psx-search__field {
	position: relative;
	display: flex;
	align-items: center;
}

.psx-search__input {
	width: 100%;
	box-sizing: border-box;
	padding: 12px 16px;
	padding-inline-start: 46px;
	font-size: 16px;
	font-family: inherit;
	color: var( --psx-text, inherit );
	border: 1px solid #d0d5dd;
	border-radius: 12px;
	background: var( --psx-bg, #f7f8fa );
	outline: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.psx-search__input:focus {
	border-color: #ef4056;
	box-shadow: 0 0 0 3px rgba( 239, 64, 86, 0.12 );
}

.psx-search__icon {
	position: absolute;
	inset-inline-start: 14px;
	top: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	color: #98a2b3;
	pointer-events: none;
	z-index: 1;
	opacity: 1;
	transition: opacity 0.15s ease, transform 0.15s ease;
}

/* Hide the magnifier while typing/focused so text isn't cramped under it. */
.psx-search.is-focused .psx-search__icon,
.psx-search__field:focus-within .psx-search__icon {
	opacity: 0;
	visibility: hidden;
	transform: scale( 0.85 );
}

/* Rotating animated placeholder */
.psx-search__rotator {
	position: absolute;
	inset-inline-start: 46px;
	inset-inline-end: 16px;
	top: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	color: var( --psx-placeholder, #9aa0a6 );
	font-size: 15px;
	pointer-events: none;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	transition: opacity 0.35s ease;
}

.psx-search__rotator::before {
	content: attr( data-text );
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.psx-search__rotator.is-fading {
	opacity: 0;
}

/* Results dropdown */
.psx-search__results {
	position: absolute;
	z-index: 9999;
	inset-inline: 0;
	top: calc( 100% + 8px );
	max-height: 70vh;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: #fff;
	border: 1px solid #e4e7ec;
	border-radius: 14px;
	box-shadow: 0 12px 40px rgba( 16, 24, 40, 0.16 );
	scrollbar-width: thin;
	scrollbar-color: #cbd2d9 transparent;
}

.psx-search__results::-webkit-scrollbar {
	width: 10px;
}

.psx-search__results::-webkit-scrollbar-track {
	background: transparent;
}

.psx-search__results::-webkit-scrollbar-thumb {
	background: #cbd2d9;
	border-radius: 999px;
	border: 3px solid #fff;
	background-clip: padding-box;
}

.psx-search__results::-webkit-scrollbar-thumb:hover {
	background: #aeb6bf;
	border: 3px solid #fff;
	background-clip: padding-box;
}

.psx-search__list {
	list-style: none;
	margin: 0;
	padding: 6px;
}

.psx-search__item {
	position: relative;
	margin: 0;
}

/* Faint divider between results, inset from both edges. */
.psx-search__item:not( :last-child )::after {
	content: "";
	position: absolute;
	bottom: 0;
	inset-inline: 16px;
	height: 1px;
	background: #eef0f2;
}

.psx-search__link {
	display: flex;
	gap: 12px;
	align-items: center;
	padding: 12px;
	border-radius: 10px;
	text-decoration: none;
	color: inherit;
}

.psx-search__link:hover,
.psx-search__link.is-active {
	background: #f6f7f9;
}

.psx-search__thumb {
	width: 48px;
	height: 48px;
	object-fit: cover;
	border-radius: 12px;
	border: 1px solid #eef0f2;
	flex: 0 0 auto;
	background: #fff;
}

.psx-search__meta {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.psx-search__title {
	font-weight: 600;
	font-size: 14px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.psx-search__price {
	font-size: 13px;
	color: #15803d;
}

/* "Fits model X" badge — shown when the matched word lives in the product's
   vehicle-compatibility (short description), not its visible title. */
.psx-search__fit {
	align-self: flex-start;
	max-width: 100%;
	margin: 1px 0;
	padding: 2px 8px;
	font-size: 11.5px;
	font-weight: 600;
	line-height: 1.6;
	color: #027a48;
	background: #ecfdf3;
	border: 1px solid #abefc6;
	border-radius: 6px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.psx-search__stock--out {
	font-size: 12px;
	color: #b42318;
}

.psx-search__empty,
.psx-search__loading {
	padding: 18px;
	text-align: center;
	color: #667085;
	font-size: 14px;
}

/* Most-searched (empty) state */
.psx-search__top {
	padding: 14px 16px 4px;
}

.psx-search__top-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 10px;
}

.psx-search__top-title {
	font-weight: 700;
	font-size: 13px;
	color: #1d2939;
}

.psx-search__clear {
	background: none;
	border: none;
	color: #ef4056;
	font-size: 12px;
	font-family: inherit;
	cursor: pointer;
	padding: 2px 4px;
}

.psx-search__clear:hover {
	text-decoration: underline;
}

.psx-search__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.psx-chip {
	background: #f2f4f7;
	border: none;
	border-radius: 999px;
	padding: 7px 14px;
	font-size: 13px;
	font-family: inherit;
	color: #344054;
	cursor: pointer;
	transition: background 0.15s ease;
}

.psx-chip:hover {
	background: #e4e7ec;
}

/* Promo banner */
.psx-search__banner {
	display: block;
	margin: 12px;
	border-radius: 12px;
	overflow: hidden;
}

.psx-search__banner-img {
	display: block;
	width: 100%;
	height: auto;
	max-height: 96px;
	object-fit: cover;
}

/* Dark mode */
@media ( prefers-color-scheme: dark ) {
	.psx-search__input {
		background: #1f2937;
		color: #f9fafb;
		border-color: #374151;
	}

	.psx-search__input:focus {
		background: #111827;
	}

	.psx-search__results {
		background: #111827;
		border-color: #374151;
	}

	.psx-search__link:hover,
	.psx-search__link.is-active {
		background: #1f2937;
	}

	.psx-search__top-title {
		color: #e5e7eb;
	}

	.psx-chip {
		background: #1f2937;
		color: #e5e7eb;
	}

	.psx-chip:hover {
		background: #374151;
	}

	.psx-search__empty,
	.psx-search__loading {
		color: #9ca3af;
	}

	.psx-search__item:not( :last-child )::after {
		background: #1f2937;
	}

	.psx-search__thumb {
		border-color: #374151;
		background: #1f2937;
	}

	.psx-search__fit {
		color: #6ce9a6;
		background: rgba( 5, 122, 72, 0.18 );
		border-color: rgba( 108, 233, 166, 0.35 );
	}

	.psx-search__results {
		scrollbar-color: #374151 transparent;
	}

	.psx-search__results::-webkit-scrollbar-thumb {
		background: #374151;
		border-color: #111827;
	}
}
