/*
 * Floating contact buttons (Telegram + «Замовити дзвінок») and the callback
 * dialog. Markup: inc/floating-contact.php, behaviour: assets/js/floating-contact.js.
 *
 * Only transform and opacity are animated. The block sits above page content
 * (z-index 80) and below the header (100), the mobile drawer and every
 * <dialog> (top layer). Fixed bars at the bottom of the screen (product
 * purchase bar, «Монтаж»/«Сервіс» bar, cart and checkout buttons) lift the
 * block above them through --ec-lift. The bar heights are kept on <body> as
 * --ec-bar-h, which the promo banner (assets/css/promo.css) reads too, so
 * both stand on the same bar.
 */

.ec-fab {
	--ec-size: 56px;
	--ec-edge: 24px;
	--ec-gap: 14px;
	--ec-lift: var(--ec-bar-h, 0px);
	--ec-safe: 0px;
	position: fixed;
	right: var(--ec-edge);
	bottom: calc(var(--ec-edge) + var(--ec-safe));
	z-index: 80;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--ec-gap);
	margin: 0;
	transform: translateY(calc(-1 * var(--ec-lift)));
	transition: transform 0.25s ease, opacity 0.2s ease, visibility 0.2s;
}

/* Fixed bars at the bottom of the screen: stand on top of them. */
body:has(.pdp-sticky:not([hidden])) {
	--ec-bar-h: calc(76px + env(safe-area-inset-bottom, 0px));
}

body:has(.ef-inst-sticky.is-shown) {
	--ec-bar-h: calc(var(--ef-install-sticky-h, 68px) + env(safe-area-inset-bottom, 0px));
}

/* The menu drawer and any open dialog cover the buttons. */
body:has(.is-drawer-open) .ec-fab {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

/* --- Buttons ---------------------------------------------------------------- */

.ec-fab__btn {
	position: relative;
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: var(--ec-size);
	height: var(--ec-size);
	padding: 0;
	border: 0;
	border-radius: 50%;
	isolation: isolate;
	color: #fff;
	cursor: pointer;
	text-decoration: none;
	-webkit-tap-highlight-color: transparent;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22), 0 1px 3px rgba(0, 0, 0, 0.18);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	animation: ec-in 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 1.6s backwards;
}

.ec-fab__btn[hidden] {
	display: none;
}

.ec-fab__btn--tg {
	background: linear-gradient(145deg, #2aabee, #229ed9);
}

.ec-fab__btn--call {
	background: linear-gradient(145deg, #2b2b2b, #111);
	/* The light hairline keeps it visible on the dark hero and footer. */
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22), 0 1px 3px rgba(0, 0, 0, 0.18), 0 0 0 1.5px rgba(255, 255, 255, 0.45);
	animation-delay: 1.8s;
}

/* Two soft rings, out of phase. */
.ec-fab__btn::before,
.ec-fab__btn::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: inherit;
	opacity: 0;
	z-index: -1;
	pointer-events: none;
	animation: ec-ring 3.6s ease-out infinite 3s;
}

.ec-fab__btn::after {
	animation-delay: 4.8s;
}

.ec-fab__btn--call::before {
	animation-delay: 4.2s;
}

.ec-fab__btn--call::after {
	animation-delay: 6s;
}

.ec-fab__btn:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 5px #111, 0 6px 18px rgba(0, 0, 0, 0.22);
}

.ec-fab__btn--call:focus-visible {
	box-shadow: 0 0 0 5px #111, 0 0 0 7px #fff;
}

.ec-fab__btn:active {
	transform: scale(0.95);
}

.ec-fab__icon {
	display: block;
	flex: none;
}

.ec-fab__icon--phone {
	transform-origin: 50% 50%;
	animation: ec-ring-phone 7s ease-in-out infinite 5s;
}

/* Tooltip on the left; mouse devices only. */
.ec-fab__tip {
	position: absolute;
	top: 50%;
	right: calc(100% + 12px);
	padding: 8px 12px;
	border-radius: 8px;
	background: #111;
	color: #fff;
	font: 600 13px/1.2 var(--wp--preset--font-family--manrope, Manrope, system-ui, sans-serif);
	white-space: nowrap;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translate(6px, -50%);
	transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

@media (hover: hover) and (pointer: fine) {
	.ec-fab__btn:hover {
		transform: scale(1.08);
		box-shadow: 0 10px 24px rgba(0, 0, 0, 0.26), 0 2px 4px rgba(0, 0, 0, 0.18);
	}

	.ec-fab__btn:hover .ec-fab__tip,
	.ec-fab__btn:focus-visible .ec-fab__tip {
		opacity: 1;
		visibility: visible;
		transform: translate(0, -50%);
	}

	.ec-fab__btn:active {
		transform: scale(0.95);
	}
}

@keyframes ec-in {
	from {
		opacity: 0;
		transform: translateY(40px) scale(0.8);
	}
}

@keyframes ec-ring {
	0% {
		opacity: 0.38;
		transform: scale(1);
	}

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

/* A short shake at the start of each cycle, then rest. */
@keyframes ec-ring-phone {
	0%,
	12%,
	100% {
		transform: rotate(0);
	}

	2% {
		transform: rotate(-16deg);
	}

	4% {
		transform: rotate(14deg);
	}

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

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

	10% {
		transform: rotate(-5deg);
	}
}

/* --- Phones ------------------------------------------------------------------ */

@media (max-width: 767px) {
	.ec-fab {
		--ec-size: 48px;
		--ec-edge: 14px;
		--ec-gap: 12px;
		--ec-safe: env(safe-area-inset-bottom, 0px);
		bottom: calc(16px + var(--ec-safe));
	}

	/* The bars already clear the home indicator themselves. */
	body:has(.pdp-sticky:not([hidden])) .ec-fab,
	body:has(.ef-inst-sticky.is-shown) .ec-fab {
		--ec-safe: 0px;
		bottom: 16px;
	}

	.ec-fab__tip {
		display: none;
	}
}

@media (max-width: 782px) {
	body:has(.wc-block-cart__submit-container--sticky) {
		--ec-bar-h: 82px;
	}

	body:has(.wc-block-cart__submit-container--sticky) .ec-fab {
		--ec-safe: 0px;
		bottom: 16px;
	}
}

@media (max-width: 1023px) {
	body:has(.ef-mobile-bar:not([hidden])) {
		--ec-bar-h: calc(84px + env(safe-area-inset-bottom, 0px));
	}

	body:has(.ef-mobile-bar:not([hidden])) .ec-fab {
		--ec-safe: 0px;
		bottom: 16px;
	}
}

/* Narrow phones: the buttons must not crowd the content. */
@media (max-width: 360px) {
	.ec-fab {
		--ec-edge: 10px;
	}
}

/* --- Dialog -------------------------------------------------------------------- */

html.ec-lock {
	overflow: hidden;
}

.ec-modal {
	width: min(440px, calc(100vw - 24px));
	max-width: none;
	max-height: calc(100dvh - 24px);
	margin: auto;
	padding: 0;
	border: 0;
	background: transparent;
	color: #111;
	font-family: var(--wp--preset--font-family--manrope, Manrope, system-ui, sans-serif);
	overflow: visible;
}

.ec-modal::backdrop {
	background: rgba(0, 0, 0, 0.55);
}

.ec-modal[open] {
	animation: ec-modal-in 0.24s cubic-bezier(0.2, 0.7, 0.2, 1);
}

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

:where(.ec-modal) p {
	margin: 0;
}

.ec-modal__card {
	position: relative;
	max-height: calc(100dvh - 24px);
	padding: 28px 24px 24px;
	overflow-y: auto;
	overscroll-behavior: contain;
	border-radius: 16px;
	background: #fff;
	box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
}

.ec-modal__close {
	position: absolute;
	top: 8px;
	right: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #111;
	cursor: pointer;
}

.ec-modal__close:hover {
	background: #f0f0f0;
}

.ec-modal :focus-visible {
	outline: 2px solid #111;
	outline-offset: 3px;
}

.ec-form__title {
	padding-right: 40px;
	font-size: 22px;
	font-weight: 700;
	line-height: 1.2;
}

.ec-form__lede {
	margin: 6px 0 18px;
	color: #555;
	font-size: 14px;
	line-height: 1.45;
}

.ec-field {
	margin-bottom: 14px;
}

.ec-label {
	display: block;
	margin-bottom: 6px;
	font-size: 13px;
	font-weight: 600;
}

.ec-opt {
	color: #777;
	font-weight: 400;
}

.ec-input {
	display: block;
	width: 100%;
	height: 48px;
	padding: 0 14px;
	border: 1px solid #cfcfcf;
	border-radius: 10px;
	background: #fff;
	color: #111;
	/* 16px keeps iOS from zooming the page on focus. */
	font-family: inherit;
	font-size: 16px;
	font-weight: 500;
	line-height: 1.2;
	appearance: none;
	-webkit-appearance: none;
}

.ec-select {
	padding-right: 38px;
	background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23111' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E") right 14px center / 12px 8px no-repeat;
}

.ec-input:focus {
	border-color: #111;
	outline: none;
	box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.12);
}

.ec-input[aria-invalid="true"] {
	border-color: #c0392b;
}

.ec-err {
	margin-top: 6px;
	color: #c0392b;
	font-size: 13px;
	line-height: 1.35;
}

.ec-err[hidden],
.ec-alert[hidden] {
	display: none;
}

.ec-alert {
	margin-bottom: 14px;
	padding: 10px 12px;
	border-radius: 10px;
	background: #fdecea;
	color: #8e2a1f;
	font-size: 14px;
	line-height: 1.4;
}

.ec-consent {
	display: flex;
	gap: 10px;
	align-items: flex-start;
	margin: 4px 0 0;
	font-size: 13px;
	line-height: 1.4;
	color: #444;
	cursor: pointer;
}

.ec-consent a {
	color: inherit;
	text-decoration: underline;
}

.ec-consent input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
}

.ec-consent__box {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	margin-top: 1px;
	border: 1.5px solid #8a8a8a;
	border-radius: 6px;
	background: #fff;
	color: transparent;
}

.ec-consent input:checked + .ec-consent__box {
	border-color: #111;
	background: #111;
	color: #fff;
}

.ec-consent input:focus-visible + .ec-consent__box {
	outline: 2px solid #111;
	outline-offset: 3px;
}

.ec-consent.has-error .ec-consent__box {
	border-color: #c0392b;
}

.ec-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: 100%;
	min-height: 50px;
	margin-top: 16px;
	padding: 0 20px;
	border: 1px solid #111;
	border-radius: 10px;
	font-family: inherit;
	font-size: 16px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
}

.ec-btn--dark {
	background: #111;
	color: #fff;
}

.ec-btn--dark:hover {
	background: #3d3d3d;
}

.ec-btn--ghost {
	background: #fff;
	color: #111;
}

.ec-btn[disabled] {
	opacity: 0.7;
	cursor: progress;
}

.ec-spinner {
	display: none;
	width: 18px;
	height: 18px;
	border: 2px solid rgba(255, 255, 255, 0.4);
	border-top-color: #fff;
	border-radius: 50%;
	animation: ec-spin 0.7s linear infinite;
}

.ec-form.is-loading .ec-spinner {
	display: block;
}

.ec-hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.ec-modal__done {
	padding: 12px 0 4px;
	text-align: center;
}

.ec-modal__done[hidden],
.ec-form[hidden] {
	display: none;
}

.ec-modal__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	margin-bottom: 14px;
	border-radius: 50%;
	background: #111;
	color: #fff;
}

.ec-modal__done-title {
	font-size: 20px;
	font-weight: 700;
	line-height: 1.3;
}

.ec-modal__done:focus {
	outline: none;
}

@keyframes ec-modal-in {
	from {
		opacity: 0;
		transform: translateY(16px);
	}
}

@keyframes ec-sheet-in {
	from {
		transform: translateY(100%);
	}
}

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

/* Bottom sheet on phones. */
@media (max-width: 767px) {
	.ec-modal {
		width: 100%;
		max-height: 92dvh;
		margin: auto 0 0;
	}

	.ec-modal[open] {
		animation: ec-sheet-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
	}

	.ec-modal__card {
		max-height: 92dvh;
		padding: 24px 18px calc(20px + env(safe-area-inset-bottom, 0px));
		border-radius: 20px 20px 0 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ec-fab__btn,
	.ec-fab__icon--phone {
		animation: none;
	}

	.ec-fab__btn::before,
	.ec-fab__btn::after {
		display: none;
	}

	.ec-fab,
	.ec-fab__btn,
	.ec-fab__tip {
		transition: none;
	}

	.ec-modal[open] {
		animation: none;
	}
}
