/* Header icon: same size and spacing as the account and cart icons next to it. */
.mg-search {
	display: flex;
	align-items: center;
}

.mg-search__toggle {
	display: flex;
	align-items: center;
	padding: 0.5em;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	line-height: 1;
	cursor: pointer;
}

.mg-search__toggle .mg-search__icon {
	display: block;
	width: 1.5em;
	height: 1.5em;
}

.mg-search__toggle:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 4px;
}

/* Overlay. */
html.mg-search-open {
	overflow: hidden;
}

.mg-search__dialog {
	width: 100%;
	max-width: 100%;
	height: 100%;
	max-height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--main, #15101b);
	overflow: hidden;
}

.mg-search__dialog::backdrop {
	background: rgb(21 16 27 / 55%);
	backdrop-filter: blur(2px);
}

.mg-search__dialog[open] .mg-search__panel {
	animation: mg-search-in 0.18s ease-out;
}

@keyframes mg-search-in {
	from {
		opacity: 0;
		transform: translateY(-12px);
	}
}

@media (prefers-reduced-motion: reduce) {
	.mg-search__dialog[open] .mg-search__panel {
		animation: none;
	}
}

.mg-search__panel {
	display: flex;
	flex-direction: column;
	width: min(760px, calc(100% - 2rem));
	max-height: calc(100% - 2 * clamp(1rem, 8vh, 6rem));
	margin: clamp(1rem, 8vh, 6rem) auto 0;
	border-radius: 12px;
	background: var(--wp--preset--color--base, #fff);
	box-shadow: 0 20px 50px rgb(21 16 27 / 30%);
	overflow: hidden;
}

.mg-search__form {
	display: flex;
	flex: none;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 0.75rem 0.75rem 1.25rem;
	margin: 0;
	border-bottom: 1px solid var(--wp--preset--color--border-light, #d1d5db);
}

.mg-search__form .mg-search__icon {
	flex: none;
	width: 1.5rem;
	height: 1.5rem;
	color: var(--wp--preset--color--secondary, #4b5563);
}

.mg-search.is-loading .mg-search__form .mg-search__icon {
	animation: mg-search-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes mg-search-pulse {
	to {
		opacity: 0.35;
	}
}

.mg-search .mg-search__form .mg-search__input {
	flex: 1;
	min-width: 0;
	padding: 0.5rem 0;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 1.25rem; /* ≥16px, so iOS doesn't zoom in. */
	border-radius: 0;
	box-shadow: none;
	outline: none;
	-webkit-appearance: none;
	appearance: none;
}

.mg-search__input::-webkit-search-cancel-button {
	display: none;
}

.mg-search__input::placeholder {
	color: var(--wp--preset--color--secondary, #4b5563);
	opacity: 0.8;
}

.mg-search__close {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.mg-search__close:hover,
.mg-search__close:focus-visible {
	background: var(--wp--preset--color--tertiary, #f9fafb);
}

.mg-search__close svg {
	width: 1.25rem;
	height: 1.25rem;
}

.mg-search__results {
	padding-top: 0.75rem;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* Space below the last result, before the "all results" line (or the panel edge). */
.mg-search__item:last-child,
.mg-search__item:has(+ .mg-search__all) {
	margin-bottom: 0.75rem;
}

.mg-search__results:empty {
	display: none;
}

.mg-search__item {
	display: grid;
	grid-template-columns: 56px 1fr auto;
	align-items: center;
	gap: 0.75rem 1rem;
	padding: 0.5rem 1.25rem;
	color: inherit;
	text-decoration: none;
}

.mg-search__item[aria-selected="true"] {
	background: var(--wp--preset--color--tertiary, #f9fafb);
	box-shadow: inset 3px 0 0 var(--wp--preset--color--primary, #ce1520);
}

.mg-search__item.is-out-of-stock {
	opacity: 0.6;
}

.mg-search__image {
	width: 56px;
	height: 56px;
	border-radius: 6px;
	object-fit: cover;
	background: var(--wp--preset--color--tertiary, #f9fafb);
}

.mg-search__name {
	font-weight: 600;
	line-height: 1.3;
}

.mg-search__price {
	color: var(--wp--preset--color--secondary, #4b5563);
	font-size: 0.9em;
	white-space: nowrap;
	text-align: right;
}

.mg-search__price del {
	opacity: 0.6;
}

.mg-search__price ins {
	text-decoration: none;
}

.mg-search__all {
	display: block;
	padding: 0.9rem 1.25rem;
	border-top: 1px solid var(--wp--preset--color--border-light, #d1d5db);
	color: var(--wp--preset--color--primary, #ce1520);
	font-weight: 700;
	text-decoration: none;
}

.mg-search__all:hover,
.mg-search__all:focus-visible {
	text-decoration: underline;
}

.mg-search__status {
	margin: 0;
	padding: 0 1.25rem;
	color: var(--wp--preset--color--secondary, #4b5563);
}

.mg-search__status:not(:empty) {
	padding: 1.25rem;
}

/* Phones: full-screen sheet. */
@media (max-width: 600px) {
	.mg-search__panel {
		width: 100%;
		height: 100%;
		max-height: 100%;
		margin: 0;
		border-radius: 0;
	}

	.mg-search__results {
		flex: 1;
	}

	.mg-search__item {
		grid-template-columns: 48px 1fr;
		padding: 0.5rem 1rem;
	}

	.mg-search__image {
		grid-row: span 2;
		width: 48px;
		height: 48px;
	}

	.mg-search__price {
		text-align: left;
	}
}
