/* Кнопка «Чат с менеджером» и окно переписки на NOUT.KG и ULTRA.KG (local/include/nout_chat_widget.php, js/nout-chat.js).
   ПК — кнопка-«таблетка» справа внизу, окно над ней. Телефон — круглая кнопка над нижним меню
   (и над панелью «В корзину» карточки товара), окно на весь экран.
   Правила — от корня #noutChat: работают в обоих шаблонах и сильнее общих правил темы для input/textarea.
   Цвета — переменные; ULTRA.KG (.nout-chat--s1) — фирменный красный. */

#noutChat {
	--nout-chat-blue: var(--n-blue, #0b74de);
	--nout-chat-blue-600: var(--n-blue-600, #075fc0);
	--nout-chat-navy: var(--n-navy, #0a2540);
	--nout-chat-ice: var(--n-ice, #f2f6fb);
	--nout-chat-line: var(--n-line, #dce6f2);
	--nout-chat-muted: var(--n-muted, #5b6b82);
	--nout-chat-bubble: var(--nout-chat-blue);       /* сообщения посетителя */
	--nout-chat-focus: var(--nout-chat-blue);        /* рамка поля в фокусе */
	--nout-chat-shadow: rgb(11 116 222 / 32%);       /* тень кнопки */
	--nout-chat-ring: rgb(11 116 222 / 35%);         /* обводка и «дыхание» кнопки */
	position: fixed;
	right: max(24px, env(safe-area-inset-right, 0px));
	bottom: calc(var(--nout-chat-bottom, 0px) + 24px);
	z-index: 1250;
	font: 14px/1.45 robotoregular, Roboto, Arial, sans-serif;
	color: var(--n-text, #0d1b2e);
}
/* ULTRA.KG: красный — кнопка и отправка; сообщения посетителя и рамка поля — графит, чтобы не путать с ошибкой */
#noutChat.nout-chat--s1 {
	--nout-chat-blue: #ed1c24;
	--nout-chat-blue-600: #c8141b;
	--nout-chat-navy: #2b2b2b;
	--nout-chat-ice: #f5f5f5;
	--nout-chat-line: #e3e3e3;
	--nout-chat-muted: #6f6f6f;
	--nout-chat-bubble: #2b2b2b;
	--nout-chat-focus: #2b2b2b;
	--nout-chat-shadow: rgb(237 28 36 / 30%);
	--nout-chat-ring: rgb(237 28 36 / 35%);
	color: #1a1a1a;
}
#noutChat *, #noutChat *::before, #noutChat *::after { box-sizing: border-box; }
#noutChat [hidden] { display: none !important; }

/* Кнопка */
#noutChat .nout-chat__fab {
	position: relative;
	display: inline-flex; align-items: center; gap: 10px;
	height: 52px; padding: 0 20px 0 16px;
	border: 0; border-radius: 999px;
	background: var(--nout-chat-blue); color: #fff;
	font: 15px/1 robotomedium, robotobold, Arial, sans-serif;
	box-shadow: 0 12px 28px var(--nout-chat-shadow);
	cursor: pointer;
	transition: background-color .15s ease, transform .15s ease;
}
#noutChat .nout-chat__fab:hover { background: var(--nout-chat-blue-600); }
#noutChat .nout-chat__fab:active { transform: scale(.97); }
#noutChat .nout-chat__fab:focus-visible { outline: 3px solid var(--nout-chat-ring); outline-offset: 3px; }
#noutChat .nout-chat__fab .nout-icon { width: 24px; height: 24px; }
#noutChat.is-open .nout-chat__fab { display: none; }
#noutChat .nout-chat__badge {
	position: absolute; top: -4px; right: -4px;
	min-width: 22px; height: 22px; padding: 0 6px;
	border: 2px solid #fff; border-radius: 999px;
	background: #e5484d; color: #fff;
	font: 12px/18px robotobold, Arial, sans-serif; text-align: center;
}

/* Есть непрочитанный ответ — кнопка мягко «дышит», число пульсирует */
#noutChat.has-unread .nout-chat__fab { animation: noutChatGlow 2.4s ease-in-out infinite; }
#noutChat.has-unread .nout-chat__badge { animation: noutChatPulse 2.4s ease-in-out infinite; }
@keyframes noutChatGlow {
	0%, 100% { box-shadow: 0 12px 28px var(--nout-chat-shadow), 0 0 0 0 var(--nout-chat-ring); }
	50% { box-shadow: 0 12px 28px var(--nout-chat-shadow), 0 0 0 10px transparent; }
}
@keyframes noutChatPulse {
	0%, 100% { transform: scale(1); }
	50% { transform: scale(1.15); }
}

/* Превью нового ответа над кнопкой */
#noutChat .nout-chat__preview {
	position: absolute; right: 0; bottom: calc(100% + 12px);
	display: flex; align-items: flex-start;
	width: min(300px, calc(100vw - 32px));
	border: 1px solid var(--nout-chat-line); border-radius: 16px 16px 6px 16px;
	background: #fff;
	box-shadow: 0 16px 40px rgb(10 37 64 / 18%);
	animation: noutChatIn .25s ease-out;
}
#noutChat.is-open .nout-chat__preview { display: none; }
#noutChat .nout-chat__preview-body {
	display: grid; gap: 2px; flex: 1 1 auto; min-width: 0;
	padding: 12px 4px 12px 14px;
	border: 0; background: none; color: var(--n-text, #0d1b2e);
	font: 14px/1.4 robotoregular, Roboto, Arial, sans-serif; text-align: left; cursor: pointer;
}
#noutChat .nout-chat__preview-body b { color: var(--nout-chat-blue); font: 13px/1.3 robotomedium, robotobold, Arial, sans-serif; }
#noutChat .nout-chat__preview-body span { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow-wrap: anywhere; }
#noutChat .nout-chat__preview-close {
	flex: 0 0 auto; width: 32px; height: 32px; margin: 6px 6px 0 0; padding: 0;
	border: 0; border-radius: 50%; background: none; color: var(--nout-chat-muted);
	font-size: 20px; line-height: 1; cursor: pointer;
}
#noutChat .nout-chat__preview-close:hover { background: var(--nout-chat-ice); }
@keyframes noutChatIn {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: none; }
}

/* Окно */
#noutChat .nout-chat__panel {
	position: absolute; right: 0; bottom: 0;
	display: flex; flex-direction: column;
	width: 380px; height: min(560px, calc(100vh - 140px));
	overflow: hidden;
	border: 1px solid var(--nout-chat-line); border-radius: 18px;
	background: #fff;
	box-shadow: 0 24px 60px rgb(10 37 64 / 22%);
}
#noutChat .nout-chat__head {
	display: flex; align-items: center; gap: 12px;
	padding: 14px 12px 14px 16px;
	background: var(--nout-chat-navy); color: #fff;
}
#noutChat .nout-chat__avatar {
	display: grid; place-items: center; flex: 0 0 auto;
	width: 40px; height: 40px; border-radius: 50%;
	background: rgb(255 255 255 / 14%);
}
#noutChat .nout-chat__avatar .nout-icon { width: 22px; height: 22px; }
#noutChat .nout-chat__head-text { display: grid; min-width: 0; flex: 1 1 auto; }
#noutChat .nout-chat__head-text b { font: 16px/1.25 robotobold, Arial, sans-serif; }
#noutChat .nout-chat__head-text small { overflow: hidden; color: rgb(255 255 255 / 72%); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
/* WhatsApp — зелёная «таблетка» в шапке, на любом сайте одного цвета (узнаваемый цвет WhatsApp) */
#noutChat .nout-chat__wa {
	display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
	height: 34px; padding: 0 12px 0 9px;
	border-radius: 999px;
	background: #25d366; color: #fff;
	font: 13px/1 robotomedium, robotobold, Arial, sans-serif;
	text-decoration: none;
	transition: background-color .15s ease;
}
#noutChat .nout-chat__wa:hover, #noutChat .nout-chat__wa:focus-visible { background: #1da851; color: #fff; text-decoration: none; }
#noutChat .nout-chat__wa:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#noutChat .nout-chat__wa .nout-icon { width: 18px; height: 18px; }
/* С кнопкой WhatsApp значок чата в шапке убираем — иначе «Чат с менеджером» переносится на две строки */
#noutChat .nout-chat__head--wa .nout-chat__avatar { display: none; }
#noutChat .nout-chat__head--wa .nout-chat__head-text b { white-space: nowrap; }
#noutChat .nout-chat__close {
	display: grid; place-items: center; flex: 0 0 auto;
	width: 36px; height: 36px; padding: 0;
	border: 0; border-radius: 50%;
	background: transparent; color: #fff; cursor: pointer;
}
#noutChat .nout-chat__close:hover { background: rgb(255 255 255 / 12%); }
#noutChat .nout-chat__close .nout-icon { width: 20px; height: 20px; }

/* Переписка: посетитель — справа синим, менеджер — слева серым */
#noutChat .nout-chat__log {
	display: flex; flex-direction: column; gap: 10px;
	flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
	padding: 16px;
	background: var(--nout-chat-ice);
}
#noutChat .nout-chat__msg { display: grid; gap: 3px; max-width: 85%; }
#noutChat .nout-chat__msg--in { align-self: flex-end; justify-items: end; }
#noutChat .nout-chat__msg--out { align-self: flex-start; justify-items: start; }
#noutChat .nout-chat__bubble {
	padding: 9px 13px;
	border-radius: 16px;
	white-space: pre-wrap; overflow-wrap: anywhere;
}
#noutChat .nout-chat__msg--in .nout-chat__bubble { border-bottom-right-radius: 6px; background: var(--nout-chat-bubble); color: #fff; }
#noutChat .nout-chat__msg--out .nout-chat__bubble { border-bottom-left-radius: 6px; background: #fff; color: var(--n-text, #0d1b2e); box-shadow: 0 1px 2px rgb(10 37 64 / 8%); }
#noutChat .nout-chat__bubble a { color: var(--nout-chat-blue); font-family: robotomedium, robotobold, Arial, sans-serif; white-space: nowrap; }
#noutChat .nout-chat__meta { padding: 0 4px; color: var(--nout-chat-muted); font-size: 11px; }
/* «Менеджер … присоединился к чату» — посередине, мелко */
#noutChat .nout-chat__msg--sys {
	align-self: center; max-width: 100%;
	padding: 4px 10px; border-radius: 999px;
	background: rgb(10 37 64 / 6%); color: var(--nout-chat-muted);
	font-size: 12px; line-height: 1.4; text-align: center;
}
#noutChat .nout-chat__msg--sys time { white-space: nowrap; opacity: .75; }

/* Ввод */
#noutChat .nout-chat__form { display: grid; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--nout-chat-line); background: #fff; }
/* Имя и телефон — с подписями над полями: подсказка внутри поля исчезает, как только начинаешь печатать */
#noutChat .nout-chat__contact { display: grid; gap: 6px; }
#noutChat .nout-chat__fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#noutChat .nout-chat__field { display: grid; gap: 4px; margin: 0; }
#noutChat .nout-chat__label { color: var(--n-text, #0d1b2e); font: 12px/1.3 robotomedium, robotobold, Arial, sans-serif; }
#noutChat .nout-chat__label--message { margin-top: 4px; }
#noutChat .nout-chat__req { color: #c62828; font-weight: normal; }
#noutChat .nout-chat__hint { margin: 0; color: var(--nout-chat-muted); font-size: 12px; line-height: 1.35; }
#noutChat .nout-chat__contact input,
#noutChat .nout-chat__compose textarea {
	width: 100%; margin: 0;
	border: 1.5px solid var(--nout-chat-line); border-radius: 12px;
	background: #fff; color: var(--n-text, #0d1b2e);
	font: 14px/1.4 robotoregular, Roboto, Arial, sans-serif;
	box-shadow: none; outline: none;
}
#noutChat .nout-chat__contact input { height: 42px; padding: 0 12px; background: var(--nout-chat-ice); }
#noutChat .nout-chat__contact input:focus { background: #fff; }
#noutChat .nout-chat__contact input[aria-invalid="true"] { border-color: #c62828; background: #fff; }
#noutChat .nout-chat__contact input[type="tel"] { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
#noutChat .nout-chat__contact input::placeholder,
#noutChat .nout-chat__compose textarea::placeholder { color: #9aa8b8; opacity: 1; }
#noutChat .nout-chat__contact input:focus,
#noutChat .nout-chat__compose textarea:focus { border-color: var(--nout-chat-focus); }
#noutChat .nout-chat__compose { display: flex; align-items: flex-end; gap: 8px; }
#noutChat .nout-chat__compose textarea { flex: 1 1 auto; min-height: 44px; max-height: 120px; padding: 11px 12px; resize: none; }
#noutChat .nout-chat__send {
	display: grid; place-items: center; flex: 0 0 auto;
	width: 44px; height: 44px; padding: 0;
	border: 0; border-radius: 12px;
	background: var(--nout-chat-blue); color: #fff; cursor: pointer;
}
#noutChat .nout-chat__send:hover { background: var(--nout-chat-blue-600); }
#noutChat .nout-chat__send svg { width: 22px; height: 22px; }
#noutChat .nout-chat__form.is-sending .nout-chat__send { opacity: .6; cursor: progress; }
#noutChat .nout-chat__trap { position: absolute !important; left: -9999px; width: 1px; height: 1px; opacity: 0; }
#noutChat .nout-chat__error { margin: 0; color: #c62828; font-size: 13px; }

/* Телефон */
@media (max-width: 768px) {
	#noutChat { right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(var(--nout-chat-bottom, 0px) + 12px); }
	#noutChat .nout-chat__fab { width: 56px; height: 56px; padding: 0; justify-content: center; }
	#noutChat .nout-chat__fab-label { display: none; }
	#noutChat.is-open { inset: 0; right: 0; bottom: 0; z-index: 1400; }
	#noutChat .nout-chat__panel {
		position: fixed; inset: 0;
		width: auto; height: 100%; height: 100dvh;
		border: 0; border-radius: 0;
		padding-top: env(safe-area-inset-top, 0px);
		padding-bottom: env(safe-area-inset-bottom, 0px);
		background: var(--nout-chat-navy);
	}
	#noutChat .nout-chat__log { padding: 14px 12px; }
	#noutChat .nout-chat__head { gap: 10px; }
	#noutChat .nout-chat__fields { grid-template-columns: 1fr; }
	/* 16px — иначе iPhone увеличивает страницу, когда ставишь курсор в поле */
	#noutChat .nout-chat__contact input,
	#noutChat .nout-chat__compose textarea { font-size: 16px; }
}

/* Очень узкий экран: у WhatsApp остаётся только значок */
@media (max-width: 359px) {
	#noutChat .nout-chat__wa { width: 34px; padding: 0; justify-content: center; }
	#noutChat .nout-chat__wa span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	#noutChat * { transition: none !important; animation: none !important; }
}
