/* =========================================================
   Chatbot n8n - Public Stylesheet
   پشتیبانی کامل از RTL، ریسپانسیو، حالت تاریک و انیمیشن
   ========================================================= */

:root {
	--cbn8n-primary: #2563eb;
	--cbn8n-secondary: #f1f5f9;
	--cbn8n-radius: 12px;
	--cbn8n-icon-size: 64px;
	--cbn8n-font-size: 14px;
	--cbn8n-font: 'Vazirmatn', Tahoma, Arial, sans-serif;
	--cbn8n-bg: #ffffff;
	--cbn8n-text: #1e293b;
	--cbn8n-border: #e2e8f0;
	--cbn8n-shadow: 0 10px 40px rgba(0, 0, 0, 0.16);
}

/* حالت تاریک خودکار بر اساس ترجیح سیستم کاربر */
@media (prefers-color-scheme: dark) {
	.cbn8n-root[data-dark-auto="1"] {
		--cbn8n-bg: #1e293b;
		--cbn8n-text: #f1f5f9;
		--cbn8n-border: #334155;
		--cbn8n-secondary: #334155;
	}
}

.cbn8n-root {
	position: fixed;
	bottom: 24px;
	z-index: 999999;
	font-family: var(--cbn8n-font);
	direction: rtl;
	box-sizing: border-box;
}
.cbn8n-root * {
	box-sizing: border-box;
}
.cbn8n-root.cbn8n-pos-left {
	left: 24px;
}
.cbn8n-root.cbn8n-pos-right {
	right: 24px;
}

.cbn8n-toggle-wrap {
	position: relative;
	display: flex;
	align-items: center;
	gap: 10px;
}
.cbn8n-root.cbn8n-pos-right .cbn8n-toggle-wrap {
	flex-direction: row-reverse;
}

.cbn8n-toggle-label {
	background: #fff;
	color: var(--cbn8n-text, #1e293b);
	font-size: 13px;
	font-weight: 600;
	white-space: nowrap;
	min-width: 0;
	padding: 9px 16px;
	border-radius: 999px;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
	opacity: 0;
	transform: translateY(10px);
	animation: cbn8n-fade-slide-up 0.5s ease forwards;
	animation-delay: 0.5s;
}
.cbn8n-root[data-animations="0"] .cbn8n-toggle-label {
	opacity: 1;
	transform: none;
	animation: none;
}
.cbn8n-root.cbn8n-open .cbn8n-toggle-label {
	display: none;
}

/* دکمه شناور */
.cbn8n-toggle-btn {
	flex-shrink: 0;
	width: var(--cbn8n-icon-size);
	height: var(--cbn8n-icon-size);
	border-radius: 50%;
	border: none;
	background: var(--cbn8n-primary);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
	transition: transform 0.25s ease, box-shadow 0.25s ease;
	opacity: 0;
	transform: translateY(16px);
	animation: cbn8n-fade-slide-up 0.5s ease forwards;
	animation-delay: 0.2s;
}
.cbn8n-toggle-btn svg {
	width: calc(var(--cbn8n-icon-size) * 0.46);
	height: calc(var(--cbn8n-icon-size) * 0.46);
}
.cbn8n-root[data-animations="0"] .cbn8n-toggle-btn {
	opacity: 1;
	transform: none;
	animation: none;
}
.cbn8n-toggle-btn:hover {
	transform: scale(1.08);
	box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}
.cbn8n-icon-close {
	display: none;
}
.cbn8n-root.cbn8n-open .cbn8n-icon-open {
	display: none;
}
.cbn8n-root.cbn8n-open .cbn8n-icon-close {
	display: inline-flex;
}

@keyframes cbn8n-fade-slide-up {
	from {
		opacity: 0;
		transform: translateY(16px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* پنجره چت */
.cbn8n-chat-window {
	position: absolute;
	bottom: calc(var(--cbn8n-icon-size) + 16px);
	width: 380px;
	height: 600px;
	max-height: 80vh;
	background: var(--cbn8n-bg);
	color: var(--cbn8n-text);
	border-radius: var(--cbn8n-radius);
	box-shadow: var(--cbn8n-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border: 1px solid var(--cbn8n-border);
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	transition: opacity 0.22s ease, transform 0.22s ease;
	pointer-events: none;
}
.cbn8n-root.cbn8n-pos-left .cbn8n-chat-window {
	left: 0;
}
.cbn8n-root.cbn8n-pos-right .cbn8n-chat-window {
	right: 0;
}
.cbn8n-chat-window.cbn8n-visible {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* هدر */
.cbn8n-header {
	background: var(--cbn8n-primary);
	color: #fff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}
.cbn8n-header-info {
	display: flex;
	align-items: center;
	gap: 10px;
}
.cbn8n-header-avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	object-fit: cover;
	background: #fff;
}
.cbn8n-header-text {
	display: flex;
	flex-direction: column;
	line-height: 1.3;
}
.cbn8n-header-title {
	font-weight: 700;
	font-size: 15px;
}
.cbn8n-header-status {
	font-size: 12px;
	opacity: 0.85;
}
.cbn8n-header-status::before {
	content: '';
	display: inline-block;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4ade80;
	margin-inline-end: 5px;
}
.cbn8n-header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
}
.cbn8n-icon-btn {
	background: transparent;
	border: none;
	color: #fff;
	cursor: pointer;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
	line-height: 1;
	transition: background 0.15s ease;
}
.cbn8n-icon-btn:hover {
	background: rgba(255, 255, 255, 0.18);
}

/* ناحیه پیام‌ها */
.cbn8n-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}
.cbn8n-messages::-webkit-scrollbar {
	width: 6px;
}
.cbn8n-messages::-webkit-scrollbar-thumb {
	background: var(--cbn8n-border);
	border-radius: 10px;
}

.cbn8n-msg {
	max-width: 82%;
	display: flex;
	flex-direction: column;
	animation: cbn8n-msg-in 0.25s ease;
}
.cbn8n-root[data-animations="0"] .cbn8n-msg {
	animation: none;
}
@keyframes cbn8n-msg-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}
.cbn8n-msg-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	font-size: var(--cbn8n-font-size);
	line-height: 1.7;
	word-wrap: break-word;
	white-space: pre-wrap;
}
.cbn8n-msg-user {
	align-self: flex-start;
}
.cbn8n-msg-user .cbn8n-msg-bubble {
	background: var(--cbn8n-primary);
	color: #fff;
	border-bottom-left-radius: 4px;
}
.cbn8n-msg-bot {
	align-self: flex-end;
}
.cbn8n-msg-bot .cbn8n-msg-bubble {
	background: var(--cbn8n-secondary);
	color: var(--cbn8n-text);
	border-bottom-right-radius: 4px;
}
.cbn8n-msg-bubble a {
	color: inherit;
	text-decoration: underline;
}
.cbn8n-msg-time {
	font-size: 10px;
	opacity: 0.55;
	margin-top: 3px;
	padding: 0 4px;
}
.cbn8n-msg-user .cbn8n-msg-time {
	align-self: flex-start;
}
.cbn8n-msg-bot .cbn8n-msg-time {
	align-self: flex-end;
}

/* دکمه کپی برای پیام‌های ربات */
.cbn8n-copy-btn {
	background: transparent;
	border: none;
	cursor: pointer;
	font-size: 11px;
	color: var(--cbn8n-primary);
	margin-top: 4px;
	align-self: flex-end;
	opacity: 0.75;
	padding: 2px 4px;
}
.cbn8n-copy-btn:hover {
	opacity: 1;
	text-decoration: underline;
}

/* دکمه‌های سریع (Quick Replies) */
.cbn8n-quick-replies {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 6px;
	align-self: flex-end;
}
.cbn8n-quick-reply-btn {
	border: 1px solid var(--cbn8n-primary);
	background: transparent;
	color: var(--cbn8n-primary);
	border-radius: 999px;
	padding: 6px 12px;
	font-size: 12px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}
.cbn8n-quick-reply-btn:hover {
	background: var(--cbn8n-primary);
	color: #fff;
}

/* کارت محصول / اطلاعاتی از JSON */
.cbn8n-card {
	border: 1px solid var(--cbn8n-border);
	border-radius: 10px;
	overflow: hidden;
	background: var(--cbn8n-bg);
	max-width: 240px;
	align-self: flex-end;
}
.cbn8n-card img {
	width: 100%;
	display: block;
	max-height: 140px;
	object-fit: cover;
}
.cbn8n-card-body {
	padding: 8px 10px;
}
.cbn8n-card-title {
	font-weight: 700;
	font-size: 13px;
	margin-bottom: 4px;
}
.cbn8n-card-desc {
	font-size: 12px;
	opacity: 0.8;
}
.cbn8n-card-link {
	display: inline-block;
	margin-top: 6px;
	font-size: 12px;
	color: var(--cbn8n-primary);
	text-decoration: underline;
}

/* جدول اطلاعات از JSON */
.cbn8n-table-wrap {
	overflow-x: auto;
	align-self: flex-end;
	max-width: 100%;
}
.cbn8n-table {
	border-collapse: collapse;
	font-size: 12px;
}
.cbn8n-table th,
.cbn8n-table td {
	border: 1px solid var(--cbn8n-border);
	padding: 6px 8px;
	text-align: right;
}
.cbn8n-table th {
	background: var(--cbn8n-secondary);
}

/* نشانگر تایپ */
.cbn8n-typing-indicator {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 0 16px 10px;
	flex-shrink: 0;
}
.cbn8n-typing-avatar {
	width: 22px;
	height: 22px;
	border-radius: 50%;
	object-fit: cover;
}
.cbn8n-typing-dots {
	display: inline-flex;
	gap: 3px;
	background: var(--cbn8n-secondary);
	padding: 8px 12px;
	border-radius: 14px;
}
.cbn8n-typing-dots i {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.5;
	display: inline-block;
	animation: cbn8n-blink 1.2s infinite ease-in-out;
}
.cbn8n-typing-dots i:nth-child(2) {
	animation-delay: 0.2s;
}
.cbn8n-typing-dots i:nth-child(3) {
	animation-delay: 0.4s;
}
@keyframes cbn8n-blink {
	0%, 80%, 100% {
		opacity: 0.25;
	}
	40% {
		opacity: 1;
	}
}

/* بنر خطا */
.cbn8n-error-banner {
	margin: 0 16px 10px;
	padding: 8px 12px;
	background: #fee2e2;
	color: #b91c1c;
	border-radius: 8px;
	font-size: 12px;
	flex-shrink: 0;
}

/* فرم ورودی */
.cbn8n-input-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--cbn8n-border);
	flex-shrink: 0;
	background: var(--cbn8n-bg);
}
.cbn8n-input-field {
	flex: 1;
	resize: none;
	max-height: 100px;
	min-height: 40px;
	border: 1px solid var(--cbn8n-border);
	border-radius: 18px;
	padding: 10px 14px;
	font-family: inherit;
	font-size: var(--cbn8n-font-size);
	color: var(--cbn8n-text);
	background: var(--cbn8n-bg);
	outline: none;
}
.cbn8n-input-field:focus {
	border-color: var(--cbn8n-primary);
}
.cbn8n-send-btn {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: none;
	background: var(--cbn8n-primary);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: opacity 0.15s ease;
}
.cbn8n-send-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* =========================================================
   ریسپانسیو - Responsive Breakpoints
   ========================================================= */

/* تبلت */
@media (max-width: 1024px) and (min-width: 601px) {
	.cbn8n-chat-window {
		width: 350px;
		height: 500px;
	}
}

/* موبایل: تمام‌صفحه */
@media (max-width: 600px) {
	.cbn8n-root.cbn8n-pos-left,
	.cbn8n-root.cbn8n-pos-right {
		left: 0;
		right: 0;
		bottom: 16px;
	}
	.cbn8n-toggle-wrap {
		position: absolute;
		bottom: 0;
		max-width: calc(100% - 32px);
	}
	.cbn8n-toggle-label {
		max-width: 60vw;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.cbn8n-root.cbn8n-pos-left .cbn8n-toggle-wrap {
		left: 16px;
	}
	.cbn8n-root.cbn8n-pos-right .cbn8n-toggle-wrap {
		right: 16px;
	}
	.cbn8n-chat-window {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100%;
		max-height: 100%;
		border-radius: 0;
		bottom: 0;
	}
}

/* موبایل - حالت افقی (Landscape) */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
	.cbn8n-chat-window {
		height: 100%;
	}
	.cbn8n-messages {
		padding: 10px 16px;
	}
}
