/*
 * Fenêtre de recherche (parts/search-palette.php, assets/scripts/front/search-palette.js)
 * Mise en page commune aux thèmes enfants qui l'activent (add_theme_support('mairie-search-palette')) ;
 * couleurs, rayon et police viennent de leurs jetons (--surface, --ink, --brand…).
 * Un thème peut les remplacer par les jetons --search-palette-* posés sur :root.
 * La liste des suggestions est celle de search-suggestions.js, remise dans le flux de la fenêtre.
 */

.search-palette {
	--sp-surface: var(--search-palette-surface, var(--surface, #fff));
	--sp-surface-alt: var(--search-palette-surface-alt, var(--surface-alt, #f4f4f5));
	--sp-ink: var(--search-palette-ink, var(--ink, #1d1d1f));
	--sp-ink-soft: var(--search-palette-ink-soft, var(--ink-soft, #52525b));
	--sp-line: var(--search-palette-line, var(--line, #e4e4e7));
	--sp-brand: var(--search-palette-brand, var(--brand, #1f16c7));
	--sp-brand-soft: var(--search-palette-brand-soft, var(--brand-soft, #ecebfb));
	--sp-brand-strong: var(--search-palette-brand-strong, var(--brand-strong, var(--brand, #1f16c7)));
	--sp-radius: var(--search-palette-radius, var(--radius-small, 0.75rem));
	--sp-item-radius: calc(var(--sp-radius) * 0.6);

	width: min(100vw - 2rem, 42rem);
	max-width: none;
	max-height: min(80vh, 40rem);
	max-height: min(80dvh, 40rem);
	margin: 10vh auto auto;
	padding: 0;
	overflow: hidden;
	font-family: var(--search-palette-font, var(--font-body, inherit));
	color: var(--sp-ink);
	background: var(--sp-surface);
	border: 1px solid var(--sp-line);
	border-radius: var(--sp-radius);
	box-shadow: 0 24px 64px rgb(0 0 0 / 0.3);
}

.search-palette[open] {
	display: flex;
	flex-direction: column;
}

.search-palette::backdrop {
	background: rgb(0 0 0 / 0.5);
}

/* La page ne défile pas sous la fenêtre */
html:has(.search-palette[open]) {
	overflow: hidden;
}

@media (prefers-reduced-motion: no-preference) {
	.search-palette[open] {
		animation: search-palette-in 0.16s ease-out;
	}
}

@keyframes search-palette-in {
	from {
		opacity: 0;
		transform: translateY(-0.5rem);
	}
}

.search-palette-form {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-height: 0;
	margin: 0;
}

/* Barre de saisie */
.search-palette-bar {
	display: flex;
	flex: none;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 0.75rem 0.75rem 1.25rem;
	border-bottom: 1px solid var(--sp-line);
}

.search-palette-bar > svg {
	flex: none;
	width: 1.25rem;
	height: 1.25rem;
	color: var(--sp-ink-soft);
}

/* Le contour de focus est le trait sous la barre */
.search-palette-bar:has(input:focus-visible) {
	border-bottom-color: var(--sp-brand);
	box-shadow: inset 0 -2px 0 var(--sp-brand);
}

.search-palette .search-palette-bar input {
	flex: 1;
	min-width: 0;
	min-height: 3rem;
	padding: 0;
	font: inherit;
	font-size: 1.125rem;
	color: var(--sp-ink);
	background: transparent;
	border: 0;
	border-radius: 0;
	outline: 0;
	box-shadow: none;
	appearance: none;
}

.search-palette .search-palette-bar input::placeholder {
	color: var(--sp-ink-soft);
	opacity: 1;
}

.search-palette .search-palette-bar input::-webkit-search-cancel-button {
	appearance: none;
}

.search-palette-close {
	display: grid;
	flex: none;
	place-items: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	color: var(--sp-ink);
	background: transparent;
	border: 1px solid var(--sp-line);
	border-radius: 50%;
	cursor: pointer;
}

.search-palette-close:hover {
	color: var(--sp-brand-strong);
	border-color: var(--sp-brand);
}

.search-palette-close svg {
	width: 1.25rem;
	height: 1.25rem;
}

/* Suggestions : dans le flux de la fenêtre, qui défile si elles sont nombreuses */
.search-palette .search-suggestions {
	position: static;
	z-index: auto;
	flex: 1;
	min-height: 0;
	max-height: none;
	margin: 0;
	padding: 0.5rem;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: transparent;
	border: 0;
	border-radius: 0;
	box-shadow: none;
}

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

.search-palette .search-suggestions-group {
	margin: 0;
	padding: 0;
	list-style: none;
	border: 0;
}

.search-palette .search-suggestions-group + .search-suggestions-group {
	margin-top: 0.5rem;
	padding-top: 0;
	border-top: 0;
}

.search-palette .search-suggestions-group-title {
	padding: 0.5rem 0.75rem 0.25rem;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--sp-ink-soft);
}

/* Une suggestion : pictogramme du groupe dans une pastille, libellé, puis destination ou type de contenu */
.search-palette .search-suggestion {
	--sp-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='8' height='4' x='8' y='2' rx='1'/%3E%3Cpath d='M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2'/%3E%3Cpath d='M12 11h4'/%3E%3Cpath d='M12 16h4'/%3E%3Cpath d='M8 11h.01'/%3E%3Cpath d='M8 16h.01'/%3E%3C/svg%3E");

	display: grid;
	grid-template-columns: 2.25rem 1fr;
	column-gap: 0.875rem;
	row-gap: 0.125rem;
	align-items: center;
	padding: 0.625rem 0.75rem;
	border-radius: var(--sp-item-radius);
	outline: 0;
	cursor: pointer;
}

.search-palette [aria-labelledby$="-contenus"] .search-suggestion {
	--sp-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z'/%3E%3Cpath d='M14 2v4a2 2 0 0 0 2 2h4'/%3E%3Cpath d='M16 13H8'/%3E%3Cpath d='M16 17H8'/%3E%3Cpath d='M10 9H8'/%3E%3C/svg%3E");
}

.search-palette .search-suggestion::before,
.search-palette .search-suggestion::after {
	content: "";
	grid-row: 1 / span 2;
	grid-column: 1;
	place-self: center;
}

.search-palette .search-suggestion::before {
	width: 2.25rem;
	height: 2.25rem;
	background: var(--sp-surface);
	border: 1px solid var(--sp-line);
	border-radius: var(--sp-item-radius);
}

.search-palette .search-suggestion::after {
	width: 1.125rem;
	height: 1.125rem;
	background: currentColor;
	mask: var(--sp-icon) center / contain no-repeat;
}

.search-palette .search-suggestion-label,
.search-palette .search-suggestion-hint {
	grid-column: 2;
	min-width: 0;
}

.search-palette .search-suggestion-label {
	font-weight: 600;
	line-height: 1.35;
	color: var(--sp-ink);
}

.search-palette .search-suggestion-hint {
	font-size: 0.875rem;
	line-height: 1.4;
	color: var(--sp-ink-soft);
}

.search-palette .search-suggestion-hint svg {
	width: 0.875em;
	height: 0.875em;
	margin-left: 0.25em;
	vertical-align: -0.0625em;
}

.search-palette .search-suggestion:hover,
.search-palette .search-suggestion[aria-selected="true"] {
	background: var(--sp-brand-soft);
}

.search-palette .search-suggestion[aria-selected="true"] .search-suggestion-label {
	color: var(--sp-brand-strong);
}

/* Suggestion active : visible aussi en mode de contraste élevé */
.search-palette .search-suggestion[aria-selected="true"] {
	outline: 2px solid var(--sp-brand);
	outline-offset: -2px;
}

/* Recherche complète */
.search-palette-all {
	display: flex;
	flex: none;
	align-items: center;
	gap: 0.875rem;
	width: 100%;
	padding: 0.875rem 1.25rem;
	font: inherit;
	font-weight: 600;
	color: var(--sp-brand-strong);
	text-align: left;
	background: transparent;
	border: 0;
	border-top: 1px solid var(--sp-line);
	cursor: pointer;
}

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

.search-palette-all:hover {
	background: var(--sp-brand-soft);
}

.search-palette-all:focus-visible {
	outline: 2px solid var(--sp-brand);
	outline-offset: -2px;
}

.search-palette-all svg {
	flex: none;
	width: 1.125rem;
	height: 1.125rem;
}

.search-palette-all svg:last-child {
	margin-left: auto;
}

.search-palette-all > span {
	min-width: 0;
	overflow-wrap: anywhere;
}

/* Aide sur les touches, inutile sur écran tactile */
.search-palette-keys {
	display: flex;
	flex: none;
	flex-wrap: wrap;
	gap: 0.25rem 1rem;
	margin: 0;
	padding: 0.625rem 1.25rem;
	font-size: 0.8125rem;
	color: var(--sp-ink-soft);
	background: var(--sp-surface-alt);
	border-top: 1px solid var(--sp-line);
}

@media (hover: none) {
	.search-palette-keys {
		display: none;
	}
}

.search-palette kbd,
.search-palette-shortcut {
	padding: 0.0625rem 0.375rem;
	font-family: inherit;
	font-size: 0.75rem;
	line-height: 1.5;
	white-space: nowrap;
	color: var(--search-palette-ink-soft, var(--ink-soft, currentColor));
	background: var(--search-palette-surface, var(--surface, transparent));
	border: 1px solid var(--search-palette-line, var(--line, currentColor));
	border-radius: 0.25rem;
}

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

/* Petit écran : plein écran */
@media (max-width: 37.5em) {
	.search-palette {
		width: 100vw;
		height: 100vh;
		height: 100dvh;
		max-height: none;
		margin: 0;
		border: 0;
		border-radius: 0;
	}

	.search-palette-bar {
		padding-left: 1rem;
	}
}
