/* ==========================================================================
   AI Website Assistant — Chat Widget Styles
   Reusable: All selectors are prefixed with .aiwa- to avoid theme collisions.

   COLOR CUSTOMIZATION:
   Override --aiwa-primary, --aiwa-header-bg, --aiwa-user-bubble, and
   --aiwa-accent on the .aiwa-chat-root element (injected via PHP inline style)
   to change the entire widget palette without touching this file.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design Tokens (CSS Custom Properties — defaults; overridden by PHP)
   -------------------------------------------------------------------------- */
.aiwa-chat-root {
	/* Primary brand color (toggle button, user bubble) */
	--aiwa-primary: #2563eb;
	--aiwa-primary-dark: #1d4ed8;

	/* Chat panel header background */
	--aiwa-header-bg: #1e293b;

	/* User chat bubble background */
	--aiwa-user-bubble: #2563eb;

	/* Accent (source chips, action cards) */
	--aiwa-accent: #0ea5e9;

	/* Pulse ring color behind the toggle button */
	--aiwa-pulse-color: rgba(37, 99, 235, 0.35);

	/* Close (✕) button background — independently customizable */
	--aiwa-close-bg: rgba(255, 255, 255, 0.12);
	--aiwa-close-bg-hover: rgba(255, 255, 255, 0.28);

	/* Send button background — independently customizable */
	--aiwa-send-bg: #2563eb;
	--aiwa-send-bg-hover: #1d4ed8;
}

/* --------------------------------------------------------------------------
   Root container
   -------------------------------------------------------------------------- */
.aiwa-chat-root {
	position: fixed;
	right: 1.5rem;
	bottom: 1.5rem;
	z-index: 99999;
	font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* --------------------------------------------------------------------------
   Toggle button — circular with robot avatar
   -------------------------------------------------------------------------- */
.aiwa-chat-toggle {
	/* Circular shape */
	width: 64px;
	height: 64px;
	border-radius: 50%;
	border: none;
	cursor: pointer;
	padding: 0;
	outline: none;

	/* Color */
	background: var(--aiwa-primary);
	color: #fff;

	/* Shadow + transition */
	box-shadow:
		0 6px 20px var(--aiwa-pulse-color),
		0 2px 8px rgba(0, 0, 0, 0.18);
	transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;

	/* Center the SVG avatar */
	display: flex;
	align-items: center;
	justify-content: center;

	/* Continuous pulse ring animation */
	position: relative;
}

/* Pulse ring — decorative outer glow ring */
.aiwa-chat-toggle::before {
	content: '';
	position: absolute;
	inset: -5px;
	border-radius: 50%;
	border: 3px solid var(--aiwa-shadow-color);
	opacity: 0;
	animation: aiwa-pulse-ring 2.4s ease-out infinite;
	pointer-events: none;
}

@keyframes aiwa-pulse-ring {
	0% {
		transform: scale(1);
		opacity: 0.7;
	}

	80% {
		transform: scale(1.45);
		opacity: 0;
	}

	100% {
		transform: scale(1.45);
		opacity: 0;
	}
}

.aiwa-chat-toggle:hover {
	background: var(--aiwa-primary-dark);
	transform: translateY(-3px) scale(1.06);
	box-shadow:
		0 10px 30px var(--aiwa-pulse-color),
		0 4px 12px rgba(0, 0, 0, 0.22);
}

.aiwa-chat-toggle:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 3px;
}

/* Robot avatar SVG inside the toggle */
.aiwa-toggle-robot {
	width: 36px;
	height: 36px;
	fill: #fff;
	flex-shrink: 0;
	transition: transform 0.3s ease;
}

/* When panel is open, rotate the icon slightly */
.aiwa-chat-toggle[aria-expanded="true"] .aiwa-toggle-robot {
	transform: rotate(10deg) scale(0.9);
}

/* Hide the old text label — kept in HTML for screen readers */
.aiwa-chat-toggle-label {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Panel — Glassmorphism frosted-glass card
   Reusable pattern: backdrop-filter + semi-transparent bg for glass effect.
   -------------------------------------------------------------------------- */
.aiwa-chat-panel {
	position: absolute;
	right: 0;
	bottom: 4.5rem; /* space above 64 px circular button */

	/* Responsive width: fills viewport on mobile, capped at 360px on desktop */
	width: min(360px, calc(100vw - 2rem));

	/* Reduced height as requested — flex children fill the space */
	height: 420px;

	/* ── Glassmorphism ── */
	background: var(--aiwa-panel-bg, rgba(255, 255, 255, 0.55));
	backdrop-filter: blur(20px) saturate(180%);
	-webkit-backdrop-filter: blur(20px) saturate(180%);
	border: 1px solid rgba(255, 255, 255, 0.45);

	border-radius: 20px;
	box-shadow:
		0 8px 32px rgba(15, 23, 42, 0.18),
		0 2px 8px  rgba(15, 23, 42, 0.10),
		inset 0 1px 0 rgba(255, 255, 255, 0.75);

	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: aiwa-slide-up 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes aiwa-slide-up {
	from {
		opacity: 0;
		transform: translateY(16px) scale(0.96);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

.aiwa-chat-panel[hidden] {
	display: none !important;
}

/* --------------------------------------------------------------------------
   Responsive — small screens (≤ 480 px width)
   Panel stretches to near-full viewport so nothing gets clipped on phones.
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
	.aiwa-chat-root {
		right: 0.75rem;
		bottom: 0.75rem;
	}

	.aiwa-chat-panel {
		/* Full-width minus gutters on mobile */
		width: calc(100vw - 1.5rem);
		/* Taller on mobile so keyboard doesn't swallow content */
		height: min(80svh, 480px);
		bottom: 4.5rem;
		right: 0;
	}
}

/* Extra-small phones (≤ 360px) */
@media (max-width: 360px) {
	.aiwa-chat-panel {
		width: calc(100vw - 1rem);
		height: min(75svh, 440px);
	}
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.aiwa-chat-header {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	justify-content: space-between;
	padding: 0.9rem 1rem;
	background: var(--aiwa-header-bg);
	color: #fff;
	border-radius: 18px 18px 0 0;
}

/* Small robot icon inside the header */
.aiwa-header-robot {
	width: 30px;
	height: 30px;
	fill: #fff;
	flex-shrink: 0;
	opacity: 0.92;
}

.aiwa-header-info {
	flex: 1;
	min-width: 0;
}

.aiwa-chat-title {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 700;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.aiwa-header-status {
	font-size: 0.72rem;
	opacity: 0.65;
	margin-top: 1px;
	display: flex;
	align-items: center;
	gap: 0.3rem;
}

/* Green "online" dot */
.aiwa-header-status::before {
	content: '';
	display: inline-block;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4ade80;
	animation: aiwa-online-blink 2.5s ease-in-out infinite;
}

@keyframes aiwa-online-blink {

	0%,
	100% {
		opacity: 1;
	}

	50% {
		opacity: 0.4;
	}
}

.aiwa-chat-close {
	/* Uses its own token so color is independently changeable from primary */
	background: var(--aiwa-close-bg);
	/* Hard resets — prevent WordPress themes from injecting a coloured border on button states */
	border: none !important;
	outline: none;
	box-shadow: none;
	color: #fff;
	font-size: 1.1rem;
	cursor: pointer;
	line-height: 1;
	opacity: 0.85;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s, opacity 0.15s;
	flex-shrink: 0;
}

.aiwa-chat-close:hover {
	/* Base fallback — overridden by high-specificity #aiwa-chat-root rule in template */
	background: var(--aiwa-close-bg-hover);
	color: #fff;
	opacity: 1;
}

/* --------------------------------------------------------------------------
   Messages area — transparent so glassmorphism panel bg shows through
   -------------------------------------------------------------------------- */
.aiwa-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 0.8rem 0.85rem;
	display: flex;
	flex-direction: column;
	gap: 0.45rem;
	scroll-behavior: smooth;

	/* Transparent so the frosted glass panel background is visible */
	background: transparent;

	/* Custom scrollbar */
	scrollbar-width: thin;
	scrollbar-color: rgba(148, 163, 184, 0.5) transparent;
}

.aiwa-chat-messages::-webkit-scrollbar {
	width: 3px;
}

.aiwa-chat-messages::-webkit-scrollbar-track {
	background: transparent;
}

.aiwa-chat-messages::-webkit-scrollbar-thumb {
	background: rgba(148, 163, 184, 0.55);
	border-radius: 4px;
}

/* --------------------------------------------------------------------------
   Turn wrapper (groups bubble + optional sources)
   -------------------------------------------------------------------------- */
.aiwa-chat-turn {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.aiwa-chat-turn--user {
	align-items: flex-end;
}

.aiwa-chat-turn--assistant {
	align-items: flex-start;
}

/* --------------------------------------------------------------------------
   Bubbles
   -------------------------------------------------------------------------- */
.aiwa-chat-bubble {
	max-width: 84%;
	padding: 0.6rem 0.9rem;
	border-radius: 14px;
	font-size: 0.88rem;
	line-height: 1.55;
	word-break: break-word;
}

.aiwa-chat-bubble--user {
	background: var(--aiwa-user-bubble);
	color: var(--aiwa-user-text, #ffffff);
	border-bottom-right-radius: 4px;
}

.aiwa-chat-bubble--assistant {
	/* Frosted glass bubble — blends into the panel's glass background */
	background: var(--aiwa-bot-bubble-bg, rgba(241, 245, 249, 0.72));
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	border: 1px solid rgba(255, 255, 255, 0.6);
	color: var(--aiwa-bot-bubble-text, #1e293b);
	border-bottom-left-radius: 4px;
}

/* --------------------------------------------------------------------------
   Typing indicator (three bouncing dots)
   -------------------------------------------------------------------------- */
.aiwa-chat-bubble--typing {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 0.8rem 1rem;
}

.aiwa-chat-bubble--typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #94a3b8;
	display: inline-block;
	animation: aiwa-bounce 1.2s infinite ease-in-out;
}

.aiwa-chat-bubble--typing span:nth-child(1) {
	animation-delay: 0s;
}

.aiwa-chat-bubble--typing span:nth-child(2) {
	animation-delay: 0.2s;
}

.aiwa-chat-bubble--typing span:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes aiwa-bounce {

	0%,
	80%,
	100% {
		transform: scale(0.8);
		opacity: 0.5;
	}

	40% {
		transform: scale(1.2);
		opacity: 1;
	}
}

/* --------------------------------------------------------------------------
   Source citation chips
   -------------------------------------------------------------------------- */
.aiwa-chat-sources {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	padding-left: 0.25rem;
}

.aiwa-chat-source-chip {
	display: inline-block;
	font-size: 0.72rem;
	padding: 0.2rem 0.55rem;
	border-radius: 999px;
	background: #e0f2fe;
	color: #0369a1;
	text-decoration: none;
	border: 1px solid #bae6fd;
	transition: background 0.15s;
	max-width: 200px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.aiwa-chat-source-chip:hover {
	background: #bae6fd;
	text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Input form — glass-tinted footer bar
   -------------------------------------------------------------------------- */
.aiwa-chat-form {
	display: flex;
	gap: 0.5rem;
	padding: 0.65rem 0.75rem;
	border-top: 1px solid rgba(226, 232, 240, 0.6);
	/* Slightly frosted footer so it visually separates from messages */
	background: rgba(255, 255, 255, 0.65);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
}

.aiwa-chat-input {
	flex: 1;
	/* Glass-style input field */
	border: 1.5px solid rgba(203, 213, 225, 0.7);
	border-radius: 10px;
	padding: 0.5rem 0.8rem;
	font-size: 0.88rem;
	outline: none;
	background: rgba(248, 250, 252, 0.8);
	transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
	font-family: inherit;
	min-width: 0; /* prevents flex overflow on tiny screens */
}

.aiwa-chat-input:focus {
	border-color: var(--aiwa-primary);
	background: rgba(255, 255, 255, 0.95);
	box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.aiwa-chat-send {
	/* Uses its own token so color is independently changeable from primary */
	background: var(--aiwa-send-bg);
	/* Hard resets — prevent WordPress themes from injecting a coloured border on button states */
	border: none !important;
	outline: none;
	box-shadow: none;
	color: #fff;
	border-radius: 10px;
	padding: 0.55rem 1rem;
	cursor: pointer;
	font-weight: 600;
	font-size: 0.88rem;
	font-family: inherit;
	transition: background 0.2s, transform 0.1s;
	white-space: nowrap;
	display: flex;
	align-items: center;
	gap: 0.35rem;
}

.aiwa-chat-send:hover {
	/* Base fallback — overridden by high-specificity #aiwa-chat-root rule in template */
	background: var(--aiwa-send-bg-hover);
	color: #fff;
}

.aiwa-chat-send:active {
	transform: scale(0.96);
}

/* Send arrow icon */
.aiwa-send-icon {
	width: 16px;
	height: 16px;
	fill: #fff;
	flex-shrink: 0;
}

/* ==========================================================================
   Phase 4 additions — Action Cards + Lead Form
   ========================================================================== */

/* --------------------------------------------------------------------------
   Intent Action Card
   -------------------------------------------------------------------------- */
.aiwa-action-card {
	margin: 0.5rem 0;
	padding: 0.85rem 1rem;
	background: #f0f9ff;
	border: 1px solid #bae6fd;
	border-radius: 12px;
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	animation: aiwa-slide-up 0.2s ease;
}

.aiwa-action-card__text {
	margin: 0;
	font-size: 0.88rem;
	color: #0c4a6e;
	line-height: 1.45;
}

/* --------------------------------------------------------------------------
   Buttons (shared across action card + lead form)
   -------------------------------------------------------------------------- */
.aiwa-btn {
	display: inline-block;
	border: none;
	border-radius: 8px;
	padding: 0.45rem 1rem;
	font-size: 0.85rem;
	font-weight: 600;
	cursor: pointer;
	font-family: inherit;
	transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
	text-align: center;
}

.aiwa-btn--primary {
	background: var(--aiwa-primary);
	color: #fff;
}

.aiwa-btn--primary:hover {
	background: var(--aiwa-primary-dark);
}

.aiwa-btn--primary:active {
	transform: scale(0.97);
}

.aiwa-btn--secondary {
	background: #e2e8f0;
	color: #334155;
}

.aiwa-btn--secondary:hover {
	background: #cbd5e1;
}

.aiwa-btn--ghost {
	background: transparent;
	color: #64748b;
	border: 1px solid #cbd5e1;
}

.aiwa-btn--ghost:hover {
	background: #f8fafc;
}

/* Card buttons full width */
.aiwa-action-card .aiwa-btn {
	width: 100%;
}

/* --------------------------------------------------------------------------
   Lead Capture Form
   -------------------------------------------------------------------------- */
.aiwa-lead-form {
	margin: 0.5rem 0;
	padding: 0.85rem 1rem;
	background: #fafafa;
	border: 1px solid #e2e8f0;
	border-radius: 12px;
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	animation: aiwa-slide-up 0.2s ease;
}

.aiwa-lead-form__label {
	font-size: 0.85rem;
	font-weight: 600;
	color: #1e293b;
}

.aiwa-lead-form__input {
	width: 100%;
	padding: 0.45rem 0.75rem;
	border: 1.5px solid #e2e8f0;
	border-radius: 8px;
	font-size: 0.88rem;
	font-family: inherit;
	outline: none;
	box-sizing: border-box;
	transition: border-color 0.15s;
	background: #fff;
}

.aiwa-lead-form__input:focus {
	border-color: var(--aiwa-primary);
}

/* Confirm step */
.aiwa-lead-form--confirm .aiwa-lead-form__confirm-text {
	margin: 0;
	font-size: 0.85rem;
	color: #475569;
}

.aiwa-lead-form__summary {
	background: #f1f5f9;
	border-radius: 8px;
	padding: 0.5rem 0.75rem;
	font-size: 0.82rem;
	color: #334155;
	white-space: pre-wrap;
	word-break: break-word;
	margin: 0;
	font-family: inherit;
}

.aiwa-lead-form .aiwa-btn {
	width: 100%;
}