/* ===================================
   AI-чат виджет
   =================================== */

.chat-widget {
	--cw-primary: #182968;
	--cw-primary-hover: #2f3e77;
	--cw-accent: #c72c30;
	--cw-bg: #ffffff;
	--cw-bg-soft: #f3f5fb;
	--cw-text: #24324d;
	--cw-text-muted: #5e6f8d;
	--cw-border: rgba(24, 41, 104, 0.1);
	--cw-shadow: 0 16px 48px rgba(24, 41, 104, 0.18);
	--cw-radius: 18px;
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 9000;
	font-family: "Proxima Nova", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* --- Плавающая кнопка --- */
.chat-widget__toggle {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--cw-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 12px 28px rgba(24, 41, 104, 0.32);
	transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s, background 0.25s;
	position: relative;
}

.chat-widget__toggle:hover {
	background: var(--cw-primary-hover);
	transform: translateY(-2px);
	box-shadow: 0 18px 36px rgba(24, 41, 104, 0.4);
}

.chat-widget__toggle:active {
	transform: translateY(0);
}

.chat-widget__toggle-icon {
	width: 26px;
	height: 26px;
	transition: opacity 0.2s, transform 0.2s;
}

.chat-widget__toggle-icon--close {
	position: absolute;
	opacity: 0;
	transform: rotate(-45deg);
}

.chat-widget--open .chat-widget__toggle-icon--open {
	opacity: 0;
	transform: rotate(45deg);
}

.chat-widget--open .chat-widget__toggle-icon--close {
	opacity: 1;
	transform: rotate(0);
}

/* Лёгкая пульсация для привлечения внимания (один раз при загрузке) */
.chat-widget:not(.chat-widget--open) .chat-widget__toggle::before {
	content: "";
	position: absolute;
	inset: -4px;
	border-radius: 50%;
	border: 2px solid var(--cw-primary);
	opacity: 0;
	animation: cwPulse 2.4s ease-out 1s 2;
}

@keyframes cwPulse {
	0% { opacity: 0.6; transform: scale(1); }
	100% { opacity: 0; transform: scale(1.3); }
}

/* --- Окно чата --- */
.chat-widget__panel {
	position: absolute;
	bottom: 76px;
	right: 0;
	width: 380px;
	height: 560px;
	max-height: calc(100vh - 120px);
	background: var(--cw-bg);
	border-radius: var(--cw-radius);
	box-shadow: var(--cw-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(20px) scale(0.96);
	pointer-events: none;
	transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-widget--open .chat-widget__panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: all;
}

/* --- Шапка --- */
.chat-widget__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	background: var(--cw-primary);
	color: #fff;
	flex-shrink: 0;
}

.chat-widget__header-info {
	display: flex;
	align-items: center;
	gap: 12px;
}

.chat-widget__avatar {
	width: 40px;
	height: 40px;
	border-radius: 12px;
	background: rgba(255, 255, 255, 0.15);
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	flex-shrink: 0;
}

.chat-widget__avatar svg {
	width: 22px;
	height: 22px;
}

.chat-widget__header-title {
	font-size: 15px;
	font-weight: 700;
	color: #fff;
	line-height: 1.2;
}

.chat-widget__header-subtitle {
	font-size: 12px;
	color: rgba(255, 255, 255, 0.7);
	margin-top: 2px;
}

.chat-widget__close {
	width: 32px;
	height: 32px;
	border-radius: 8px;
	background: transparent;
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s;
}

.chat-widget__close:hover {
	background: rgba(255, 255, 255, 0.15);
}

.chat-widget__close svg {
	width: 18px;
	height: 18px;
}

/* --- Лента сообщений --- */
.chat-widget__messages {
	flex: 1;
	overflow-y: auto;
	padding: 18px 16px;
	background: var(--cw-bg-soft);
	display: flex;
	flex-direction: column;
	gap: 12px;
	scrollbar-width: thin;
	scrollbar-color: rgba(24, 41, 104, 0.2) transparent;
}

.chat-widget__messages::-webkit-scrollbar {
	width: 6px;
}

.chat-widget__messages::-webkit-scrollbar-thumb {
	background: rgba(24, 41, 104, 0.2);
	border-radius: 3px;
}

/* --- Сообщение --- */
.chat-widget__message {
	display: flex;
	max-width: 85%;
	animation: cwMessageIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes cwMessageIn {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

.chat-widget__message--user {
	align-self: flex-end;
}

.chat-widget__message--bot {
	align-self: flex-start;
}

.chat-widget__bubble {
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 14px;
	line-height: 1.5;
	word-wrap: break-word;
	white-space: pre-wrap;
}

.chat-widget__message--bot .chat-widget__bubble {
	background: #fff;
	color: var(--cw-text);
	border: 1px solid var(--cw-border);
	border-bottom-left-radius: 4px;
}

.chat-widget__message--user .chat-widget__bubble {
	background: var(--cw-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.chat-widget__message--error .chat-widget__bubble {
	background: #fef2f2;
	color: var(--cw-accent);
	border: 1px solid rgba(199, 44, 48, 0.2);
}

/* Гиперссылки внутри сообщений */
.chat-widget__bubble a {
	color: var(--cw-primary);
	text-decoration: underline;
	text-underline-offset: 2px;
	word-break: break-word;
	transition: color 0.2s;
}

.chat-widget__bubble a:hover {
	color: var(--cw-primary-hover);
}

.chat-widget__message--user .chat-widget__bubble a {
	color: #fff;
	text-decoration: underline;
}

.chat-widget__message--user .chat-widget__bubble a:hover {
	color: rgba(255, 255, 255, 0.85);
}

.chat-widget__bubble strong {
	font-weight: 700;
}

/* --- Индикатор «печатает» --- */
.chat-widget__typing {
	display: flex;
	gap: 4px;
	padding: 4px 0;
}

.chat-widget__typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--cw-text-muted);
	animation: cwTyping 1.3s infinite ease-in-out;
}

.chat-widget__typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-widget__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cwTyping {
	0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
	30% { opacity: 1; transform: translateY(-4px); }
}

/* --- Форма ввода --- */
.chat-widget__form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 12px 8px;
	background: #fff;
	border-top: 1px solid var(--cw-border);
	flex-shrink: 0;
}

.chat-widget__input {
	flex: 1;
	border: 1px solid var(--cw-border);
	border-radius: 12px;
	padding: 10px 14px;
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	color: var(--cw-text);
	background: var(--cw-bg-soft);
	resize: none;
	max-height: 120px;
	transition: border-color 0.2s, background 0.2s;
}

.chat-widget__input:focus {
	outline: none;
	border-color: var(--cw-primary);
	background: #fff;
}

.chat-widget__input::placeholder {
	color: var(--cw-text-muted);
}

.chat-widget__send {
	width: 40px;
	height: 40px;
	border-radius: 12px;
	background: var(--cw-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s, transform 0.1s;
	flex-shrink: 0;
}

.chat-widget__send:hover:not(:disabled) {
	background: var(--cw-primary-hover);
}

.chat-widget__send:active:not(:disabled) {
	transform: scale(0.95);
}

.chat-widget__send:disabled {
	background: rgba(24, 41, 104, 0.3);
	cursor: not-allowed;
}

.chat-widget__send svg {
	width: 18px;
	height: 18px;
	margin-left: -2px;
}

/* --- Футер --- */
.chat-widget__footer {
	padding: 6px 16px 10px;
	background: #fff;
	color: var(--cw-text-muted);
	font-size: 11px;
	text-align: center;
	flex-shrink: 0;
}

/* --- Адаптив --- */
@media (max-width: 480px) {
	.chat-widget {
		bottom: 16px;
		right: 16px;
	}

	.chat-widget__panel {
		position: fixed;
		bottom: 88px;
		right: 16px;
		left: 16px;
		width: auto;
		height: calc(100vh - 110px);
		max-height: none;
	}

	.chat-widget__toggle {
		width: 56px;
		height: 56px;
	}
}
