/* ==========================================================================
   خانم الکترون — استایل ویجت فرانت‌اند
   تمام قوانین زیر مقیّد به #khelectron-root است تا با قالب یا افزونه‌های
   دیگر سایت تداخل نداشته باشد (هیچ استایل سراسری تغییر داده نمی‌شود).
   ========================================================================== */

#khelectron-root {
	--khe-color-body: #FFC42D;
	--khe-color-body-dark: #E8A400;
	--khe-color-face: #FFFFFF;
	--khe-color-gloves: #FFFFFF;
	--khe-color-glow: #FFF59D;
	--khe-color-cheeks: #FDBA8C;
	--khe-popup-bg: #FFFFFF;
	--khe-popup-text-color: #1F2937;
	--khe-popup-accent: #CA8A04;
	--khe-icon-size: 72px;
	--khe-scale: 1;

	position: fixed;
	inset: 0;
	width: 0;
	height: 0;
	z-index: 2147483000;
	pointer-events: none;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, "IRANSans", "Vazirmatn", Arial, sans-serif;
	direction: rtl;
}

#khelectron-root * {
	box-sizing: border-box;
}

#khelectron-root .khe-hidden {
	display: none !important;
}

/* --------------------------------------------------------------------
   شخصیت
   -------------------------------------------------------------------- */
.khe-character {
	position: fixed;
	width: calc(var(--khe-icon-size) * var(--khe-scale));
	height: calc(var(--khe-icon-size) * 1.55 * var(--khe-scale));
	pointer-events: auto;
	transition: left 2.4s cubic-bezier(.45, 0, .3, 1), top 2.4s cubic-bezier(.45, 0, .3, 1);
	will-change: left, top;
	cursor: grab;
	touch-action: none;
}

.khe-character.khe-dragging {
	transition: none;
	cursor: grabbing;
}
.khe-character.khe-dragging .khe-character-inner {
	animation-play-state: paused;
}

.khe-character-inner {
	position: relative;
	width: 100%;
	height: 100%;
	animation: khe-bob 3.6s ease-in-out infinite;
	filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .18));
}

@keyframes khe-bob {
	0%, 100% { transform: translateY(0); }
	50%      { transform: translateY(-6%); }
}

.khe-svg {
	width: 100%;
	height: 100%;
	overflow: visible;
	display: block;
}

/* بدنه */
.khe-body-fill {
	fill: var(--khe-color-body);
}
.khe-body-shade {
	fill: var(--khe-color-body-dark);
	opacity: .35;
}

/* حلقه‌های الکترون (نشانه‌ی الکتریسیته) */
.khe-orbit-ring {
	fill: none;
	stroke: var(--khe-color-glow);
	stroke-width: 2;
	opacity: .8;
}
.khe-electron-dot {
	fill: var(--khe-color-glow);
	filter: drop-shadow(0 0 3px var(--khe-color-glow));
}

/* صورت */
.khe-eye {
	fill: #26313f;
}
.khe-eye-shine {
	fill: #ffffff;
}
.khe-mouth {
	fill: none;
	stroke: #26313f;
	stroke-width: 2.6;
	stroke-linecap: round;
}
.khe-cheek {
	fill: var(--khe-color-cheeks);
	opacity: .55;
}

/* پاها (رنگ بدنه) */
.khe-limb {
	fill: var(--khe-color-body);
}
/* دست‌ها — دستکش سفید کوچک، به‌صورت پیش‌فرض پشت بدن پنهانند */
.khe-hand {
	fill: var(--khe-color-gloves);
}
.khe-shadow {
	fill: #0f172a;
	opacity: .18;
	filter: blur(1.5px);
}

.khe-arm-left,
.khe-arm-right {
	transform-origin: 50px 76px;
}
.khe-arm-right {
	transition: transform .5s cubic-bezier(.34, 1.56, .64, 1);
}

/* حالت «سوال دارم»: دست راست از پشت بیرون می‌آید و رو به کاربر دراز می‌شود */
.khe-character.khe-hand-raised .khe-arm-right {
	transform: translate(32px, -44px) rotate(-22deg);
}

/* دست تکان دادن (سلام) هنگام بارگذاری صفحه */
@keyframes khe-wave {
	0%   { transform: translate(0, 0) rotate(0deg); }
	14%  { transform: translate(30px, -42px) rotate(-8deg); }
	30%  { transform: translate(34px, -44px) rotate(24deg); }
	46%  { transform: translate(34px, -44px) rotate(-16deg); }
	62%  { transform: translate(34px, -44px) rotate(24deg); }
	78%  { transform: translate(34px, -44px) rotate(-8deg); }
	100% { transform: translate(0, 0) rotate(0deg); }
}
.khe-arm-right.khe-wave {
	animation: khe-wave 2.3s ease-in-out 1;
}

/* راه رفتن پاها هنگام جابه‌جایی روی صفحه */
.khe-leg-left {
	transform-origin: 38px 112px;
}
.khe-leg-right {
	transform-origin: 62px 112px;
}
@keyframes khe-walk-left {
	0%, 100% { transform: rotate(0deg); }
	25%       { transform: rotate(16deg); }
	75%       { transform: rotate(-16deg); }
}
@keyframes khe-walk-right {
	0%, 100% { transform: rotate(0deg); }
	25%       { transform: rotate(-16deg); }
	75%       { transform: rotate(16deg); }
}
.khe-character.khe-walking .khe-leg-left {
	animation: khe-walk-left .5s ease-in-out infinite;
}
.khe-character.khe-walking .khe-leg-right {
	animation: khe-walk-right .5s ease-in-out infinite;
}

/* ظاهرشدن چرخشی هنگام بارگذاری/رفرش صفحه */
@keyframes khe-entrance {
	0%   { transform: scale(0) rotate(0deg); opacity: 0; }
	60%  { transform: scale(1.12) rotate(360deg); opacity: 1; }
	100% { transform: scale(1) rotate(360deg); opacity: 1; }
}
.khe-character.khe-entering {
	animation: khe-entrance .9s cubic-bezier(.34, 1.56, .64, 1) 1;
}

/* چرخش کوتاه هنگام رفتن به گوشه‌ی صفحه (پس از «سوالی ندارم») */
@keyframes khe-turn {
	from { transform: rotate(0deg); }
	to   { transform: rotate(360deg); }
}
.khe-character.khe-turning {
	animation: khe-turn .6s ease-in-out 1;
}

/* --------------------------------------------------------------------
   برچسب‌های بالای سر (سوال دارم / سوالی ندارم)
   -------------------------------------------------------------------- */
.khe-labels {
	position: absolute;
	bottom: calc(100% + 6px);
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	gap: 6px;
	white-space: nowrap;
}

.khe-label-btn {
	font-size: 11px;
	line-height: 1;
	padding: 6px 10px;
	border: none;
	border-radius: 999px;
	background: var(--khe-popup-accent);
	color: #fff;
	box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
	cursor: pointer;
	opacity: .92;
	transition: transform .15s ease, opacity .15s ease;
}
.khe-label-btn:hover,
.khe-label-btn:focus-visible {
	transform: translateY(-2px);
	opacity: 1;
}

/* --------------------------------------------------------------------
   دکمه‌ی «همین‌جا بمون» (سنجاق)
   -------------------------------------------------------------------- */
.khe-pin-btn {
	position: absolute;
	top: -4px;
	inset-inline-end: -4px;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	border: none;
	background: #ffffff;
	color: var(--khe-popup-accent);
	box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
	cursor: pointer;
	opacity: .6;
	transition: opacity .2s ease, transform .2s ease, background .2s ease, color .2s ease;
}
.khe-character:hover .khe-pin-btn,
.khe-pin-btn:focus-visible {
	opacity: 1;
}
.khe-pin-btn.khe-pin-active {
	opacity: 1;
	background: var(--khe-popup-accent);
	color: #fff;
	transform: rotate(45deg);
}

/* --------------------------------------------------------------------
   پاپ‌آپ‌ها (پایه‌ی مشترک)
   -------------------------------------------------------------------- */
.khe-popup {
	position: fixed;
	max-width: min(320px, 88vw);
	background: var(--khe-popup-bg);
	color: var(--khe-popup-text-color);
	border-radius: 16px;
	box-shadow: 0 12px 30px rgba(0, 0, 0, .22);
	padding: 14px 16px;
	pointer-events: auto;
	z-index: 2147483001;
	animation: khe-pop-in .28s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes khe-pop-in {
	0%   { opacity: 0; transform: scale(.85) translateY(6px); }
	100% { opacity: 1; transform: scale(1) translateY(0); }
}

.khe-popup-close {
	position: absolute;
	top: 8px;
	inset-inline-start: 8px;
	width: 22px;
	height: 22px;
	border: none;
	border-radius: 50%;
	background: rgba(220, 38, 38, .12);
	color: #dc2626;
	font-size: 14px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background .15s ease, color .15s ease;
}
.khe-popup-close:hover,
.khe-popup-close:focus-visible {
	background: #dc2626;
	color: #fff;
}

.khe-popup-tail {
	position: absolute;
	width: 14px;
	height: 14px;
	background: inherit;
	transform: rotate(45deg);
}

.khe-popup-title {
	font-weight: 700;
	font-size: 14px;
	margin: 0 22px 8px 0;
}

.khe-popup-body {
	font-size: 13.5px;
	line-height: 1.9;
	margin: 0;
	padding-inline-start: 2px;
}

/* رشته‌ی گفتگو (سوال و پاسخ‌های پیاپی در همان پاپ‌آپ) */
.khe-chat-thread {
	display: flex;
	flex-direction: column;
	gap: 8px;
	flex: 1 1 auto;
	min-height: 50px;
	overflow-y: auto;
	margin: 4px 0 10px;
	padding-inline-end: 2px;
}
.khe-msg {
	font-size: 13px;
	line-height: 1.8;
	padding: 8px 12px;
	border-radius: 14px;
	max-width: 88%;
	word-break: break-word;
}
.khe-msg-user {
	align-self: flex-end;
	background: var(--khe-popup-accent);
	color: #fff;
	border-end-end-radius: 4px;
}
.khe-msg-bot {
	align-self: flex-start;
	background: rgba(0, 0, 0, .06);
	color: var(--khe-popup-text-color);
	border-end-start-radius: 4px;
}
.khe-msg-bot.khe-msg-error {
	background: rgba(220, 38, 38, .08);
	color: #b91c1c;
}
.khe-msg-bot .khe-listen-btn {
	margin-top: 6px;
}

/* حباب گفتگوی کوچک */
.khe-popup-speech {
	max-width: min(240px, 80vw);
	font-size: 13px;
	padding: 10px 14px;
}

.khe-msg-quote {
	font-size: 11.5px;
	opacity: .8;
	border-inline-start: 2px solid currentColor;
	padding-inline-start: 6px;
	margin-bottom: 4px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.khe-msg-actions {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 6px;
	flex-wrap: wrap;
}

.khe-reply-btn {
	border: none;
	background: rgba(0, 0, 0, .06);
	color: var(--khe-popup-text-color);
	border-radius: 999px;
	padding: 5px 10px;
	font-size: 12px;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	cursor: pointer;
	white-space: nowrap;
	opacity: .8;
}
.khe-reply-btn:hover {
	background: rgba(0, 0, 0, .12);
	opacity: 1;
}

.khe-reply-banner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	background: rgba(0, 0, 0, .05);
	border-inline-start: 3px solid var(--khe-popup-accent);
	border-radius: 8px;
	padding: 6px 10px;
	margin-top: 6px;
	font-size: 11.5px;
}
.khe-reply-banner-text {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex: 1;
}
.khe-reply-cancel {
	border: none;
	background: transparent;
	color: inherit;
	font-size: 14px;
	line-height: 1;
	cursor: pointer;
	flex: none;
	padding: 2px 4px;
}
.khe-reply-cancel:hover {
	color: #dc2626;
}

/* دفترچه‌ی سوال */
/* دفترچه‌ی سوال / رشته‌ی گفتگو — چیدمان ستونی برای پشتیبانی از تغییر سایز */
.khe-popup-notebook {
	display: flex;
	flex-direction: column;
	overflow: hidden;
}
.khe-popup-notebook.khe-resizing {
	transition: none;
	box-shadow: 0 0 0 2px var(--khe-popup-accent), 0 12px 30px rgba(0, 0, 0, .22);
}

.khe-resize-handle {
	position: absolute;
	touch-action: none;
	flex: none;
}
.khe-resize-corner {
	right: 2px;
	bottom: 2px;
	width: 18px;
	height: 18px;
	cursor: nwse-resize;
	display: none;
	background: linear-gradient(
		135deg,
		transparent 0 40%,
		rgba(0, 0, 0, .28) 40% 46%,
		transparent 46% 58%,
		rgba(0, 0, 0, .28) 58% 64%,
		transparent 64% 100%
	);
}
@media (min-width: 600px) {
	.khe-popup-notebook .khe-resize-corner {
		display: block;
	}
}

.khe-resize-handle-mobile {
	display: none;
	justify-content: center;
	align-items: center;
	padding: 2px 0 8px;
	cursor: ns-resize;
	flex: none;
}
.khe-resize-handle-mobile::before {
	content: '';
	width: 36px;
	height: 4px;
	border-radius: 2px;
	background: rgba(0, 0, 0, .2);
}
@media (max-width: 599px) {
	.khe-popup-notebook .khe-resize-handle-mobile {
		display: flex;
		position: static;
	}
	.khe-popup-notebook {
		overflow: hidden !important; /* رشته‌ی گفتگو خودش اسکرول می‌شود، نه کل پاپ‌آپ */
	}
}

.khe-notebook-textarea {
	width: 100%;
	min-height: 64px;
	resize: vertical;
	border: 1px solid rgba(0, 0, 0, .12);
	border-radius: 10px;
	padding: 10px;
	font-family: inherit;
	font-size: 13.5px;
	margin-top: 4px;
	background: repeating-linear-gradient(
		to bottom,
		transparent,
		transparent 27px,
		rgba(0, 0, 0, .07) 28px
	);
	color: var(--khe-popup-text-color);
}
.khe-notebook-textarea:focus {
	outline: 2px solid var(--khe-popup-accent);
	outline-offset: 1px;
}

.khe-send-btn {
	margin-top: 10px;
	width: 100%;
	border: none;
	border-radius: 10px;
	padding: 9px 12px;
	background: var(--khe-popup-accent);
	color: #fff;
	font-size: 13.5px;
	font-weight: 600;
	cursor: pointer;
	transition: filter .15s ease;
}
.khe-send-btn:hover {
	filter: brightness(1.08);
}
.khe-send-btn:disabled {
	opacity: .6;
	cursor: default;
}

/* در حال بارگذاری */
.khe-loading-row {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
}
.khe-spinner {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	border: 2.5px solid rgba(0, 0, 0, .15);
	border-top-color: var(--khe-popup-accent);
	animation: khe-spin .8s linear infinite;
	flex: none;
}
@keyframes khe-spin {
	to { transform: rotate(360deg); }
}

.khe-listen-btn {
	border: none;
	background: rgba(0, 0, 0, .06);
	color: var(--khe-popup-accent);
	border-radius: 999px;
	padding: 5px 10px;
	font-size: 12px;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	cursor: pointer;
	white-space: nowrap;
}
.khe-listen-btn:hover {
	background: rgba(0, 0, 0, .12);
}
.khe-listen-btn.khe-listening {
	background: var(--khe-popup-accent);
	color: #fff;
}
.khe-listen-btn.khe-tts-loading {
	opacity: .8;
	cursor: default;
}
.khe-listen-btn.khe-tts-error {
	background: rgba(220, 38, 38, .12);
	color: #dc2626;
}
.khe-mini-spinner {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	border: 2px solid rgba(0, 0, 0, .15);
	border-top-color: var(--khe-popup-accent);
	animation: khe-spin .7s linear infinite;
	display: inline-block;
}

/* --------------------------------------------------------------------
   واکنش‌گرا: تبلت و موبایل
   -------------------------------------------------------------------- */
@media (max-width: 1024px) {
	.khe-character { --khe-scale: 0.9; }
}

@media (max-width: 600px) {
	.khe-character { --khe-scale: 0.75; }

	.khe-popup:not(.khe-popup-speech) {
		left: 0 !important;
		right: 0;
		bottom: 0 !important;
		top: auto !important;
		max-width: 100%;
		width: 100%;
		border-radius: 18px 18px 0 0;
		max-height: 75vh;
		overflow-y: auto;
		box-shadow: 0 -8px 24px rgba(0, 0, 0, .25);
	}
	.khe-popup:not(.khe-popup-speech) .khe-popup-tail {
		display: none;
	}

	.khe-labels {
		bottom: calc(100% + 4px);
	}
	.khe-label-btn {
		font-size: 10px;
		padding: 5px 8px;
	}
}

@media (max-width: 360px) {
	#khelectron-root.khe-hide-on-tiny {
		display: none;
	}
}

/* احترام به تنظیم کاهش حرکت سیستم‌عامل کاربر */
@media (prefers-reduced-motion: reduce) {
	.khe-character-inner {
		animation: none;
	}
	.khe-electron-dot animateMotion,
	.khe-orbit-ring {
		animation-play-state: paused;
	}
	.khe-character {
		transition: none;
	}
	.khe-character.khe-entering,
	.khe-character.khe-turning,
	.khe-character.khe-walking .khe-leg-left,
	.khe-character.khe-walking .khe-leg-right,
	.khe-arm-right.khe-wave {
		animation: none;
	}
}
