/**
 * AI Sales & Support Copilot - Frontend Chat Widget
 *
 * Everything is scoped to #waic-chat so theme styles cannot break the
 * widget and the widget cannot break the theme.
 *
 * Brand colours come from the admin Design tab as CSS variables:
 * --waic-primary, --waic-secondary, --waic-radius
 *
 * Logical properties (inset-inline, margin-inline...) give automatic
 * RTL support.
 *
 * Table of contents
 * -----------------
 * 01. Tokens & reset
 * 02. Launcher button
 * 03. Chat window
 * 04. Header
 * 05. Messages & bubbles
 * 06. Typing indicator
 * 07. Quick reply chips
 * 08. Product cards
 * 09. Message form
 * 10. Mobile (full screen)
 * 11. Reduced motion
 */


/* ==========================================================================
   01. Tokens & reset
   ========================================================================== */

#waic-chat {
	--waic-primary: #6d28d9;
	--waic-secondary: #db2777;
	--waic-radius: 18px;
	--waic-text: #111827;
	--waic-muted: #6b7280;
	--waic-border: #e5e7eb;
	--waic-surface: #ffffff;
	--waic-soft: #f6f7fb;
	--waic-gradient: linear-gradient(135deg, var(--waic-primary), var(--waic-secondary));
	--waic-shadow: 0 24px 60px rgba(17, 24, 39, 0.22);
	--waic-offset: 24px;

	position: fixed;
	bottom: var(--waic-offset);
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 14px;
	line-height: 1.5;
	color: var(--waic-text);
}

/* Physical side chosen in the admin (left / right) */
#waic-chat[data-position="right"] {
	right: var(--waic-offset);
}

#waic-chat[data-position="left"] {
	left: var(--waic-offset);
}

#waic-chat *,
#waic-chat *::before,
#waic-chat *::after {
	box-sizing: border-box;
}

/* Neutralise common theme button / input styles inside the widget */
#waic-chat button,
#waic-chat textarea {
	margin: 0;
	font: inherit;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	box-shadow: none;
}

#waic-chat button {
	cursor: pointer;
}

#waic-chat .waic-icon {
	display: block;
	flex-shrink: 0;
}

#waic-chat .waic-icon-wrap {
	display: inline-flex;
	flex-shrink: 0;
}

#waic-chat a {
	text-decoration: none;
}

#waic-chat :focus-visible {
	outline: 2px solid var(--waic-primary);
	outline-offset: 2px;
}

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


/* ==========================================================================
   02. Launcher button
   ========================================================================== */

#waic-chat .waic-chat__launcher {
	position: relative;
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--waic-gradient);
	color: #fff;
	box-shadow: 0 12px 28px rgba(17, 24, 39, 0.25);
	transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#waic-chat .waic-chat__launcher:hover {
	transform: translateY(-2px) scale(1.04);
	box-shadow: 0 16px 34px rgba(17, 24, 39, 0.3);
}

/* Soft pulse ring to draw attention while closed */
#waic-chat[data-state="closed"] .waic-chat__launcher::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: var(--waic-gradient);
	opacity: 0.45;
	z-index: -1;
	animation: waic-pulse 2.6s ease-out infinite;
}

@keyframes waic-pulse {
	0% {
		transform: scale(1);
		opacity: 0.45;
	}

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

/* Swap between the open icon and the close (X) icon */
#waic-chat .waic-chat__launcher-icon {
	grid-area: 1 / 1;
	display: grid;
	place-items: center;
	transition: transform 0.25s ease, opacity 0.2s ease;
}

#waic-chat .waic-chat__launcher-icon.is-close {
	opacity: 0;
	transform: rotate(-90deg) scale(0.6);
}

#waic-chat[data-state="open"] .waic-chat__launcher-icon.is-open {
	opacity: 0;
	transform: rotate(90deg) scale(0.6);
}

#waic-chat[data-state="open"] .waic-chat__launcher-icon.is-close {
	opacity: 1;
	transform: none;
}


/* ==========================================================================
   03. Chat window
   ========================================================================== */

#waic-chat .waic-chat__window {
	position: absolute;
	bottom: 76px;
	display: flex;
	flex-direction: column;
	width: 390px;
	height: 620px;
	max-height: calc(100vh - 120px);
	overflow: hidden;
	border: 1px solid rgba(17, 24, 39, 0.06);
	border-radius: var(--waic-radius);
	background: var(--waic-surface);
	box-shadow: var(--waic-shadow);
	animation: waic-pop-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

#waic-chat[data-position="right"] .waic-chat__window {
	right: 0;
	transform-origin: bottom right;
}

#waic-chat[data-position="left"] .waic-chat__window {
	left: 0;
	transform-origin: bottom left;
}

#waic-chat .waic-chat__window[hidden] {
	display: none;
}

@keyframes waic-pop-in {
	from {
		opacity: 0;
		transform: translateY(16px) scale(0.96);
	}

	to {
		opacity: 1;
		transform: none;
	}
}


/* ==========================================================================
   04. Header
   ========================================================================== */

#waic-chat .waic-chat__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 16px 14px 16px 18px;
	background: var(--waic-gradient);
	color: #fff;
}

#waic-chat .waic-chat__avatar {
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	border: 1px solid rgba(255, 255, 255, 0.3);
	flex-shrink: 0;
}

#waic-chat .waic-chat__meta {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
}

#waic-chat .waic-chat__title {
	overflow: hidden;
	font-size: 15px;
	font-weight: 700;
	white-space: nowrap;
	text-overflow: ellipsis;
}

#waic-chat .waic-chat__status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	opacity: 0.85;
}

/* Green "online" dot */
#waic-chat .waic-chat__status::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #34d399;
	box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.3);
}

#waic-chat .waic-chat__icon-btn {
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 10px;
	background: transparent;
	color: #fff;
	transition: background-color 0.2s ease;
}

#waic-chat .waic-chat__icon-btn:hover {
	background: rgba(255, 255, 255, 0.18);
}


/* ==========================================================================
   05. Messages & bubbles
   ========================================================================== */

#waic-chat .waic-chat__messages {
	display: flex;
	flex-direction: column;
	gap: 14px;
	flex: 1;
	padding: 18px 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--waic-soft);
	scroll-behavior: smooth;
}

#waic-chat .waic-msg {
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-width: 88%;
	animation: waic-msg-in 0.25s ease;
}

#waic-chat .waic-msg--bot {
	align-self: flex-start;
}

#waic-chat .waic-msg--user {
	align-self: flex-end;
	align-items: flex-end;
}

#waic-chat .waic-msg.is-restored {
	animation: none;
}

@keyframes waic-msg-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

#waic-chat .waic-bubble {
	padding: 11px 14px;
	border-radius: calc(var(--waic-radius) * 0.8);
	font-size: 14px;
	line-height: 1.55;
	white-space: pre-line;
	overflow-wrap: anywhere;
}

#waic-chat .waic-msg--bot .waic-bubble {
	border: 1px solid var(--waic-border);
	background: var(--waic-surface);
	color: var(--waic-text);
	border-end-start-radius: 4px;
}

#waic-chat .waic-msg--user .waic-bubble {
	background: var(--waic-gradient);
	color: #fff;
	border-end-end-radius: 4px;
}

/* Error message bubble */
#waic-chat .waic-msg--error .waic-bubble {
	display: flex;
	gap: 8px;
	border-color: #fecaca;
	background: #fef2f2;
	color: #b91c1c;
}


/* ==========================================================================
   06. Typing indicator
   ========================================================================== */

#waic-chat .waic-typing {
	display: inline-flex;
	gap: 5px;
	align-self: flex-start;
	padding: 14px 16px;
	border: 1px solid var(--waic-border);
	border-radius: calc(var(--waic-radius) * 0.8);
	background: var(--waic-surface);
	border-end-start-radius: 4px;
}

#waic-chat .waic-typing span:not(.waic-sr-only) {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--waic-primary);
	opacity: 0.35;
	animation: waic-typing 1.2s ease-in-out infinite;
}

#waic-chat .waic-typing span:nth-child(2) {
	animation-delay: 0.15s;
}

#waic-chat .waic-typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes waic-typing {
	0%,
	60%,
	100% {
		opacity: 0.35;
		transform: none;
	}

	30% {
		opacity: 1;
		transform: translateY(-4px);
	}
}


/* ==========================================================================
   07. Quick reply chips
   ========================================================================== */

#waic-chat .waic-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

#waic-chat .waic-chip {
	padding: 7px 13px;
	border: 1px solid color-mix(in srgb, var(--waic-primary) 35%, transparent);
	border-radius: 999px;
	background: var(--waic-surface);
	color: var(--waic-primary);
	font-size: 13px;
	font-weight: 600;
	line-height: 1.3;
	transition: background-color 0.2s ease, color 0.2s ease;
}

#waic-chat .waic-chip:hover {
	background: var(--waic-primary);
	color: #fff;
}


/* ==========================================================================
   08. Product cards
   ========================================================================== */

#waic-chat .waic-products {
	display: grid;
	gap: 10px;
	width: 100%;
	min-width: 270px;
}

#waic-chat .waic-product {
	display: grid;
	grid-template-columns: 72px minmax(0, 1fr);
	gap: 12px;
	padding: 10px;
	border: 1px solid var(--waic-border);
	border-radius: calc(var(--waic-radius) * 0.7);
	background: var(--waic-surface);
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#waic-chat .waic-product:hover {
	border-color: color-mix(in srgb, var(--waic-primary) 40%, transparent);
	box-shadow: 0 8px 20px rgba(17, 24, 39, 0.08);
}

#waic-chat .waic-product__media {
	position: relative;
	display: block;
	width: 72px;
	height: 72px;
	overflow: hidden;
	border-radius: 10px;
	background: #f3f4f6;
}

#waic-chat .waic-product__media img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	object-fit: cover;
}

#waic-chat .waic-product__badge {
	position: absolute;
	top: 5px;
	inset-inline-start: 5px;
	padding: 2px 6px;
	border-radius: 6px;
	background: #ef4444;
	color: #fff;
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
}

#waic-chat .waic-product__body {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
}

#waic-chat .waic-product__name {
	display: -webkit-box;
	overflow: hidden;
	color: var(--waic-text);
	font-size: 14px;
	font-weight: 600;
	line-height: 1.35;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

#waic-chat .waic-product__name:hover {
	color: var(--waic-primary);
}

#waic-chat .waic-product__price {
	color: var(--waic-primary);
	font-size: 14px;
	font-weight: 700;
}

/* WooCommerce price HTML (sale prices) */
#waic-chat .waic-product__price del {
	margin-inline-end: 4px;
	color: var(--waic-muted);
	font-weight: 400;
	opacity: 0.8;
}

#waic-chat .waic-product__price ins {
	background: none;
	text-decoration: none;
}

#waic-chat .waic-product__rating {
	color: #f59e0b;
	font-size: 12px;
	font-weight: 600;
}

#waic-chat .waic-product__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin-block-start: 6px;
}

#waic-chat .waic-product__btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 12px;
	border: 0;
	border-radius: 999px;
	background: var(--waic-gradient);
	color: #fff;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.2;
	transition: transform 0.15s ease, opacity 0.2s ease;
}

#waic-chat .waic-product__btn:hover {
	color: #fff;
	transform: translateY(-1px);
}

#waic-chat .waic-product__btn:disabled {
	opacity: 0.7;
	cursor: wait;
	transform: none;
}

#waic-chat .waic-product__btn.is-added {
	background: #059669;
	cursor: default;
}

#waic-chat .waic-product__link {
	color: var(--waic-primary);
	font-size: 12px;
	font-weight: 600;
	text-decoration: underline;
}


/* ==========================================================================
   09. Message form
   ========================================================================== */

#waic-chat .waic-chat__form {
	display: flex;
	align-items: flex-end;
	gap: 10px;
	margin: 0;
	padding: 12px 14px;
	border-block-start: 1px solid var(--waic-border);
	background: var(--waic-surface);
}

#waic-chat .waic-chat__input {
	flex: 1;
	min-height: 44px;
	max-height: 120px;
	padding: 11px 14px;
	border: 1px solid var(--waic-border);
	border-radius: 14px;
	background: var(--waic-soft);
	color: var(--waic-text);
	font-size: 14px;
	line-height: 1.45;
	resize: none;
	outline: none;
	transition: border-color 0.2s ease, background-color 0.2s ease;
}

#waic-chat .waic-chat__input:focus {
	border-color: var(--waic-primary);
	background: var(--waic-surface);
}

#waic-chat .waic-chat__send {
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--waic-gradient);
	color: #fff;
	flex-shrink: 0;
	transition: transform 0.15s ease, opacity 0.2s ease;
}

#waic-chat .waic-chat__send:hover {
	transform: scale(1.06);
}

#waic-chat .waic-chat__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}

/* Flip the send arrow in RTL */
[dir="rtl"] #waic-chat .waic-chat__send .waic-icon {
	transform: scaleX(-1);
}

#waic-chat .waic-chat__note {
	margin: 0;
	padding: 0 14px 10px;
	background: var(--waic-surface);
	color: var(--waic-muted);
	font-size: 11px;
	text-align: center;
}


/* ==========================================================================
   10. Mobile (full screen)
   ========================================================================== */

@media (max-width: 480px) {
	#waic-chat {
		--waic-offset: 16px;
	}

	#waic-chat .waic-chat__window {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100%;
		height: 100dvh;
		max-height: none;
		border: 0;
		border-radius: 0;
	}

	/* The header close button is used on mobile instead */
	#waic-chat[data-state="open"] .waic-chat__launcher {
		display: none;
	}

	#waic-chat .waic-msg {
		max-width: 94%;
	}

	#waic-chat .waic-products {
		min-width: 0;
	}

	/* 16px stops iOS from zooming into the input */
	#waic-chat .waic-chat__input {
		font-size: 16px;
	}
}


/* ==========================================================================
   11. Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	#waic-chat *,
	#waic-chat *::before,
	#waic-chat *::after {
		animation: none !important;
		transition: none !important;
		scroll-behavior: auto !important;
	}
}
