/**
 * AI Chatbot — Frontend styles.
 *
 * Uses CSS custom properties injected on the #aichat-widget element:
 *   --aichat-primary, --aichat-user-bubble, --aichat-text, --aichat-bg
 */

.aichat-widget {
	--aichat-primary: #4f46e5;
	--aichat-primary-dark: #4338ca;
	--aichat-user-bubble: #4f46e5;
	--aichat-text: #1f2937;
	--aichat-bg: #ffffff;

	position: fixed;
	inset-block-end: 24px;
	inset-inline-end: 24px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Vazirmatn", "Iranian Sans", Tahoma, Arial, sans-serif;
	line-height: 1.65;
	color: var(--aichat-text);
	box-sizing: border-box;
	-webkit-font-smoothing: antialiased;
}

.aichat-widget *,
.aichat-widget *::before,
.aichat-widget *::after {
	box-sizing: border-box;
}

.aichat-widget.aichat-pos-left {
	inset-inline-end: auto;
	inset-inline-start: 24px;
}

/* ------------------------------------------------------------------ */
/* Launcher button                                                     */
/* ------------------------------------------------------------------ */

.aichat-launcher {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--aichat-primary);
	color: #ffffff;
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
	transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
	position: relative;
	-webkit-tap-highlight-color: transparent;
}

.aichat-launcher:hover,
.aichat-launcher:focus-visible {
	transform: translateY(-3px) scale(1.03);
	box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
	background: var(--aichat-primary-dark);
	outline: none;
}

.aichat-launcher svg {
	width: 26px;
	height: 26px;
	display: block;
}

.aichat-launcher .aichat-launcher-close {
	display: none;
}

.aichat-widget.aichat-open .aichat-launcher .aichat-launcher-icon {
	display: none;
}

.aichat-widget.aichat-open .aichat-launcher .aichat-launcher-close {
	display: block;
}

/* Online pulse indicator */
.aichat-launcher::after {
	content: "";
	position: absolute;
	inset-block-start: 2px;
	inset-inline-end: 2px;
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: #22c55e;
	border: 2px solid #ffffff;
	animation: aichat-pulse 2s infinite;
}

.aichat-widget.aichat-open .aichat-launcher::after {
	display: none;
}

@keyframes aichat-pulse {
	0%, 100% {
		box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
	}
	50% {
		box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
	}
}

/* ------------------------------------------------------------------ */
/* Chat window                                                         */
/* ------------------------------------------------------------------ */

.aichat-window {
	position: absolute;
	inset-block-end: 76px;
	inset-inline-end: 0;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 140px);
	display: flex;
	flex-direction: column;
	background: var(--aichat-bg);
	border-radius: 20px;
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
	overflow: hidden;
	opacity: 0;
	transform: translateY(16px) scale(0.96);
	transform-origin: bottom;
	pointer-events: none;
	transition: opacity 0.28s ease, transform 0.28s ease;
}

.aichat-widget.aichat-open .aichat-window {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* Header */
.aichat-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 16px 18px;
	background: linear-gradient(135deg, var(--aichat-primary), var(--aichat-primary-dark));
	color: #ffffff;
	flex-shrink: 0;
}

.aichat-header-avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	font-size: 20px;
	flex-shrink: 0;
}

.aichat-header-info {
	display: flex;
	flex-direction: column;
	min-width: 0;
	flex: 1;
}

.aichat-header-title {
	font-size: 15px;
	font-weight: 700;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.aichat-header-status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	opacity: 0.9;
}

.aichat-status-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6);
	animation: aichat-pulse 2s infinite;
}

.aichat-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: #ffffff;
	cursor: pointer;
	transition: background 0.2s ease;
	flex-shrink: 0;
}

.aichat-close:hover {
	background: rgba(255, 255, 255, 0.2);
}

.aichat-close svg {
	width: 18px;
	height: 18px;
}

/* Messages */
.aichat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 18px;
	background: var(--aichat-bg);
	scroll-behavior: smooth;
}

.aichat-messages::-webkit-scrollbar {
	width: 6px;
}

.aichat-messages::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.18);
	border-radius: 8px;
}

.aichat-msg-row {
	display: flex;
	gap: 8px;
	margin-block: 8px;
	animation: aichat-msg-in 0.25s ease;
}

@keyframes aichat-msg-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.aichat-msg-bot {
	justify-content: flex-start;
}

.aichat-msg-user {
	justify-content: flex-end;
}

.aichat-msg-avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: #f1f5f9;
	font-size: 15px;
	flex-shrink: 0;
	margin-block-start: 2px;
}

.aichat-msg-bubble {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: 16px;
	font-size: 14px;
	white-space: pre-wrap;
	word-break: break-word;
	overflow-wrap: anywhere;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.aichat-msg-bot .aichat-msg-bubble {
	background: #f1f5f9;
	color: var(--aichat-text);
	border-end-start-radius: 4px;
}

.aichat-msg-user .aichat-msg-bubble {
	background: var(--aichat-user-bubble);
	color: #ffffff;
	border-end-end-radius: 4px;
}

.aichat-msg-bubble a {
	color: inherit;
	text-decoration: underline;
	word-break: break-all;
}

/* Typing indicator */
.aichat-typing-row .aichat-msg-bubble {
	display: flex;
	gap: 5px;
	align-items: center;
	padding: 14px 16px;
}

.aichat-typing-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #94a3b8;
	animation: aichat-typing 1.2s infinite ease-in-out;
}

.aichat-typing-dot:nth-child(2) {
	animation-delay: 0.15s;
}

.aichat-typing-dot:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes aichat-typing {
	0%, 60%, 100% {
		transform: translateY(0);
		opacity: 0.5;
	}
	30% {
		transform: translateY(-5px);
		opacity: 1;
	}
}

/* Composer */
.aichat-composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px;
	border-top: 1px solid #e5e7eb;
	background: var(--aichat-bg);
	flex-shrink: 0;
}

.aichat-input {
	flex: 1;
	resize: none;
	border: 1px solid #e5e7eb;
	border-radius: 14px;
	padding: 10px 14px;
	font-size: 14px;
	font-family: inherit;
	line-height: 1.5;
	background: #f8fafc;
	color: var(--aichat-text);
	min-height: 42px;
	max-height: 120px;
	outline: none;
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.aichat-input:focus {
	border-color: var(--aichat-primary);
	box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
	background: #ffffff;
}

.aichat-input::placeholder {
	color: #9ca3af;
}

.aichat-send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--aichat-primary);
	color: #ffffff;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.aichat-send:hover {
	background: var(--aichat-primary-dark);
	transform: scale(1.05);
}

.aichat-send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}

.aichat-send svg {
	width: 18px;
	height: 18px;
}

/* Error message styling */
.aichat-msg-bubble.aichat-error {
	background: #fef2f2;
	color: #b91c1c;
	border: 1px solid #fecaca;
}

/* ------------------------------------------------------------------ */
/* Mobile                                                              */
/* ------------------------------------------------------------------ */

@media (max-width: 480px) {
	.aichat-widget {
		inset-block-end: 16px;
		inset-inline-end: 16px;
	}

	.aichat-widget.aichat-pos-left {
		inset-inline-start: 16px;
		inset-inline-end: auto;
	}

	.aichat-window {
		position: fixed;
		inset: 12px;
		width: auto;
		height: auto;
		max-height: none;
		border-radius: 18px;
	}

	.aichat-launcher {
		width: 56px;
		height: 56px;
	}
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
	.aichat-widget *,
	.aichat-widget *::before,
	.aichat-widget *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}
