/**
 * Générateur d'affichette « chat perdu / trouvé » (shortcode [affiche_perdu]).
 * Palette et polices reprises des tokens du thème.
 */

.cc-aff {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
	gap: clamp(1.5rem, 4vw, 3rem);
	align-items: start;
	margin: 2rem 0;
}
@media (max-width: 860px) {
	.cc-aff { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ *
 *  Formulaire
 * ------------------------------------------------------------------ */
.cc-aff__form {
	display: flex;
	flex-direction: column;
	gap: 1.4rem;
	min-width: 0;
}
.cc-aff__group {
	margin: 0;
	padding: 1.1rem 1.2rem 1.3rem;
	border: 1px solid color-mix(in srgb, var(--wp--preset--color--contrast, #2b2a2e) 15%, transparent);
	border-radius: 12px;
	background: var(--wp--preset--color--base, #fbf2ef);
}
.cc-aff__group > legend {
	padding: 0 .5rem;
	font-weight: 700;
	font-size: .95rem;
	color: var(--wp--preset--color--primary-dark, #2a4276);
}
.cc-aff-field {
	margin: .85rem 0 0;
	display: flex;
	flex-direction: column;
	gap: .3rem;
}
.cc-aff-field:first-of-type { margin-top: 0; }
.cc-aff-field > label,
.cc-aff-field__lbl {
	font-weight: 600;
	font-size: .9rem;
}
.cc-aff-field input[type="text"],
.cc-aff-field input[type="tel"],
.cc-aff-field input[type="email"],
.cc-aff-field input[type="date"],
.cc-aff-field select,
.cc-aff-field textarea {
	width: 100%;
	max-width: 100%;
	padding: .5rem .6rem;
	font: inherit;
	border: 1px solid color-mix(in srgb, var(--wp--preset--color--contrast, #2b2a2e) 30%, transparent);
	border-radius: 8px;
	background: #fff;
}
.cc-aff-field textarea { resize: vertical; }

/* Champ photo : bouton personnalisé (masque le natif « Choisir un fichier ») */
.cc-aff-file__row {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: .5rem .75rem;
}
.cc-aff-file__input {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}
.cc-aff-file__btn {
	display: inline-block;
	padding: .5rem 1.1rem;
	border-radius: 999px;
	font-weight: 600;
	font-size: .9rem;
	color: #fff;
	background: var(--wp--preset--color--primary, #3a5899);
	cursor: pointer;
}
.cc-aff-file__btn:hover,
.cc-aff-file__input:focus + .cc-aff-file__btn {
	background: var(--wp--preset--color--primary-dark, #2a4276);
}
.cc-aff-file__input:focus-visible + .cc-aff-file__btn {
	outline: 2px solid var(--wp--preset--color--primary-dark, #2a4276);
	outline-offset: 2px;
}
.cc-aff-file__name {
	font-size: .85rem;
	color: var(--wp--preset--color--muted, #6a6570);
	overflow-wrap: anywhere;
	min-width: 0;
}
.cc-aff-file__name.is-set {
	color: var(--wp--preset--color--contrast, #2b2a2e);
	font-weight: 600;
}

/* Curseur de recadrage de la photo */
.cc-aff-frame__row {
	display: flex;
	align-items: center;
	gap: .6rem;
	font-size: .8rem;
	color: var(--wp--preset--color--muted, #6a6570);
}
.cc-aff-frame__row input[type="range"] {
	flex: 1 1 auto;
	min-width: 0;
	accent-color: var(--wp--preset--color--primary, #3a5899);
}
.cc-aff-field--radio,
.cc-aff-field--check {
	flex-direction: row;
	flex-wrap: wrap;
	align-items: center;
	gap: .4rem 1rem;
}
.cc-aff-field--radio label,
.cc-aff-field--check label {
	display: inline-flex;
	align-items: center;
	gap: .35rem;
	font-weight: 400;
	font-size: .92rem;
}
.cc-aff-field--radio .cc-aff-field__lbl { flex: 1 1 100%; }
.cc-aff-hint {
	margin: .5rem 0 0;
	font-size: .82rem;
	color: var(--wp--preset--color--muted, #6a6570);
}

/* ------------------------------------------------------------------ *
 *  Aperçu + barre d'actions
 * ------------------------------------------------------------------ */
.cc-aff__side {
	position: sticky;
	top: 1.5rem;
	display: flex;
	flex-direction: column;
	gap: .9rem;
	min-width: 0;
}
@media (max-width: 860px) {
	.cc-aff__side { position: static; }
}
.cc-aff__toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: .5rem;
}
.cc-aff__btn {
	appearance: none;
	border: 1px solid var(--wp--preset--color--primary, #3a5899);
	border-radius: 999px;
	padding: .55rem 1.1rem;
	font: inherit;
	font-weight: 600;
	font-size: .9rem;
	color: var(--wp--preset--color--primary, #3a5899);
	background: #fff;
	cursor: pointer;
}
.cc-aff__btn--primary {
	color: #fff;
	background: var(--wp--preset--color--primary, #3a5899);
}
.cc-aff__btn:hover,
.cc-aff__btn:focus-visible {
	background: var(--wp--preset--color--primary-dark, #2a4276);
	border-color: var(--wp--preset--color--primary-dark, #2a4276);
	color: #fff;
}
.cc-aff__btn[disabled] { opacity: .5; cursor: progress; }

.cc-aff__paper {
	border-radius: 10px;
	overflow: hidden;
	background: #fff;
	box-shadow: 0 12px 34px -14px rgba(29, 44, 77, .4);
}
.cc-aff__paper svg {
	display: block;
	width: 100%;
	height: auto;
}
.cc-aff__loading {
	margin: 0;
	padding: 3rem 1rem;
	text-align: center;
	color: #6a6570; /* fond « papier » toujours clair, couleur figée */
}
.cc-aff__status:empty { display: none; }
.cc-aff__status { color: var(--wp--preset--color--primary-dark, #2a4276); font-weight: 600; }

/* ------------------------------------------------------------------ *
 *  Mode sombre : les champs et boutons secondaires ont un fond blanc
 *  codé en dur ; on les repasse sur les tokens sombres du thème.
 *  (L'aperçu .cc-aff__paper reste blanc : c'est un aperçu d'impression.)
 * ------------------------------------------------------------------ */
:root[data-theme='dark'] .cc-aff-field input[type="text"],
:root[data-theme='dark'] .cc-aff-field input[type="tel"],
:root[data-theme='dark'] .cc-aff-field input[type="email"],
:root[data-theme='dark'] .cc-aff-field input[type="date"],
:root[data-theme='dark'] .cc-aff-field select,
:root[data-theme='dark'] .cc-aff-field textarea {
	background: var(--wp--preset--color--surface, #211f28);
	color: var(--wp--preset--color--contrast, #ece8e3);
	border-color: color-mix(in srgb, var(--wp--preset--color--contrast, #ece8e3) 30%, transparent);
}
:root[data-theme='dark'] .cc-aff-field ::placeholder {
	color: color-mix(in srgb, var(--wp--preset--color--contrast, #ece8e3) 55%, transparent);
}
:root[data-theme='dark'] .cc-aff__btn:not(.cc-aff__btn--primary) {
	background: var(--wp--preset--color--surface, #211f28);
}
:root[data-theme='dark'] .cc-aff__btn--primary,
:root[data-theme='dark'] .cc-aff__btn:hover,
:root[data-theme='dark'] .cc-aff__btn:focus-visible,
:root[data-theme='dark'] .cc-aff-file__btn {
	color: var(--cc-btn-fg, #14141a);
}

/* ------------------------------------------------------------------ *
 *  Impression : une seule page A4 = 4 affichettes (2 × 2)
 *  La feuille est injectée en JS comme enfant direct de <body>.
 * ------------------------------------------------------------------ */
#cc-aff-print-sheet { display: none; }

@media print {
	/* on masque toute la page… */
	body > * { display: none !important; }
	/* …sauf la feuille d'impression (l'ID l'emporte sur la règle ci-dessus) */
	#cc-aff-print-sheet {
		display: grid !important;
		grid-template-columns: 1fr 1fr;
		grid-template-rows: 1fr 1fr;
		gap: 4mm;
		width: 194mm;   /* A4 (210) − marges @page 8mm × 2 */
		height: 281mm;  /* A4 (297) − marges @page 8mm × 2 */
		box-sizing: border-box;
		overflow: hidden;
		break-inside: avoid;
		page-break-inside: avoid;
	}
	/* 1 affichette pleine page */
	#cc-aff-print-sheet.cc-aff-print-sheet--single {
		grid-template-columns: 1fr;
		grid-template-rows: 1fr;
		gap: 0;
	}
	.cc-aff-print-cell {
		display: flex;
		align-items: center;
		justify-content: center;
		overflow: hidden;
		break-inside: avoid;
		page-break-inside: avoid;
	}
	.cc-aff-print-cell svg {
		width: 100% !important;
		height: 100% !important;
		max-width: 100%;
		max-height: 100%;
	}
	html, body {
		width: auto !important;
		height: auto !important;
		margin: 0 !important;
		padding: 0 !important;
		background: #fff !important;
	}
	@page { size: A4 portrait; margin: 8mm; }
}
