/**
 * SB Crop — recortador de fotos de pantalla completa, componente compartido.
 * Enqueued desde includes/sb-crop.php, registrado pero NO encolado por
 * defecto: cada plugin consumidor llama a sb_crop_enqueue() en su propio
 * hook de assets (mismo espíritu que sb-scanner.php, pero sin atarlo a
 * sb_appnav_is_visible() porque el registro no vive dentro del app-shell).
 *
 * Familia visual de sb-scan.css: mismo navy, misma trama diagonal, mismas
 * esquinas menta de 26px (misma retícula que el escáner QR).
 * Referencia: wp-content/uploads/soulbuddy-mockups/sb-recorte-de-fotos.html,
 * pestaña "6 · Spec para Leo".
 */

.sb-crop {
	position: fixed;
	inset: 0;
	z-index: 1500;
	background: #131F51;
	display: flex;
	flex-direction: column;
	font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
	color: #fff;
}

.sb-crop[hidden],
.sb-crop [hidden] {
	display: none !important;
}

.sb-crop__top {
	height: 56px;
	padding-top: env(safe-area-inset-top);
	display: flex;
	align-items: center;
	gap: 10px;
	padding-left: 12px;
	padding-right: 12px;
	flex: 0 0 auto;
}

.sb-crop__title {
	font-family: "Gabarito", system-ui, -apple-system, "Segoe UI", sans-serif;
	font-weight: 700;
	font-size: 16px;
}

.sb-crop__close {
	margin-left: auto;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	background: rgba(255, 255, 255, .14);
	color: #fff;
	border: 0;
	cursor: pointer;
}

.sb-crop__close:focus-visible {
	outline: 2px solid #45E5BB;
	outline-offset: 2px;
}

.sb-crop__view {
	flex: 1;
	position: relative;
	display: grid;
	place-items: center;
	overflow: hidden;
	background: repeating-linear-gradient(45deg, #0F1A44, #0F1A44 12px, #121E4D 12px, #121E4D 24px);
}

.sb-crop__loading {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 24px;
	text-align: center;
	font-size: 14px;
	line-height: 1.5;
	color: #fff;
}
.sb-crop__loading[hidden] { display: none; }
.sb-crop__loading > span:last-child { color: #d8dcef; }
.sb-crop__spinner {
	width: 32px;
	height: 32px;
	border: 3px solid #ffffff35;
	border-top-color: #45E5BB;
	border-radius: 50%;
	animation: sb-crop-spin .8s linear infinite;
}
.sb-crop[data-state="loading"] .sb-crop__frame,
.sb-crop[data-state="loading"] .sb-crop__hint { visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
	.sb-crop__spinner { animation: none; }
}

/* marco: la ventana real que se exporta */
.sb-crop__frame {
	position: relative;
	touch-action: none;
	cursor: grab;
	overflow: hidden;
	width: min(78vw, 300px);
	aspect-ratio: 1;
	user-select: none;
	-webkit-user-select: none;
}

.sb-crop__frame:active {
	cursor: grabbing;
}

.sb-crop[data-ratio="3"] .sb-crop__frame {
	width: min(92vw, 340px);
	aspect-ratio: 3 / 1;
}

.sb-crop__frame img {
	position: absolute;
	left: 0;
	top: 0;
	transform-origin: 0 0;
	max-width: none;
	will-change: transform;
	pointer-events: none;
	-webkit-user-drag: none;
}

/* máscara: scrim gigante por box-shadow */
.sb-crop__mask {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 2;
	box-shadow: 0 0 0 9999px rgba(10, 17, 44, .74);
	border: 2px solid rgba(255, 255, 255, .95);
	border-radius: 4px;
}

.sb-crop[data-mask="circle"] .sb-crop__mask {
	border-radius: 50%;
}

/* esquinas menta: mismo lenguaje que la retícula del escáner (sb-scan__reticle).
   Dicen "el cuadrado completo se guarda", sin una línea de copy. */
.sb-crop__corners {
	position: absolute;
	inset: 0;
	z-index: 3;
	pointer-events: none;
}

.sb-crop__corners i {
	position: absolute;
	width: 26px;
	height: 26px;
	border: 3px solid #45E5BB;
}

.sb-crop__corners i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.sb-crop__corners i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
.sb-crop__corners i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
.sb-crop__corners i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }

/* portada: guía de zona segura (lo que sobrevive en la banda del móvil) */
.sb-crop__safe {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--sb-crop-safe, 16.67%);
	right: var(--sb-crop-safe, 16.67%);
	z-index: 3;
	pointer-events: none;
	border-left: 1px dashed rgba(255, 255, 255, .42);
	border-right: 1px dashed rgba(255, 255, 255, .42);
}

.sb-crop__safe[hidden] {
	display: none;
}

.sb-crop__hint {
	color: rgba(255, 255, 255, .82);
	font-size: 13.5px;
	text-align: center;
	padding: 14px 24px 2px;
	line-height: 1.5;
	margin: 0;
	flex: 0 0 auto;
	min-height: 42px;
}

.sb-crop[data-state="error"] .sb-crop__hint {
	color: #FF8270;
	font-weight: 600;
}

/* zoom */
.sb-crop__zoom {
	flex: 0 0 auto;
	padding: 8px 22px 2px;
	display: flex;
	align-items: center;
	gap: 12px;
}

.sb-crop__zoom svg {
	width: 17px;
	height: 17px;
	color: rgba(255, 255, 255, .6);
	flex: 0 0 auto;
}

.sb-crop__range {
	flex: 1;
	-webkit-appearance: none;
	appearance: none;
	background: transparent;
	height: 24px;
	margin: 0;
}

.sb-crop__range::-webkit-slider-runnable-track {
	height: 4px;
	border-radius: 999px;
	background: linear-gradient(#45E5BB, #45E5BB) 0 / var(--fill, 0%) 100% no-repeat rgba(255, 255, 255, .22);
}

.sb-crop__range::-moz-range-track {
	height: 4px;
	border-radius: 999px;
	background: rgba(255, 255, 255, .22);
}

.sb-crop__range::-moz-range-progress {
	height: 4px;
	border-radius: 999px;
	background: #45E5BB;
}

.sb-crop__range::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: #fff;
	border: 0;
	margin-top: -9px;
	box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
	cursor: pointer;
}

.sb-crop__range::-moz-range-thumb {
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: #fff;
	border: 0;
	box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
	cursor: pointer;
}

.sb-crop__range:focus-visible {
	outline: 2px solid #45E5BB;
	outline-offset: 4px;
	border-radius: 999px;
}

.sb-crop__foot {
	padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
	display: flex;
	gap: 10px;
	flex: 0 0 auto;
}

.sb-crop__btn {
	flex: 1;
	height: 48px;
	border-radius: 999px;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	font-size: 14.5px;
	font-weight: 700;
	cursor: pointer;
	border: 0;
	font-family: inherit;
}

.sb-crop__btn--ghost {
	background: rgba(255, 255, 255, .13);
	color: #fff;
}

.sb-crop__btn--ghost:hover {
	background: rgba(255, 255, 255, .2);
}

.sb-crop__btn--go {
	background: #45E5BB;
	color: #0B3B31;
}

.sb-crop__btn--go:hover {
	filter: brightness(1.06);
}

.sb-crop__btn:focus-visible {
	outline: 2px solid #45E5BB;
	outline-offset: 2px;
}

.sb-crop__btn[disabled] {
	opacity: .45;
	cursor: not-allowed;
}

.sb-crop__btn.is-loading {
	pointer-events: none;
	color: transparent;
	position: relative;
}

.sb-crop__btn.is-loading::after {
	content: "";
	position: absolute;
	width: 15px;
	height: 15px;
	border-radius: 50%;
	border: 2px solid rgba(11, 59, 49, .28);
	border-top-color: #0B3B31;
	animation: sb-crop-spin .7s linear infinite;
}

.sb-crop__btn--ghost.is-loading::after {
	border-color: rgba(255, 255, 255, .3);
	border-top-color: #fff;
}

@keyframes sb-crop-spin {
	to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
	.sb-crop__btn.is-loading::after {
		animation: none;
	}
}

/* estado de error: sin marco, sin zoom, un solo botón */
.sb-crop[data-state="error"] .sb-crop__view {
	background: #131F51;
}

.sb-crop[data-state="error"] .sb-crop__frame,
.sb-crop[data-state="error"] .sb-crop__zoom {
	display: none;
}

/* error: un solo botón ("Elegir otra foto"), no Cancelar + Usar foto */
.sb-crop[data-state="error"] [data-sb-crop-cancel],
.sb-crop[data-state="error"] [data-sb-crop-done] {
	display: none;
}

.sb-crop[data-state="error"] [data-sb-crop-retry] {
	display: flex;
}

.sb-crop__errico {
	width: 64px;
	height: 64px;
	border-radius: 50%;
	background: rgba(255, 130, 112, .14);
	display: none;
	place-items: center;
	color: #FF8270;
}

.sb-crop__errico svg {
	width: 30px;
	height: 30px;
}

.sb-crop[data-state="error"] .sb-crop__errico {
	display: grid;
}
