/*
 * SearchWP Modal Form block styles
 *
 * Enqueued for searchwp/modal-form via wp_enqueue_block_style(): the header
 * search icon and the modal it opens.
 *
 * The plugin prints its default template CSS inline in the footer, after the
 * theme's stylesheets, at `.searchwp-modal-form-default .element` (0,2,0) and
 * `.searchwp-modal-form-default .searchwp-modal-form__content .search-form …`
 * (0,3,x) for the form. The rules here are scoped one class deeper
 * (`.searchwp-modal-form .searchwp-modal-form-default …`) so they win without
 * !important. The plugin keeps handling positioning and the open/close
 * animation.
 *
 * The search field matches the SearchWP results-page form
 * (searchwp-search-form.css): a 56px field with a magnifier on the left, a
 * Navy 200 border and the brand focus ring (3px Teal 500 at 28%).
 *
 * @package Kindling
 * @since Kindling 4.1.0
 */

/* Header trigger: a 44px tap target around an 18px magnifier (20px with the hamburger). */
.searchwp-modal-form-trigger-el {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	color: var(--wp--custom--color--text--heading);
	text-decoration: none;

	&:hover {
		color: var(--wp--custom--color--text--link-hover);
	}

	&:focus-visible {
		outline: 2px solid var(--wp--custom--color--focus);
		outline-offset: 2px;
	}

	.searchwp-modal-form-trigger-icon {
		display: flex;
	}

	/*
	 * render_searchwp_trigger_icon() prints the icon twice, each drawn on its
	 * own pixel grid; show them at their native size only, so they stay crisp.
	 */
	svg {
		flex: none;
	}

	.kindling-search-icon--20 {
		display: none;
	}

	/* Beside the hamburger (the header-menu breakpoint in core-navigation.css). */
	@media only screen and (max-width: 1279px) {
		.kindling-search-icon--18 {
			display: none;
		}

		.kindling-search-icon--20 {
			display: block;
		}
	}
}

.searchwp-modal-form .searchwp-modal-form-default {
	/* Light tokens: the dialog is always a white panel, whatever surface the trigger sits on. */
	--wp--custom--color--focus: var(--wp--preset--color--theme-13);

	/* Navy 900 scrim; the dialog sits in the upper part of the screen. */
	.searchwp-modal-form__overlay {
		align-items: flex-start;
		padding: clamp(var(--wp--preset--spacing--40), 15vh, 10rem)
			var(--wp--custom--layout--site-outer-padding) var(--wp--preset--spacing--40);
		background: color-mix(in srgb, var(--wp--preset--color--theme-08) 85%, transparent);
		backdrop-filter: blur(4px);
	}

	.searchwp-modal-form__container {
		position: relative;
		max-width: 640px;
	}

	/* The top padding clears the 44px close button in the corner. */
	.searchwp-modal-form__content {
		padding: var(--wp--preset--spacing--50);
		padding-top: calc(44px + var(--wp--custom--spacing--12));
		border-radius: 0;
		background-color: var(--wp--custom--color--surface--background);
		box-shadow: var(--wp--preset--shadow--raised);
	}

	/*
	 * WordPress' search form: field and submit on one row. The plugin scopes
	 * its form rules through __content, so these do too.
	 */
	.searchwp-modal-form__content .search-form {
		display: flex;
		align-items: stretch;
		gap: var(--wp--custom--spacing--12);
	}

	.searchwp-modal-form__content .search-form label {
		position: relative;
		flex: 1;
		padding: 0;
		margin: 0;

		/* Magnifier inside the field's leading edge. */
		&::after {
			content: '';
			position: absolute;
			top: 50%;
			left: var(--wp--custom--spacing--16);
			width: 24px;
			height: 24px;
			transform: translateY(-50%);
			background-color: var(--wp--preset--color--theme-07);
			mask: url('../../images/icons/search.svg') no-repeat center / contain;
			-webkit-mask: url('../../images/icons/search.svg') no-repeat center / contain;
			pointer-events: none;
		}
	}

	.searchwp-modal-form__content .search-form .search-field {
		box-sizing: border-box;
		height: 56px;
		padding: 0 var(--wp--custom--spacing--16) 0 calc(var(--wp--custom--spacing--16) + 24px + var(--wp--custom--spacing--12));
		border: 1px solid var(--wp--preset--color--theme-18);
		border-radius: 0;
		background-color: var(--wp--preset--color--theme-01);
		color: var(--wp--custom--color--text--heading);
		font-size: var(--wp--preset--font-size--body-large);
		appearance: none;

		&::placeholder {
			color: var(--wp--preset--color--theme-07);
			opacity: 1;
		}

		&:focus {
			outline: none;
			border-color: var(--wp--preset--color--theme-13);
			box-shadow: 0 0 0 3px color-mix(in srgb, var(--wp--preset--color--theme-14) 28%, transparent);
		}
	}

	/* Submit as the theme's primary (fill) button. */
	.searchwp-modal-form__content .search-form .search-submit {
		flex-shrink: 0;
		padding: 0 var(--wp--custom--spacing--28);
		border: 1px solid var(--wp--custom--color--button--fill--border);
		border-radius: 0;
		background-color: var(--wp--custom--color--button--fill--background);
		color: var(--wp--custom--color--button--fill--text);
		font-family: var(--wp--custom--font-family--body);
		font-size: var(--wp--preset--font-size--medium);
		font-weight: 600;
		line-height: 1;
		cursor: pointer;

		&:hover {
			border-color: var(--wp--custom--color--button--fill--hover--border);
			background-color: var(--wp--custom--color--button--fill--hover--background);
			color: var(--wp--custom--color--button--fill--hover--text);
		}

		&:active {
			border-color: var(--wp--custom--color--button--fill--active--border);
			background-color: var(--wp--custom--color--button--fill--active--background);
			color: var(--wp--custom--color--button--fill--active--text);
		}

		&:focus-visible {
			outline: 2px solid var(--wp--custom--color--focus);
			outline-offset: 2px;
		}
	}

	/* Close: a 44px "×" in the dialog's top-right corner instead of below it. */
	.searchwp-modal-form__footer {
		position: absolute;
		top: 0;
		right: 0;
		z-index: 9999999; /* The plugin gives __content z-index: 9999998. */
		padding: 0;
	}

	.searchwp-modal-form__close {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		padding: 0;
		margin: 0;
		color: var(--wp--custom--color--text--heading);
		line-height: 1;
		cursor: pointer;

		&::before {
			font-size: 1.75rem;
		}

		&:hover {
			color: var(--wp--custom--color--text--link-hover);
		}

		&:focus-visible {
			outline: 2px solid var(--wp--custom--color--focus);
			outline-offset: -2px;
		}
	}

	/* Phones: the submit drops below the field, full width. */
	@media (max-width: 599px) {
		.searchwp-modal-form__content {
			padding-inline: var(--wp--preset--spacing--30);
			padding-bottom: var(--wp--preset--spacing--30);
		}

		.searchwp-modal-form__content .search-form {
			flex-wrap: wrap;
		}

		.searchwp-modal-form__content .search-form label,
		.searchwp-modal-form__content .search-form .search-submit {
			flex-basis: 100%;
		}

		.searchwp-modal-form__content .search-form .search-submit {
			height: 52px;
		}
	}
}
