/**
 * ویجت پشتیبانی هوشمند — RTL و ریسپانسیو.
 */

.ais-root {
	--ais-c: #0e9f6e;
	--ais-c-dark: #0b7f58;
	--ais-bg: #ffffff;
	--ais-text: #1f2937;
	--ais-muted: #6b7280;
	--ais-border: #e5e7eb;
	position: fixed;
	bottom: 18px;
	left: 18px;
	z-index: 999999;
	font-family: inherit;
}

.ais-root.ais-pos-right {
	left: auto;
	right: 18px;
}

/* ---------- دکمه شناور ---------- */

.ais-fab {
	position: relative;
	width: 58px;
	height: 58px;
	border-radius: 50%;
	border: none;
	cursor: pointer;
	background: var(--ais-c);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
	transition: transform 0.2s ease, background 0.2s ease;
}

.ais-fab:hover {
	transform: scale(1.06);
	background: var(--ais-c-dark);
}

.ais-fab.ais-has-unread::after {
	content: '';
	position: absolute;
	inset: -3px;
	border-radius: 50%;
	border: 2px solid var(--ais-c);
	opacity: 0.5;
	animation: ais-pulse 1.6s ease-out infinite;
}

@keyframes ais-pulse {
	0% { transform: scale(1); opacity: 0.5; }
	100% { transform: scale(1.35); opacity: 0; }
}

.ais-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 10px;
	background: #ef4444;
	color: #fff;
	font-size: 12px;
	font-weight: 700;
	line-height: 20px;
	text-align: center;
	direction: ltr;
}

/* ---------- پنل ---------- */

.ais-panel {
	position: absolute;
	bottom: 70px;
	left: 0;
	width: 370px;
	max-width: calc(100vw - 36px);
	height: 540px;
	max-height: calc(100vh - 100px);
	background: var(--ais-bg);
	border-radius: 16px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	direction: rtl;
}

/* حالت بسته: باید بر display:flex قاعده بالا غلبه کند. */
.ais-panel[hidden] {
	display: none !important;
}

.ais-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 14px 16px;
	background: var(--ais-c);
	color: #fff;
	flex-shrink: 0;
}

.ais-title {
	font-size: 15px;
	font-weight: 700;
}

.ais-sub {
	font-size: 11.5px;
	opacity: 0.92;
	margin-top: 3px;
}

.ais-close {
	background: transparent;
	border: none;
	color: #fff;
	font-size: 16px;
	cursor: pointer;
	padding: 4px 6px;
	border-radius: 6px;
	opacity: 0.85;
}

.ais-close:hover {
	background: rgba(255, 255, 255, 0.15);
	opacity: 1;
}

.ais-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

/* ---------- نمای چت ---------- */

.ais-view-chat {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
}

.ais-msgs {
	flex: 1;
	overflow-y: auto;
	padding: 14px 12px 8px;
	background: #f7f8fa;
}

.ais-row {
	display: flex;
	margin-bottom: 10px;
}

.ais-row-user {
	justify-content: flex-start; /* در RTL: پیام کاربر سمت چپ (مطابق عادت پیام‌رسان‌های ایرانی) */
	flex-direction: row-reverse;
}

.ais-row-ai,
.ais-row-operator {
	justify-content: flex-start;
}

.ais-bubble {
	max-width: 82%;
	padding: 9px 12px;
	border-radius: 14px;
	font-size: 13.5px;
	line-height: 1.7;
	word-wrap: break-word;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
}

.ais-row-user .ais-bubble {
	background: var(--ais-c);
	color: #fff;
	border-bottom-left-radius: 4px;
}

.ais-row-ai .ais-bubble,
.ais-row-operator .ais-bubble {
	background: #ffffff;
	color: var(--ais-text);
	border: 1px solid var(--ais-border);
	border-bottom-right-radius: 4px;
}

.ais-row-operator .ais-bubble {
	border-color: var(--ais-c);
}

.ais-bubble-time {
	font-size: 10px;
	opacity: 0.65;
	margin-top: 4px;
	text-align: left;
	direction: ltr;
}

.ais-sysline {
	text-align: center;
	font-size: 11.5px;
	color: var(--ais-muted);
	background: #eef1f4;
	border-radius: 8px;
	padding: 6px 10px;
	margin: 6px 8px 10px;
	line-height: 1.7;
	white-space: pre-wrap;
}

/* ---------- «در حال نوشتن» ---------- */

.ais-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 6px 14px;
	background: #f7f8fa;
	font-size: 11.5px;
	color: var(--ais-muted);
}

.ais-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--ais-c);
	animation: ais-blink 1.2s infinite;
}

.ais-dot:nth-child(2) { animation-delay: 0.2s; }
.ais-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ais-blink {
	0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
	30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- کارت پیشنهاد تیکت ---------- */

.ais-ticket-hint {
	padding: 0 12px;
}

.ais-hint-btn {
	width: 100%;
	border: 1px dashed var(--ais-c);
	background: #f0faf6;
	color: var(--ais-c-dark);
	border-radius: 10px;
	padding: 10px;
	font-size: 12.5px;
	cursor: pointer;
	text-align: right;
}

.ais-hint-btn:hover {
	background: #e2f5ec;
}

/* ---------- اکشن‌ها: دو ردیف دو دکمه‌ای ---------- */

.ais-actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 6px;
	padding: 8px 12px;
	background: #f7f8fa;
	border-top: 1px solid var(--ais-border);
}

/* نقل‌قول «در پاسخ به» داخل حباب پاسخ کارشناس */
.ais-quote {
	font-size: 11.5px;
	opacity: 0.75;
	border-right: 2px solid currentColor;
	padding: 0 6px 0 0;
	margin-bottom: 4px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	text-align: right;
	direction: rtl;
}

.ais-act {
	border: 1px solid var(--ais-border);
	background: #fff;
	color: var(--ais-text);
	border-radius: 8px;
	padding: 8px 4px;
	font-size: 11px;
	line-height: 1.5;
	cursor: pointer;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	text-align: center;
}

.ais-act:hover {
	border-color: var(--ais-c);
	color: var(--ais-c-dark);
}

.ais-act:disabled {
	opacity: 0.75;
	cursor: default;
}

/* دکمه حالت فعال (پیش‌فرض: گفتگو با ربات) */
.ais-act-on,
.ais-act-on:hover {
	background: var(--ais-c);
	border-color: var(--ais-c);
	color: #fff;
}

.ais-act-on:disabled {
	opacity: 0.85;
}

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

.ais-inputrow {
	display: flex;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--ais-border);
	background: #fff;
	flex-shrink: 0;
}

.ais-input {
	flex: 1;
	border: 1px solid var(--ais-border);
	border-radius: 22px;
	padding: 10px 14px;
	font-size: 13.5px;
	outline: none;
	font-family: inherit;
	direction: rtl;
}

.ais-input:focus {
	border-color: var(--ais-c);
	box-shadow: 0 0 0 2px rgba(14, 159, 110, 0.15);
}

.ais-sendbtn {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	border: none;
	background: var(--ais-c);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.ais-sendbtn:hover { background: var(--ais-c-dark); }
.ais-sendbtn:disabled { opacity: 0.6; }

/* جهت آیکون ارسال: در رابط فارسی نوک هواپیما به سمت چپ (سمت خروج پیام) */
.ais-sendbtn svg {
	transform: scaleX(-1);
}

/* ---------- پیوست فایل/تصویر ---------- */

.ais-attachbtn {
	width: 40px;
	height: 42px;
	border: none;
	background: transparent;
	color: var(--ais-muted);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	border-radius: 10px;
}

.ais-attachbtn:hover {
	color: var(--ais-c-dark);
	background: #eef1f4;
}

.ais-attach-chip {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin: 0 12px 8px;
	padding: 6px 10px;
	background: #f0faf6;
	border: 1px dashed var(--ais-c);
	border-radius: 10px;
	font-size: 12px;
	color: var(--ais-c-dark);
	flex-shrink: 0;
}

.ais-attach-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ais-attach-rm {
	border: none;
	background: transparent;
	color: inherit;
	cursor: pointer;
	font-size: 13px;
	flex-shrink: 0;
	padding: 0 4px;
}

/* نمایش پیوست داخل حباب پیام */
.ais-att {
	margin-top: 6px;
}

.ais-att-img {
	max-width: 100%;
	max-height: 220px;
	border-radius: 10px;
	display: block;
	cursor: zoom-in;
}

.ais-att-file {
	font-size: 12.5px;
	text-decoration: underline;
	word-break: break-all;
	display: inline-block;
}

.ais-row-ai .ais-att-file,
.ais-row-operator .ais-att-file {
	color: var(--ais-c-dark);
}

.ais-row-user .ais-att-file {
	color: #fff;
}

/* ---------- فرم تیکت ---------- */

.ais-view-ticket,
.ais-view-tickets {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
	padding: 14px;
	gap: 10px;
	background: #f7f8fa;
	overflow-y: auto;
}

.ais-view-title {
	font-size: 14.5px;
	font-weight: 700;
	color: var(--ais-text);
}

.ais-field {
	width: 100%;
	box-sizing: border-box;
	border: 1px solid var(--ais-border);
	border-radius: 10px;
	padding: 10px 12px;
	font-size: 13px;
	font-family: inherit;
	direction: rtl;
	background: #fff;
}

.ais-field:focus {
	border-color: var(--ais-c);
	outline: none;
}

.ais-area {
	resize: vertical;
	min-height: 90px;
}

.ais-form-msg {
	font-size: 12px;
	min-height: 16px;
	color: var(--ais-muted);
}

.ais-form-err {
	color: #dc2626;
	font-weight: 600;
}

.ais-submit {
	background: var(--ais-c);
	color: #fff;
	border: none;
	border-radius: 10px;
	padding: 11px;
	font-size: 13.5px;
	font-weight: 700;
	cursor: pointer;
	font-family: inherit;
}

.ais-submit:hover { background: var(--ais-c-dark); }
.ais-submit:disabled { opacity: 0.6; }

.ais-act-back {
	flex: none;
	min-width: 0;
	padding: 9px 14px;
}

/* ---------- کارت تیکت ---------- */

.ais-ticket-card {
	background: #fff;
	border: 1px solid var(--ais-border);
	border-radius: 12px;
	padding: 10px 12px;
	font-size: 12.5px;
}

.ais-ticket-top {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
}

.ais-ticket-status {
	font-size: 10.5px;
	padding: 3px 8px;
	border-radius: 8px;
	background: #eef1f4;
	color: var(--ais-muted);
	white-space: nowrap;
	flex-shrink: 0;
}

.ais-status-ثبت-شده,
.ais-status-پاسخ-داده-شد { background: #e6f7ee; color: #15803d; }

.ais-ticket-date {
	font-size: 10.5px;
	color: var(--ais-muted);
	margin-top: 4px;
	direction: ltr;
	text-align: left;
}

.ais-ticket-reply {
	margin-top: 8px;
	padding: 8px 10px;
	background: #f0faf6;
	border-radius: 8px;
	line-height: 1.7;
	white-space: pre-wrap;
}

.ais-ticket-reply-label {
	font-size: 11px;
	font-weight: 700;
	color: var(--ais-c-dark);
	margin-bottom: 3px;
}

.ais-mtlist {
	display: flex;
	flex-direction: column;
	gap: 8px;
	overflow-y: auto;
	flex: 1;
}

/* ---------- موبایل ---------- */

@media (max-width: 480px) {
	.ais-root {
		bottom: 12px;
		left: 12px;
	}

	.ais-root.ais-pos-right {
		left: auto;
		right: 12px;
	}

	.ais-fab {
		width: 52px;
		height: 52px;
	}

	.ais-panel {
		position: fixed;
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: 100%;
		border-radius: 0;
		bottom: 0;
		left: 0;
	}
}

/* چاپ و reduce-motion */
@media (prefers-reduced-motion: reduce) {
	.ais-fab.ais-has-unread::after,
	.ais-dot {
		animation: none;
	}
}
