/**
 * Плавающий чат-виджет НебоЛЮКС — дизайн-система 6-B.
 *
 * Терракотовый акцент #E07856, кремовый фон #FBF7F0, мягкие тени,
 * скругления 12-16px, аккуратная типографика. Все стили изолированы
 * под корневой селектор .nbl-chat, чтобы не конфликтовать с темой.
 *
 * @package NeboLUKS Chat Widget
 */

/* =========================================================================
   1. Переменные (палитра 6-B)
   ========================================================================= */
.nbl-chat {
	--nbl-terracotta: #E07856;
	--nbl-terracotta-dark: #C4552D;
	--nbl-terracotta-soft: #F5B49A;
	--nbl-cream: #FBF7F0;
	--nbl-cream-2: #F7F1E8;
	--nbl-ink: #2E2A26;
	--nbl-muted: #8A8177;
	--nbl-line: #E3D9CB;
	--nbl-success: #2F7D4F;
	--nbl-error: #C4552D;
	--nbl-radius: 12px;
	--nbl-radius-sm: 10px;
	--nbl-shadow: 0 10px 30px rgba(46, 42, 38, 0.16);
	--nbl-shadow-sm: 0 4px 14px rgba(46, 42, 38, 0.12);
	--nbl-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
		"Helvetica Neue", Arial, sans-serif;
}

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

/* =========================================================================
   2. Кнопка-кружок (~50px, терракот, справа снизу)
   ========================================================================= */
.nbl-chat__fab {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99990;
	width: 56px;
	height: 56px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--nbl-terracotta);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--nbl-shadow);
	transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
	-webkit-tap-highlight-color: transparent;
}

.nbl-chat__fab:hover {
	background: var(--nbl-terracotta-dark);
	transform: translateY(-2px);
	box-shadow: 0 14px 34px rgba(196, 85, 45, 0.32);
}

.nbl-chat__fab:active {
	transform: translateY(0) scale(0.96);
}

.nbl-chat__fab:focus-visible {
	outline: 3px solid rgba(224, 120, 86, 0.45);
	outline-offset: 2px;
}

/* Иконка чата и крестик закрытия — переключаем через класс .nbl-chat--open */
.nbl-chat__fab-icon,
.nbl-chat__fab-close {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.nbl-chat__fab-icon svg {
	width: 26px;
	height: 26px;
	display: block;
}

.nbl-chat__fab-close {
	opacity: 0;
	transform: rotate(-45deg) scale(0.6);
}

.nbl-chat__fab-close svg {
	width: 20px;
	height: 20px;
}

.nbl-chat--open .nbl-chat__fab-icon {
	opacity: 0;
	transform: rotate(45deg) scale(0.6);
}

.nbl-chat--open .nbl-chat__fab-close {
	opacity: 1;
	transform: rotate(0) scale(1);
}

/* Пульсирующее кольцо-подсказка (только пока панель закрыта) */
.nbl-chat__ping {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 2px solid var(--nbl-terracotta-soft);
	animation: nbl-ping 2.6s ease-out infinite;
	pointer-events: none;
}

.nbl-chat--open .nbl-chat__ping {
	display: none;
}

@keyframes nbl-ping {
	0%   { transform: scale(1); opacity: 0.7; }
	70%  { transform: scale(1.55); opacity: 0; }
	100% { transform: scale(1.55); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.nbl-chat__ping { animation: none; display: none; }
	.nbl-chat__fab { transition: none; }
}

/* =========================================================================
   3. Панель чата (десктоп 380×560, крем)
   ========================================================================= */
.nbl-chat__panel {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99991;
	width: 380px;
	height: 560px;
	max-height: calc(100vh - 40px);
	display: flex;
	flex-direction: column;
	background: var(--nbl-cream);
	border: 1px solid var(--nbl-line);
	border-radius: 16px;
	box-shadow: var(--nbl-shadow);
	overflow: hidden;
	transform-origin: bottom right;
	opacity: 0;
	transform: translateY(12px) scale(0.96);
	pointer-events: none;
	visibility: hidden;
	transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.nbl-chat--open .nbl-chat__panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
	visibility: visible;
}

/* =========================================================================
   4. Шапка панели
   ========================================================================= */
.nbl-chat__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--nbl-terracotta) 0%, var(--nbl-terracotta-dark) 100%);
	color: #fff;
	flex: 0 0 auto;
}

.nbl-chat__avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.18);
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
}

.nbl-chat__avatar svg {
	width: 22px;
	height: 22px;
}

.nbl-chat__header-text {
	flex: 1;
	min-width: 0;
}

.nbl-chat__title {
	margin: 0;
	font-size: 1rem;
	font-weight: 700;
	line-height: 1.2;
}

.nbl-chat__subtitle {
	margin: 2px 0 0;
	font-size: 0.78rem;
	opacity: 0.9;
	line-height: 1.3;
}

.nbl-chat__close {
	width: 32px;
	height: 32px;
	flex: 0 0 auto;
	border: none;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.14);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease;
}

.nbl-chat__close:hover {
	background: rgba(255, 255, 255, 0.28);
}

.nbl-chat__close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 1px;
}

.nbl-chat__close svg {
	width: 18px;
	height: 18px;
}

/* =========================================================================
   5. Лента сообщений
   ========================================================================= */
.nbl-chat__messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background:
		radial-gradient(circle at 15% 10%, rgba(224, 120, 86, 0.05), transparent 40%),
		radial-gradient(circle at 85% 90%, rgba(224, 120, 86, 0.04), transparent 40%),
		var(--nbl-cream);
	scroll-behavior: smooth;
}

.nbl-chat__msg {
	max-width: 82%;
	padding: 10px 13px;
	font-size: 0.92rem;
	line-height: 1.45;
	border-radius: var(--nbl-radius);
	word-wrap: break-word;
	animation: nbl-msg-in 0.22s ease both;
}

@keyframes nbl-msg-in {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: translateY(0); }
}

.nbl-chat__msg--bot {
	align-self: flex-start;
	background: #fff;
	border: 1px solid var(--nbl-line);
	border-bottom-left-radius: 4px;
	color: var(--nbl-ink);
}

.nbl-chat__msg--user {
	align-self: flex-end;
	background: var(--nbl-terracotta);
	border-bottom-right-radius: 4px;
	color: #fff;
}

.nbl-chat__msg--typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 12px 16px;
}

.nbl-chat__msg--typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--nbl-muted);
	animation: nbl-blink 1.2s infinite both;
}

.nbl-chat__msg--typing span:nth-child(2) { animation-delay: 0.2s; }
.nbl-chat__msg--typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes nbl-blink {
	0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-3px); }
}

/* =========================================================================
   6. Дисклеймер приватности
   ========================================================================= */
.nbl-chat__disclaimer {
	flex: 0 0 auto;
	padding: 9px 16px;
	font-size: 0.74rem;
	line-height: 1.4;
	color: var(--nbl-muted);
	text-align: center;
	background: var(--nbl-cream-2);
	border-top: 1px solid var(--nbl-line);
}

.nbl-chat__disclaimer a {
	color: var(--nbl-terracotta-dark);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.nbl-chat__disclaimer a:hover {
	color: var(--nbl-terracotta);
}

/* =========================================================================
   7. Нижняя панель: input + кнопки
   ========================================================================= */
.nbl-chat__composer {
	flex: 0 0 auto;
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--nbl-line);
	background: var(--nbl-cream);
}

.nbl-chat__input-row {
	display: flex;
	gap: 8px;
	align-items: flex-end;
}

.nbl-chat__input {
	flex: 1;
	min-height: 44px;
	max-height: 120px;
	padding: 11px 13px;
	font-size: 0.95rem;
	font-family: var(--nbl-font);
	color: var(--nbl-ink);
	background: #fff;
	border: 1px solid var(--nbl-line);
	border-radius: var(--nbl-radius-sm);
	resize: none;
	line-height: 1.4;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.nbl-chat__input::placeholder {
	color: var(--nbl-muted);
}

.nbl-chat__input:focus {
	outline: none;
	border-color: var(--nbl-terracotta);
	box-shadow: 0 0 0 3px rgba(224, 120, 86, 0.15);
}

.nbl-chat__send {
	width: 44px;
	height: 44px;
	flex: 0 0 auto;
	border: none;
	border-radius: var(--nbl-radius-sm);
	background: var(--nbl-terracotta);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease, transform 0.05s ease;
}

.nbl-chat__send:hover {
	background: var(--nbl-terracotta-dark);
}

.nbl-chat__send:active {
	transform: translateY(1px);
}

.nbl-chat__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.nbl-chat__send:focus-visible {
	outline: 3px solid rgba(224, 120, 86, 0.45);
	outline-offset: 1px;
}

.nbl-chat__send svg {
	width: 20px;
	height: 20px;
}

/* Кнопка «Оставить заявку» (лид) */
.nbl-chat__lead {
	width: 100%;
	padding: 12px 14px;
	font-size: 0.95rem;
	font-weight: 700;
	color: var(--nbl-terracotta-dark);
	background: var(--nbl-cream-2);
	border: 1.5px solid var(--nbl-terracotta);
	border-radius: var(--nbl-radius-sm);
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.nbl-chat__lead:hover {
	background: var(--nbl-terracotta);
	color: #fff;
}

.nbl-chat__lead:focus-visible {
	outline: 3px solid rgba(224, 120, 86, 0.45);
	outline-offset: 1px;
}

/* =========================================================================
   8. Быстрые подсказки (чипы) и предложение оператора
   ========================================================================= */
.nbl-chat__chips {
	display: none;
	flex-wrap: wrap;
	gap: 6px;
	padding: 2px 0;
	align-self: flex-start;
	max-width: 100%;
}

.nbl-chat__chips--visible {
	display: flex;
}

.nbl-chat__chip {
	padding: 7px 13px;
	font-size: 0.82rem;
	font-weight: 600;
	line-height: 1.2;
	color: var(--nbl-ink);
	background: var(--nbl-cream-2);
	border: 1px solid var(--nbl-line);
	border-radius: 999px;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
	-webkit-tap-highlight-color: transparent;
}

.nbl-chat__chip:hover {
	background: #fff;
	border-color: var(--nbl-terracotta-soft);
	color: var(--nbl-terracotta-dark);
}

.nbl-chat__chip:focus-visible {
	outline: 3px solid rgba(224, 120, 86, 0.45);
	outline-offset: 1px;
}

.nbl-chat__chip--lead {
	color: #fff;
	background: var(--nbl-terracotta);
	border-color: var(--nbl-terracotta);
}

.nbl-chat__chip--lead:hover {
	background: var(--nbl-terracotta-dark);
	border-color: var(--nbl-terracotta-dark);
	color: #fff;
}

/* Сообщение-предложение: «передать вопрос оператору» */
.nbl-chat__msg--suggest {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px 13px;
}

.nbl-chat__suggest-text {
	margin: 0;
	font-size: 0.92rem;
	line-height: 1.45;
}

.nbl-chat__suggest-btn {
	align-self: flex-start;
	padding: 8px 14px;
	font-size: 0.85rem;
	font-weight: 700;
	color: var(--nbl-terracotta-dark);
	background: transparent;
	border: 1.5px solid var(--nbl-terracotta);
	border-radius: var(--nbl-radius-sm);
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.nbl-chat__suggest-btn:hover {
	background: var(--nbl-terracotta-soft);
	color: var(--nbl-terracotta-dark);
}

.nbl-chat__suggest-btn:focus-visible {
	outline: 3px solid rgba(224, 120, 86, 0.45);
	outline-offset: 1px;
}

/* =========================================================================
   9. Мобильный: fullscreen bottom sheet + visualViewport
   ========================================================================= */
@media (max-width: 480px) {
	.nbl-chat__fab {
		right: 14px;
		bottom: 14px;
	}

	.nbl-chat__panel {
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100%;
		max-height: none;
		border-radius: 0;
		border: none;
		transform: translateY(100%);
		transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
	}

	.nbl-chat--open .nbl-chat__panel {
		transform: translateY(0);
	}
}

/* Коррекция высоты под виртуальную клавиатуру (iOS Safari) —
   задаётся из JS через visualViewport. */
.nbl-chat--keyboard .nbl-chat__panel {
	height: calc(var(--nbl-vh, 100vh) - var(--nbl-vv-offset, 0px));
	transform: translateY(0);
}
