/**
 * Nik AI Search & Filters — storefront styles.
 *
 * Everything is scoped under .nsf-* and driven by custom properties, so a theme
 * can restyle the panel by redefining a handful of variables instead of
 * fighting specificity. Colours inherit from the theme wherever possible.
 */

/*
 * Every knob below is a custom property with a sensible default. The admin's
 * appearance settings re-declare a few of them in an inline block after this
 * file; a theme can override any of them with one rule. Nothing here needs
 * !important or a child theme to restyle.
 */
.nsf-panel,
.nsf-search,
.nsf-verdict {
	--nsf-gap: 18px;
	--nsf-radius: 8px;
	--nsf-list-height: 260px;
	--nsf-border: rgba( 0, 0, 0, 0.12 );
	--nsf-muted: rgba( 0, 0, 0, 0.55 );
	--nsf-accent: currentColor;
	--nsf-surface: #fff;
	--nsf-on-surface: #1a1a1a;
	--nsf-depth: 0;
	--nsf-font-scale: 0.95;

	/*
	 * Named `elevation`, not `depth`: --nsf-depth already carries the nesting
	 * level of a category row and drives its indent, so reusing it for shadow
	 * would have flattened every subcategory the moment a shop picked a raised
	 * look.
	 */
	--nsf-elevation: 0;
	--nsf-shadow: none;
}

/*
 * Shadow steps are spelled out rather than computed: a shop owner choosing
 * "raised" is picking a look, not authoring a box-shadow.
 */
.nsf-panel[data-elevation="1"],
.nsf-search[data-elevation="1"] {
	--nsf-shadow: 0 1px 3px rgba( 0, 0, 0, 0.07 );
}

.nsf-panel[data-elevation="2"],
.nsf-search[data-elevation="2"] {
	--nsf-shadow: 0 2px 10px rgba( 0, 0, 0, 0.10 );
}

.nsf-panel[data-elevation="3"],
.nsf-search[data-elevation="3"] {
	--nsf-shadow: 0 8px 24px rgba( 0, 0, 0, 0.16 );
}

.nsf-panel {
	position: relative;
	font-size: calc( var( --nsf-font-scale ) * 1em );
}

.nsf-search {
	font-size: calc( var( --nsf-font-scale ) * 1em );
}

/*
 * Dark colours are declared once and applied from three places: the system
 * preference, and the two classes the appearance setting can force. Repeating
 * the palette per selector is how the light and dark versions drift apart.
 */
@media ( prefers-color-scheme: dark ) {
	.nsf-panel:not( .nsf-scheme--light ),
	.nsf-search:not( .nsf-scheme--light ),
	.nsf-verdict:not( .nsf-scheme--light ) {
		--nsf-border: rgba( 255, 255, 255, 0.18 );
		--nsf-muted: rgba( 255, 255, 255, 0.6 );
		--nsf-surface: #1e1e1e;
		--nsf-on-surface: #f0f0f0;
	}
}

.nsf-panel.nsf-scheme--dark,
.nsf-search.nsf-scheme--dark,
.nsf-verdict.nsf-scheme--dark {
	--nsf-border: rgba( 255, 255, 255, 0.18 );
	--nsf-muted: rgba( 255, 255, 255, 0.6 );
	--nsf-surface: #1e1e1e;
	--nsf-on-surface: #f0f0f0;
}

.nsf-panel__title {
	margin: 0 0 var( --nsf-gap );
	font-size: 1.1em;
}

.nsf-panel.is-busy {
	pointer-events: none;
}

.nsf-panel.is-busy .nsf-panel__busy {
	position: absolute;
	inset: 0;
	background: rgba( 255, 255, 255, 0.55 );
	border-radius: var( --nsf-radius );
	z-index: 2;
}

@media ( prefers-color-scheme: dark ) {
	.nsf-panel.is-busy .nsf-panel__busy {
		background: rgba( 0, 0, 0, 0.45 );
	}
}

/* Active filter chips ---------------------------------------------------- */

.nsf-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: var( --nsf-gap );
}

.nsf-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 10px;
	border: 1px solid var( --nsf-border );
	border-radius: 999px;
	font-size: 0.85em;
	line-height: 1.6;
	text-decoration: none;
	transition: border-color 0.15s ease, opacity 0.15s ease;
}

.nsf-chip:hover {
	border-color: var( --nsf-accent );
}

.nsf-chip__x {
	font-size: 1.1em;
	opacity: 0.6;
}

.nsf-chip--clear {
	border-style: dashed;
	opacity: 0.75;
}

/* Groups ----------------------------------------------------------------- */

.nsf-group {
	border-bottom: 1px solid var( --nsf-border );
	padding-bottom: 12px;
	margin-bottom: 12px;
}

.nsf-group:last-child {
	border-bottom: 0;
}

/*
 * Raised looks turn each group into its own surface. The divider line is the
 * separator when everything sits flat; once the groups are cards, that line
 * would be a seam drawn across a gap.
 */
.nsf-panel:not( [data-elevation="0"] ) .nsf-group {
	background: var( --nsf-surface );
	color: var( --nsf-on-surface );
	border: 1px solid var( --nsf-border );
	border-radius: var( --nsf-radius );
	box-shadow: var( --nsf-shadow );
	padding: 14px 16px;
	margin-bottom: var( --nsf-gap );
}

.nsf-panel:not( [data-elevation="0"] ) .nsf-group:last-child {
	border: 1px solid var( --nsf-border );
}

.nsf-group__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: 6px 0;
	background: none;
	border: 0;
	font: inherit;
	font-weight: 600;
	color: inherit;
	cursor: pointer;
	text-align: left;
}

.nsf-group__chevron {
	width: 8px;
	height: 8px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate( 45deg );
	transition: transform 0.2s ease;
	opacity: 0.5;
	flex: none;
}

.nsf-group.is-collapsed .nsf-group__chevron {
	transform: rotate( -45deg );
}

.nsf-group.is-collapsed .nsf-group__body {
	display: none;
}

.nsf-group__body {
	padding-top: 6px;
}

.nsf-group__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	margin-left: 6px;
	border: 1px solid currentColor;
	border-radius: 999px;
	font-size: 11px;
	font-weight: 600;
	line-height: 1;
	flex: none;
}

/* Bar layout: a row of dropdowns above the listing ------------------------ */

.nsf-panel--bar {
	margin-bottom: 24px;
}

.nsf-panel--bar .nsf-panel__form {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: flex-start;
}

.nsf-panel--bar .nsf-group {
	position: relative;
	border: 0;
	padding: 0;
	margin: 0;
	flex: 0 0 auto;
}

.nsf-panel--bar .nsf-group__head {
	width: auto;
	gap: 8px;
	padding: 8px 12px;
	border: 1px solid var( --nsf-border );
	border-radius: 999px;
	font-weight: 500;
	white-space: nowrap;
}

.nsf-panel--bar .nsf-group.has-selection .nsf-group__head {
	border-color: currentColor;
	font-weight: 600;
}

.nsf-panel--bar .nsf-group__chevron {
	width: 6px;
	height: 6px;
	transform: rotate( 45deg );
	margin-top: -3px;
}

.nsf-panel--bar .nsf-group:not( .is-collapsed ) .nsf-group__chevron {
	transform: rotate( -135deg );
	margin-top: 2px;
}

.nsf-panel--bar .nsf-group__body {
	position: absolute;
	z-index: 40;
	top: calc( 100% + 6px );
	left: 0;
	min-width: 240px;
	max-width: min( 340px, 90vw );
	padding: 12px 14px;
	background: var( --nsf-surface );
	color: var( --nsf-on-surface );
	border: 1px solid var( --nsf-border );
	border-radius: var( --nsf-radius );
	box-shadow: 0 12px 32px rgba( 0, 0, 0, 0.16 );
}

/* A dropdown near the right edge would otherwise open off-screen. */
.nsf-panel--bar .nsf-group:last-child .nsf-group__body,
.nsf-panel--bar .nsf-group--toggle .nsf-group__body {
	left: auto;
	right: 0;
}

.nsf-panel--bar .nsf-options {
	max-height: var( --nsf-list-height );
}

@media ( max-width: 600px ) {
	.nsf-panel--bar .nsf-group,
	.nsf-panel--bar .nsf-group__head {
		width: 100%;
	}

	.nsf-panel--bar .nsf-group__body {
		position: static;
		min-width: 0;
		max-width: none;
		box-shadow: none;
		margin-top: 6px;
	}
}

/* Options ---------------------------------------------------------------- */

.nsf-options {
	list-style: none;
	margin: 0;
	padding: 0;
	max-height: var( --nsf-list-height );
	overflow-y: auto;
}

.nsf-option {
	display: flex;
	align-items: center;
	gap: 8px;
	padding-left: calc( var( --nsf-depth, 0 ) * 14px );
	line-height: 1.9;
}

.nsf-option__box {
	flex: none;
	margin: 0;
	pointer-events: none;
}

.nsf-option__link {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	flex: 1 1 auto;
	min-width: 0;
	text-decoration: none;
	color: inherit;
}

.nsf-option__label {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	cursor: pointer;
	pointer-events: none;
}

.nsf-option__count {
	flex: none;
	font-size: 0.8em;
	color: var( --nsf-muted );
}

.nsf-option.is-selected .nsf-option__label {
	font-weight: 600;
}

.nsf-option.is-empty {
	opacity: 0.45;
}

.nsf-option__link:hover .nsf-option__label {
	text-decoration: underline;
}

/* Button style: the same options as tappable pills ----------------------- */

.nsf-panel--buttons .nsf-options {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.nsf-panel--buttons .nsf-option {
	padding-left: 0;
	line-height: 1.4;
}

/* The checkbox is the state carrier for the no-JS form; the pill itself is
   what the shopper sees, so the box is hidden without being removed. */
.nsf-panel--buttons .nsf-option__box {
	position: absolute;
	opacity: 0;
	pointer-events: none;
	width: 1px;
	height: 1px;
}

.nsf-panel--buttons .nsf-option__link {
	justify-content: flex-start;
	gap: 6px;
	padding: 5px 11px;
	border: 1px solid var( --nsf-border );
	border-radius: 999px;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.nsf-panel--buttons .nsf-option__link:hover {
	border-color: var( --nsf-accent );
}

.nsf-panel--buttons .nsf-option__link:hover .nsf-option__label {
	text-decoration: none;
}

.nsf-panel--buttons .nsf-option.is-selected .nsf-option__link {
	border-color: var( --nsf-accent );
	background: color-mix( in srgb, var( --nsf-accent ) 12%, transparent );
}

/* color-mix is recent; without it the pill still reads as selected from the
   border and weight alone, so no fallback rule is needed. */

.nsf-panel--buttons .nsf-option__count {
	font-size: 0.75em;
	opacity: 0.7;
}

/* Rating ----------------------------------------------------------------- */

.nsf-options--rating .nsf-option__link {
	justify-content: flex-start;
}

.nsf-star {
	opacity: 0.28;
	font-size: 1.05em;
	line-height: 1;
}

.nsf-star.is-on {
	opacity: 1;
	color: #f5a623;
}

.nsf-option.is-selected .nsf-stars {
	outline: 2px solid var( --nsf-accent );
	outline-offset: 3px;
	border-radius: 3px;
}

/* Price ------------------------------------------------------------------ */

.nsf-price__track {
	position: relative;
	height: 28px;
	margin: 6px 0 10px;
}

.nsf-price__track::before {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	top: 13px;
	height: 3px;
	border-radius: 3px;
	background: var( --nsf-border );
}

.nsf-price__range {
	position: absolute;
	top: 13px;
	height: 3px;
	border-radius: 3px;
	background: var( --nsf-accent );
	opacity: 0.75;
}

.nsf-price__slider {
	position: absolute;
	left: 0;
	right: 0;
	top: 0;
	width: 100%;
	height: 28px;
	margin: 0;
	background: none;
	pointer-events: none;
	appearance: none;
	-webkit-appearance: none;
}

.nsf-price__slider:focus {
	outline: none;
}

.nsf-price__slider::-webkit-slider-thumb {
	pointer-events: auto;
	appearance: none;
	-webkit-appearance: none;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid currentColor;
	cursor: grab;
}

.nsf-price__slider::-moz-range-thumb {
	pointer-events: auto;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid currentColor;
	cursor: grab;
}

.nsf-price__slider:focus-visible::-webkit-slider-thumb {
	outline: 2px solid var( --nsf-accent );
	outline-offset: 2px;
}

.nsf-price__inputs {
	display: flex;
	align-items: center;
	gap: 6px;
}

.nsf-price__field {
	flex: 1 1 0;
	min-width: 0;
}

.nsf-price__inputs input {
	width: 100%;
	min-width: 0;
	padding: 4px 6px;
	font-size: 0.9em;
}

.nsf-price__dash,
.nsf-price__currency {
	flex: none;
	color: var( --nsf-muted );
	font-size: 0.9em;
}

.nsf-apply {
	margin-top: 10px;
}

/* Search box ------------------------------------------------------------- */

.nsf-search {
	position: relative;
}

.nsf-search__form {
	display: flex;
	align-items: stretch;
	gap: 6px;
}

.nsf-search__input {
	flex: 1 1 auto;
	min-width: 0;
}

.nsf-search__icon {
	display: block;
	width: 14px;
	height: 14px;
	border: 2px solid currentColor;
	border-radius: 50%;
	position: relative;
}

.nsf-search__icon::after {
	content: "";
	position: absolute;
	right: -5px;
	bottom: -4px;
	width: 7px;
	height: 2px;
	background: currentColor;
	transform: rotate( 45deg );
}

.nsf-search__submit {
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0 12px;
	background: none;
	border: 1px solid var( --nsf-border );
	border-radius: var( --nsf-radius );
	color: inherit;
	cursor: pointer;
}

.nsf-search.is-thinking .nsf-search__submit {
	animation: nsf-pulse 1.1s ease-in-out infinite;
}

@keyframes nsf-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.35; }
}

@media ( prefers-reduced-motion: reduce ) {
	.nsf-search.is-thinking .nsf-search__submit {
		animation: none;
	}
}

/*
 * An adopted field: the theme drew the input, we only add the panel. The shell
 * is an empty, zero-height marker positioned under the field and appended to
 * the body, so nothing in the theme's own layout is wrapped or moved. It must
 * not intercept pointer events — it covers whatever sits below the search box,
 * and an invisible element eating clicks is a bug nobody would think to blame
 * on a search plugin.
 */
.nsf-search--adopted {
	position: absolute;
	height: 0;
	pointer-events: none;
}

.nsf-search--adopted .nsf-search__panel {
	pointer-events: auto;
	/* Above a sticky header, which is where the field it belongs to usually is. */
	z-index: 100000;
}

/*
 * The shop's spoken answer above a results page — "we don't stock tyres, but
 * here is what we do sell". Same sentence the suggestion dropdown gives, so a
 * shopper who pressed Enter is not told less than one who waited.
 */
.nsf-verdict {
	margin: 0 0 16px;
	padding: 12px 14px;
	background: var( --nsf-surface );
	color: var( --nsf-on-surface );
	border: 1px solid var( --nsf-border );
	border-radius: var( --nsf-radius );
}

/* Suggestions ------------------------------------------------------------ */

.nsf-search__panel {
	position: absolute;
	z-index: 30;
	left: 0;
	right: 0;
	top: calc( 100% + 4px );
	max-height: 70vh;
	overflow-y: auto;
	padding: 10px;
	background: var( --nsf-surface );
	color: var( --nsf-on-surface );
	border: 1px solid var( --nsf-border );
	border-radius: var( --nsf-radius );
	box-shadow: 0 12px 32px rgba( 0, 0, 0, 0.14 );
}

.nsf-search__panel[hidden] {
	display: none;
}

.nsf-suggest__section + .nsf-suggest__section {
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid rgba( 0, 0, 0, 0.08 );
}

.nsf-suggest__title {
	display: block;
	margin-bottom: 6px;
	font-size: 0.75em;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	opacity: 0.55;
}

.nsf-suggest__list,
.nsf-suggest__cats {
	list-style: none;
	margin: 0;
	padding: 0;
}

.nsf-suggest__list a {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 6px 4px;
	border-radius: 6px;
	text-decoration: none;
	color: inherit;
}

.nsf-suggest__list a:hover,
.nsf-suggest__cats a:hover {
	background: rgba( 0, 0, 0, 0.05 );
}

.nsf-suggest__list img {
	width: 40px;
	height: 40px;
	object-fit: cover;
	border-radius: 4px;
	flex: none;
}

.nsf-suggest__name {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.nsf-suggest__price {
	flex: none;
	font-size: 0.9em;
	opacity: 0.75;
}

.nsf-suggest__cats a {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	padding: 5px 4px;
	border-radius: 6px;
	text-decoration: none;
	color: inherit;
}

.nsf-suggest__count {
	opacity: 0.5;
	font-size: 0.85em;
}

.nsf-suggest__all {
	display: block;
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px solid rgba( 0, 0, 0, 0.08 );
	text-align: center;
	font-size: 0.9em;
}

.nsf-suggest__empty {
	margin: 0;
	padding: 8px 4px;
	opacity: 0.65;
	font-size: 0.9em;
}

/* AI summary ------------------------------------------------------------- */

.nsf-ai-summary {
	margin: 0 0 16px;
	padding: 10px 14px;
	border-left: 3px solid var( --nsf-accent, currentColor );
	background: rgba( 0, 0, 0, 0.03 );
	border-radius: 0 6px 6px 0;
	font-size: 0.92em;
}

.nsf-ai-summary.is-fallback {
	border-left-color: #d98200;
	opacity: 0.85;
}

/* The suggestion panel's own colours come from --nsf-surface, which already
   flips at the top of this file — only the hover tint needs a dark variant. */
@media ( prefers-color-scheme: dark ) {
	.nsf-ai-summary {
		background: rgba( 255, 255, 255, 0.05 );
	}

	.nsf-suggest__list a:hover,
	.nsf-suggest__cats a:hover {
		background: rgba( 255, 255, 255, 0.08 );
	}
}

/* AI stage inside the suggestion panel ----------------------------------- */

/* What the model understood, shown above its results. Quiet on purpose — the
   shopper asked for products, not for a report on how they were found. */
.nsf-suggest__note {
	margin: 0 0 8px;
	padding: 0 4px 8px;
	border-bottom: 1px solid var( --nsf-border );
	font-size: 0.85em;
	color: var( --nsf-muted );
}

/* "We don't sell that." A verdict, not an error: it is a complete and useful
   answer, so it reads as normal text rather than a warning. */
.nsf-suggest__verdict {
	margin: 0;
	padding: 10px 4px;
	font-size: 0.92em;
	line-height: 1.5;
}
