/* =========================================================
   چت برازندگان — استایل فرانت
   تم روشن گلس‌مورفیسم، راست‌چین، فونت وزیرمتن
   ========================================================= */

#brz-chat-root {
	/* --- پالت روشن --- */
	--brz-glass: rgba(255, 255, 255, .62);
	--brz-glass-2: rgba(255, 255, 255, .46);
	--brz-glass-3: rgba(255, 255, 255, .78);
	--brz-line: rgba(255, 255, 255, .65);
	--brz-line-2: rgba(15, 23, 42, .08);
	--brz-orange: #e8791a;
	--brz-orange-2: #ff9c46;
	--brz-orange-soft: rgba(232, 121, 26, .12);
	--brz-text: #1c2430;
	--brz-muted: #6b7482;
	--brz-radius: 22px;
	--brz-shadow: 0 24px 60px -18px rgba(23, 33, 51, .35), 0 2px 10px rgba(23, 33, 51, .08);
	--brz-blur: blur(22px) saturate(175%);
	--brz-font: "Vazirmatn", "Vazir", "IRANSans", system-ui, sans-serif;

	position: fixed;
	inset-block-end: 0;
	/* سمت راست صفحه، مستقل از راست‌چین بودن */
	right: 0;
	left: auto;
	z-index: 99990;
	font-family: var(--brz-font);
	direction: rtl;
}

#brz-chat-root *,
#brz-chat-root *::before,
#brz-chat-root *::after {
	box-sizing: border-box;
}

/* ---------- دکمه معلق ---------- */

.brz-launcher {
	position: fixed;
	inset-block-end: 24px;
	right: 24px;
	left: auto;
	width: 66px;
	height: 66px;
	display: grid;
	place-items: center;
	border: 0;
	padding: 0;
	cursor: pointer;
	/* گرد کامل */
	border-radius: 50%;
	background: linear-gradient(150deg, var(--brz-orange-2), var(--brz-orange) 55%, #d0680f);
	box-shadow:
		0 14px 30px -8px rgba(232, 121, 26, .55),
		0 0 0 6px rgba(255, 255, 255, .35),
		inset 0 1px 0 rgba(255, 255, 255, .45);
	color: #fff;
	transition: transform .22s cubic-bezier(.34, 1.56, .64, 1), box-shadow .22s ease;
	-webkit-tap-highlight-color: transparent;
}

.brz-launcher:hover {
	transform: translateY(-3px) scale(1.05);
	box-shadow:
		0 20px 38px -8px rgba(232, 121, 26, .68),
		0 0 0 8px rgba(255, 255, 255, .42),
		inset 0 1px 0 rgba(255, 255, 255, .5);
}

.brz-launcher:focus-visible {
	outline: 3px solid var(--brz-orange);
	outline-offset: 4px;
}

.brz-launcher svg {
	max-width: none !important;
	display: block;
	pointer-events: none;
}

/* آیکن داخل دکمه — بزرگ‌تر */
.brz-launcher .brz-ico-chat {
	width: 44px !important;
	height: 44px !important;
	color: #fff;
}

.brz-launcher .brz-ico-close {
	width: 26px !important;
	height: 26px !important;
	display: none;
}

#brz-chat-root.is-open .brz-launcher .brz-ico-chat {
	display: none;
}

#brz-chat-root.is-open .brz-launcher .brz-ico-close {
	display: block;
}

/* حلقه ضربانی — نشانه در دسترس بودن */
.brz-launcher::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	border: 2px solid var(--brz-orange);
	animation: brz-pulse 2.8s ease-out infinite;
	pointer-events: none;
}

#brz-chat-root.is-open .brz-launcher::after {
	display: none;
}

@keyframes brz-pulse {
	0%   { opacity: .5; transform: scale(1); }
	70%  { opacity: 0;  transform: scale(1.4); }
	100% { opacity: 0;  transform: scale(1.4); }
}

/* نشان پیام خوانده‌نشده */
.brz-badge {
	position: absolute;
	inset-block-start: -2px;
	left: -2px;
	right: auto;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: 999px;
	background: #fff;
	color: var(--brz-orange);
	font-size: 12px;
	font-weight: 700;
	line-height: 22px;
	text-align: center;
	box-shadow: 0 3px 10px rgba(23, 33, 51, .22);
	display: none;
}

.brz-badge.is-on {
	display: block;
}

/* ---------- پنجره کوچک خوش‌آمد (تیزر) ---------- */

.brz-teaser {
	position: fixed;
	inset-block-end: 104px;
	right: 24px;
	left: auto;
	max-width: min(268px, calc(100vw - 40px));
	display: flex;
	align-items: flex-start;
	gap: 4px;
	padding: 4px;
	border-radius: 18px;
	background: var(--brz-glass-3);
	-webkit-backdrop-filter: var(--brz-blur);
	backdrop-filter: var(--brz-blur);
	border: 1px solid var(--brz-line);
	box-shadow: var(--brz-shadow);
	opacity: 0;
	visibility: hidden;
	transform: translateY(10px) scale(.94);
	transform-origin: bottom right;
	transition: opacity .28s ease, transform .32s cubic-bezier(.34, 1.4, .64, 1), visibility .32s;
	pointer-events: none;
}

.brz-teaser.is-on {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
	pointer-events: auto;
	animation: brz-float 3.6s ease-in-out 0.4s infinite;
}

#brz-chat-root.is-open .brz-teaser {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	animation: none;
}

@keyframes brz-float {
	0%, 100% { transform: translateY(0); }
	50%      { transform: translateY(-4px); }
}

/* دنبالهٔ حباب — به سمت دکمه */
.brz-teaser::after {
	content: "";
	position: absolute;
	inset-block-end: -6px;
	right: 26px;
	width: 14px;
	height: 14px;
	background: var(--brz-glass-3);
	border-right: 1px solid var(--brz-line);
	border-bottom: 1px solid var(--brz-line);
	transform: rotate(45deg);
	border-end-end-radius: 3px;
}

.brz-teaser-open {
	flex: 1 1 auto;
	display: flex;
	align-items: center;
	gap: 9px;
	padding: 9px 10px;
	border: 0;
	border-radius: 14px;
	background: transparent;
	font-family: inherit;
	font-size: 13.5px;
	font-weight: 600;
	line-height: 1.7;
	color: var(--brz-text);
	text-align: right;
	cursor: pointer;
	transition: background .16s ease;
}

.brz-teaser-open:hover {
	background: var(--brz-orange-soft);
}

.brz-teaser-avatar {
	flex: 0 0 auto;
	width: 34px;
	height: 34px;
	display: grid;
	place-items: center;
	border-radius: 50%;
	background: linear-gradient(150deg, var(--brz-orange-2), var(--brz-orange));
	color: #fff;
	box-shadow: 0 4px 12px -4px rgba(232, 121, 26, .7);
}

.brz-teaser-avatar svg {
	width: 22px !important;
	height: 22px !important;
	max-width: none !important;
	display: block;
}

.brz-teaser-x {
	flex: 0 0 auto;
	width: 24px;
	height: 24px;
	margin-block-start: 4px;
	display: grid;
	place-items: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(15, 23, 42, .06);
	color: var(--brz-muted);
	cursor: pointer;
	transition: background .16s ease, color .16s ease;
}

.brz-teaser-x:hover {
	background: rgba(15, 23, 42, .12);
	color: var(--brz-text);
}

.brz-teaser-x svg {
	width: 12px !important;
	height: 12px !important;
	max-width: none !important;
	display: block;
}

/* ---------- پنجره چت ---------- */

.brz-panel {
	position: fixed;
	inset-block-end: 104px;
	right: 24px;
	left: auto;
	width: 384px;
	max-width: calc(100vw - 32px);
	height: 566px;
	max-height: calc(100vh - 148px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--brz-glass);
	-webkit-backdrop-filter: var(--brz-blur);
	backdrop-filter: var(--brz-blur);
	border: 1px solid var(--brz-line);
	border-radius: var(--brz-radius);
	box-shadow: var(--brz-shadow);
	color: var(--brz-text);
	opacity: 0;
	visibility: hidden;
	transform: translateY(16px) scale(.97);
	transform-origin: bottom right;
	transition: opacity .2s ease, transform .24s cubic-bezier(.34, 1.4, .64, 1), visibility .24s;
}

#brz-chat-root.is-open .brz-panel {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

/* ---------- سربرگ ---------- */

.brz-head {
	position: relative;
	padding: 16px 18px 14px;
	background: linear-gradient(180deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, .18));
	border-bottom: 1px solid var(--brz-line-2);
	flex: 0 0 auto;
}

/* خط نارنجی بالای سربرگ — امضای بصری، هنگام نوشتن ربات می‌درخشد */
.brz-head::before {
	content: "";
	position: absolute;
	inset-block-start: 0;
	inset-inline: 0;
	height: 3px;
	background: linear-gradient(90deg, transparent, var(--brz-orange) 20%, var(--brz-orange-2) 50%, var(--brz-orange) 80%, transparent);
	opacity: .85;
}

#brz-chat-root.is-typing .brz-head::before {
	animation: brz-glow 1.4s ease-in-out infinite;
}

@keyframes brz-glow {
	0%, 100% { opacity: .35; }
	50%      { opacity: 1; }
}

.brz-title {
	margin: 0;
	font-size: 15px;
	font-weight: 700;
	color: var(--brz-text);
	letter-spacing: -.2px;
}

.brz-sub {
	margin: 3px 0 0;
	font-size: 12px;
	color: var(--brz-muted);
	display: flex;
	align-items: center;
	gap: 6px;
}

.brz-dot {
	width: 7px;
	height: 7px;
	border-radius: 999px;
	background: #22c55e;
	box-shadow: 0 0 0 3px rgba(34, 197, 94, .18);
	flex: 0 0 auto;
}

.brz-dot.is-off {
	background: #94a3b8;
	box-shadow: 0 0 0 3px rgba(148, 163, 184, .18);
}

/* ---------- ناحیه پیام‌ها ---------- */

.brz-body {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px 16px 8px;
	background: linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .3));
	scrollbar-width: thin;
	scrollbar-color: rgba(15, 23, 42, .2) transparent;
}

.brz-body::-webkit-scrollbar {
	width: 8px;
}

.brz-body::-webkit-scrollbar-thumb {
	background: rgba(15, 23, 42, .18);
	border-radius: 8px;
}

.brz-msg {
	max-width: 82%;
	margin-bottom: 10px;
	padding: 10px 13px;
	font-size: 13.5px;
	line-height: 1.85;
	border-radius: 16px;
	white-space: pre-wrap;
	word-break: break-word;
	animation: brz-in .26s ease both;
}

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

/* پیام ربات و کارشناس — سمت راست (شروع خط در راست‌چین) */
.brz-msg.is-bot,
.brz-msg.is-agent {
	background: rgba(255, 255, 255, .72);
	border: 1px solid var(--brz-line);
	box-shadow: 0 4px 14px -8px rgba(23, 33, 51, .25);
	color: var(--brz-text);
	border-start-start-radius: 5px;
}

.brz-msg.is-agent {
	border-inline-start: 2px solid var(--brz-orange);
}

/* پیام بازدیدکننده — سمت چپ */
.brz-msg.is-visitor {
	margin-inline-start: auto;
	background: linear-gradient(160deg, var(--brz-orange-2), var(--brz-orange) 70%);
	color: #fff;
	border: 1px solid rgba(255, 255, 255, .35);
	box-shadow: 0 6px 18px -10px rgba(232, 121, 26, .8);
	border-end-end-radius: 5px;
}

.brz-msg.is-system {
	max-width: 100%;
	margin-inline: auto;
	background: none;
	border: 0;
	box-shadow: none;
	color: var(--brz-muted);
	font-size: 12px;
	text-align: center;
	padding: 4px 0;
}

.brz-who {
	display: block;
	margin-bottom: 3px;
	font-size: 11px;
	font-weight: 700;
	color: #c9600d;
}

.brz-time {
	display: block;
	margin-top: 4px;
	font-size: 10.5px;
	opacity: .6;
	text-align: left;
	font-variant-numeric: tabular-nums;
}

/* نشانگر «در حال نوشتن» */
.brz-typing {
	display: none;
	gap: 4px;
	align-items: center;
	width: fit-content;
	margin-bottom: 10px;
	padding: 12px 14px;
	background: rgba(255, 255, 255, .72);
	border: 1px solid var(--brz-line);
	border-radius: 16px;
	border-start-start-radius: 5px;
}

#brz-chat-root.is-typing .brz-typing {
	display: flex;
}

.brz-typing i {
	width: 6px;
	height: 6px;
	border-radius: 999px;
	background: var(--brz-orange);
	animation: brz-bounce 1s ease-in-out infinite;
}

.brz-typing i:nth-child(2) { animation-delay: .15s; }
.brz-typing i:nth-child(3) { animation-delay: .3s; }

@keyframes brz-bounce {
	0%, 100% { transform: translateY(0); opacity: .45; }
	50%      { transform: translateY(-5px); opacity: 1; }
}

/* ---------- دکمه‌های میان‌بر ---------- */

.brz-quick {
	display: flex;
	flex-wrap: wrap;
	gap: 7px;
	padding: 4px 16px 12px;
	background: rgba(255, 255, 255, .3);
	flex: 0 0 auto;
}

.brz-quick:empty {
	display: none;
}

.brz-chip {
	font-family: inherit;
	font-size: 12.5px;
	padding: 7px 13px;
	border-radius: 999px;
	border: 1px solid rgba(232, 121, 26, .4);
	background: rgba(255, 255, 255, .6);
	color: #c9600d;
	cursor: pointer;
	transition: background .16s ease, transform .16s ease, color .16s ease;
}

.brz-chip:hover {
	background: var(--brz-orange);
	border-color: var(--brz-orange);
	color: #fff;
	transform: translateY(-1px);
}

.brz-chip:focus-visible {
	outline: 2px solid var(--brz-orange);
	outline-offset: 2px;
}

/* ---------- ورودی ---------- */

.brz-foot {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px;
	background: rgba(255, 255, 255, .45);
	border-top: 1px solid var(--brz-line-2);
	flex: 0 0 auto;
}

.brz-input {
	flex: 1 1 auto;
	resize: none;
	max-height: 96px;
	min-height: 42px;
	padding: 11px 14px;
	font-family: inherit;
	font-size: 13.5px;
	line-height: 1.6;
	color: var(--brz-text);
	background: rgba(255, 255, 255, .75);
	border: 1px solid var(--brz-line-2);
	border-radius: 14px;
	outline: none;
	transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.brz-input::placeholder {
	color: #9aa2ad;
}

.brz-input:focus {
	border-color: rgba(232, 121, 26, .55);
	background: #fff;
	box-shadow: 0 0 0 3px rgba(232, 121, 26, .12);
}

.brz-send {
	flex: 0 0 auto;
	width: 42px;
	height: 42px;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	color: #fff;
	background: linear-gradient(150deg, var(--brz-orange-2), var(--brz-orange));
	box-shadow: 0 8px 18px -8px rgba(232, 121, 26, .85);
	transition: transform .16s ease, opacity .16s ease;
}

.brz-send:hover {
	transform: translateY(-1px);
}

.brz-send:disabled {
	opacity: .4;
	cursor: default;
	transform: none;
	box-shadow: none;
}

.brz-send svg {
	width: 19px !important;
	height: 19px !important;
	max-width: none !important;
	display: block;
}

.brz-note {
	padding: 0 16px 10px;
	margin: 0;
	font-size: 10.5px;
	color: var(--brz-muted);
	text-align: center;
	background: rgba(255, 255, 255, .45);
}

/* ---------- موبایل: پنجره تمام‌صفحه ---------- */

@media (max-width: 520px) {
	.brz-launcher {
		inset-block-end: 18px;
		right: 18px;
		left: auto;
		width: 60px;
		height: 60px;
	}

	.brz-launcher .brz-ico-chat {
		width: 40px !important;
		height: 40px !important;
	}

	.brz-teaser {
		inset-block-end: 90px;
		right: 18px;
		max-width: min(250px, calc(100vw - 34px));
	}

	.brz-teaser::after {
		right: 22px;
	}

	.brz-panel {
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: none;
		border: 0;
		border-radius: 0;
		/* در حالت تمام‌صفحه شیشه باید مات‌تر باشد تا متن خوانا بماند */
		background: rgba(255, 255, 255, .88);
		padding-block-end: env(safe-area-inset-bottom);
		transform-origin: bottom center;
	}

	#brz-chat-root.is-open .brz-launcher {
		display: none;
	}

	.brz-head {
		padding-block-start: max(16px, env(safe-area-inset-top));
	}

	.brz-close-m {
		position: absolute;
		inset-block-start: max(14px, env(safe-area-inset-top));
		inset-inline-start: 14px;
		width: 32px;
		height: 32px;
		display: grid;
		place-items: center;
		border: 1px solid var(--brz-line-2);
		border-radius: 10px;
		background: rgba(255, 255, 255, .7);
		color: var(--brz-text);
		cursor: pointer;
	}

	.brz-close-m svg {
		width: 16px !important;
		height: 16px !important;
		max-width: none !important;
	}
}

@media (min-width: 521px) {
	.brz-close-m {
		display: none;
	}
}

/* ---------- مرورگرهای بدون پشتیبانی از بلور ---------- */

@supports not ((backdrop-filter: blur(4px)) or (-webkit-backdrop-filter: blur(4px))) {
	.brz-panel,
	.brz-teaser,
	.brz-teaser::after {
		background: rgba(255, 255, 255, .95);
	}
}

/* ---------- احترام به کاهش حرکت ---------- */

@media (prefers-reduced-motion: reduce) {
	#brz-chat-root *,
	#brz-chat-root *::before,
	#brz-chat-root *::after {
		animation: none !important;
		transition-duration: .01ms !important;
	}
}
