/**
 * W Tools — styles.
 *
 * Toutes les classes sont préfixées .imgt- et scopées sous .imgt-tool
 * pour éviter tout conflit avec Divi ou le thème. Aucune balise globale
 * (button, input…) n'est ciblée sans préfixe.
 *
 * @package Image_Tools
 */

/* -------------------------------------------------------------------------
 * Variables (faciles à personnaliser en haut du fichier)
 * ---------------------------------------------------------------------- */
.imgt-tool {
	--imgt-accent: #6366f1;
	--imgt-accent-hover: #4f46e5;
	--imgt-card-bg: #ffffff;
	--imgt-drop-bg: #f8fafc;
	--imgt-text: #0f172a;
	--imgt-text-soft: #475569;
	--imgt-border: #e2e8f0;
	--imgt-success: #10b981;
	--imgt-error: #ef4444;
	--imgt-radius-card: 16px;
	--imgt-radius-btn: 12px;
	--imgt-shadow: 0 4px 24px rgba( 15, 23, 42, 0.08 );
	--imgt-shadow-hover: 0 8px 28px rgba( 15, 23, 42, 0.14 );

	box-sizing: border-box;
	max-width: 760px;
	margin: 1.5rem auto;
	font-family: inherit;
	color: var( --imgt-text );
	line-height: 1.5;
}

/* Reset ciblé : uniquement les descendants de .imgt-tool. */
.imgt-tool *,
.imgt-tool *::before,
.imgt-tool *::after {
	box-sizing: border-box;
}

/* -------------------------------------------------------------------------
 * Carte
 * ---------------------------------------------------------------------- */
.imgt-card {
	background: var( --imgt-card-bg );
	border: 1px solid var( --imgt-border );
	border-radius: var( --imgt-radius-card );
	box-shadow: var( --imgt-shadow );
	padding: clamp( 1.25rem, 3vw, 2rem );
}

.imgt-title {
	margin: 0 0 0.25rem;
	font-size: clamp( 1.25rem, 2.5vw, 1.6rem );
	font-weight: 700;
	color: var( --imgt-text );
	line-height: 1.2;
}

.imgt-desc {
	margin: 0 0 1.25rem;
	font-size: 0.95rem;
	color: var( --imgt-text-soft );
}

/* -------------------------------------------------------------------------
 * Zone de dépôt
 * ---------------------------------------------------------------------- */
.imgt-dropzone {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.35rem;
	padding: clamp( 1.5rem, 5vw, 2.5rem );
	text-align: center;
	background: var( --imgt-drop-bg );
	border: 2px dashed var( --imgt-border );
	border-radius: var( --imgt-radius-card );
	color: var( --imgt-text-soft );
	cursor: pointer;
	transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.imgt-dropzone:hover,
.imgt-dropzone:focus-visible {
	border-color: var( --imgt-accent );
	background: rgba( 99, 102, 241, 0.05 );
}

.imgt-dropzone:focus-visible {
	outline: 3px solid rgba( 99, 102, 241, 0.4 );
	outline-offset: 2px;
}

.imgt-dropzone.is-dragover {
	border-color: var( --imgt-accent );
	background: rgba( 99, 102, 241, 0.1 );
	transform: translateY( -2px );
}

.imgt-dropzone.is-filled {
	border-style: solid;
	border-color: var( --imgt-accent );
	background: rgba( 99, 102, 241, 0.04 );
}

/* Input fichier : invisible mais couvre toute la zone (fallback clic). */
.imgt-file {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	cursor: pointer;
}

.imgt-dropzone-icon {
	color: var( --imgt-accent );
}

.imgt-dropzone-text {
	margin: 0;
	font-size: 1rem;
}

.imgt-dropzone-text strong {
	color: var( --imgt-text );
	font-weight: 600;
}

.imgt-dropzone-hint {
	margin: 0;
	font-size: 0.8rem;
	opacity: 0.8;
}

/* -------------------------------------------------------------------------
 * Contrôles (sliders, selects, number)
 * ---------------------------------------------------------------------- */
.imgt-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 1.1rem;
	margin-top: 1.25rem;
}

.imgt-control {
	flex: 1 1 220px;
	min-width: 0;
}

.imgt-label {
	display: block;
	margin-bottom: 0.4rem;
	font-size: 0.85rem;
	font-weight: 600;
	color: var( --imgt-text );
}

.imgt-output {
	display: inline-block;
	min-width: 2.2em;
	padding: 0.05rem 0.4rem;
	margin-left: 0.25rem;
	font-variant-numeric: tabular-nums;
	color: var( --imgt-accent );
	background: rgba( 99, 102, 241, 0.1 );
	border-radius: 6px;
}

.imgt-help {
	margin: 0.4rem 0 0;
	font-size: 0.78rem;
	color: var( --imgt-text-soft );
}

/* Select / number */
.imgt-select,
.imgt-number {
	width: 100%;
	padding: 0.6rem 0.7rem;
	font-family: inherit;
	font-size: 0.95rem;
	color: var( --imgt-text );
	background: var( --imgt-card-bg );
	border: 1px solid var( --imgt-border );
	border-radius: var( --imgt-radius-btn );
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.imgt-select:focus,
.imgt-number:focus {
	outline: none;
	border-color: var( --imgt-accent );
	box-shadow: 0 0 0 3px rgba( 99, 102, 241, 0.25 );
}

/* Slider */
.imgt-slider {
	-webkit-appearance: none;
	appearance: none;
	width: 100%;
	height: 6px;
	margin: 0.5rem 0;
	background: var( --imgt-border );
	border-radius: 999px;
	outline: none;
	cursor: pointer;
}

.imgt-slider::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 20px;
	height: 20px;
	background: var( --imgt-accent );
	border: 3px solid #fff;
	border-radius: 50%;
	box-shadow: 0 1px 4px rgba( 15, 23, 42, 0.25 );
	transition: transform 0.15s ease, background 0.15s ease;
}

.imgt-slider::-webkit-slider-thumb:hover {
	transform: scale( 1.12 );
	background: var( --imgt-accent-hover );
}

.imgt-slider::-moz-range-thumb {
	width: 20px;
	height: 20px;
	background: var( --imgt-accent );
	border: 3px solid #fff;
	border-radius: 50%;
	box-shadow: 0 1px 4px rgba( 15, 23, 42, 0.25 );
	cursor: pointer;
}

.imgt-slider:focus-visible {
	box-shadow: 0 0 0 3px rgba( 99, 102, 241, 0.3 );
}

/* -------------------------------------------------------------------------
 * Erreur
 * ---------------------------------------------------------------------- */
.imgt-error {
	margin-top: 1rem;
	padding: 0.75rem 1rem;
	font-size: 0.9rem;
	color: #fff;
	background: var( --imgt-error );
	border-radius: var( --imgt-radius-btn );
}

/* -------------------------------------------------------------------------
 * Barre de progression
 * ---------------------------------------------------------------------- */
.imgt-progress {
	margin-top: 1.25rem;
	height: 6px;
	overflow: hidden;
	background: var( --imgt-border );
	border-radius: 999px;
}

.imgt-progress-bar {
	width: 40%;
	height: 100%;
	background: var( --imgt-accent );
	border-radius: 999px;
}

.imgt-progress-bar.is-active {
	animation: imgt-indeterminate 1.1s ease-in-out infinite;
}

@keyframes imgt-indeterminate {
	0% {
		margin-left: -40%;
	}
	100% {
		margin-left: 100%;
	}
}

/* -------------------------------------------------------------------------
 * Aperçus avant / après
 * ---------------------------------------------------------------------- */
.imgt-previews {
	display: grid;
	grid-template-columns: repeat( 2, minmax( 0, 1fr ) );
	gap: 1rem;
	margin-top: 1.5rem;
}

.imgt-preview {
	margin: 0;
	min-width: 0;
}

.imgt-preview-frame {
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 4 / 3;
	overflow: hidden;
	background: var( --imgt-drop-bg );
	border: 1px solid var( --imgt-border );
	border-radius: 12px;
}

.imgt-preview-frame img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	display: block;
}

.imgt-preview figcaption {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	margin-top: 0.5rem;
}

.imgt-preview-label {
	font-size: 0.8rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var( --imgt-text-soft );
}

.imgt-preview-label--after {
	color: var( --imgt-accent );
}

.imgt-meta {
	font-size: 0.8rem;
	color: var( --imgt-text-soft );
	font-variant-numeric: tabular-nums;
}

.imgt-meta--gain {
	color: var( --imgt-success );
	font-weight: 600;
}

/* -------------------------------------------------------------------------
 * Actions / boutons
 * ---------------------------------------------------------------------- */
.imgt-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.6rem;
	margin-top: 1.5rem;
}

.imgt-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	padding: 0.7rem 1.25rem;
	font-family: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	border: 2px solid transparent;
	border-radius: var( --imgt-radius-btn );
	cursor: pointer;
	transition: all 0.2s ease;
}

.imgt-btn:focus-visible {
	outline: 3px solid rgba( 99, 102, 241, 0.4 );
	outline-offset: 2px;
}

.imgt-btn:disabled {
	opacity: 0.65;
	cursor: default;
}

.imgt-btn-primary {
	color: #fff;
	background: var( --imgt-accent );
}

.imgt-btn-primary:hover:not( :disabled ) {
	background: var( --imgt-accent-hover );
	transform: translateY( -1px );
	box-shadow: var( --imgt-shadow-hover );
}

.imgt-btn-secondary {
	color: var( --imgt-text );
	background: transparent;
	border-color: var( --imgt-border );
}

.imgt-btn-secondary:hover {
	border-color: var( --imgt-accent );
	color: var( --imgt-accent );
	transform: translateY( -1px );
}

.imgt-btn-success {
	color: #fff;
	background: var( --imgt-success );
}

.imgt-btn-success:hover {
	filter: brightness( 0.95 );
	transform: translateY( -1px );
	box-shadow: var( --imgt-shadow-hover );
}

/* Spinner du bouton d'action (visible quand .is-busy). */
.imgt-spinner {
	display: none;
	width: 15px;
	height: 15px;
	border: 2px solid rgba( 255, 255, 255, 0.5 );
	border-top-color: #fff;
	border-radius: 50%;
	animation: imgt-spin 0.7s linear infinite;
}

.imgt-tool.is-busy .imgt-spinner {
	display: inline-block;
}

@keyframes imgt-spin {
	to {
		transform: rotate( 360deg );
	}
}

/* -------------------------------------------------------------------------
 * Apparition en fondu du résultat
 * ---------------------------------------------------------------------- */
.imgt-fade-in {
	animation: imgt-fade 0.4s ease both;
}

@keyframes imgt-fade {
	from {
		opacity: 0;
		transform: translateY( 8px );
	}
	to {
		opacity: 1;
		transform: translateY( 0 );
	}
}

/* -------------------------------------------------------------------------
 * Responsive (mobile first : la grille passe en colonne)
 * ---------------------------------------------------------------------- */
@media ( max-width: 560px ) {
	.imgt-previews {
		grid-template-columns: 1fr;
	}

	.imgt-actions .imgt-btn {
		flex: 1 1 100%;
	}
}

/* Respect des préférences de mouvement réduit. */
@media ( prefers-reduced-motion: reduce ) {
	.imgt-tool *,
	.imgt-tool *::before,
	.imgt-tool *::after {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}

/* -------------------------------------------------------------------------
 * Mode sombre
 * ---------------------------------------------------------------------- */
@media ( prefers-color-scheme: dark ) {
	.imgt-tool {
		--imgt-card-bg: #0f172a;
		--imgt-drop-bg: #1e293b;
		--imgt-text: #f1f5f9;
		--imgt-text-soft: #94a3b8;
		--imgt-border: #334155;
		--imgt-shadow: 0 4px 24px rgba( 0, 0, 0, 0.4 );
		--imgt-shadow-hover: 0 8px 28px rgba( 0, 0, 0, 0.55 );
	}

	.imgt-dropzone:hover,
	.imgt-dropzone:focus-visible {
		background: rgba( 99, 102, 241, 0.15 );
	}

	.imgt-slider::-webkit-slider-thumb,
	.imgt-slider::-moz-range-thumb {
		border-color: #0f172a;
	}
}
