/* seAI (سیای) — © 2026 Nulvar — Tana Media (https://tanamedia.ir) — All rights reserved. This notice, the license module and the integrity manifest are protected; removing or altering them violates the license terms and is detected at runtime. */
/**
 * AI Support Chatbot — frontend widget styles.
 * Themable via CSS custom properties; RTL-aware via logical properties.
 */

.wp-ai-chatbot-app {
	--wpai-accent: #37dcf2;
	--wpai-bg: #ffffff;
	--wpai-fg: #1c2430;
	--wpai-muted: #6b7686;
	--wpai-radius: 18px;
	--wpai-shadow: 0 12px 40px rgba(15, 23, 42, 0.22);
	--wpai-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Vazirmatn, Tahoma, sans-serif;
	--wpai-font-size: 15px;
	/* v1.5.0 — theme studio variables (JS overrides per-widget). */
	--wpai-header-bg: var(--wpai-accent);
	--wpai-header-text: #08222b;
	--wpai-chat-bg: #f6f8fa;
	--wpai-bot-bg: #ffffff;
	--wpai-bot-text: var(--wpai-fg);
	--wpai-user-bg: var(--wpai-accent);
	--wpai-user-text: #08222b;
	--wpai-link: var(--wpai-accent);

	position: fixed;
	inset-block-end: 20px;
	inset-inline-end: 20px; /* bottom-right by default; .wp-ai-chatbot-pos-bottom-left flips */
	z-index: 99990;
	font-family: var(--wpai-font);
	font-size: var(--wpai-font-size);
	line-height: 1.5;
	color: var(--wpai-fg);
}

.wp-ai-chatbot-pos-bottom-left {
	inset-inline-end: auto;
	inset-inline-start: 20px;
}

/* ---------------- Toggle button ---------------- */

.wp-ai-chatbot-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 58px;
	height: 58px;
	margin-inline-start: auto;
	border: none;
	border-radius: 50%;
	background: var(--wpai-accent);
	color: #08222b;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba(15, 23, 42, 0.3);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.wp-ai-chatbot-toggle:hover,
.wp-ai-chatbot-toggle:focus-visible {
	transform: translateY(-2px) scale(1.04);
	box-shadow: 0 10px 26px rgba(15, 23, 42, 0.35);
	outline: 2px solid var(--wpai-accent);
	outline-offset: 3px;
}

/* ------------------------------------------------------------------ */
/* The HTML hidden attribute always wins over layout rules.           */
/* Without this guard, `display: flex` on the chat window would       */
/* override [hidden] and show an empty window on page load.           */
/* ------------------------------------------------------------------ */

.wp-ai-chatbot-app [hidden] {
	display: none !important;
}

/* ---------------- Chat window ---------------- */

.wp-ai-chatbot-window {
	position: absolute;
	inset-block-end: 74px;
	inset-inline-end: 0;
	display: flex;
	flex-direction: column;
	width: 372px;
	max-width: calc(100vw - 32px);
	height: var(--wpai-height, 560px);
	max-height: calc(100vh - 120px);
	max-height: calc(100dvh - 120px); /* dynamic viewport (mobile toolbars) */
	background: var(--wpai-bg);
	border-radius: var(--wpai-radius);
	box-shadow: var(--wpai-shadow);
	overflow: hidden;
	animation: wpai-in 0.22s ease;
}

.wp-ai-chatbot-pos-bottom-left .wp-ai-chatbot-window {
	inset-inline-end: auto;
	inset-inline-start: 0;
}

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

/* ---------------- Header ---------------- */

.wpai-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	background: var(--wpai-header-bg);
	color: var(--wpai-header-text);
	flex: 0 0 auto;
}

.wpai-header-dot {
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: #0a8f6b;
	box-shadow: 0 0 0 3px rgba(10, 143, 107, 0.25);
}

.wpai-title {
	font-weight: 700;
	flex: 1 1 auto;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.wpai-header-actions {
	display: flex;
	gap: 4px;
}

.wpai-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: none;
	border-radius: 8px;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.wpai-icon-btn:hover,
.wpai-icon-btn:focus-visible {
	background: rgba(0, 0, 0, 0.1);
	outline: none;
}

/* ---------------- Messages ---------------- */

.wpai-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--wpai-chat-bg);
	scroll-behavior: smooth;
}

.wpai-msg {
	display: flex;
	max-width: 86%;
}

.wpai-msg-user {
	align-self: flex-end; /* flips automatically in RTL */
}

.wpai-msg-bot {
	align-self: flex-start;
}

[dir="rtl"] .wpai-msg-user {
	align-self: flex-start;
}

[dir="rtl"] .wpai-msg-bot {
	align-self: flex-end;
}

.wpai-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	word-break: break-word;
}

.wpai-msg-user .wpai-bubble {
	background: var(--wpai-user-bg);
	color: var(--wpai-user-text);
	border-end-end-radius: 4px;
}

.wpai-msg-bot .wpai-bubble {
	background: var(--wpai-bot-bg);
	color: var(--wpai-bot-text);
	border-end-start-radius: 4px;
	box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

/* Links & inline highlights inside answers. */
.wpai-bubble a { color: var(--wpai-link); text-decoration: underline; }
.wpai-bubble mark { background: color-mix(in srgb, var(--wpai-link) 22%, transparent); color: inherit; border-radius: 4px; padding: 0 3px; }

/* Typing indicator */
.wpai-typing {
	display: inline-flex;
	gap: 5px;
	align-items: center;
	padding: 14px 16px;
}

.wpai-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--wpai-muted);
	animation: wpai-dot 1.2s infinite ease-in-out;
}

.wpai-typing span:nth-child(2) { animation-delay: 0.15s; }
.wpai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes wpai-dot {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
	30% { transform: translateY(-5px); opacity: 1; }
}

/* Rating row */
.wpai-rating {
	display: flex;
	gap: 6px;
	padding-top: 4px;
	align-self: inherit;
}

.wpai-rate {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	padding: 0;
	border: 1px solid #d7dee7;
	border-radius: 8px;
	background: #ffffff;
	color: var(--wpai-muted);
	cursor: pointer;
}

.wpai-rate:hover { color: var(--wpai-fg); border-color: var(--wpai-muted); }
.wpai-rate-active { color: var(--wpai-accent); border-color: var(--wpai-accent); }
.wpai-rated-up .wpai-rate:first-child { color: #16a34a; border-color: #16a34a; }
.wpai-rated-down .wpai-rate:last-child { color: #dc2626; border-color: #dc2626; }

/* ---------------- Composer ---------------- */

.wpai-composer {
	display: flex;
	gap: 8px;
	padding: 12px;
	background: var(--wpai-bg);
	border-top: 1px solid #e6ebf1;
	flex: 0 0 auto;
}

.wpai-input {
	flex: 1 1 auto;
	min-width: 0;
	padding: 11px 14px;
	border: 1px solid #d7dee7;
	border-radius: 24px;
	background: #ffffff;
	color: var(--wpai-fg);
	font: inherit;
}

.wpai-input:focus {
	outline: 2px solid var(--wpai-accent);
	outline-offset: 1px;
	border-color: transparent;
}

.wpai-input:disabled { opacity: 0.6; }

.wpai-send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--wpai-accent);
	color: #08222b;
	cursor: pointer;
	transition: transform 0.15s ease;
}

.wpai-send:hover { transform: scale(1.06); }
.wpai-send:focus-visible { outline: 2px solid var(--wpai-fg); outline-offset: 2px; }

/* Stop button state while streaming */
.wpai-send.wpai-stop {
	background: #ef4444;
	color: #ffffff;
}

/* ---------------- Mobile ---------------- */

/* ---------------- Mobile ---------------- */

/* Tablet (portrait & small laptops): fluid window width. */
@media (max-width: 768px) {
	.wp-ai-chatbot-window {
		width: min(420px, calc(100vw - 40px));
	}
	.wpai-input { font-size: 16px; } /* no iOS focus zoom on tablets either */
}

@media (max-width: 480px) {
	.wp-ai-chatbot-app {
		inset-block-end: 0;
		inset-inline-end: 0;
		inset-inline-start: 0;
	}

	.wp-ai-chatbot-pos-bottom-left {
		inset-inline-start: 0;
	}

	.wp-ai-chatbot-toggle {
		width: 52px;
		height: 52px;
		margin-inline-end: 14px;
		/* Keep clear of the iOS home-indicator / Android gesture bar. */
		margin-block-end: calc(14px + env(safe-area-inset-bottom, 0px));
	}

	/* iOS zooms the viewport when focusing inputs smaller than 16px. */
	.wpai-input { font-size: 16px; }

	/* Comfortable thumb targets (44px minimum, Apple HIG). */
	.wpai-send,
	.wpai-mic-btn { min-width: 44px; min-height: 44px; }

	.wpai-chip { padding: 10px 15px; font-size: 14px; }

	.wpai-msg .wpai-bubble { max-width: 88%; }

	.wp-ai-chatbot-app .wp-ai-chatbot-window {
		position: fixed;
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100vh;
		height: 100dvh; /* tracks the collapsing Safari/Chrome toolbar */
		max-height: 100vh;
		max-height: 100dvh;
		border-radius: 0;
	}

	/* Composer sits above the home indicator on notched phones. */
	.wpai-composer {
		padding-block-end: calc(10px + env(safe-area-inset-bottom, 0px));
	}
}

/* Landscape phones: a full-width bottom sheet instead of a square
   fullscreen — keeps the input reachable above the keyboard. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
	.wp-ai-chatbot-app .wp-ai-chatbot-window {
		position: fixed;
		inset: auto 0 0 0;
		width: 100%;
		max-width: 100%;
		height: 100vh;
		height: 100dvh;
		max-height: 100dvh;
		border-radius: var(--wpai-radius) var(--wpai-radius) 0 0;
	}
}

/* Respect reduced motion preferences. */
@media (prefers-reduced-motion: reduce) {
	.wp-ai-chatbot-window,
	.wpai-typing span,
	.wp-ai-chatbot-toggle {
		animation: none !important;
		transition: none !important;
	}
	.wpai-messages { scroll-behavior: auto; }
}

/* ------------------------------------------------------------------ */
/* Support / sales chips (v1.4.0)                                       */
/* ------------------------------------------------------------------ */

.wpai-support-row,
.wpai-sales-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	margin-top: 6px;
}

.wpai-support-phone {
	font-size: 12px;
	color: var(--wpai-muted);
	white-space: nowrap;
}

.wpai-sales-link {
	border: 1px solid var(--wpai-accent);
	color: var(--wpai-accent);
	font-weight: 600;
}

.wpai-sales-form-btn {
	border-style: dashed;
}

/* ------------------------------------------------------------------ */
/* Related-question suggestions (after fallback answers)                */
/* ------------------------------------------------------------------ */

.wpai-quick-replies.wpai-suggested {
	padding: 4px 0 2px;
	border-top: 1px dashed #e3e8ef;
}

/* ------------------------------------------------------------------ */
/* Inline embeds (shortcode / Elementor / Gutenberg)                    */
/* ------------------------------------------------------------------ */

.wp-ai-chatbot-app.wp-ai-chatbot-inline {
	position: static;
	inset: auto;
	width: 100%;
	max-width: 560px;
	margin-inline: auto;
}

.wp-ai-chatbot-inline .wp-ai-chatbot-window {
	position: relative;
	inset: auto;
	display: flex;
	width: 100%;
	max-width: 100%;
	height: 540px;
	max-height: 75vh;
	animation: none;
}

/* ------------------------------------------------------------------ */
/* Header extras: avatar                                               */
/* ------------------------------------------------------------------ */

.wpai-avatar {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	object-fit: cover;
	background: rgba(255, 255, 255, 0.4);
}

/* ------------------------------------------------------------------ */
/* Quick replies                                                       */
/* ------------------------------------------------------------------ */

.wpai-quick-replies {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 2px 0;
}

.wpai-chip {
	border: 1px solid var(--wpai-accent);
	background: #ffffff;
	color: #1c2430;
	border-radius: 16px;
	padding: 7px 14px;
	font: 500 13px/1 var(--wpai-font, inherit);
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.wpai-chip:hover,
.wpai-chip:focus-visible {
	background: var(--wpai-accent);
	color: #08222b;
	outline: none;
}

/* ------------------------------------------------------------------ */
/* Composer tools: mic button                                          */
/* ------------------------------------------------------------------ */

.wpai-composer-tools {
	display: flex;
	align-items: center;
}

.wpai-mic-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 44px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: var(--wpai-muted);
	cursor: pointer;
}

.wpai-mic-btn:hover { color: var(--wpai-fg); }
.wpai-mic-btn:focus-visible { outline: 2px solid var(--wpai-accent); outline-offset: 1px; }

.wpai-mic-active {
	color: #dc2626;
	animation: wpai-pulse 1.2s infinite;
}

@keyframes wpai-pulse {
	0%, 100% { transform: scale(1); }
	50% { transform: scale(1.18); }
}

/* ------------------------------------------------------------------ */
/* Message extras: copy, sources, fullscreen                            */
/* ------------------------------------------------------------------ */

.wpai-copy-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	padding: 0;
	border: 1px solid #d7dee7;
	border-radius: 8px;
	background: #ffffff;
	color: var(--wpai-muted);
	cursor: pointer;
}

.wpai-copy-btn:hover { color: var(--wpai-fg); border-color: var(--wpai-muted); }
.wpai-copy-done { color: #16a34a; border-color: #16a34a; }

.wpai-sources {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 5px;
	padding-top: 4px;
}

.wpai-sources-label {
	font-size: 11px;
	color: var(--wpai-muted);
}

.wpai-source-chip {
	display: inline-block;
	font-size: 11px;
	padding: 2px 9px;
	border-radius: 10px;
	background: #eef2f6;
	color: #445;
	max-width: 160px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.wp-ai-chatbot-window.wpai-fullscreen {
	position: fixed;
	inset: 0;
	z-index: 99999;
	width: 100%;
	max-width: 100%;
	height: 100%;
	max-height: 100%;
	border-radius: 0;
}

/* ------------------------------------------------------------------ */
/* Disclaimer                                                          */
/* ------------------------------------------------------------------ */

.wpai-disclaimer {
	padding: 7px 14px;
	font-size: 11px;
	line-height: 1.5;
	color: var(--wpai-muted);
	background: var(--wpai-bg);
	border-top: 1px solid #e6ebf1;
	text-align: center;
}

/* ------------------------------------------------------------------ */
/* Attribution (license-protected credit line)                         */
/* ------------------------------------------------------------------ */

.wpai-attribution {
	padding: 6px 14px;
	font-size: 11px;
	line-height: 1.4;
	text-align: center;
	border-top: 1px solid #e6ebf1;
	background: var(--wpai-bg);
}

.wpai-attribution a {
	color: var(--wpai-muted);
	text-decoration: none;
	font-weight: 500;
	transition: color 0.15s ease;
}

.wpai-attribution a:hover,
.wpai-attribution a:focus-visible {
	color: var(--wpai-accent, #37DCF2);
	text-decoration: underline;
}

/* ------------------------------------------------------------------ */
/* Human handoff                                                       */
/* ------------------------------------------------------------------ */

.wpai-handoff-row { margin-top: 6px; }

.wpai-handoff-btn {
	border: 1px dashed var(--wpai-accent);
	background: rgba(55, 220, 242, 0.06);
	color: #1c2430;
	border-radius: 12px;
	padding: 8px 14px;
	font: 600 12px/1.3 var(--wpai-font, inherit);
	cursor: pointer;
}

.wpai-handoff-btn:hover { background: rgba(55, 220, 242, 0.15); }

.wpai-handoff-form {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: 8px;
	padding: 10px;
	border: 1px solid #d7dee7;
	border-radius: 12px;
	background: #ffffff;
	width: 100%;
	max-width: 340px;
}

.wpai-handoff-input {
	border: 1px solid #d7dee7;
	border-radius: 10px;
	padding: 8px 11px;
	font: inherit;
	font-size: 13px;
	width: 100%;
}

.wpai-handoff-input:focus {
	outline: 2px solid var(--wpai-accent);
	border-color: transparent;
}

.wpai-handoff-textarea { resize: vertical; }

.wpai-hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	opacity: 0;
}

.wpai-handoff-actions {
	display: flex;
	gap: 8px;
	justify-content: flex-end;
}

.wpai-handoff-submit {
	border: none;
	border-radius: 10px;
	background: var(--wpai-accent);
	color: #08222b;
	font: 600 13px/1 var(--wpai-font, inherit);
	padding: 10px 16px;
	cursor: pointer;
}

.wpai-handoff-cancel {
	border: none;
	background: transparent;
	color: var(--wpai-muted);
	font: 500 13px/1 var(--wpai-font, inherit);
	padding: 10px 8px;
	cursor: pointer;
}

.wpai-handoff-status { font-size: 12px; min-height: 16px; }
.wpai-handoff-ok { color: #16a34a; }
.wpai-handoff-err { color: #dc2626; }

/* ------------------------------------------------------------------ */
/* Proactive teaser bubble                                             */
/* ------------------------------------------------------------------ */

.wpai-teaser {
	position: absolute;
	inset-block-end: 74px;
	inset-inline-end: 0;
	width: min(280px, calc(100vw - 90px));
	padding: 12px 16px;
	border: none;
	border-radius: 14px;
	background: #1c2430;
	color: #f2f6fa;
	font: 500 13px/1.5 var(--wpai-font, inherit);
	text-align: start;
	box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3);
	cursor: pointer;
	animation: wpai-in 0.25s ease;
}

.wpai-teaser:hover { background: #273140; }
.wpai-teaser:focus-visible { outline: 2px solid var(--wpai-accent); outline-offset: 2px; }

.wp-ai-chatbot-pos-bottom-left .wpai-teaser {
	inset-inline-end: auto;
	inset-inline-start: 0;
}

/* Inline embeds hide the teaser. */
.wp-ai-chatbot-inline .wpai-teaser { display: none; }

/* ------------------------------------------------------------------ */
/* v1.5.0 — micro-interactions (bubbles pop in, chips lift on hover)   */
/* ------------------------------------------------------------------ */

/* Bubbles pop in softly (respects reduced motion). */
@keyframes wpai-pop {
	from { opacity: 0; transform: translateY(6px) scale(0.98); }
	to { opacity: 1; transform: none; }
}

.wpai-msg {
	animation: wpai-pop 0.22s ease-out;
}

/* Chips get a tiny lift on hover. */
.wpai-chip {
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.wpai-chip:hover {
	transform: translateY(-1px);
	box-shadow: 0 3px 10px rgba(15, 23, 42, 0.14);
}

/* Header brand logo. */
.wpai-logo {
	width: 26px;
	height: 26px;
	object-fit: contain;
	border-radius: 6px;
	flex: 0 0 auto;
	background: rgba(255, 255, 255, 0.35);
}

/* Respect users who prefer less motion. */
@media (prefers-reduced-motion: reduce) {
	.wpai-msg { animation: none; }
}
