/*
	Виджет «Умный помощник» для stom24. Визуальный макет.

	Палитра из ТЗ: #E0F2FE — фон, #0EA5E9 — акцент, #FFFFFF — карточки.
	Всё в отдельном пространстве имён .s24w-*, чтобы не пересекаться со
	стилями сайта (на сайте есть глобальные правила вида `.row a { }`).
	Зависимостей нет: ни jQuery, ни иконочных шрифтов, иконки — inline SVG.
*/

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

.s24w {
	--s24w-bg: #e0f2fe;
	--s24w-accent: #0ea5e9;
	--s24w-accent-dark: #0284c7;
	--s24w-card: #ffffff;
	--s24w-text: #0f2431;
	--s24w-muted: #6b8296;
	--s24w-line: #d8e9f5;
	--s24w-danger: #e8453c;
	--s24w-radius: 14px;
	--s24w-shadow: 0 18px 44px rgba(9, 45, 66, .18);

	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 99999;
	font-family: "ProximaNova", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
	color: var(--s24w-text);
}

/* ---------- кнопка запуска ---------- */
.s24w__launcher {
	display: flex;
	align-items: center;
	gap: 10px;
	height: 60px;
	padding: 0 22px 0 16px;
	border: none;
	border-radius: 30px;
	background: var(--s24w-accent);
	color: #fff;
	font-family: inherit;
	font-size: 16px;
	font-weight: 700;
	cursor: pointer;
	box-shadow: var(--s24w-shadow);
	transition: background-color .15s ease, transform .15s ease;
}
.s24w__launcher:hover { background: var(--s24w-accent-dark); }
.s24w__launcher:active { transform: scale(.97); }
.s24w__launcher svg { width: 26px; height: 26px; flex: none; }
.s24w__launcher-dot {
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: #34d399;
	box-shadow: 0 0 0 0 rgba(52, 211, 153, .7);
	animation: s24w-pulse 2.4s infinite;
}
@keyframes s24w-pulse {
	0%   { box-shadow: 0 0 0 0 rgba(52, 211, 153, .7); }
	70%  { box-shadow: 0 0 0 9px rgba(52, 211, 153, 0); }
	100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}
.s24w.is-open .s24w__launcher { display: none; }

/* ---------- панель ---------- */
.s24w__panel {
	display: none;
	flex-direction: column;
	/*
		width без min-width: 0 не держит панель: сетка категорий считает свой
		min-content по самой длинной надписи («Пародонтология»), и панель
		разъезжается за пределы экрана, потому что контейнер прижат к right.
	*/
	width: 440px;
	min-width: 0;
	max-width: calc(100vw - 48px);
	height: 580px;
	max-height: calc(100vh - 48px);
	background: var(--s24w-bg);
	border-radius: var(--s24w-radius);
	box-shadow: var(--s24w-shadow);
	overflow: hidden;
}
.s24w.is-open .s24w__panel {
	display: flex;
	animation: s24w-in .18s ease-out;
}
@keyframes s24w-in {
	from { opacity: 0; transform: translateY(12px); }
	to   { opacity: 1; transform: none; }
}

/* ---------- шапка ---------- */
.s24w__head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	background: var(--s24w-card);
	border-bottom: 1px solid var(--s24w-line);
	flex: none;
}
.s24w__back {
	display: none;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	flex: none;
	border: 1px solid var(--s24w-line);
	border-radius: 9px;
	background: #fff;
	color: var(--s24w-accent);
	cursor: pointer;
	padding: 0;
}
.s24w__back:hover { background: var(--s24w-bg); }
.s24w__back svg { width: 17px; height: 17px; }
.s24w.can-back .s24w__back { display: inline-flex; }

.s24w__avatar {
	width: 38px;
	height: 38px;
	flex: none;
	border-radius: 50%;
	background: var(--s24w-bg);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--s24w-accent);
}
.s24w__avatar svg { width: 22px; height: 22px; }
.s24w__title { flex: 1 1 auto; min-width: 0; }
.s24w__title b {
	display: block;
	font-size: 15px;
	font-weight: 700;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.s24w__status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12.5px;
	color: var(--s24w-muted);
}
.s24w__status::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #34d399;
	flex: none;
}
.s24w__close {
	width: 34px;
	height: 34px;
	flex: none;
	border: none;
	border-radius: 9px;
	background: transparent;
	color: var(--s24w-muted);
	cursor: pointer;
	font-size: 22px;
	line-height: 1;
	padding: 0;
}
.s24w__close:hover { background: var(--s24w-bg); color: var(--s24w-text); }

/* ---------- лента диалога ---------- */
.s24w__body {
	flex: 1 1 auto;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 16px 14px 6px;
	scroll-behavior: smooth;
}
.s24w__msg {
	display: flex;
	gap: 8px;
	margin-bottom: 12px;
	animation: s24w-msg .2s ease-out;
}
@keyframes s24w-msg {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: none; }
}
.s24w__msg-avatar {
	width: 30px;
	height: 30px;
	flex: none;
	border-radius: 50%;
	background: var(--s24w-card);
	color: var(--s24w-accent);
	display: flex;
	align-items: center;
	justify-content: center;
	align-self: flex-end;
}
.s24w__msg-avatar svg { width: 17px; height: 17px; }
.s24w__bubble {
	max-width: 84%;
	padding: 10px 13px;
	border-radius: 14px 14px 14px 4px;
	background: var(--s24w-card);
	border: 1px solid var(--s24w-line);
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
.s24w__msg--user { justify-content: flex-end; }
.s24w__msg--user .s24w__bubble {
	background: var(--s24w-accent);
	border-color: var(--s24w-accent);
	color: #fff;
	border-radius: 14px 14px 4px 14px;
}
.s24w__bubble a { color: inherit; }

/* индикатор набора текста */
.s24w__typing {
	display: inline-flex;
	gap: 4px;
	padding: 4px 2px;
}
.s24w__typing i {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--s24w-muted);
	opacity: .45;
	animation: s24w-dot 1.1s infinite;
}
.s24w__typing i:nth-child(2) { animation-delay: .16s; }
.s24w__typing i:nth-child(3) { animation-delay: .32s; }
@keyframes s24w-dot {
	0%, 60%, 100% { transform: none; opacity: .35; }
	30%           { transform: translateY(-4px); opacity: .9; }
}

/* ---------- варианты ответа ---------- */
.s24w__options {
	display: grid;
	/* minmax(0, 1fr), иначе колонка не может стать уже своего содержимого */
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 8px;
	padding: 0 14px 12px;
	flex: none;
	min-width: 0;
}
.s24w__options--single { grid-template-columns: minmax(0, 1fr); }
.s24w__opt {
	display: flex;
	align-items: center;
	/* иконка и отступы ужаты: «Пародонтология» должна помещаться в колонку
	   шириной 176px, иначе слово уходит в перенос даже с дефисом */
	gap: 8px;
	min-height: 48px;
	padding: 9px 10px;
	border: 1px solid var(--s24w-line);
	border-radius: 11px;
	background: var(--s24w-card);
	color: var(--s24w-text);
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.25;
	text-align: left;
	cursor: pointer;
	min-width: 0;
	transition: border-color .15s ease, background-color .15s ease, transform .1s ease;
}
/*
	Перенос только по слогам. overflow-wrap: anywhere здесь стоять не должен:
	он рвёт слово в произвольном месте, и «Пародонтология» переносилась
	последней буквой на отдельную строку. hyphens: auto ставит дефис по
	правилам языка, поэтому корню виджета в JS проставляется lang="ru".
*/
.s24w__opt > span:not(.s24w__opt-icon) {
	min-width: 0;
	-webkit-hyphens: auto;
	-ms-hyphens: auto;
	hyphens: auto;
	hyphenate-limit-chars: 8 4 4;   /* не переносить огрызками короче 4 букв */
	word-break: normal;
}
.s24w__opt:hover { border-color: var(--s24w-accent); background: #f3fbff; }
.s24w__opt:active { transform: scale(.985); }
.s24w__opt-icon {
	width: 28px;
	height: 28px;
	flex: none;
	border-radius: 8px;
	background: var(--s24w-bg);
	color: var(--s24w-accent);
	display: flex;
	align-items: center;
	justify-content: center;
}
.s24w__opt-icon svg { width: 19px; height: 19px; }
.s24w__opt--primary {
	background: var(--s24w-accent);
	border-color: var(--s24w-accent);
	color: #fff;
	justify-content: center;
}
.s24w__opt--primary:hover { background: var(--s24w-accent-dark); border-color: var(--s24w-accent-dark); }
.s24w__opt--phone {
	justify-content: center;
	color: var(--s24w-accent);
	text-decoration: none;
}

/* ---------- форма контактов ---------- */
.s24w__form {
	padding: 0 14px 12px;
	display: grid;
	gap: 8px;
	flex: none;
}
.s24w__field { display: grid; gap: 4px; }
.s24w__input {
	width: 100%;
	min-height: 48px;
	padding: 11px 13px;
	border: 1px solid var(--s24w-line);
	border-radius: 11px;
	background: var(--s24w-card);
	font-family: inherit;
	font-size: 16px;              /* 16px — иначе iOS зумит страницу при фокусе */
	color: var(--s24w-text);
}
.s24w__input:focus {
	outline: none;
	border-color: var(--s24w-accent);
	box-shadow: 0 0 0 3px rgba(14, 165, 233, .16);
}
.s24w__input.is-error { border-color: var(--s24w-danger); }
.s24w__error {
	font-size: 12.5px;
	color: var(--s24w-danger);
	min-height: 0;
}
.s24w__note {
	font-size: 12px;
	line-height: 1.4;
	color: var(--s24w-muted);
}
.s24w__note a { color: var(--s24w-accent); }

/* ---------- нижняя строка ввода ---------- */
.s24w__foot {
	display: flex;
	gap: 8px;
	padding: 10px 14px;
	background: var(--s24w-card);
	border-top: 1px solid var(--s24w-line);
	flex: none;
}
.s24w__text {
	flex: 1 1 auto;
	min-width: 0;
	min-height: 44px;
	max-height: 96px;
	padding: 11px 13px;
	border: 1px solid var(--s24w-line);
	border-radius: 11px;
	background: #fff;
	font-family: inherit;
	font-size: 16px;
	line-height: 1.3;
	resize: none;
	color: var(--s24w-text);
}
.s24w__text:focus {
	outline: none;
	border-color: var(--s24w-accent);
}
.s24w__send {
	width: 44px;
	height: 44px;
	flex: none;
	align-self: flex-end;
	border: none;
	border-radius: 11px;
	background: var(--s24w-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
}
.s24w__send:hover { background: var(--s24w-accent-dark); }
.s24w__send svg { width: 19px; height: 19px; }

.s24w__restart {
	border: none;
	background: none;
	padding: 0;
	color: var(--s24w-accent);
	font: inherit;
	font-size: 13px;
	cursor: pointer;
	text-decoration: underline dashed;
	text-underline-offset: 3px;
}

/* ---------- мобильный ---------- */
@media (max-width: 600px) {
	.s24w { right: 12px; bottom: 12px; left: 12px; }
	.s24w__launcher { margin-left: auto; }

	.s24w__panel {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100%;
		/* max-width задан выше для десктопа (панель у правого края не должна
		   вылезать за экран); в полноэкранном мобильном режиме он оставлял
		   пустую полосу 48px справа — снимаем оба ограничения */
		max-width: none;
		max-height: none;
		border-radius: 0;
	}
	/* кнопки на 100% ширины — требование ТЗ */
	.s24w__options { grid-template-columns: 1fr; }
	.s24w__opt { min-height: 50px; font-size: 15px; }
	.s24w__body { padding-bottom: 4px; }
}

@media (prefers-reduced-motion: reduce) {
	.s24w *,
	.s24w *::before,
	.s24w *::after {
		animation-duration: .001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: .001ms !important;
	}
	.s24w__body { scroll-behavior: auto; }
}

/* блокировка прокрутки страницы под открытым чатом на мобильном */
html.s24w-lock,
html.s24w-lock body {
	overflow: hidden;
	height: 100%;
}
