/**
 * GAI Agent Chat — floating widget.
 *
 * Palette follows the UGPUS brand (Elementor globals):
 *   primary  #FFD800   secondary #F35A09
 *   dark     #0d141a / #1B2329
 *   light    #F4F7FA / #B8C0CC
 * Accent, accent text and header colours are overridable per site via the
 * custom properties set inline on .gai-agent-chat.
 *
 * Everything is namespaced under .gai-agent-chat and resets aggressively,
 * because Elementor and most themes apply broad element rules that would
 * otherwise leak into the panel.
 */

.gai-agent-chat {
	--gai-accent: #FFD800;
	--gai-accent-text: #0d141a;
	--gai-header-bg: #1B2329;
	--gai-secondary: #F35A09;
	--gai-surface: #ffffff;
	--gai-canvas: #F4F7FA;
	--gai-ink: #0d141a;
	--gai-muted: #5b6672;
	--gai-line: #e2e8f0;
	--gai-radius: 16px;
	--gai-shadow: 0 18px 48px rgba(13, 20, 26, .22), 0 4px 12px rgba(13, 20, 26, .10);
	--gai-font: "Rubik", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

	position: fixed;
	bottom: 24px;
	z-index: 99990;
	font-family: var(--gai-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--gai-ink);
	-webkit-font-smoothing: antialiased;
}

.gai-agent-chat.gai-pos-right { right: 24px; }
.gai-agent-chat.gai-pos-left  { left: 24px; }

.gai-agent-chat *,
.gai-agent-chat *::before,
.gai-agent-chat *::after {
	box-sizing: border-box;
}

.gai-agent-chat [hidden] { display: none !important; }

.gai-sr {
	position: absolute !important;
	width: 1px; height: 1px;
	margin: -1px; padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Honeypot — off-screen rather than display:none, which some bots skip. */
.gai-hp {
	position: absolute !important;
	left: -9999px !important;
	top: auto !important;
	width: 1px !important;
	height: 1px !important;
	overflow: hidden !important;
}

/* ── Launcher ─────────────────────────────────────────────────────────── */
.gai-agent-chat .gai-launcher {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--gai-accent);
	color: var(--gai-accent-text);
	box-shadow: var(--gai-shadow);
	cursor: pointer;
	transition: transform .18s ease, box-shadow .18s ease;
	-webkit-appearance: none;
	appearance: none;
}

.gai-agent-chat.gai-pos-left .gai-launcher { margin-left: 0; }
.gai-agent-chat.gai-pos-right .gai-launcher { margin-left: auto; }

.gai-agent-chat .gai-launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 22px 56px rgba(13, 20, 26, .28), 0 6px 14px rgba(13, 20, 26, .14);
}

.gai-agent-chat .gai-launcher:focus-visible {
	outline: 3px solid var(--gai-secondary);
	outline-offset: 3px;
}

.gai-agent-chat .gai-launcher__icon,
.gai-agent-chat .gai-launcher__close {
	display: flex;
	transition: opacity .16s ease, transform .16s ease;
}

.gai-agent-chat .gai-launcher__close {
	position: absolute;
	opacity: 0;
	transform: rotate(-45deg) scale(.7);
}

.gai-agent-chat.is-open .gai-launcher__icon {
	opacity: 0;
	transform: rotate(45deg) scale(.7);
}

.gai-agent-chat.is-open .gai-launcher__close {
	opacity: 1;
	transform: none;
}

/* Tooltip beside the bubble. */
.gai-agent-chat .gai-launcher__tip {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	white-space: nowrap;
	background: var(--gai-header-bg);
	color: #fff;
	font-size: 13px;
	font-weight: 500;
	padding: 7px 12px;
	border-radius: 8px;
	opacity: 0;
	pointer-events: none;
	transition: opacity .16s ease;
}

.gai-agent-chat.gai-pos-right .gai-launcher__tip { right: calc(100% + 12px); }
.gai-agent-chat.gai-pos-left  .gai-launcher__tip { left: calc(100% + 12px); }

.gai-agent-chat .gai-launcher:hover .gai-launcher__tip { opacity: 1; }
.gai-agent-chat.is-open .gai-launcher__tip { opacity: 0 !important; }

/* Attention pulse, once, until first opened. */
.gai-agent-chat .gai-launcher::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 2px solid var(--gai-accent);
	animation: gai-pulse 2.6s ease-out 3;
	pointer-events: none;
}

.gai-agent-chat.is-open .gai-launcher::after,
.gai-agent-chat.has-opened .gai-launcher::after { animation: none; opacity: 0; }

@keyframes gai-pulse {
	0%   { transform: scale(1);   opacity: .8; }
	70%  { transform: scale(1.5); opacity: 0; }
	100% { transform: scale(1.5); opacity: 0; }
}

/* ── Panel ────────────────────────────────────────────────────────────── */
.gai-agent-chat .gai-panel {
	position: absolute;
	bottom: calc(100% + 14px);
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 140px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--gai-surface);
	border-radius: var(--gai-radius);
	box-shadow: var(--gai-shadow);
	opacity: 0;
	transform: translateY(12px) scale(.98);
	transform-origin: bottom right;
	transition: opacity .2s ease, transform .2s ease;
}

.gai-agent-chat.gai-pos-right .gai-panel { right: 0; }
.gai-agent-chat.gai-pos-left  .gai-panel { left: 0; transform-origin: bottom left; }

.gai-agent-chat.is-open .gai-panel {
	opacity: 1;
	transform: none;
}

/* Header */
.gai-agent-chat .gai-panel__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 16px;
	background: var(--gai-header-bg);
	border-bottom: 3px solid var(--gai-accent);
	color: #fff;
	flex: 0 0 auto;
}

.gai-agent-chat .gai-panel__id {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}

.gai-agent-chat .gai-panel__dot {
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: #22c55e;
	box-shadow: 0 0 0 3px rgba(34, 197, 94, .22);
	flex: 0 0 auto;
}

.gai-agent-chat .gai-panel__title,
.gai-agent-chat .gai-panel__subtitle {
	margin: 0;
	padding: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: #fff;
}

.gai-agent-chat .gai-panel__title {
	font-size: 15px;
	font-weight: 600;
	letter-spacing: .1px;
}

.gai-agent-chat .gai-panel__subtitle {
	font-size: 12px;
	font-weight: 400;
	color: #B8C0CC;
	margin-top: 1px;
}

.gai-agent-chat .gai-panel__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, .10);
	color: #fff;
	cursor: pointer;
	flex: 0 0 auto;
	transition: background .15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.gai-agent-chat .gai-panel__close:hover { background: rgba(255, 255, 255, .2); }
.gai-agent-chat .gai-panel__close:focus-visible { outline: 2px solid var(--gai-accent); outline-offset: 1px; }

/* Log */
.gai-agent-chat .gai-log {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px;
	background: var(--gai-canvas);
	display: flex;
	flex-direction: column;
	gap: 10px;
	scrollbar-width: thin;
}

.gai-agent-chat .gai-log::-webkit-scrollbar { width: 8px; }
.gai-agent-chat .gai-log::-webkit-scrollbar-thumb {
	background: #cbd5e1;
	border-radius: 8px;
}

.gai-agent-chat .gai-msg {
	max-width: 86%;
	padding: 10px 13px;
	border-radius: 14px;
	font-size: 14.5px;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	animation: gai-in .18s ease-out;
}

@keyframes gai-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: none; }
}

.gai-agent-chat .gai-msg--agent {
	align-self: flex-start;
	background: var(--gai-surface);
	border: 1px solid var(--gai-line);
	border-bottom-left-radius: 5px;
	color: var(--gai-ink);
}

.gai-agent-chat .gai-msg--user {
	align-self: flex-end;
	background: var(--gai-header-bg);
	color: #fff;
	border-bottom-right-radius: 5px;
}

.gai-agent-chat .gai-msg--note {
	align-self: center;
	background: rgba(243, 90, 9, .10);
	border: 1px solid rgba(243, 90, 9, .25);
	color: #8a3406;
	font-size: 13px;
	text-align: center;
	max-width: 100%;
}

/* Typing indicator */
.gai-agent-chat .gai-typing {
	align-self: flex-start;
	display: flex;
	gap: 4px;
	padding: 13px;
	background: var(--gai-surface);
	border: 1px solid var(--gai-line);
	border-radius: 14px;
	border-bottom-left-radius: 5px;
}

.gai-agent-chat .gai-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9aa5b1;
	animation: gai-bounce 1.3s infinite ease-in-out;
}

.gai-agent-chat .gai-typing span:nth-child(2) { animation-delay: .16s; }
.gai-agent-chat .gai-typing span:nth-child(3) { animation-delay: .32s; }

@keyframes gai-bounce {
	0%, 60%, 100% { transform: none; opacity: .45; }
	30%           { transform: translateY(-4px); opacity: 1; }
}

/* Turnstile slot */
.gai-agent-chat .gai-turnstile {
	padding: 10px 16px 0;
	background: var(--gai-canvas);
	display: flex;
	justify-content: center;
}

/* Composer */
.gai-agent-chat .gai-composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	background: var(--gai-surface);
	border-top: 1px solid var(--gai-line);
	flex: 0 0 auto;
	margin: 0;
}

.gai-agent-chat .gai-composer__input {
	flex: 1 1 auto;
	min-height: 42px;
	max-height: 120px;
	padding: 10px 12px;
	border: 1px solid var(--gai-line);
	border-radius: 11px;
	background: var(--gai-canvas);
	font-family: inherit;
	font-size: 14.5px;
	line-height: 1.45;
	color: var(--gai-ink);
	resize: none;
	outline: none;
	transition: border-color .15s ease, box-shadow .15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.gai-agent-chat .gai-composer__input:focus {
	border-color: var(--gai-accent);
	box-shadow: 0 0 0 3px rgba(255, 216, 0, .35);
	background: var(--gai-surface);
}

.gai-agent-chat .gai-composer__input::placeholder { color: #94a3b8; opacity: 1; }

.gai-agent-chat .gai-composer__send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	flex: 0 0 auto;
	padding: 0;
	border: 0;
	border-radius: 11px;
	background: var(--gai-accent);
	color: var(--gai-accent-text);
	cursor: pointer;
	transition: filter .15s ease, opacity .15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.gai-agent-chat .gai-composer__send:hover:not(:disabled) { filter: brightness(.94); }
.gai-agent-chat .gai-composer__send:focus-visible { outline: 2px solid var(--gai-header-bg); outline-offset: 2px; }
.gai-agent-chat .gai-composer__send:disabled { opacity: .45; cursor: default; }

.gai-agent-chat .gai-footnote {
	margin: 0;
	padding: 0 12px 10px;
	background: var(--gai-surface);
	color: var(--gai-muted);
	font-size: 11px;
	line-height: 1.4;
	text-align: center;
	flex: 0 0 auto;
}

/* ── Small screens: full-height sheet ─────────────────────────────────── */
@media (max-width: 480px) {
	.gai-agent-chat {
		bottom: 16px;
	}
	.gai-agent-chat.gai-pos-right { right: 16px; }
	.gai-agent-chat.gai-pos-left  { left: 16px; }

	.gai-agent-chat .gai-panel {
		position: fixed;
		inset: 0;
		width: 100vw;
		max-width: 100vw;
		height: 100%;
		height: 100dvh;
		max-height: none;
		border-radius: 0;
		transform-origin: bottom center;
	}

	.gai-agent-chat .gai-panel__header {
		padding-top: max(14px, env(safe-area-inset-top));
	}

	.gai-agent-chat .gai-footnote {
		padding-bottom: max(10px, env(safe-area-inset-bottom));
	}
}

@media (prefers-reduced-motion: reduce) {
	.gai-agent-chat *,
	.gai-agent-chat *::after {
		animation: none !important;
		transition: none !important;
	}
}
