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

#brz-chat-root {
	--brz-ink: #101114;
	--brz-panel: #16181c;
	--brz-elev: #1e2228;
	--brz-elev-2: #24282f;
	--brz-line: rgba(255, 255, 255, .08);
	--brz-orange: #e8791a;
	--brz-orange-2: #ff9c46;
	--brz-text: #eceef1;
	--brz-muted: #9299a2;
	--brz-radius: 18px;
	--brz-shadow: 0 18px 50px -12px rgba(0, 0, 0, .65);
	--brz-font: "Vazirmatn", "Vazir", "IRANSans", system-ui, sans-serif;

	position: fixed;
	inset-block-end: 0;
	inset-inline-end: 0;
	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;
	inset-inline-end: 24px;
	width: 62px;
	height: 62px;
	display: grid;
	place-items: center;
	border: 0;
	padding: 0;
	cursor: pointer;
	border-radius: 20px;
	background: linear-gradient(150deg, var(--brz-orange-2), var(--brz-orange) 55%, #c9600d);
	box-shadow: 0 10px 28px -8px rgba(232, 121, 26, .7), inset 0 1px 0 rgba(255, 255, 255, .25);
	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.04);
	box-shadow: 0 16px 34px -8px rgba(232, 121, 26, .85), inset 0 1px 0 rgba(255, 255, 255, .3);
}

.brz-launcher:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 3px;
}

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

.brz-launcher .brz-ico-close {
	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: .55; transform: scale(1); }
	70%  { opacity: 0;   transform: scale(1.45); }
	100% { opacity: 0;   transform: scale(1.45); }
}

/* نشان پیام خوانده‌نشده */
.brz-badge {
	position: absolute;
	inset-block-start: -4px;
	inset-inline-start: -4px;
	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 2px 8px rgba(0, 0, 0, .4);
	display: none;
}

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

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

.brz-panel {
	position: fixed;
	inset-block-end: 100px;
	inset-inline-end: 24px;
	width: 384px;
	max-width: calc(100vw - 32px);
	height: 566px;
	max-height: calc(100vh - 140px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--brz-panel);
	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, #1a1d22, var(--brz-panel));
	border-bottom: 1px solid var(--brz-line);
	flex: 0 0 auto;
}

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

#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;
	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: #4ade80;
	box-shadow: 0 0 0 3px rgba(74, 222, 128, .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-color: var(--brz-ink);
	/* بافت خط‌های مورب — اشاره‌ای به تم صنعتی، بسیار کم‌رنگ */
	background-image: repeating-linear-gradient(
		135deg,
		rgba(255, 255, 255, .022) 0 1px,
		transparent 1px 9px
	);
	scrollbar-width: thin;
	scrollbar-color: #33383f transparent;
}

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

.brz-body::-webkit-scrollbar-thumb {
	background: #33383f;
	border-radius: 8px;
}

.brz-msg {
	max-width: 82%;
	margin-bottom: 10px;
	padding: 10px 13px;
	font-size: 13.5px;
	line-height: 1.85;
	border-radius: 14px;
	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: var(--brz-elev);
	border: 1px solid var(--brz-line);
	border-start-start-radius: 4px;
}

.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), #cf6a11);
	color: #fff;
	border-end-end-radius: 4px;
}

.brz-msg.is-system {
	max-width: 100%;
	margin-inline: auto;
	background: 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: var(--brz-orange-2);
}

.brz-time {
	display: block;
	margin-top: 4px;
	font-size: 10.5px;
	opacity: .55;
	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: var(--brz-elev);
	border: 1px solid var(--brz-line);
	border-radius: 14px;
	border-start-start-radius: 4px;
}

#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: var(--brz-ink);
	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, .45);
	background: rgba(232, 121, 26, .09);
	color: var(--brz-orange-2);
	cursor: pointer;
	transition: background .16s ease, transform .16s ease, color .16s ease;
}

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

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

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

.brz-foot {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px;
	background: var(--brz-panel);
	border-top: 1px solid var(--brz-line);
	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: var(--brz-elev);
	border: 1px solid var(--brz-line);
	border-radius: 12px;
	outline: none;
	transition: border-color .16s ease, background .16s ease;
}

.brz-input::placeholder {
	color: #6f767f;
}

.brz-input:focus {
	border-color: rgba(232, 121, 26, .6);
	background: var(--brz-elev-2);
}

.brz-send {
	flex: 0 0 auto;
	width: 42px;
	height: 42px;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 12px;
	cursor: pointer;
	color: #fff;
	background: linear-gradient(150deg, var(--brz-orange-2), var(--brz-orange));
	box-shadow: 0 6px 16px -6px rgba(232, 121, 26, .8);
	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: #6f767f;
	text-align: center;
	background: var(--brz-panel);
}

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

@media (max-width: 520px) {
	.brz-launcher {
		inset-block-end: 18px;
		inset-inline-end: 18px;
		width: 56px;
		height: 56px;
	}

	.brz-panel {
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: none;
		border: 0;
		border-radius: 0;
		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);
		border-radius: 10px;
		background: var(--brz-elev);
		color: var(--brz-text);
		cursor: pointer;
	}
}

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

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

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