/**
 * XCPH Search — styles front.
 *
 * Monochrome par défaut, typographie héritée du thème : la recherche
 * doit se lire comme une extension du site, pas comme un greffon.
 * Tout est surchargeable par les variables ci-dessous.
 */

:root {
	--xcph-paper: #ffffff;
	--xcph-ink: #000000;
	--xcph-muted: #6b6b6b;
	--xcph-rule: #e3e3e3;
	--xcph-veil: rgba( 0, 0, 0, 0.4 );
	--xcph-gap: 24px;
	--xcph-max: 1180px;
	--xcph-bar: 88px;
}

/* ---------------------------------------------------------------
 * Déclencheur
 * ------------------------------------------------------------- */

.xcph-trigger {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 0;
	margin: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	line-height: 1;
	cursor: pointer;
}

.xcph-trigger:focus-visible {
	outline: 1px solid currentColor;
	outline-offset: 4px;
}

.xcph-trigger__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.xcph-trigger__icon svg {
	display: block;
	width: 18px;
	height: 18px;
}

/* ---------------------------------------------------------------
 * Variante « champ »
 *
 * Proportions relevées au pixel sur la maquette : le bloc sombre est
 * un carré parfait de la hauteur du cadre, dont il recouvre le trait
 * sur trois côtés. Tout est dérivé de --xcph-field-h : une seule
 * valeur à changer, la géométrie reste juste.
 *
 *   bloc sombre  = 1 × hauteur          (147 / 145 px relevés)
 *   loupe        = 0.231 × hauteur      (34 / 147)
 *   retrait texte= 0.186 × hauteur      (27 / 145)
 *   corps de texte = 0.33 × hauteur
 * ------------------------------------------------------------- */

.xcph-trigger--field {
	--xcph-field-h: 56px;
	--xcph-field-paper: #ffffff;
	--xcph-field-line: #000000;
	--xcph-field-block: #2d2d2d;
	--xcph-field-text: #525961;
	--xcph-field-mark: #ffffff;

	display: flex;
	align-items: stretch;
	justify-content: space-between;
	gap: 0;
	box-sizing: border-box;
	width: 100%;
	max-width: var( --xcph-field-max, none );
	height: var( --xcph-field-h );
	padding: 0;
	border: 1px solid var( --xcph-field-line );
	border-radius: 0;
	background: var( --xcph-field-paper );
	text-align: left;
	overflow: hidden;
}

.xcph-trigger--field .xcph-trigger__label {
	display: flex;
	align-items: center;
	flex: 1 1 auto;
	min-width: 0;
	padding-inline: calc( var( --xcph-field-h ) * 0.186 ) 12px;
	color: var( --xcph-field-text );
	font-size: calc( var( --xcph-field-h ) * 0.33 );
	font-weight: 400;
	line-height: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.xcph-trigger--field .xcph-trigger__icon {
	flex: 0 0 auto;
	width: var( --xcph-field-h );
	height: var( --xcph-field-h );
	/* Le carré déborde sur le trait, comme sur la maquette. */
	margin: -1px -1px -1px 0;
	background: var( --xcph-field-block );
	color: var( --xcph-field-mark );
}

.xcph-trigger--field .xcph-trigger__icon svg {
	width: calc( var( --xcph-field-h ) * 0.231 );
	height: calc( var( --xcph-field-h ) * 0.231 );
}

.xcph-trigger--field:focus-visible {
	outline: 2px solid var( --xcph-field-line );
	outline-offset: 2px;
}

@media ( max-width: 767px ) {
	.xcph-trigger--field {
		--xcph-field-h: 48px;
	}
}

/* ---------------------------------------------------------------
 * Overlay
 * ------------------------------------------------------------- */

.xcph-locked {
	overflow: hidden;
}

.xcph-overlay {
	position: fixed;
	inset: 0;
	z-index: 99999;
}

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

.xcph-overlay__backdrop {
	position: absolute;
	inset: 0;
	background: var( --xcph-veil );
	opacity: 0;
	transition: opacity 180ms ease;
}

.xcph-overlay.is-open .xcph-overlay__backdrop {
	opacity: 1;
}

.xcph-overlay__panel {
	position: relative;
	display: flex;
	flex-direction: column;
	max-height: 100%;
	background: var( --xcph-paper );
	color: var( --xcph-ink );
	transform: translateY( -12px );
	opacity: 0;
	transition: transform 180ms ease, opacity 180ms ease;
}

.xcph-overlay.is-open .xcph-overlay__panel {
	transform: translateY( 0 );
	opacity: 1;
}

.xcph-overlay__bar {
	display: flex;
	align-items: center;
	gap: var( --xcph-gap );
	width: 100%;
	max-width: var( --xcph-max );
	min-height: var( --xcph-bar );
	margin: 0 auto;
	padding: 0 var( --xcph-gap );
	border-bottom: 1px solid var( --xcph-rule );
}

.xcph-overlay__field {
	flex: 1 1 auto;
	display: block;
	margin: 0;
}

.xcph-overlay__input,
.xcph-page__input {
	width: 100%;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: clamp( 20px, 3vw, 30px );
	line-height: 1.2;
	letter-spacing: -0.01em;
	appearance: none;
}

.xcph-overlay__input:focus,
.xcph-page__input:focus {
	outline: none;
	box-shadow: none;
}

.xcph-overlay__input::-webkit-search-cancel-button {
	display: none;
}

.xcph-overlay__close {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
}

.xcph-overlay__close:focus-visible {
	outline: 1px solid currentColor;
	outline-offset: 2px;
}

.xcph-overlay__body {
	flex: 1 1 auto;
	width: 100%;
	max-width: var( --xcph-max );
	margin: 0 auto;
	padding: 0 var( --xcph-gap );
	overflow-y: auto;
	overscroll-behavior: contain;
}

.xcph-overlay__body:empty {
	padding: 0;
}

/* ---------------------------------------------------------------
 * Blocs
 * ------------------------------------------------------------- */

.xcph-block {
	padding: calc( var( --xcph-gap ) * 1.5 ) 0;
	border-bottom: 1px solid var( --xcph-rule );
}

.xcph-block:last-child {
	border-bottom: 0;
}

.xcph-block__title {
	margin: 0 0 var( --xcph-gap );
	padding: 0;
	color: var( --xcph-muted );
	font-size: 13px;
	font-weight: 400;
	line-height: 1;
	letter-spacing: 0.02em;
}

.xcph-correction {
	margin: 0;
	padding: var( --xcph-gap ) 0 0;
	color: var( --xcph-muted );
	font-size: 14px;
}

.xcph-correction strong {
	color: var( --xcph-ink );
	font-weight: 600;
}

.xcph-empty {
	margin: 0;
	padding: calc( var( --xcph-gap ) * 2 ) 0;
	color: var( --xcph-muted );
	font-size: 15px;
}

/* ---------------------------------------------------------------
 * Catégories — traitées comme de la navigation, pas comme des cartes
 * ------------------------------------------------------------- */

.xcph-categories {
	display: block;
	border-top: 1px solid var( --xcph-rule );
}

.xcph-category {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var( --xcph-gap );
	padding: 14px 0;
	border-bottom: 1px solid var( --xcph-rule );
	color: inherit;
	text-decoration: none;
}

.xcph-category:hover .xcph-category__name,
.xcph-category:focus-visible .xcph-category__name {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.xcph-category:focus-visible {
	outline: 1px solid currentColor;
	outline-offset: 2px;
}

.xcph-category__body {
	display: flex;
	align-items: baseline;
	gap: 10px;
	min-width: 0;
}

.xcph-category__path {
	flex: 0 0 auto;
	color: var( --xcph-muted );
	font-size: 13px;
}

.xcph-category__path::after {
	content: '/';
	margin-left: 10px;
	color: var( --xcph-rule );
}

.xcph-category__name {
	font-size: clamp( 17px, 2vw, 21px );
	font-weight: 600;
	line-height: 1.25;
}

.xcph-category__count {
	flex: 0 0 auto;
	color: var( --xcph-muted );
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------
 * Produits
 * ------------------------------------------------------------- */

.xcph-grid {
	display: grid;
	grid-template-columns: repeat( 4, minmax( 0, 1fr ) );
	gap: calc( var( --xcph-gap ) * 1.5 ) var( --xcph-gap );
}

.xcph-product {
	display: flex;
	flex-direction: column;
	gap: 12px;
	color: inherit;
	text-decoration: none;
}

.xcph-product:focus-visible {
	outline: 1px solid currentColor;
	outline-offset: 4px;
}

.xcph-product__media {
	display: block;
	position: relative;
	/* Format natif du catalogue XCPH : 550 × 340 px sur l'ensemble des
	   fiches, soit 1,618. Le cadre épouse le fichier, aucun recadrage. */
	aspect-ratio: var( --xcph-media-ratio, 550 / 340 );
	overflow: hidden;
	background: var( --xcph-media-bg, #f6f6f6 );
}

.xcph-product__media img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	/* contain plutôt que cover : si un visuel hors format arrive un jour
	   au catalogue, le produit reste entier au lieu d'être rogné. */
	object-fit: var( --xcph-media-fit, contain );
	object-position: center;
	display: block;
}

.xcph-product__body {
	display: flex;
	flex-direction: column;
	gap: 4px;
	min-width: 0;
}

.xcph-product__category {
	color: var( --xcph-muted );
	font-size: 12px;
	line-height: 1.3;
}

.xcph-product__name {
	font-size: 15px;
	font-weight: 500;
	line-height: 1.35;
}

.xcph-product:hover .xcph-product__name {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.xcph-product__price {
	color: var( --xcph-muted );
	font-size: 14px;
	font-variant-numeric: tabular-nums;
}

.xcph-product__price del {
	opacity: 0.5;
}

.xcph-product__price ins {
	text-decoration: none;
}

/* ---------------------------------------------------------------
 * Pied de résultats
 * ------------------------------------------------------------- */

.xcph-block--more {
	display: flex;
	justify-content: center;
}

.xcph-more {
	display: inline-block;
	padding: 14px 28px;
	border: 1px solid var( --xcph-ink );
	color: var( --xcph-ink );
	font-size: 14px;
	line-height: 1;
	text-decoration: none;
	transition: background-color 140ms ease, color 140ms ease;
}

.xcph-more:hover,
.xcph-more:focus-visible {
	background: var( --xcph-ink );
	color: var( --xcph-paper );
}

/* ---------------------------------------------------------------
 * Page de résultats
 * ------------------------------------------------------------- */

.xcph-page {
	width: 100%;
	max-width: var( --xcph-max );
	margin: 0 auto;
}

.xcph-page__form {
	display: flex;
	align-items: center;
	gap: var( --xcph-gap );
	padding-bottom: 18px;
	border-bottom: 1px solid var( --xcph-ink );
}

.xcph-page__field {
	flex: 1 1 auto;
	display: block;
	margin: 0;
}

.xcph-page__submit {
	flex: 0 0 auto;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	font-size: 14px;
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 4px;
}

.xcph-page__results .xcph-block:first-child {
	padding-top: calc( var( --xcph-gap ) * 1.5 );
}

/* ---------------------------------------------------------------
 * Points de rupture — la grille reste symétrique à chaque palier
 * ------------------------------------------------------------- */

@media ( max-width: 1024px ) {
	.xcph-grid {
		grid-template-columns: repeat( 3, minmax( 0, 1fr ) );
	}
}

@media ( max-width: 767px ) {
	:root {
		--xcph-gap: 16px;
		--xcph-bar: 68px;
	}

	.xcph-grid {
		grid-template-columns: repeat( 2, minmax( 0, 1fr ) );
	}

	.xcph-overlay__panel {
		height: 100%;
		max-height: 100%;
	}

	.xcph-category {
		padding: 12px 0;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.xcph-overlay__panel,
	.xcph-overlay__backdrop,
	.xcph-more {
		transition: none;
	}
}
