/* ربات هوش مصنوعی طرحستان — ویجت چت. تمام کلاس‌ها با پیشوند tfa-ai- هستند تا با Eduma و افزونه‌ها تداخل نکنند. */

#tfa-ai-root {
	--tfa-navy-1: #16213e;
	--tfa-navy-2: #0f3460;
	--tfa-accent: #f79521;
	--tfa-bg: #ffffff;
	--tfa-bubble-bot: #f3f5f9;
	--tfa-bubble-user: var(--tfa-navy-2);
	--tfa-text: #1b2030;
	--tfa-border: #e4e7ee;
	--tfa-radius: 16px;
	position: fixed;
	z-index: 999999;
	bottom: 20px;
	direction: rtl;
	font-family: inherit;
}
#tfa-ai-root.tfa-ai-pos-left { left: 20px; }
#tfa-ai-root.tfa-ai-pos-right { right: 20px; }

#tfa-ai-root * { box-sizing: border-box; }

.tfa-ai-fab {
	width: 58px; height: 58px; border-radius: 50%;
	background: linear-gradient(135deg, var(--tfa-navy-2), var(--tfa-navy-1));
	color: #fff; border: none; cursor: pointer;
	display: flex; align-items: center; justify-content: center;
	box-shadow: 0 10px 24px rgba(15, 52, 96, .35);
	transition: transform .18s ease;
	padding: 0;
}
.tfa-ai-fab:hover { transform: translateY(-2px); }
.tfa-ai-fab__dot {
	position: absolute; top: 4px; inset-inline-end: 4px;
	width: 10px; height: 10px; border-radius: 50%;
	background: var(--tfa-accent); border: 2px solid #fff;
}

.tfa-ai-welcome {
	position: absolute; bottom: 70px;
	inset-inline-start: 0;
	/* #tfa-ai-root has no explicit width (it shrinks to the 58px FAB button, its
	   only in-flow child), and this box's only inset is inset-inline-start — so
	   with just max-width (not width), the browser's shrink-to-fit sizing was
	   bounded by that 58px containing block and wrapped the text into a thin,
	   tall column. An explicit width removes that dependency; it's free to
	   render at its real size since absolutely positioned boxes aren't clipped
	   by their containing block. */
	width: min(280px, calc(100vw - 40px));
	background: #fff; color: var(--tfa-text);
	border: 1px solid var(--tfa-border); border-radius: var(--tfa-radius);
	padding: 14px 16px 14px 36px; box-shadow: 0 12px 30px rgba(20, 30, 60, .18);
	cursor: pointer; font-size: 14px; line-height: 1.8;
	animation: tfa-ai-pop .25s ease;
}
.tfa-ai-welcome p { margin: 0; }
.tfa-ai-welcome button {
	position: absolute; top: 8px; inset-inline-start: 8px;
	background: transparent; border: none; color: #9aa1b3; cursor: pointer; padding: 4px;
}

.tfa-ai-panel {
	position: absolute; bottom: 70px;
	inset-inline-start: 0;
	width: 370px; max-width: calc(100vw - 32px);
	height: min(600px, calc(100vh - 110px));
	background: var(--tfa-bg); border-radius: var(--tfa-radius);
	box-shadow: 0 20px 50px rgba(15, 20, 40, .25);
	display: flex; flex-direction: column; overflow: hidden;
	border: 1px solid var(--tfa-border);
	animation: tfa-ai-pop .22s ease;
}

.tfa-ai-panel__head {
	display: flex; align-items: center; justify-content: space-between;
	padding: 14px 16px; background: linear-gradient(135deg, var(--tfa-navy-2), var(--tfa-navy-1)); color: #fff;
	flex-shrink: 0;
}
.tfa-ai-panel__id { display: flex; align-items: center; gap: 10px; }
.tfa-ai-panel__avatar {
	width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.15);
	display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.tfa-ai-panel__id strong { display: block; font-size: 14px; }
.tfa-ai-status { color: #ffd49a; font-size: 11px; display: block; }
.tfa-ai-panel__actions { display: flex; gap: 4px; }
.tfa-ai-icon-btn {
	background: rgba(255,255,255,.12); border: none; color: #fff; border-radius: 8px;
	width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; cursor: pointer;    padding: 0;
}
.tfa-ai-icon-btn:hover { background: rgba(255,255,255,.25); }

.tfa-ai-panel__intro { padding: 10px 16px 0; margin: 0; font-size: 12.5px; color: #6b7280; line-height: 1.8; }
.tfa-ai-consult-btn {
	margin: 10px 16px 0; align-self: flex-start;
	background: #fff4e6; color: #a35a00; border: 1px solid #ffdca8;
	border-radius: 20px; padding: 6px 14px; font-size: 12.5px; cursor: pointer;
}
.tfa-ai-consult-btn:hover { background: #ffe9c7; }

.tfa-ai-messages {
	flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
	scroll-behavior: smooth;
}

.tfa-ai-msg { max-width: 86%; display: flex; flex-direction: column; gap: 4px; }
.tfa-ai-msg__bubble {
	padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.9; white-space: pre-wrap; word-break: break-word;
}
.tfa-ai-msg time { font-size: 10.5px; color: #9aa1b3; padding: 0 4px; }

.tfa-ai-msg--bot { align-self: flex-start; }
.tfa-ai-msg--bot .tfa-ai-msg__bubble { background: var(--tfa-bubble-bot); color: var(--tfa-text); border-top-right-radius: 4px; }
.tfa-ai-msg--user { align-self: flex-end; }
.tfa-ai-msg--user .tfa-ai-msg__bubble { background: var(--tfa-bubble-user); color: #fff; border-top-left-radius: 4px; }
.tfa-ai-msg--agent .tfa-ai-msg__bubble { background: #e8f6ee; color: #14532d; border: 1px solid #bfe8cf; }
.tfa-ai-msg--system { align-self: center; }
.tfa-ai-msg--system .tfa-ai-msg__bubble { background: #fef3f2; color: #9a3412; font-size: 12px; }

.tfa-ai-handoff-link {
	align-self: flex-start; background: none; border: none; color: var(--tfa-navy-2);
	text-decoration: underline; font-size: 12px; cursor: pointer; padding: 0 4px;
}

.tfa-ai-handoff-form, .tfa-ai-consult-card {
	background: #f8f9fc; border: 1px solid var(--tfa-border); border-radius: 12px; padding: 12px; font-size: 13px;
}
.tfa-ai-handoff-form label { display: block; margin: 8px 0 4px; font-size: 12.5px; color: #4b5162; }
.tfa-ai-handoff-form input[type="text"], .tfa-ai-handoff-form input[type="tel"] {
	width: 100%; padding: 7px 10px; border: 1px solid var(--tfa-border); border-radius: 8px; font-size: 13px;
}
.tfa-ai-consent { display: flex !important; align-items: flex-start; gap: 6px; font-size: 12px !important; }
.tfa-ai-consent input { margin-top: 3px; }
.tfa-ai-handoff-form__err { color: #c0392b; font-size: 12px; margin-top: 6px; }
.tfa-ai-btn-primary, .tfa-ai-handoff-form [data-submit] {
	margin-top: 10px; background: var(--tfa-navy-2); color: #fff; border: none; border-radius: 8px;
	padding: 8px 16px; font-size: 13px; cursor: pointer;
}
.tfa-ai-consult-card__body :where(form) { display: flex; flex-direction: column; gap: 8px; }
.tfa-ai-consult-card__body :where(input, textarea, select) {
	width: 100%; padding: 7px 10px; border: 1px solid var(--tfa-border); border-radius: 8px; font-size: 13px;
}
.tfa-ai-consult-empty { color: #6b7280; margin: 0; }

.tfa-ai-typing { padding: 0 16px 8px; display: flex; gap: 4px; }
.tfa-ai-typing span {
	width: 6px; height: 6px; border-radius: 50%; background: #c6cbd8;
	animation: tfa-ai-blink 1.1s infinite ease-in-out;
}
.tfa-ai-typing span:nth-child(2) { animation-delay: .15s; }
.tfa-ai-typing span:nth-child(3) { animation-delay: .3s; }

.tfa-ai-composer {
	display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--tfa-border); flex-shrink: 0; background: #fff;
}
.tfa-ai-composer textarea {
	flex: 1; resize: none; border: 1px solid var(--tfa-border); border-radius: 12px; padding: 9px 12px;
	font-size: 13.5px; max-height: 120px; font-family: inherit; line-height: 1.6;
}
.tfa-ai-composer textarea:focus { outline: 2px solid var(--tfa-navy-2); outline-offset: 1px; }
.tfa-ai-send {
	width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%; border: none; cursor: pointer;
	background: var(--tfa-navy-2); color: #fff; display: flex; align-items: center; justify-content: center;
	    padding: 0;
}
.tfa-ai-send:hover { background: var(--tfa-navy-1); }

@keyframes tfa-ai-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes tfa-ai-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

#tfa-ai-root.tfa-ai-reduced-motion .tfa-ai-panel,
#tfa-ai-root.tfa-ai-reduced-motion .tfa-ai-welcome { animation: none; }
#tfa-ai-root.tfa-ai-reduced-motion .tfa-ai-fab { transition: none; }
#tfa-ai-root.tfa-ai-reduced-motion .tfa-ai-typing span { animation-duration: 0s; opacity: .6; }

@media (prefers-reduced-motion: reduce) {
	.tfa-ai-panel, .tfa-ai-welcome { animation: none !important; }
	.tfa-ai-typing span { animation: none !important; opacity: .6; }
}

@media (max-width: 480px) {
	#tfa-ai-root.tfa-ai-pos-left, #tfa-ai-root.tfa-ai-pos-right { left: 12px; right: 12px; bottom: 12px; }
	.tfa-ai-panel, .tfa-ai-welcome { inset-inline-start: 0; inset-inline-end: 0; width: auto; }
	.tfa-ai-panel { height: min(100dvh - 90px, 640px); }
}

.tfa-ai-panel:focus-within .tfa-ai-send { outline-offset: 2px; }
