/**
 * Contacto Flotante - estilos del botón flotante.
 */

.ctc {
	--ctc-size: 60px;
	--ctc-offset-x: 20px;
	--ctc-offset-y: 20px;
	--ctc-z: 9999;
	--ctc-main: #128c7e;
	--ctc-icon: #ffffff;
	--ctc-wa: #25d366;
	--ctc-tel: #0b6bcb;
	--ctc-gap: 12px;
	--ctc-btn: var(--ctc-size);
	--ctc-action-size: 48px;

	position: fixed;
	z-index: var(--ctc-z);
	display: flex;
	flex-direction: column;
	gap: var(--ctc-gap);
	box-sizing: border-box;
	font-family: inherit;
	line-height: 1.3;
	-webkit-tap-highlight-color: transparent;
}

.ctc *,
.ctc *::before,
.ctc *::after {
	box-sizing: border-box;
}

/* ---------------------------------------------------------------- Posición */

.ctc--bottom-right,
.ctc--bottom-left {
	bottom: calc(var(--ctc-offset-y) + env(safe-area-inset-bottom, 0px));
}

.ctc--middle-right,
.ctc--middle-left {
	top: 50%;
	transform: translateY(-50%);
}

.ctc--bottom-right,
.ctc--middle-right {
	right: calc(var(--ctc-offset-x) + env(safe-area-inset-right, 0px));
	align-items: flex-end;
}

.ctc--bottom-left,
.ctc--middle-left {
	left: calc(var(--ctc-offset-x) + env(safe-area-inset-left, 0px));
	align-items: flex-start;
}

/* ------------------------------------------------------------------- Panel */

/*
 * El panel se posiciona en absoluto para que, cerrado, no reserve espacio:
 * si quedase en el flujo separaría la burbuja del botón.
 */
.ctc__panel {
	position: absolute;
	bottom: calc(var(--ctc-btn) + var(--ctc-gap));
	display: flex;
	flex-direction: column-reverse;
	gap: 10px;
	margin: 0;
	padding: 0;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateY(14px) scale(0.94);
	transform-origin: bottom center;
	transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2), visibility 0s linear 0.22s;
}

.ctc--bottom-right .ctc__panel,
.ctc--middle-right .ctc__panel {
	right: 0;
	align-items: flex-end;
}

.ctc--bottom-left .ctc__panel,
.ctc--middle-left .ctc__panel {
	left: 0;
	align-items: flex-start;
}

.ctc.is-open .ctc__panel {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: none;
	transition-delay: 0s;
}

/* ---------------------------------------------------------------- Acciones */

.ctc__action {
	display: inline-flex;
	align-items: center;
	justify-content: flex-end;
	gap: 10px;
	max-width: min(280px, calc(100vw - 2 * var(--ctc-offset-x) - 16px));
	text-decoration: none;
	border: 0;
	background: none;
	opacity: 0;
	transform: translateY(10px);
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.ctc--bottom-left .ctc__action,
.ctc--middle-left .ctc__action {
	flex-direction: row-reverse;
	justify-content: flex-start;
}

.ctc.is-open .ctc__action {
	opacity: 1;
	transform: none;
}

.ctc.is-open .ctc__panel > *:nth-child(1) {
	transition-delay: 0.02s;
}

.ctc.is-open .ctc__panel > *:nth-child(2) {
	transition-delay: 0.06s;
}

.ctc__label {
	display: inline-block;
	padding: 8px 14px;
	border-radius: 999px;
	background: #ffffff;
	color: #1d2327;
	font-size: 14px;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.ctc--no-labels .ctc__label {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
	box-shadow: none;
}

.ctc__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: var(--ctc-action-size);
	height: var(--ctc-action-size);
	border-radius: 50%;
	color: var(--ctc-icon);
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
	transition: transform 0.15s ease;
}

.ctc__icon svg {
	width: 55%;
	height: 55%;
	display: block;
}

.ctc__action--wa .ctc__icon {
	background: var(--ctc-wa);
}

.ctc__action--tel .ctc__icon {
	background: var(--ctc-tel);
}

.ctc__action:hover .ctc__icon,
.ctc__action:focus-visible .ctc__icon {
	transform: scale(1.08);
}

.ctc__action:focus-visible {
	outline: 3px solid var(--ctc-main);
	outline-offset: 3px;
	border-radius: 999px;
}

/* --------------------------------------------------------- Botón principal */

.ctc__toggle {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--ctc-btn);
	height: var(--ctc-btn);
	min-width: 44px;
	min-height: 44px;
	padding: 0;
	margin: 0;
	border: 0;
	border-radius: 50%;
	background: var(--ctc-main);
	color: var(--ctc-icon);
	cursor: pointer;
	touch-action: manipulation;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ctc__toggle:hover {
	transform: scale(1.06);
}

.ctc__toggle:active {
	transform: scale(0.96);
}

.ctc__toggle:focus-visible {
	outline: 3px solid var(--ctc-main);
	outline-offset: 3px;
}

.ctc__toggle-icon {
	position: absolute;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inset: 0;
	transition: opacity 0.18s ease, transform 0.25s ease;
}

.ctc__toggle-icon svg {
	width: 48%;
	height: 48%;
}

.ctc__toggle-icon--close {
	opacity: 0;
	transform: rotate(-90deg) scale(0.6);
}

.ctc.is-open .ctc__toggle-icon--open {
	opacity: 0;
	transform: rotate(90deg) scale(0.6);
}

.ctc.is-open .ctc__toggle-icon--close {
	opacity: 1;
	transform: none;
}

/* -------------------------------------------------------------- Animación */

.ctc--anim-pulse .ctc__toggle::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: var(--ctc-main);
	opacity: 0.55;
	z-index: -1;
	animation: ctc-pulse 2.4s ease-out infinite;
}

.ctc--anim-shake .ctc__toggle {
	animation: ctc-shake 4s ease-in-out infinite;
}

.ctc.is-open .ctc__toggle::before,
.ctc.is-open.ctc--anim-shake .ctc__toggle {
	animation: none;
}

@keyframes ctc-pulse {
	0% {
		transform: scale(1);
		opacity: 0.55;
	}

	70% {
		transform: scale(1.7);
		opacity: 0;
	}

	100% {
		transform: scale(1.7);
		opacity: 0;
	}
}

@keyframes ctc-shake {
	0%, 82%, 100% {
		transform: rotate(0deg);
	}

	85% {
		transform: rotate(-12deg);
	}

	88% {
		transform: rotate(12deg);
	}

	91% {
		transform: rotate(-8deg);
	}

	94% {
		transform: rotate(8deg);
	}
}

/* --------------------------------------------------------------- Burbuja */

.ctc__bubble {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	max-width: min(240px, calc(100vw - 40px));
	padding: 10px 12px 10px 14px;
	border-radius: 14px;
	background: #ffffff;
	color: #1d2327;
	font-size: 14px;
	font-weight: 500;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
	animation: ctc-fade-in 0.3s ease both;
}

.ctc__bubble[hidden] {
	display: none;
}

.ctc__bubble-text {
	flex: 1 1 auto;
}

.ctc__bubble-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 22px;
	height: 22px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.06);
	color: #50575e;
	cursor: pointer;
	touch-action: manipulation;
}

.ctc__bubble-close svg {
	width: 12px;
	height: 12px;
}

.ctc__bubble-close:hover {
	background: rgba(0, 0, 0, 0.12);
}

@keyframes ctc-fade-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

/* ----------------------------------------------------------------- Móvil */

@media (max-width: 600px) {
	.ctc {
		--ctc-gap: 10px;
		--ctc-action-size: 52px;
		/* En pantallas pequeñas el botón no debería comerse la vista. */
		--ctc-btn: min(var(--ctc-size), 62px);

		max-width: calc(100vw - 24px);
	}

	.ctc--bottom-right,
	.ctc--bottom-left {
		bottom: calc(max(var(--ctc-offset-y), 14px) + env(safe-area-inset-bottom, 0px));
	}

	.ctc--bottom-right,
	.ctc--middle-right {
		right: calc(max(var(--ctc-offset-x), 14px) + env(safe-area-inset-right, 0px));
	}

	.ctc--bottom-left,
	.ctc--middle-left {
		left: calc(max(var(--ctc-offset-x), 14px) + env(safe-area-inset-left, 0px));
	}

	.ctc__label {
		font-size: 15px;
		padding: 10px 16px;
	}

	.ctc__action {
		max-width: calc(100vw - 40px);
	}
}

/* Pantallas muy bajas en horizontal: el panel no debe salirse. */
@media (max-height: 420px) {
	.ctc--middle-right,
	.ctc--middle-left {
		top: auto;
		bottom: calc(var(--ctc-offset-y) + env(safe-area-inset-bottom, 0px));
		transform: none;
	}
}

/* ------------------------------------------------------- Preferencias del SO */

@media (prefers-reduced-motion: reduce) {
	.ctc,
	.ctc *,
	.ctc *::before {
		animation: none !important;
		transition-duration: 0.01ms !important;
	}
}

@media (prefers-color-scheme: dark) {
	.ctc__label,
	.ctc__bubble {
		background: #23282d;
		color: #f0f0f1;
	}

	.ctc__bubble-close {
		background: rgba(255, 255, 255, 0.12);
		color: #f0f0f1;
	}

	.ctc__bubble-close:hover {
		background: rgba(255, 255, 255, 0.22);
	}
}

/* Impresión: el botón no aporta nada en papel. */
@media print {
	.ctc {
		display: none !important;
	}
}
