/**
 * MONA Search – storefront styles.
 *
 * Design goals
 * ------------
 * * Premium and quiet: one accent colour, generous whitespace, no shadows
 *   competing for attention.
 * * Zero layout shift: skeleton rows have exactly the height of the real
 *   rows, and images reserve their box before they load.
 * * Light and dark are both first class, driven by `prefers-color-scheme`
 *   and overridable per instance via `data-theme`.
 * * Every interactive element is reachable and visible via keyboard.
 *
 * @package MonaSearch
 */

.mona-search {
	--mona-accent: #0b6b52;
	--mona-bg: #ffffff;
	--mona-bg-soft: #f6f7f8;
	--mona-bg-hover: #f0f3f2;
	--mona-fg: #16191c;
	--mona-fg-muted: #5b6570;
	--mona-border: #e3e6e9;
	--mona-shadow: 0 12px 40px -12px rgba(16, 24, 32, .28);
	--mona-radius: 14px;
	--mona-radius-sm: 9px;
	--mona-sale: #b3261e;
	--mona-stock-in: #17694f;
	--mona-stock-out: #8a2b25;

	position: absolute;
	z-index: 999999;
	box-sizing: border-box;
	max-width: calc(100vw - 24px);
	max-height: min(72vh, 680px);
	overflow: hidden auto;
	overscroll-behavior: contain;
	background: var(--mona-bg);
	color: var(--mona-fg);
	border: 1px solid var(--mona-border);
	border-radius: var(--mona-radius);
	box-shadow: var(--mona-shadow);
	font-size: 14px;
	line-height: 1.45;
	-webkit-font-smoothing: antialiased;
	contain: layout paint;
}

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

.mona-search[hidden] {
	display: none;
}

/* ---------------------------------------------------------------------
 * Dark mode
 * ------------------------------------------------------------------ */

@media (prefers-color-scheme: dark) {
	.mona-search[data-theme="auto"] {
		--mona-bg: #14181b;
		--mona-bg-soft: #1b2024;
		--mona-bg-hover: #222a2e;
		--mona-fg: #eef2f4;
		--mona-fg-muted: #9aa7b1;
		--mona-border: #2a3238;
		--mona-shadow: 0 14px 44px -14px rgba(0, 0, 0, .7);
		--mona-sale: #ff8a80;
		--mona-stock-in: #6ddaae;
		--mona-stock-out: #ff9d95;
	}
}

.mona-search[data-theme="dark"] {
	--mona-bg: #14181b;
	--mona-bg-soft: #1b2024;
	--mona-bg-hover: #222a2e;
	--mona-fg: #eef2f4;
	--mona-fg-muted: #9aa7b1;
	--mona-border: #2a3238;
	--mona-shadow: 0 14px 44px -14px rgba(0, 0, 0, .7);
	--mona-sale: #ff8a80;
	--mona-stock-in: #6ddaae;
	--mona-stock-out: #ff9d95;
}

/* ---------------------------------------------------------------------
 * Layout variants
 * ------------------------------------------------------------------ */

.mona-search--fullscreen {
	position: fixed;
	inset: 0;
	width: 100%;
	max-width: 100%;
	max-height: 100%;
	border: 0;
	border-radius: 0;
}

/* ---------------------------------------------------------------------
 * Structure
 * ------------------------------------------------------------------ */

.mona-search__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.mona-search__body {
	padding: 6px 0;
}

.mona-search__group + .mona-search__group {
	border-top: 1px solid var(--mona-border);
}

.mona-search__group-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px 16px 6px;
}

.mona-search__group-title {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--mona-fg-muted);
}

.mona-search__clear {
	padding: 0;
	font-size: 11px;
	color: var(--mona-fg-muted);
	background: none;
	border: 0;
	cursor: pointer;
	text-decoration: underline;
}

.mona-search__clear:hover {
	color: var(--mona-fg);
}

/* ---------------------------------------------------------------------
 * Result rows
 * ------------------------------------------------------------------ */

.mona-result {
	display: flex;
	flex-direction: column;
	gap: 8px;
	min-height: 96px;
	padding: 12px 16px;
	color: inherit;
	cursor: pointer;
	text-decoration: none;
	border-left: 3px solid transparent;
	transition: background-color .12s ease, border-color .12s ease;
}

.mona-result:hover,
.mona-result.is-active {
	background: var(--mona-bg-hover);
	border-left-color: var(--mona-accent);
	text-decoration: none;
}

/*
 * Two tiers per result: the top tier (image + title + excerpt) claims the
 * full row width for text, since that is the part that actually needs it.
 * The bottom tier (SKU/rating/stock vs. price/cart button) gets its own
 * full-width row underneath instead of competing with the title for the
 * same cramped column – that competition was the layout defect a
 * single-row design produced at realistic panel widths.
 */
.mona-result__top {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	color: inherit;
	text-decoration: none;
}

.mona-result__top:hover {
	text-decoration: none;
}

.mona-result__bottom {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 8px 16px;
}

.mona-result:focus-visible {
	outline: 2px solid var(--mona-accent);
	outline-offset: -2px;
}

.mona-result__media {
	flex: 0 0 56px;
	width: 56px;
	height: 56px;
	overflow: hidden;
	background: var(--mona-bg-soft);
	border-radius: var(--mona-radius-sm);
}

.mona-result__image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	mix-blend-mode: multiply;
}

@media (prefers-color-scheme: dark) {
	.mona-search[data-theme="auto"] .mona-result__image {
		mix-blend-mode: normal;
	}
}

.mona-search[data-theme="dark"] .mona-result__image {
	mix-blend-mode: normal;
}

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

/*
 * The meta line stays on one row: "MODERN NATURA" wrapping onto a second
 * line pushed the title down and made every result look ragged. Each part
 * truncates individually instead.
 */
.mona-result__meta {
	display: flex;
	flex-wrap: nowrap;
	gap: 8px;
	margin-bottom: 2px;
	overflow: hidden;
	font-size: 11px;
	line-height: 1.35;
	color: var(--mona-fg-muted);
}

.mona-result__brand,
.mona-result__category {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.mona-result__brand {
	flex: 0 1 auto;
	font-weight: 600;
	letter-spacing: .02em;
	text-transform: uppercase;
}

.mona-result__category {
	flex: 0 1 auto;
}

/*
 * Product names are long ("Bio Ashwagandha Kapseln hochdosiert 500mg").
 * A single nowrap line cut them to "Bio Ashwa…", which tells a shopper
 * nothing. Two wrapped lines fit the whole name in almost every case and
 * still keep the row height predictable.
 */
.mona-result__title {
	display: -webkit-box;
	display: box;
	overflow: hidden;
	font-weight: 600;
	font-size: 14px;
	line-height: 1.3;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	box-orient: vertical;
	overflow-wrap: anywhere;
}

.mona-result__excerpt {
	display: -webkit-box;
	display: box;
	overflow: hidden;
	margin-top: 3px;
	font-size: 12.5px;
	line-height: 1.4;
	color: var(--mona-fg-muted);
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
	box-orient: vertical;
	overflow-wrap: anywhere;
}

.mona-result__footer {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px;
	font-size: 11.5px;
	color: var(--mona-fg-muted);
}

.mona-result__stars {
	color: #e2a52b;
	letter-spacing: 1px;
}

.mona-result__stock--instock {
	color: var(--mona-stock-in);
}

.mona-result__stock--outofstock {
	color: var(--mona-stock-out);
}

.mona-result__side {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	gap: 10px;
	margin-left: auto;
}

.mona-result__price {
	display: flex;
	align-items: baseline;
	gap: 6px;
	line-height: 1.25;
	white-space: nowrap;
}

.mona-result__price-old {
	font-size: 11.5px;
	color: var(--mona-fg-muted);
	text-decoration: line-through;
}

.mona-result__price-current {
	font-weight: 700;
	font-size: 14.5px;
	white-space: nowrap;
}

.mona-result__badge {
	padding: 1px 6px;
	font-size: 11px;
	font-weight: 700;
	color: #fff;
	background: var(--mona-sale);
	border-radius: 999px;
}

.mona-result__cart {
	padding: 6px 12px;
	font-size: 12px;
	font-weight: 600;
	font-family: inherit;
	color: #fff;
	white-space: nowrap;
	background: var(--mona-accent);
	border: 0;
	border-radius: 999px;
	cursor: pointer;
	transition: opacity .12s ease, transform .12s ease;
}

.mona-result__cart:hover {
	opacity: .9;
}

.mona-result__cart:active {
	transform: scale(.97);
}

.mona-result__cart.is-loading {
	opacity: .6;
	cursor: progress;
}

.mona-result__cart.is-done {
	background: var(--mona-stock-in);
}

/* ---------------------------------------------------------------------
 * Suggestion, chips and messages
 * ------------------------------------------------------------------ */

.mona-search__suggestion {
	padding: 10px 16px;
	font-size: 13px;
	background: var(--mona-bg-soft);
	border-bottom: 1px solid var(--mona-border);
}

.mona-search__suggestion-term {
	padding: 0;
	font-size: inherit;
	font-family: inherit;
	font-weight: 700;
	color: var(--mona-accent);
	background: none;
	border: 0;
	cursor: pointer;
	text-decoration: underline;
}

.mona-search__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 4px 16px 14px;
}

.mona-search__chip {
	padding: 6px 12px;
	font-size: 12.5px;
	font-family: inherit;
	color: inherit;
	background: var(--mona-bg-soft);
	border: 1px solid var(--mona-border);
	border-radius: 999px;
	cursor: pointer;
	transition: background-color .12s ease, border-color .12s ease;
}

.mona-search__chip:hover,
.mona-search__chip.is-active {
	background: var(--mona-bg-hover);
	border-color: var(--mona-accent);
}

.mona-search__message {
	padding: 26px 16px;
	text-align: center;
}

.mona-search__message-title {
	margin: 0 0 4px;
	font-weight: 600;
	font-size: 14px;
}

.mona-search__message-text {
	margin: 0;
	font-size: 13px;
	color: var(--mona-fg-muted);
}

.mona-search__message .mona-search__chips {
	justify-content: center;
	padding-top: 14px;
	padding-bottom: 0;
}

/* ---------------------------------------------------------------------
 * Footer
 * ------------------------------------------------------------------ */

.mona-search__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 0 16px;
	background: var(--mona-bg-soft);
	border-top: 1px solid var(--mona-border);
}

.mona-search__footer:empty {
	display: none;
}

.mona-search__all {
	display: block;
	flex: 1 1 auto;
	padding: 13px 0;
	font-weight: 600;
	font-size: 13.5px;
	color: var(--mona-accent);
	text-decoration: none;
}

.mona-search__all:hover {
	text-decoration: underline;
}

.mona-search__timing {
	font-size: 11px;
	font-variant-numeric: tabular-nums;
	color: var(--mona-fg-muted);
}

/* ---------------------------------------------------------------------
 * Skeletons – identical height to real rows, so nothing jumps
 * ------------------------------------------------------------------ */

.mona-search__skeletons {
	padding: 6px 0;
}

.mona-skel {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	min-height: 96px;
	padding: 12px 16px;
}

.mona-skel__img,
.mona-skel__line {
	background: linear-gradient(90deg, var(--mona-bg-soft) 0%, var(--mona-bg-hover) 50%, var(--mona-bg-soft) 100%);
	background-size: 220% 100%;
	border-radius: var(--mona-radius-sm);
	animation: mona-shimmer 1.3s ease-in-out infinite;
}

.mona-skel__img {
	flex: 0 0 56px;
	width: 56px;
	height: 56px;
}

.mona-skel__lines {
	flex: 1 1 auto;
}

.mona-skel__line {
	height: 12px;
	margin-bottom: 8px;
	border-radius: 6px;
}

.mona-skel__line--short {
	width: 45%;
}

.mona-skel__line--bar {
	width: 30%;
	height: 22px;
	margin-top: 12px;
	margin-bottom: 0;
	border-radius: 999px;
}

@keyframes mona-shimmer {
	0% { background-position: 120% 0; }
	100% { background-position: -20% 0; }
}

/* ---------------------------------------------------------------------
 * Highlighting
 * ------------------------------------------------------------------ */

.mona-search mark.mona-mark {
	padding: 0 1px;
	color: inherit;
	font-weight: 700;
	background: color-mix(in srgb, var(--mona-accent) 18%, transparent);
	border-radius: 3px;
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
	.mona-search mark.mona-mark {
		background: rgba(11, 107, 82, .16);
	}
}

/* ---------------------------------------------------------------------
 * Reduced motion
 * ------------------------------------------------------------------ */

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

/* ---------------------------------------------------------------------
 * Results page
 * ------------------------------------------------------------------ */

.mona-results {
	--mona-accent: #0b6b52;
	display: grid;
	grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
	gap: 32px;
	align-items: start;
}

@media (max-width: 860px) {
	.mona-results {
		grid-template-columns: minmax(0, 1fr);
	}
}

.mona-results__facets {
	position: sticky;
	top: 24px;
}

.mona-facet {
	padding-bottom: 16px;
	margin-bottom: 16px;
	border-bottom: 1px solid var(--mona-border, #e3e6e9);
}

.mona-facet__title {
	margin: 0 0 8px;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: .06em;
	text-transform: uppercase;
}

.mona-facet__option {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 3px 0;
	font-size: 13.5px;
	cursor: pointer;
}

.mona-facet__count {
	margin-left: auto;
	font-size: 12px;
	color: var(--mona-fg-muted, #5b6570);
	font-variant-numeric: tabular-nums;
}

.mona-results__toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 20px;
}

.mona-results__grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 20px;
}

.mona-results__empty {
	padding: 48px 16px;
	text-align: center;
}

/* ---------------------------------------------------------------------
 * Responsive
 * ---------------------------------------------------------------------
 *
 * This block sits at the very end of the file on purpose. Every rule here
 * overrides a base rule of the same specificity (one class), so it only
 * wins if it comes later in the source order. Placed anywhere above the
 * component sections it would be silently dead – which is exactly what
 * happened in 1.1.0-dev and is why the section is marked so prominently.
 *
 * Do not move it. New responsive rules belong here, not next to their
 * component.
 * ------------------------------------------------------------------ */

/*
 * Tablets and narrow desktops. Nothing changes structurally yet; the row
 * simply gets a little more breathing room, because the cart button is the
 * first element to run out of space.
 */
@media (max-width: 900px) {
	.mona-search {
		max-height: min(76vh, 640px);
	}

	.mona-result {
		padding: 13px 16px;
	}

	.mona-result__bottom {
		gap: 8px 12px;
	}

	.mona-result__cart {
		padding: 8px 14px;
	}
}

/*
 * Phones. The floating panel becomes a bottom sheet: anchoring a 70 %-tall
 * dropdown under a field that sits near the bottom of the viewport leaves
 * most of it off screen, and the on-screen keyboard makes that worse.
 */
@media (max-width: 640px) {
	.mona-search--panel {
		position: fixed;
		inset: auto 0 0 0;
		/*
		 * position() clears its inline top/left/width at this width, so
		 * these normally have nothing to fight. The !important stays as a
		 * safety net: if the script cannot evaluate the media query, the
		 * leftover inline `top` would fight `bottom: 0` from `inset` and
		 * stretch the sheet from the field down the whole screen.
		 */
		top: auto !important;
		left: 0 !important;
		width: 100% !important;
		transform: none !important;
		max-width: 100%;
		max-height: 82vh;
		border-right: 0;
		border-bottom: 0;
		border-left: 0;
		border-radius: var(--mona-radius) var(--mona-radius) 0 0;
	}

	/* Clear the iPhone home indicator. */
	.mona-search--panel .mona-search__footer {
		padding-bottom: env(safe-area-inset-bottom, 0);
	}

	/*
	 * Dim the page behind the sheet so the sheet reads as a layer rather
	 * than as part of the page. Purely decorative: `pointer-events: none`
	 * keeps the existing outside-click handler working unchanged.
	 */
	html.mona-search-open::after {
		content: "";
		position: fixed;
		inset: 0;
		z-index: 999998;
		background: rgba(10, 14, 18, .32);
		pointer-events: none;
	}

	.mona-result {
		min-height: 104px;
		padding: 14px 16px;
	}

	.mona-result__top {
		gap: 14px;
	}

	.mona-result__media,
	.mona-skel__img {
		flex-basis: 64px;
		width: 64px;
		height: 64px;
	}

	.mona-result__title {
		font-size: 15px;
	}

	.mona-result__excerpt {
		font-size: 13px;
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}

	.mona-search__all {
		padding: 15px 0;
		font-size: 14.5px;
	}

	.mona-search__message {
		padding: 30px 16px;
	}
}

/*
 * Very narrow phones. Price and cart button no longer fit beside the SKU
 * and stock line, so the action row stacks instead of overflowing.
 */
@media (max-width: 380px) {
	.mona-result__bottom {
		align-items: flex-start;
		flex-direction: column;
		gap: 10px;
	}

	.mona-result__side {
		width: 100%;
		margin-left: 0;
		justify-content: space-between;
	}

	.mona-result__cart {
		flex: 0 0 auto;
	}
}

/*
 * Touch devices of any size. Width is a poor proxy for input method – a
 * 1024 px tablet is still operated with a thumb – so the touch target
 * floor is keyed off the pointer instead. 44 px is the smallest reliably
 * hittable target.
 */
@media (pointer: coarse) {
	.mona-result__cart,
	.mona-search__chip {
		min-height: 44px;
	}

	.mona-search__chip {
		padding: 10px 14px;
		font-size: 13.5px;
	}

	.mona-search__suggestion {
		padding: 14px 16px;
	}

	.mona-search__suggestion-term {
		display: inline-block;
		padding: 4px 0;
	}

	.mona-search__all {
		min-height: 48px;
	}

	/*
	 * iOS zooms the page in when a focused input's font-size is below
	 * 16 px. The panel is anchored to that input, so the zoom leaves it
	 * hanging off screen. The attribute is set by the script on every
	 * input it binds, which is more reliable than guessing the theme's
	 * class name.
	 */
	input[data-mona-search-bound] {
		font-size: 16px;
	}
}
