/* ============================================================
   hg-sales-chat — кнопка и окно чата с ботом продаж «Лаки»
   Круглый аватар Лаки в правом нижнем углу; по нажатию над ним открывается
   окно с чатом открытой линии Битрикс24 (сам чат — в рамке
   /hg-sales-chat-frame.html). На телефоне окно — во весь экран.
   Логика — /js/hg-sales-chat.js.

   Подключается напрямую из footer.php с ?v=filemtime — НЕ через
   IncludeTimestamp::GetTimestamp(), иначе при наличии .min-версии
   отдастся она (хелпер сравнивает не время, а сам факт существования).

   Высота подъёма над нижними панелями сайта (панель покупки на телефоне,
   «выбранные товары», cookie, «Сообщить о проблеме») приходит из JS
   в переменной --hg-chat-lift: кнопка встаёт над панелью, а не под неё.
   ============================================================ */

.hg-chat {
	position: fixed;
	right: 24px;
	bottom: max(24px, var(--hg-chat-lift, 0px));
	z-index: 1500; /* над панелями сайта (≤1000), под модалками и питомцем акции (2000) */
	display: flex;
	align-items: center;
	gap: 10px;
	font-family: 'Montserrat', Arial, sans-serif;
	pointer-events: none; /* прозрачная область подписи не должна перехватывать клики по странице */
	transition: bottom .25s ease, opacity .2s ease, transform .2s ease;
}

.hg-chat__btn {
	position: relative;
	flex: none;
	width: 60px;
	height: 60px;
	margin: 0;
	padding: 0;
	border: 3px solid #ffe500;
	border-radius: 50%;
	background: #ffe500;
	box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
	cursor: pointer;
	pointer-events: auto;
	transition: transform .2s ease, box-shadow .2s ease;
	-webkit-tap-highlight-color: transparent;
}

.hg-chat__btn:hover {
	transform: translateY(-2px);
	box-shadow: 0 10px 24px rgba(0, 0, 0, .22);
}

.hg-chat__btn:focus-visible {
	outline: 3px solid #474a55;
	outline-offset: 3px;
}

.hg-chat__btn img {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	object-fit: cover;
}

/* Подпись слева от кнопки — только при наведении мышью */
.hg-chat__label {
	padding: 8px 12px;
	border-radius: 10px;
	background: #fff;
	color: #000;
	font-size: 13px;
	font-weight: 500;
	line-height: 1.3;
	white-space: nowrap;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .14);
	opacity: 0;
	transform: translateX(6px);
	pointer-events: none;
	transition: opacity .2s ease, transform .2s ease;
}

.hg-chat:hover .hg-chat__label {
	opacity: 1;
	transform: none;
}

/* Чат не загрузился (блокировщик рекламы, сеть) — подпись становится ссылкой
   на ту же линию в отдельной вкладке */
.hg-chat--failed .hg-chat__label {
	opacity: 1;
	transform: none;
	pointer-events: auto;
	white-space: normal;
	max-width: 220px;
}

.hg-chat__label a {
	color: #000;
	text-decoration: underline;
}

/* Точка «есть новый ответ» — когда чат закрыт, а бот или менеджер написал */
.hg-chat__dot {
	position: absolute;
	top: -3px;
	right: -3px;
	display: none;
	width: 14px;
	height: 14px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: #e62e2e;
}

.hg-chat--unread .hg-chat__dot {
	display: block;
}

/* Первая загрузка чата — кольцо вокруг аватара */
.hg-chat--loading .hg-chat__btn::after {
	content: '';
	position: absolute;
	top: -8px;
	right: -8px;
	bottom: -8px;
	left: -8px;
	border: 3px solid transparent;
	border-top-color: #474a55;
	border-radius: 50%;
	animation: hg-chat-spin .8s linear infinite;
}

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

/* Чат открыт — кнопка уходит, чтобы не торчать из-под окна чата */
.hg-chat--open {
	opacity: 0;
	transform: scale(.8);
}

.hg-chat--open .hg-chat__btn,
.hg-chat--open .hg-chat__label {
	pointer-events: none;
}

/* ---------- Окно чата ---------- */

/* Рамка грузится скрытой (visibility, а не display: none — так чат внутри
   успевает загрузиться и получать ответы, пока окно закрыто) */
.hg-chat-box {
	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 100001; /* над всем, включая плашку cookie (99999): открытый чат важнее */
	width: 400px;
	height: min(640px, calc(100vh - 48px));
	overflow: hidden;
	border-radius: 16px;
	background: #fff;
	box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
	opacity: 0;
	visibility: hidden;
	transform: translateY(12px);
	transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}

.hg-chat-box--open {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition: opacity .2s ease, transform .2s ease, visibility 0s;
}

.hg-chat-box__frame {
	display: block;
	width: 100%;
	height: 100%;
	border: 0;
}

@media (max-width: 767px) {
	.hg-chat {
		right: 16px;
		bottom: max(calc(16px + env(safe-area-inset-bottom, 0px)), var(--hg-chat-lift, 0px));
	}

	.hg-chat__btn {
		width: 54px;
		height: 54px;
	}

	.hg-chat__label {
		display: none;
	}

	.hg-chat--failed .hg-chat__label {
		display: block;
		max-width: 200px;
	}

	.hg-chat-box {
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		width: auto;
		height: auto;
		border-radius: 0;
		box-shadow: none;
	}

	/* Страница под открытым чатом не прокручивается */
	html.hg-chat-lock,
	html.hg-chat-lock body {
		overflow: hidden;
	}
}

@media (prefers-reduced-motion: reduce) {
	.hg-chat,
	.hg-chat__btn,
	.hg-chat__label,
	.hg-chat-box {
		transition: none;
	}

	.hg-chat--loading .hg-chat__btn::after {
		animation-duration: 2s;
	}
}

@media print {
	.hg-chat,
	.hg-chat-box {
		display: none !important;
	}
}
