/**
 * Онлайн-библиотекарь — стили виджета чата
 *
 * Переменные: --lc-accent (акцентный цвет задаётся из админки)
 */

:root {
	--lc-accent: #1a7f37;
	--lc-accent-dark: #146b2e;
	--lc-bg: #ffffff;
	--lc-text: #1f2933;
	--lc-muted: #7b8794;
	--lc-border: #e4e7eb;
	--lc-bot-bubble: #f0f4f8;
	--lc-user-bubble: var(--lc-accent);
	--lc-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
	--lc-radius: 14px;
}

/* ============================================================
 * КОНТЕЙНЕР
 * ============================================================ */

.lc-chat {
	position: fixed;
	bottom: 24px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	font-size: 14px;
	line-height: 1.5;
	color: var(--lc-text);
	-webkit-font-smoothing: antialiased;
}

.lc-chat--right { right: 24px; }
.lc-chat--left { left: 24px; }

.lc-chat * {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

/* ============================================================
 * КНОПКА ОТКРЫТИЯ
 * ============================================================ */

.lc-chat__toggle {
	position: relative;
	display: flex;
	align-items: center;
	gap: 10px;
	border: none;
	cursor: pointer;
	background: var(--lc-accent);
	color: #fff;
	padding: 12px 18px;
	border-radius: 40px;
	box-shadow: var(--lc-shadow);
	font-size: 14px;
	font-weight: 600;
	transition: background 0.2s, transform 0.2s;
}

.lc-chat__toggle:hover {
	background: var(--lc-accent-dark);
	transform: translateY(-2px);
}

.lc-chat__toggle-icon { font-size: 22px; line-height: 1; }
.lc-chat__toggle-close { display: none; font-size: 16px; }

.lc-chat--open .lc-chat__toggle-icon,
.lc-chat--open .lc-chat__toggle-label { display: none; }
.lc-chat--open .lc-chat__toggle-close { display: inline; }

.lc-chat__pulse {
	position: absolute;
	top: -4px;
	right: -4px;
	width: 14px;
	height: 14px;
	background: #ff5252;
	border: 2px solid #fff;
	border-radius: 50%;
	animation: lc-pulse 1.8s infinite;
}

@keyframes lc-pulse {
	0% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.6); }
	70% { box-shadow: 0 0 0 10px rgba(255, 82, 82, 0); }
	100% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0); }
}

/* ============================================================
 * ОКНО ЧАТА
 * ============================================================ */

.lc-chat__window {
	display: none;
	flex-direction: column;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 120px);
	background: var(--lc-bg);
	border-radius: var(--lc-radius);
	box-shadow: var(--lc-shadow);
	overflow: hidden;
	margin-bottom: 12px;
	border: 1px solid var(--lc-border);
}

.lc-chat--open .lc-chat__window {
	display: flex;
	animation: lc-slide-up 0.25s ease;
}

@keyframes lc-slide-up {
	from { opacity: 0; transform: translateY(16px); }
	to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
 * ШАПКА
 * ============================================================ */

.lc-chat__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: var(--lc-accent);
	color: #fff;
	flex: 0 0 auto;
}

.lc-chat__avatar {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.18);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 22px;
	flex: 0 0 auto;
}

.lc-chat__titles { flex: 1 1 auto; min-width: 0; }

.lc-chat__name {
	font-weight: 700;
	font-size: 15px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.lc-chat__status {
	font-size: 12px;
	opacity: 0.92;
	display: flex;
	align-items: center;
	gap: 5px;
}

.lc-chat__dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #7CFC9A;
	display: inline-block;
	animation: lc-blink 1.4s infinite;
}

@keyframes lc-blink {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.4; }
}

.lc-chat__close {
	border: none;
	background: rgba(255, 255, 255, 0.15);
	color: #fff;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	cursor: pointer;
	font-size: 14px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s;
}

.lc-chat__close:hover { background: rgba(255, 255, 255, 0.3); }

/* ============================================================
 * ЛЕНТА СООБЩЕНИЙ
 * ============================================================ */

.lc-chat__body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: #fafbfc;
	scroll-behavior: smooth;
}

.lc-msg {
	display: flex;
	flex-direction: column;
	max-width: 85%;
}

.lc-msg--bot { align-self: flex-start; }
.lc-msg--user { align-self: flex-end; }

.lc-msg__bubble {
	padding: 10px 14px;
	border-radius: 14px;
	word-break: break-word;
	white-space: pre-wrap;
	font-size: 14px;
}

.lc-msg--bot .lc-msg__bubble {
	background: var(--lc-bot-bubble);
	border-bottom-left-radius: 4px;
}

.lc-msg--user .lc-msg__bubble {
	background: var(--lc-user-bubble);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.lc-msg__time {
	font-size: 11px;
	color: var(--lc-muted);
	margin-top: 3px;
	padding: 0 4px;
}

.lc-msg--user .lc-msg__time { text-align: right; }

/* Индикатор «печатает…» */
.lc-typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 12px 14px;
}

.lc-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--lc-muted);
	animation: lc-typing-dot 1.2s infinite;
}

.lc-typing span:nth-child(2) { animation-delay: 0.15s; }
.lc-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes lc-typing-dot {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-5px); opacity: 1; }
}

/* Ссылки в ответах */
.lc-msg__bubble a {
	color: var(--lc-accent-dark);
	text-decoration: underline;
	word-break: break-all;
}

.lc-msg--user .lc-msg__bubble a { color: #fff; }

/* ============================================================
 * БЫСТРЫЕ КНОПКИ
 * ============================================================ */

.lc-chat__chips {
	flex: 0 0 auto;
	display: none;
	flex-direction: column;
	gap: 4px;
	padding: 8px 12px 10px;
	border-top: 1px solid var(--lc-border);
	background: #fff;
}

.lc-chat__chips-title {
	font-size: 11.5px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.4px;
	color: var(--lc-muted);
	padding: 2px 2px 4px;
	flex: 0 0 auto;
}

.lc-chat__chips-list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	max-height: 200px;
	overflow-y: auto;
	padding-right: 4px;
	scrollbar-width: thin;
	scrollbar-color: var(--lc-border) transparent;
}

.lc-chat__chips-list::-webkit-scrollbar {
	width: 5px;
}

.lc-chat__chips-list::-webkit-scrollbar-thumb {
	background: var(--lc-border);
	border-radius: 4px;
}

.lc-chat__chips-list::-webkit-scrollbar-track {
	background: transparent;
}

.lc-chat__chip {
	border: 1px solid var(--lc-accent);
	background: #fff;
	color: var(--lc-accent-dark);
	border-radius: 16px;
	padding: 5px 12px;
	font-size: 12.5px;
	cursor: pointer;
	transition: all 0.2s;
	line-height: 1.4;
}

.lc-chat__chip:hover {
	background: var(--lc-accent);
	color: #fff;
}

/* ============================================================
 * ФОРМА ОПЕРАТОРУ
 * ============================================================ */

.lc-chat__form {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	background: #fafbfc;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.lc-chat__form[hidden] { display: none; }

.lc-chat__form h4 { font-size: 15px; color: var(--lc-text); }
.lc-chat__form-note { font-size: 13px; color: var(--lc-muted); }

.lc-chat__form label {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 13px;
	color: var(--lc-muted);
}

.lc-chat__form input,
.lc-chat__form textarea {
	border: 1px solid var(--lc-border);
	border-radius: 8px;
	padding: 9px 11px;
	font-size: 14px;
	font-family: inherit;
	color: var(--lc-text);
	background: #fff;
	resize: vertical;
}

.lc-chat__form input:focus,
.lc-chat__form textarea:focus {
	outline: none;
	border-color: var(--lc-accent);
	box-shadow: 0 0 0 3px rgba(26, 127, 55, 0.15);
}

/* ============================================================
 * ВВОД
 * ============================================================ */

.lc-chat__input-row {
	flex: 0 0 auto;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--lc-border);
	background: #fff;
}

.lc-chat__input {
	flex: 1 1 auto;
	border: 1px solid var(--lc-border);
	border-radius: 20px;
	padding: 9px 14px;
	font-size: 14px;
	font-family: inherit;
	color: var(--lc-text);
	resize: none;
	max-height: 96px;
	line-height: 1.45;
	background: #fff;
}

.lc-chat__input:focus {
	outline: none;
	border-color: var(--lc-accent);
	box-shadow: 0 0 0 3px rgba(26, 127, 55, 0.15);
}

.lc-chat__input::placeholder { color: #9aa5b1; }

.lc-chat__send {
	border: none;
	background: var(--lc-accent);
	color: #fff;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	cursor: pointer;
	font-size: 16px;
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s, transform 0.2s;
}

.lc-chat__send:hover {
	background: var(--lc-accent-dark);
	transform: scale(1.05);
}

.lc-chat__send:disabled { opacity: 0.5; cursor: not-allowed; }

.lc-chat__send--primary {
	width: 100%;
	height: auto;
	border-radius: 8px;
	padding: 11px;
	font-size: 14px;
	font-weight: 600;
}

.lc-chat__back {
	border: none;
	background: none;
	color: var(--lc-muted);
	cursor: pointer;
	font-size: 13px;
	align-self: flex-start;
}

.lc-chat__back:hover { color: var(--lc-text); }

/* ============================================================
 * АДАПТИВНОСТЬ
 * ============================================================ */

@media (max-width: 480px) {
	.lc-chat { bottom: 12px; }
	.lc-chat--right { right: 12px; }
	.lc-chat--left { left: 12px; }

	.lc-chat__toggle-label { display: none; }
	.lc-chat__toggle { padding: 12px; border-radius: 50%; }

	.lc-chat__window {
		width: 100vw;
		max-width: 100vw;
		height: 100dvh;
		max-height: 100dvh;
		border-radius: 0;
		margin: 0;
		border: none;
	}

	.lc-chat--open .lc-chat__window {
		animation: none;
	}
}

/* Уважение к настройкам доступности */
@media (prefers-reduced-motion: reduce) {
	.lc-chat__pulse,
	.lc-chat__dot,
	.lc-typing span {
		animation: none;
	}
	.lc-chat--open .lc-chat__window { animation: none; }
}