/**
 * AI Assistant — floating admin chat UI.
 *
 * Everything is namespaced under .afb-ai-chat* and defensively reset so wp-admin
 * styles can't bleed in. No external fonts or libraries. Brand accent: #6d4aff
 * with a complementary indigo/blue for the gradient.
 */

.afb-ai-chat-root {
	--afb-ai-accent: #6d4aff;
	--afb-ai-accent-2: #4a7bff;
	--afb-ai-accent-3: #9b5cff;
	--afb-ai-ink: #1e2233;
	--afb-ai-ink-soft: #5b6072;
	--afb-ai-line: #e7e8f0;
	--afb-ai-bg: #ffffff;
	--afb-ai-bg-soft: #f6f7fb;
	--afb-ai-radius: 16px;
	--afb-ai-shadow: 0 12px 40px rgba(31, 27, 74, 0.22), 0 2px 8px rgba(31, 27, 74, 0.12);
}

/* ------------------------------------------------------------------ Launcher */

.afb-ai-chat-launcher {
	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 99990;
	width: 56px;
	height: 56px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	background: linear-gradient(135deg, var(--afb-ai-accent) 0%, var(--afb-ai-accent-3) 50%, var(--afb-ai-accent-2) 100%);
	box-shadow: var(--afb-ai-shadow);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	-webkit-appearance: none;
	appearance: none;
	overflow: hidden;
}

.afb-ai-chat-launcher:hover,
.afb-ai-chat-launcher:focus-visible {
	transform: scale(1.06);
	box-shadow: 0 16px 48px rgba(31, 27, 74, 0.28), 0 3px 10px rgba(31, 27, 74, 0.16);
	outline: none;
}

.afb-ai-chat-launcher:focus-visible {
	outline: 3px solid rgba(109, 74, 255, 0.4);
	outline-offset: 2px;
}

.afb-ai-chat-launcher svg {
	width: 26px;
	height: 26px;
	display: block;
	position: relative;
	z-index: 1;
}

/* Subtle idle shimmer sweeping across the button. */
.afb-ai-chat-launcher::after {
	content: "";
	position: absolute;
	top: -60%;
	left: -60%;
	width: 60%;
	height: 220%;
	background: linear-gradient(120deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.35) 50%, rgba(255, 255, 255, 0) 100%);
	transform: rotate(18deg);
	animation: afb-ai-shimmer 4.5s ease-in-out infinite;
	z-index: 0;
}

@keyframes afb-ai-shimmer {
	0%, 60% { left: -60%; }
	100% { left: 130%; }
}

.afb-ai-chat-launcher.afb-ai-is-open {
	transform: scale(0.9);
	opacity: 0.92;
}

/* A tiny notification pulse ring when idle. */
.afb-ai-chat-launcher::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	box-shadow: 0 0 0 0 rgba(109, 74, 255, 0.45);
	animation: afb-ai-pulse 3.2s ease-out infinite;
}

@keyframes afb-ai-pulse {
	0% { box-shadow: 0 0 0 0 rgba(109, 74, 255, 0.4); }
	70% { box-shadow: 0 0 0 14px rgba(109, 74, 255, 0); }
	100% { box-shadow: 0 0 0 0 rgba(109, 74, 255, 0); }
}

/* ------------------------------------------------------------------- Panel */

.afb-ai-chat-panel {
	position: fixed;
	right: 24px;
	bottom: 92px;
	z-index: 99991;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 120px);
	display: flex;
	flex-direction: column;
	background: var(--afb-ai-bg);
	border: 1px solid var(--afb-ai-line);
	border-radius: var(--afb-ai-radius);
	box-shadow: var(--afb-ai-shadow);
	overflow: hidden;
	transform: translateY(12px) scale(0.98);
	transform-origin: right bottom;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.18s ease, transform 0.18s ease;
	font-size: 14px;
	line-height: 1.5;
	color: var(--afb-ai-ink);
	box-sizing: border-box;
}

.afb-ai-chat-panel.afb-ai-is-open {
	transform: translateY(0) scale(1);
	opacity: 1;
	pointer-events: auto;
}

.afb-ai-chat-panel *,
.afb-ai-chat-panel *::before,
.afb-ai-chat-panel *::after {
	box-sizing: border-box;
}

/* ------------------------------------------------------------------ Header */

.afb-ai-chat-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 14px 14px 16px;
	color: #fff;
	background: linear-gradient(120deg, var(--afb-ai-accent) 0%, var(--afb-ai-accent-3) 55%, var(--afb-ai-accent-2) 100%);
	flex: 0 0 auto;
}

.afb-ai-chat-avatar {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.18);
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
}

.afb-ai-chat-avatar svg {
	width: 20px;
	height: 20px;
	display: block;
}

.afb-ai-chat-heading {
	flex: 1 1 auto;
	min-width: 0;
}

.afb-ai-chat-heading strong {
	display: block;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
}

.afb-ai-chat-heading span {
	display: block;
	font-size: 12px;
	opacity: 0.85;
	line-height: 1.2;
}

.afb-ai-chat-close {
	flex: 0 0 auto;
	width: 30px;
	height: 30px;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.14);
	color: #fff;
	cursor: pointer;
	font-size: 18px;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease;
	padding: 0;
}

.afb-ai-chat-close:hover {
	background: rgba(255, 255, 255, 0.28);
}

/* -------------------------------------------------------------------- Body */

.afb-ai-chat-body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	background: var(--afb-ai-bg-soft);
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.afb-ai-chat-body::-webkit-scrollbar {
	width: 8px;
}

.afb-ai-chat-body::-webkit-scrollbar-thumb {
	background: #d5d7e3;
	border-radius: 8px;
}

/* Empty state */

.afb-ai-chat-empty {
	margin: auto 0;
	text-align: center;
	padding: 8px 4px 4px;
}

.afb-ai-chat-empty-badge {
	width: 48px;
	height: 48px;
	margin: 0 auto 12px;
	border-radius: 14px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	background: linear-gradient(135deg, var(--afb-ai-accent) 0%, var(--afb-ai-accent-2) 100%);
	box-shadow: 0 8px 20px rgba(109, 74, 255, 0.35);
}

.afb-ai-chat-empty-badge svg {
	width: 26px;
	height: 26px;
}

.afb-ai-chat-empty p {
	margin: 0 0 14px;
	color: var(--afb-ai-ink-soft);
	font-size: 13.5px;
}

.afb-ai-chat-suggestions {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.afb-ai-chat-suggestion {
	border: 1px solid var(--afb-ai-line);
	background: #fff;
	color: var(--afb-ai-ink);
	border-radius: 12px;
	padding: 10px 12px;
	font-size: 13px;
	text-align: left;
	cursor: pointer;
	transition: border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.afb-ai-chat-suggestion:hover {
	border-color: var(--afb-ai-accent);
	transform: translateY(-1px);
	box-shadow: 0 4px 14px rgba(109, 74, 255, 0.15);
}

/* Messages */

.afb-ai-chat-msg {
	display: flex;
	flex-direction: column;
	max-width: 86%;
}

.afb-ai-chat-msg--user {
	align-self: flex-end;
	align-items: flex-end;
}

.afb-ai-chat-msg--assistant {
	align-self: flex-start;
	align-items: flex-start;
}

.afb-ai-chat-bubble {
	padding: 9px 13px;
	border-radius: 14px;
	font-size: 13.5px;
	line-height: 1.5;
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.afb-ai-chat-msg--user .afb-ai-chat-bubble {
	background: linear-gradient(135deg, var(--afb-ai-accent) 0%, var(--afb-ai-accent-2) 100%);
	color: #fff;
	border-bottom-right-radius: 5px;
}

.afb-ai-chat-msg--assistant .afb-ai-chat-bubble {
	background: #fff;
	color: var(--afb-ai-ink);
	border: 1px solid var(--afb-ai-line);
	border-bottom-left-radius: 5px;
}

/* Tool-run chips */

.afb-ai-chat-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 6px;
}

.afb-ai-chat-chip {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	font-size: 11.5px;
	line-height: 1;
	padding: 5px 9px;
	border-radius: 999px;
	background: rgba(109, 74, 255, 0.08);
	color: #4a3aa8;
	border: 1px solid rgba(109, 74, 255, 0.16);
}

.afb-ai-chat-chip--build {
	background: rgba(74, 123, 255, 0.1);
	color: #274a9c;
	border-color: rgba(74, 123, 255, 0.2);
}

.afb-ai-chat-chip-ico {
	font-size: 12px;
	line-height: 1;
}

/* Meta (credits) line */

.afb-ai-chat-meta {
	margin-top: 5px;
	font-size: 11px;
	color: var(--afb-ai-ink-soft);
}

/* Open-form action button */

.afb-ai-chat-action {
	margin-top: 8px;
}

.afb-ai-chat-action-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	border: 0;
	cursor: pointer;
	font-size: 13px;
	font-weight: 600;
	color: #fff;
	background: linear-gradient(135deg, var(--afb-ai-accent) 0%, var(--afb-ai-accent-2) 100%);
	border-radius: 10px;
	padding: 9px 14px;
	text-decoration: none;
	transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.afb-ai-chat-action-btn:hover {
	transform: translateY(-1px);
	box-shadow: 0 6px 18px rgba(109, 74, 255, 0.32);
	color: #fff;
}

/* Typing indicator */

.afb-ai-chat-typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 11px 14px;
	background: #fff;
	border: 1px solid var(--afb-ai-line);
	border-radius: 14px;
	border-bottom-left-radius: 5px;
	align-self: flex-start;
}

.afb-ai-chat-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #b7bacb;
	display: inline-block;
	animation: afb-ai-bounce 1.3s infinite ease-in-out;
}

.afb-ai-chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.afb-ai-chat-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes afb-ai-bounce {
	0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
	40% { transform: translateY(-5px); opacity: 1; }
}

/* Inline error / out-of-credits */

.afb-ai-chat-error {
	align-self: flex-start;
	max-width: 100%;
	background: #fff4f4;
	border: 1px solid #f3c9c9;
	color: #8a2b2b;
	border-radius: 12px;
	padding: 10px 12px;
	font-size: 13px;
}

/* ---------------------------------------------------------------- Composer */

.afb-ai-chat-composer {
	flex: 0 0 auto;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px;
	border-top: 1px solid var(--afb-ai-line);
	background: #fff;
}

.afb-ai-chat-input {
	flex: 1 1 auto;
	resize: none;
	border: 1px solid var(--afb-ai-line);
	border-radius: 12px;
	padding: 10px 12px;
	font-size: 13.5px;
	line-height: 1.4;
	font-family: inherit;
	color: var(--afb-ai-ink);
	background: #fff;
	max-height: 120px;
	min-height: 42px;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.afb-ai-chat-input:focus {
	outline: none;
	border-color: var(--afb-ai-accent);
	box-shadow: 0 0 0 3px rgba(109, 74, 255, 0.16);
}

.afb-ai-chat-send {
	flex: 0 0 auto;
	width: 42px;
	height: 42px;
	border: 0;
	border-radius: 12px;
	cursor: pointer;
	color: #fff;
	background: linear-gradient(135deg, var(--afb-ai-accent) 0%, var(--afb-ai-accent-2) 100%);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.afb-ai-chat-send:hover:not(:disabled) {
	transform: translateY(-1px);
	box-shadow: 0 6px 16px rgba(109, 74, 255, 0.3);
}

.afb-ai-chat-send:disabled {
	opacity: 0.5;
	cursor: default;
}

.afb-ai-chat-send svg {
	width: 20px;
	height: 20px;
}

/* Out-of-credits prompt injected by the shared afbAiCredits helper. */
.afb-ai-chat-body .afb-ai-ooc {
	align-self: flex-start;
	max-width: 100%;
}

/* ------------------------------------------------------- Reduced motion */

@media ( prefers-reduced-motion: reduce ) {
	.afb-ai-chat-launcher,
	.afb-ai-chat-launcher::after,
	.afb-ai-chat-launcher::before,
	.afb-ai-chat-panel,
	.afb-ai-chat-typing span,
	.afb-ai-chat-suggestion,
	.afb-ai-chat-action-btn,
	.afb-ai-chat-send {
		animation: none !important;
		transition: none !important;
	}
}

/* RTL: mirror the launcher/panel to the bottom-left corner. */
.rtl .afb-ai-chat-launcher,
.rtl .afb-ai-chat-panel {
	right: auto;
	left: 24px;
}

.rtl .afb-ai-chat-panel {
	transform-origin: left bottom;
}
