/**
 * GAI Agent Chat — floating widget.
 *
 * Ugpus.com storefront port of the WordPress plugin's widget.css (1.2.0).
 * Restyled for ugpus.com: emerald gradient (white text on #047857 is 5.5:1),
 * avatar header, borderless bubbles, pill composer with the send button inside,
 * and the storefront's system font. Markup and class names are the plugin's.
 *
 * 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: #047857;          /* emerald 700 — white text 5.5:1 */
	--gai-accent-2: #059669;        /* gradient partner */
	--gai-accent-text: #ffffff;
	--gai-header-bg: #064e3b;
	--gai-secondary: #0f172a;
	--gai-surface: #ffffff;
	--gai-canvas: #f8fafc;
	--gai-bubble: #f1f5f9;
	--gai-ink: #0f172a;
	--gai-muted: #64748b;
	--gai-line: #e2e8f0;
	--gai-radius: 22px;
	--gai-grad: linear-gradient(135deg, var(--gai-accent-2) 0%, var(--gai-accent) 55%, var(--gai-header-bg) 100%);
	--gai-shadow: 0 24px 60px -12px rgba(15, 23, 42, .28), 0 8px 20px -8px rgba(15, 23, 42, .16);
	--gai-font: system-ui, -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: linear-gradient(135deg, var(--gai-accent-2), var(--gai-accent));
	color: var(--gai-accent-text);
	box-shadow: 0 8px 20px -6px rgba(4, 120, 87, .5), 0 2px 6px rgba(15, 23, 42, .15);
	cursor: pointer;
	transition: transform .28s cubic-bezier(.34, 1.56, .64, 1), box-shadow .28s 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-dock:hover .gai-launcher {
	transform: translateY(-3px) scale(1.05);
	box-shadow: 0 12px 26px -6px rgba(4, 120, 87, .55), 0 4px 10px rgba(15, 23, 42, .16);
}

.gai-agent-chat .gai-launcher-dock:hover .gai-launcher__icon { transform: scale(1.08) rotate(-6deg); }

.gai-agent-chat .gai-launcher:active { transform: translateY(-1px) scale(.96); transition-duration: .09s; }

.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; }


/* ── Label ────────────────────────────────────────────────────────────
 * Visible above the bubble (not a hover tooltip, which phones never see).
 * Aligned to the bubble's screen edge so a longer label grows inwards. */
/* The label floats above the bubble (absolute), so the widget's box is just the bubble and
 * the open panel sits right on top of it instead of above an invisible label. */
.gai-agent-chat .gai-launcher-dock {
	position: relative;
	display: flex;
	flex-direction: column;
	pointer-events: auto;
}

.gai-agent-chat.gai-pos-right .gai-launcher-dock { align-items: flex-end; }
.gai-agent-chat.gai-pos-left  .gai-launcher-dock { align-items: flex-start; }
.gai-agent-chat.gai-pos-right .gai-launcher__label { right: 0; }
.gai-agent-chat.gai-pos-left  .gai-launcher__label { left: 0; }

.gai-agent-chat .gai-launcher__label {
	position: absolute;
	bottom: calc(100% + 10px);
	display: inline-flex;
	align-items: center;
	gap: 8px;
	max-width: min(220px, calc(100vw - 48px));
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	background: rgba(255, 255, 255, .96);
	color: var(--gai-ink);
	border: 1px solid var(--gai-line);
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	padding: 9px 14px;
	border-radius: 999px;
	box-shadow: 0 10px 24px -8px rgba(15, 23, 42, .25);
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
	cursor: pointer;
	transform-origin: bottom center;
	transition: transform .28s cubic-bezier(.34, 1.56, .64, 1), box-shadow .28s ease, opacity .2s ease;
}

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

.gai-agent-chat .gai-launcher-dock:hover .gai-launcher__label,
.gai-agent-chat .gai-launcher-dock:focus-within .gai-launcher__label {
	transform: translateY(-3px) scale(1.03);
	box-shadow: 0 14px 30px -8px rgba(15, 23, 42, .3);
}

.gai-agent-chat.is-open .gai-launcher__label {
	opacity: 0;
	transform: translateY(6px) scale(.92);
	pointer-events: none;
}

/* Attention pulse, three times, until first opened. */
.gai-agent-chat .gai-launcher::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 2px solid var(--gai-accent-2);
	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% + 12px);
	width: 390px;
	max-width: calc(100vw - 32px);
	height: 600px;
	max-height: calc(100vh - 140px);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--gai-surface);
	border: 1px solid rgba(15, 23, 42, .06);
	border-radius: var(--gai-radius);
	box-shadow: var(--gai-shadow);
	opacity: 0;
	transform: translateY(16px) scale(.97);
	transform-origin: bottom right;
	transition: opacity .22s ease, transform .26s cubic-bezier(.2, .9, .3, 1.1);
}

.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 {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 18px 18px 18px 16px;
	background: var(--gai-grad);
	color: #fff;
	flex: 0 0 auto;
	overflow: hidden;
}

/* Soft highlight in the corner — depth without an image. */
.gai-agent-chat .gai-panel__header::before {
	content: "";
	position: absolute;
	top: -60px;
	left: -40px;
	width: 180px;
	height: 180px;
	border-radius: 50%;
	background: radial-gradient(circle, rgba(255, 255, 255, .18), transparent 70%);
	pointer-events: none;
}

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

.gai-agent-chat .gai-panel__avatar {
	position: relative;
	width: 42px;
	height: 42px;
	flex: 0 0 auto;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 0 0 3px rgba(255, 255, 255, .22);
	display: flex;
	align-items: center;
	justify-content: center;
}

.gai-agent-chat .gai-panel__avatar img {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	object-fit: contain;
}

.gai-agent-chat .gai-panel__dot {
	position: absolute;
	right: -1px;
	bottom: -1px;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: #4ade80;
	border: 2px solid var(--gai-accent);
}

.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: 16px; font-weight: 700; letter-spacing: -.01em; }

.gai-agent-chat .gai-panel__subtitle { font-size: 12.5px; font-weight: 500; color: rgba(255, 255, 255, .82); margin-top: 1px; }

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

.gai-agent-chat .gai-panel__close:hover { background: rgba(255, 255, 255, .26); transform: rotate(90deg); }
.gai-agent-chat .gai-panel__close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Log */
.gai-agent-chat .gai-log {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 18px 16px;
	background: var(--gai-surface);
	display: flex;
	flex-direction: column;
	gap: 8px;
	scrollbar-width: thin;
	scrollbar-color: #cbd5e1 transparent;
}

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

.gai-agent-chat .gai-msg {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: 18px;
	font-size: 14.5px;
	line-height: 1.5;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	animation: gai-in .22s cubic-bezier(.2, .9, .3, 1.2);
}

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

.gai-agent-chat .gai-msg--agent {
	align-self: flex-start;
	background: var(--gai-bubble);
	border-bottom-left-radius: 6px;
	color: var(--gai-ink);
}

.gai-agent-chat .gai-msg--user {
	align-self: flex-end;
	background: linear-gradient(135deg, var(--gai-accent-2), var(--gai-accent));
	color: #fff;
	border-bottom-right-radius: 6px;
	box-shadow: 0 4px 12px -4px rgba(4, 120, 87, .45);
}

.gai-agent-chat .gai-msg--note {
	align-self: center;
	background: #fff7ed;
	border: 1px solid #fed7aa;
	color: #9a3412;
	font-size: 13px;
	text-align: center;
	max-width: 100%;
	border-radius: 12px;
}

/* Typing indicator */
.gai-agent-chat .gai-typing {
	align-self: flex-start;
	display: flex;
	gap: 4px;
	padding: 13px 15px;
	background: var(--gai-bubble);
	border-radius: 18px;
	border-bottom-left-radius: 6px;
}

.gai-agent-chat .gai-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--gai-accent);
	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: .35; }
	30%           { transform: translateY(-4px); opacity: 1; }
}

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

/* Composer: one rounded field with the send button inside it. */
.gai-agent-chat .gai-composer {
	position: relative;
	display: flex;
	align-items: flex-end;
	gap: 6px;
	margin: 4px 12px 8px;
	padding: 5px 5px 5px 16px;
	background: var(--gai-canvas);
	border: 1px solid var(--gai-line);
	border-radius: 26px;
	flex: 0 0 auto;
	transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.gai-agent-chat .gai-composer:focus-within {
	background: var(--gai-surface);
	border-color: var(--gai-accent);
	box-shadow: 0 0 0 4px rgba(5, 150, 105, .15);
}

.gai-agent-chat .gai-composer__input {
	flex: 1 1 auto;
	min-height: 40px;
	max-height: 120px;
	padding: 9px 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	font-family: inherit;
	font-size: 14.5px;
	line-height: 1.45;
	color: var(--gai-ink);
	resize: none;
	outline: none;
	box-shadow: none;
	-webkit-appearance: none;
	appearance: none;
}

.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: 40px;
	height: 40px;
	flex: 0 0 auto;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--gai-grad);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 4px 12px -4px rgba(4, 120, 87, .6);
	transition: transform .15s ease, opacity .15s ease, filter .15s ease;
	-webkit-appearance: none;
	appearance: none;
}

.gai-agent-chat .gai-composer__send svg { margin-left: -2px; }
.gai-agent-chat .gai-composer__send:hover:not(:disabled) { transform: scale(1.06); filter: brightness(1.05); }
.gai-agent-chat .gai-composer__send:focus-visible { outline: 2px solid var(--gai-secondary); outline-offset: 2px; }
.gai-agent-chat .gai-composer__send:disabled { opacity: .35; cursor: default; box-shadow: none; }

.gai-agent-chat .gai-footnote {
	margin: 0;
	padding: 0 16px 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;
	}

	/* Killing the transition alone leaves the hover transform, which then
	 * happens instantly — a jump, which is exactly what someone asking for
	 * reduced motion is asking not to have. The shadow still responds, so
	 * hover remains visible. */
	.gai-agent-chat .gai-launcher-dock:hover .gai-launcher,
	.gai-agent-chat .gai-launcher-dock:hover .gai-launcher__icon,
	.gai-agent-chat .gai-launcher-dock:hover .gai-launcher__label,
	.gai-agent-chat .gai-launcher-dock:focus-within .gai-launcher__label,
	.gai-agent-chat .gai-launcher:active {
		transform: none !important;
	}
}

/* Links inside an answer. The agent points visitors at the shop's own pages,
 * and a default-blue underline inside a tinted bubble reads as a foreign
 * element — inherit the bubble's colour and mark it with the underline only. */
.gai-agent-chat .gai-msg--agent a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
	word-break: break-word;
}

.gai-agent-chat .gai-msg--agent a:hover,
.gai-agent-chat .gai-msg--agent a:focus-visible {
	text-decoration-thickness: 2px;
}

/* ── Cookie consent gate (ugpus.com): shown inside the panel until cookies are accepted ── */
.gai-agent-chat .gai-consent {
	margin: 0 12px 10px;
	padding: 16px;
	background: #f0fdf4;
	border: 1px solid #bbf7d0;
	border-radius: 16px;
	text-align: center;
	animation: gai-in .25s ease-out;
}
.gai-agent-chat .gai-consent__title { margin: 0 0 4px; font-size: 14.5px; font-weight: 700; color: var(--gai-ink); }
.gai-agent-chat .gai-consent__text { margin: 0 0 12px; font-size: 13px; line-height: 1.5; color: var(--gai-muted); }
.gai-agent-chat .gai-consent__text a { color: var(--gai-accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.gai-agent-chat .gai-consent__btn {
	display: inline-flex; align-items: center; justify-content: center;
	min-height: 40px; padding: 0 20px; border: 0; border-radius: 999px;
	background: var(--gai-grad); color: #fff; font: inherit; font-size: 14px; font-weight: 700;
	cursor: pointer; box-shadow: 0 6px 16px -6px rgba(4, 120, 87, .6);
	transition: transform .15s ease, filter .15s ease;
	-webkit-appearance: none; appearance: none;
}
.gai-agent-chat .gai-consent__btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.gai-agent-chat .gai-consent__btn:focus-visible { outline: 2px solid var(--gai-secondary); outline-offset: 2px; }
/* Locked composer while consent is missing. */
.gai-agent-chat.needs-consent .gai-composer { opacity: .5; pointer-events: none; }
