/**
 * Internal Instantsearch — front end.
 *
 * Design position: this surface is a guest on somebody else's site, and lands
 * on hundreds of different ones. So it brings no palette and no typeface of its
 * own. Colour is derived from whatever text colour it inherits, the backdrop
 * comes from the system canvas, and the type is the host's. What it does bring
 * is structure: a consistent grid, a fixed typographic scale, and a price line
 * that aligns down the column so figures can be compared at a glance.
 *
 * It also styles the product card itself rather than relying on WooCommerce's
 * stylesheet, which is scoped under .woocommerce and never applies to an
 * overlay. The WooCommerce class names are kept on the markup as hooks for
 * shops that want to target them.
 */

.iis {
	/* Everything is derived; nothing is invented. */
	--iis-ink: currentColor;
	--iis-surface: Canvas;
	--iis-line: rgba( 128, 128, 128, 0.28 );
	--iis-quiet: rgba( 128, 128, 128, 1 );
	--iis-wash: rgba( 128, 128, 128, 0.1 );
	--iis-mark: rgba( 128, 128, 128, 0.22 );

	--iis-gap: 1.5rem;
	--iis-gap-tight: 0.75rem;
	--iis-radius: 10px;
	--iis-media: 1 / 1;

	/*
	 * The card has two shapes: a tile in a grid, and a row. List view and any
	 * narrow screen both switch to rows by setting these, so the row layout is
	 * written once.
	 */
	--iis-card-columns: repeat( auto-fill, minmax( 11.5rem, 1fr ) );
	--iis-card-gap: var( --iis-gap ) clamp( 1rem, 2vw, 1.75rem );
	--iis-card-direction: column;
	--iis-card-align: stretch;
	--iis-card-media: 100%;
	--iis-card-padding: 0;
	--iis-card-rule: transparent;
	--iis-card-action: inline-block;

	position: relative;
	width: 100%;
	color: inherit;
	font-size: 16px;
	line-height: 1.5;
	text-align: left;
}

/*
 * Derived tints, where the browser can do it. These read correctly on a light
 * or a dark host without the plugin knowing which it is.
 */
@supports ( color: color-mix( in oklab, currentColor 10%, transparent ) ) {
	.iis {
		--iis-line: color-mix( in oklab, currentColor 16%, transparent );
		--iis-quiet: color-mix( in oklab, currentColor 62%, transparent );
		--iis-wash: color-mix( in oklab, currentColor 6%, transparent );
		--iis-mark: color-mix( in oklab, currentColor 16%, transparent );
	}
}

.iis *,
.iis *::before,
.iis *::after {
	box-sizing: border-box;
}

/* Layout rules below must not resurrect anything the script has hidden. */
.iis [hidden] {
	display: none !important;
}

.iis :focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 3px;
}

/* ── Search field ───────────────────────────────────────────────────────── */

.iis-input {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	border-bottom: 1px solid var( --iis-line );
}

.iis-input__field {
	flex: 1 1 auto;
	width: 100%;
	min-width: 0;
	margin: 0;
	padding: 0.65rem 0;
	font: inherit;
	font-size: clamp( 1.0625rem, 1rem + 0.5vw, 1.375rem );
	line-height: 1.3;
	color: inherit;
	background: none;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	appearance: none;
}

.iis-input__field:focus {
	outline: none;
	box-shadow: none;
}

.iis-input__field::placeholder {
	color: var( --iis-quiet );
	opacity: 1;
}

/* The field owns the focus ring, so the whole row reads as one control. */
.iis-input:focus-within {
	border-bottom-color: currentColor;
}

.iis-input__clear,
.iis-input__close {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	padding: 0;
	font: inherit;
	font-size: 1.25rem;
	line-height: 1;
	color: var( --iis-quiet );
	background: none;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
}

.iis-input__clear:hover,
.iis-input__close:hover {
	color: inherit;
	background: var( --iis-wash );
}

/* ── Frame ──────────────────────────────────────────────────────────────── */

.iis__body {
	display: flex;
	align-items: flex-start;
	gap: clamp( 1.5rem, 4vw, 3rem );
	margin-top: var( --iis-gap );
}

.iis__filters {
	flex: 0 0 13rem;
	max-width: 13rem;
}

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

@media ( max-width: 860px ) {
	.iis__body {
		display: block;
	}

	.iis__filters {
		max-width: none;
		margin-bottom: var( --iis-gap );
		padding-bottom: var( --iis-gap-tight );
		border-bottom: 1px solid var( --iis-line );
	}
}

/* ── Filters ────────────────────────────────────────────────────────────── */

.iis-filter-group + .iis-filter-group {
	margin-top: 1.5rem;
}

.iis-filter-group__title {
	margin: 0 0 0.5rem;
	padding: 0;
	font-size: 0.6875rem;
	font-weight: 600;
	line-height: 1.4;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	color: var( --iis-quiet );
}

.iis ul.iis-filter-group__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.iis .iis-filter {
	margin: 0;
	padding: 0;
	list-style: none;
}

.iis-filter label {
	display: flex;
	align-items: baseline;
	gap: 0.5rem;
	padding: 0.2rem 0;
	font-size: 0.875rem;
	cursor: pointer;
}

.iis-filter.is-disabled label {
	opacity: 0.4;
	cursor: default;
}

.iis-filter__label {
	flex: 1 1 auto;
}

.iis-filter__count {
	font-size: 0.75rem;
	font-variant-numeric: tabular-nums;
	color: var( --iis-quiet );
}

/* ── Summary line ───────────────────────────────────────────────────────── */

.iis-details {
	margin-bottom: var( --iis-gap-tight );
	font-size: 0.8125rem;
	color: var( --iis-quiet );
}

.iis-details p {
	margin: 0;
	padding: 0;
}

.iis-details__empty,
.iis-details__error {
	font-size: 0.9375rem;
	color: inherit;
}

/* ── Results grid ───────────────────────────────────────────────────────── */

.iis ul.iis-results__list {
	display: grid;
	grid-template-columns: var( --iis-card-columns );
	gap: var( --iis-card-gap );
	margin: 0;
	padding: 0;
	list-style: none;
}

.iis .iis-item {
	position: relative;
	display: flex;
	flex-direction: column;
	min-width: 0;
	margin: 0;
	padding: var( --iis-card-padding );
	list-style: none;
	border-bottom: 1px solid var( --iis-card-rule );
}

.iis-item__link {
	display: flex;
	flex-direction: var( --iis-card-direction );
	flex: 1 1 auto;
	align-items: var( --iis-card-align );
	gap: 0.6rem;
	color: inherit;
	text-decoration: none;
	box-shadow: none;
}

.iis-item__link:hover,
.iis-item__link:focus {
	color: inherit;
	text-decoration: none;
}

/* ── Media ──────────────────────────────────────────────────────────────── */

/*
 * The width is set by a custom property, never the flex basis: in a tile the
 * card stacks, so a basis would be read as a height and the square would grow
 * to fill the row.
 */
.iis-item__media {
	position: relative;
	flex: 0 0 auto;
	width: var( --iis-card-media );
	overflow: hidden;
	aspect-ratio: var( --iis-media );
	background: var( --iis-wash );
	border-radius: var( --iis-radius );
}

.iis-item__media--wide {
	--iis-media: 4 / 3;
}

.iis-item__media img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	margin: 0;
	object-fit: cover;
	border-radius: inherit;
	transition: transform 220ms ease;
}

/*
 * Product photography is usually a single object on a white background, so it
 * is fitted rather than cropped, and the tile is white to match. Tinting the
 * tile instead would put a visible box around every cut-out, and on a dark site
 * a white photograph would sit on it as a glaring rectangle. A white tile is
 * read as a lightbox, which is what shops use.
 */
/*
 * Product shots are cut out on white, so the tile is white whatever the host
 * is. On a white host that would leave the shot floating, so the tile carries
 * a hairline of its own.
 */
.iis-item__media--contain {
	background: #fff;
	box-shadow: inset 0 0 0 1px var( --iis-line );
}

.iis-item__media--contain img {
	padding: 4%;
	object-fit: contain;
}

.iis-item__link:hover .iis-item__media img {
	transform: scale( 1.03 );
}

.iis-item__media-empty {
	display: block;
	width: 100%;
	height: 100%;
}

/* ── Text ───────────────────────────────────────────────────────────────── */

.iis-item__body {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	gap: 0.25rem;
	min-width: 0;
}

.iis-item__kind {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	font-size: 0.6875rem;
	font-weight: 600;
	line-height: 1.4;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var( --iis-quiet );
}

.iis-item__date {
	font-weight: 400;
	letter-spacing: 0.04em;
}

.iis-item__title {
	display: block;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.35;
	/* Danish compound words are long; let them break rather than overflow. */
	overflow-wrap: anywhere;
}

.iis-item__link:hover .iis-item__title {
	text-decoration: underline;
	text-underline-offset: 0.18em;
}

.iis-item__excerpt {
	display: -webkit-box;
	overflow: hidden;
	font-size: 0.8125rem;
	line-height: 1.5;
	color: var( --iis-quiet );
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

/*
 * The match is marked with a tint taken from the text colour rather than the
 * browser's yellow, which reads as a rendering artifact rather than a result.
 */
.iis-mark {
	padding: 0.05em 0.15em;
	margin: 0 -0.05em;
	color: inherit;
	background: var( --iis-mark );
	border-radius: 2px;
}

/* ── Price ──────────────────────────────────────────────────────────────── */

/*
 * The signature of the card. Figures are tabular so they line up down the
 * column, the payable amount always comes first, and anything struck through
 * drops back to the quiet tone so the eye is never caught by the old price.
 */
.iis-item__price {
	display: block;
	margin-top: auto;
	padding-top: 0.15rem;
	font-size: 0.9375rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	line-height: 1.4;
}

.iis-item__price ins {
	text-decoration: none;
	background: none;
}

.iis-item__price del {
	margin-left: 0.4em;
	font-size: 0.8125rem;
	font-weight: 400;
	color: var( --iis-quiet );
	opacity: 1;
}

.iis-item__price del .amount {
	text-decoration: line-through;
}

.iis-item__price .woocommerce-Price-currencySymbol {
	font-weight: inherit;
}

.iis-item__stock {
	font-size: 0.75rem;
	color: var( --iis-quiet );
}

.iis-item__stock--outofstock {
	font-style: italic;
}

.iis-item__count {
	font-size: 0.75rem;
	font-variant-numeric: tabular-nums;
	color: var( --iis-quiet );
}

/* ── Flags, ratings, terms ──────────────────────────────────────────────── */

/*
 * The flag sits over the corner of the card rather than in the text flow, so
 * every title in a row still starts on the same line.
 */
.iis-item__flag {
	position: absolute;
	top: 0.5rem;
	left: 0.5rem;
	z-index: 1;
	padding: 0.12rem 0.45rem;
	font-size: 0.625rem;
	font-weight: 700;
	line-height: 1.5;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	/*
	 * System ink on system canvas rather than currentColor, which would resolve
	 * to the same value as the text and leave the pill invisible. This also
	 * flips correctly in dark mode without the plugin knowing which it is in.
	 */
	color: Canvas;
	background: CanvasText;
	border-radius: 999px;
}

/* In a row the thumbnail is too small to carry it, so it moves to the end. */
.iis--view-list .iis-item__flag,
.iis--rows .iis-item__flag {
	top: 0.95rem;
	right: 0;
	left: auto;
}

@media ( max-width: 600px ) {
	.iis .iis-item__flag {
		top: 0.95rem;
		right: 0;
		left: auto;
	}
}

.iis-item__rating {
	display: block;
	font-size: 0.8125rem;
	line-height: 1.4;
	color: var( --iis-quiet );
}

.iis-item__rating .star-rating {
	margin: 0;
	font-size: inherit;
}

.iis-item__terms {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem;
	margin-top: 0.15rem;
}

.iis-item__term {
	padding: 0.05rem 0.4rem;
	font-size: 0.6875rem;
	line-height: 1.6;
	color: var( --iis-quiet );
	border: 1px solid var( --iis-line );
	border-radius: 999px;
}

/*
 * The card is already a link, so this is a visual affordance rather than a
 * second tab stop.
 */
.iis-item__action {
	display: var( --iis-card-action );
	/* The rule under it belongs to the words, not to the width of the card. */
	align-self: flex-start;
	margin-top: 0.5rem;
	font-size: 0.8125rem;
	font-weight: 600;
	color: inherit;
	text-decoration: none;
	border-bottom: 1px solid var( --iis-line );
}

.iis-item__action:hover {
	color: inherit;
	border-bottom-color: currentColor;
}

/* ── Rows ───────────────────────────────────────────────────────────────── */

/*
 * Used by list view, and by any screen too narrow for a grid. A phone showing
 * one full-width tile per result can only fit two results; as rows it fits six,
 * which is the difference between scrolling and choosing.
 */
.iis--view-list,
.iis--rows {
	--iis-card-columns: 1fr;
	--iis-card-gap: 0;
	--iis-card-direction: row;
	--iis-card-align: flex-start;
	--iis-card-media: 5.5rem;
	--iis-card-padding: var( --iis-gap-tight ) 0;
	--iis-card-rule: var( --iis-line );
	--iis-card-action: none;
}

@media ( max-width: 600px ) {
	.iis {
		--iis-card-columns: 1fr;
		--iis-card-gap: 0;
		--iis-card-direction: row;
	--iis-card-align: flex-start;
		--iis-card-media: 4.5rem;
		--iis-card-padding: var( --iis-gap-tight ) 0;
		--iis-card-rule: var( --iis-line );
		--iis-card-action: none;
	}
}

.iis--view-list .iis-item__link,
.iis--rows .iis-item__link {
	gap: 1rem;
}

/* A line of text is easier to read short, however wide the page is. */
.iis--view-list .iis-item__body {
	max-width: 46rem;
}

.iis--view-list .iis-item__price,
.iis--rows .iis-item__price {
	margin-top: 0.25rem;
}

/*
 * A result with no image, typically a category, still starts its text in the
 * same column as the rest, so the left edge of the list holds.
 */
.iis--view-list .iis-item:not( :has( .iis-item__media ) ) .iis-item__body {
	margin-left: calc( 5.5rem + 1rem );
}

@media ( max-width: 600px ) {
	.iis .iis-item:not( :has( .iis-item__media ) ) .iis-item__body {
		margin-left: calc( 4.5rem + 1rem );
	}
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

.iis-results__footer {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: center;
	gap: 1rem;
	margin-top: var( --iis-gap );
}

.iis-results__footer:empty {
	margin-top: 0;
}

.iis-results__loading,
.iis-results__all {
	font-size: 0.8125rem;
	color: var( --iis-quiet );
}

.iis-results__more {
	padding: 0.55rem 1.4rem;
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	color: inherit;
	background: none;
	border: 1px solid var( --iis-line );
	border-radius: 999px;
	cursor: pointer;
	transition: border-color 160ms ease, background-color 160ms ease;
}

.iis-results__more:hover {
	background: var( --iis-wash );
	border-color: currentColor;
}

/* ── Overlay ────────────────────────────────────────────────────────────── */

.iis-overlay-root {
	position: fixed;
	inset: 0;
	z-index: 100000;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: clamp( 1rem, 5vw, 4rem ) clamp( 1rem, 5vw, 3rem ) 4rem;
	color: CanvasText;
	background: Canvas;
}

@supports ( backdrop-filter: blur( 1px ) ) {
	.iis-overlay-root {
		background: color-mix( in srgb, Canvas 92%, transparent );
		backdrop-filter: blur( 20px ) saturate( 1.4 );
	}
}

.iis-overlay-root[hidden] {
	display: none;
}

.iis-overlay-open {
	overflow: hidden;
}

.iis--overlay {
	max-width: 76rem;
	margin: 0 auto;
}

/* ── Appearance ─────────────────────────────────────────────────────────── */

.iis-item {
	animation: iis-rise 260ms ease both;
}

@keyframes iis-rise {
	from {
		opacity: 0;
		transform: translateY( 6px );
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.iis *,
	.iis-overlay-root * {
		animation: none !important;
		transition: none !important;
	}

	.iis-item__link:hover .iis-item__media img {
		transform: none;
	}
}

/* ── Utilities ──────────────────────────────────────────────────────────── */

.iis .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect( 0, 0, 0, 0 );
	white-space: nowrap;
	border: 0;
}
