/**
 * ChatLaterale widget. Mobile first: under 480px the floating panel is full screen.
 *
 * Colors come from the settings through --aichat-primary,
 * --aichat-on-primary and, for the chat buttons, --aichat-btn-bg and
 * --aichat-btn-fg (set by widget.js from wp_localize_script). Button style,
 * shape and layout are classes of the root: .aichat--btn-*.
 */

.aichat {
	--aichat-primary: #1d4ed8;
	--aichat-on-primary: #fff;
	--aichat-surface: #fff;
	--aichat-text: #1f2937;
	--aichat-muted: #4b5563;
	--aichat-border: #d1d5db;
	--aichat-bot-bubble: #f1f3f5;
	--aichat-error-bg: #fef2f2;
	--aichat-error-text: #991b1b;
	--aichat-radius: 16px;
	--aichat-btn-bg: var(--aichat-primary);
	--aichat-btn-radius: 999px;
	--aichat-shadow: 0 12px 32px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
	--aichat-z: 2147483000;

	box-sizing: border-box;
	color: var(--aichat-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
	text-align: left;
}

.aichat *,
.aichat *::before,
.aichat *::after {
	box-sizing: inherit;
}

/* Themes sometimes set display on elements: keep [hidden] hidden. */
.aichat [hidden] {
	display: none !important;
}

.aichat button {
	margin: 0;
	font: inherit;
	letter-spacing: normal;
	text-transform: none;
	cursor: pointer;
}

.aichat button:disabled {
	cursor: not-allowed;
}

.aichat :focus-visible {
	outline: 2px solid var(--aichat-primary);
	outline-offset: 2px;
}

.aichat__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: out of sight and out of the tab order. */
.aichat__hp {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	border: 0;
	opacity: 0;
	pointer-events: none;
}

.aichat__svg {
	display: block;
	width: 24px;
	height: 24px;
}

/* ------------------------------------------------------------------ */
/* Launcher (floating mode)                                           */
/* ------------------------------------------------------------------ */

.aichat__launcher {
	position: fixed;
	z-index: var(--aichat-z);
	right: 16px;
	bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--aichat-primary);
	color: var(--aichat-on-primary);
	box-shadow: var(--aichat-shadow);
	transition: transform 0.15s ease;
}

.aichat__launcher:hover {
	transform: scale(1.05);
}

.aichat__launcher:focus-visible {
	outline-offset: 3px;
}

.aichat--pos-left .aichat__launcher {
	right: auto;
	left: 16px;
}

.aichat__launcher-icon .aichat__svg {
	width: 28px;
	height: 28px;
}

.aichat__launcher-icon .aichat__icon-image {
	display: block;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	object-fit: cover;
}

/* ------------------------------------------------------------------ */
/* Panel                                                              */
/* ------------------------------------------------------------------ */

.aichat__panel {
	position: relative;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--aichat-surface);
}

/* Floating, mobile: fill the visible viewport (inset, not 100dvh — that
   height overrides bottom and can leave the composer under the browser UI). */
.aichat--floating .aichat__panel {
	position: fixed;
	z-index: calc(var(--aichat-z) + 1);
	inset: 0;
	width: auto;
	height: auto;
}

/* Inline: embedded in the content. */
.aichat--inline {
	margin: 1.5em 0;
}

.aichat--inline .aichat__panel {
	width: 100%;
	height: 540px;
	max-height: 80vh;
	border: 1px solid var(--aichat-border);
	border-radius: var(--aichat-radius);
}

@media (min-width: 480px) {
	.aichat__launcher {
		right: 24px;
		bottom: 24px;
	}

	.aichat--pos-left .aichat__launcher {
		left: 24px;
	}

	.aichat--floating .aichat__panel {
		inset: auto 24px 96px auto;
		width: 380px;
		height: min(620px, calc(100vh - 120px));
		border-radius: var(--aichat-radius);
		box-shadow: var(--aichat-shadow);
	}

	.aichat--floating.aichat--pos-left .aichat__panel {
		inset: auto auto 96px 24px;
	}
}

/* Hide the launcher while the panel is open so it cannot steal taps
   from the composer (it sits in the same corner as the send button). */
.aichat--floating.is-open .aichat__launcher {
	visibility: hidden;
	pointer-events: none;
}

/* Mobile: no page scroll behind the full screen panel. Do not lock
   html — overflow:hidden there stops the on-screen keyboard on Chrome. */
@media (max-width: 479.98px) {
	html.aichat-lock body {
		overflow: hidden;
	}
}

/* ------------------------------------------------------------------ */
/* Header                                                             */
/* ------------------------------------------------------------------ */

.aichat__header {
	display: flex;
	flex: none;
	gap: 10px;
	align-items: center;
	padding: 12px 12px 12px 16px;
	background: var(--aichat-primary);
	color: var(--aichat-on-primary);
}

.aichat__header :focus-visible {
	outline-color: var(--aichat-on-primary);
}

.aichat__avatar {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	overflow: hidden;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.18);
}

.aichat__avatar .aichat__icon-image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.aichat .aichat__title {
	flex: 1;
	margin: 0;
	padding: 0;
	overflow: hidden;
	color: inherit;
	font-family: inherit;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.3;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.aichat__icon-button {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
}

.aichat__icon-button:hover {
	background: rgba(127, 127, 127, 0.2);
}

.aichat__icon-button .aichat__svg {
	width: 20px;
	height: 20px;
}

/* ------------------------------------------------------------------ */
/* Body: consent gate, messages, notices                              */
/* ------------------------------------------------------------------ */

.aichat__body {
	position: relative;
	display: flex;
	flex: 1;
	flex-direction: column;
	min-height: 0;
}

.aichat.is-loading .aichat__body::before {
	content: "";
	width: 28px;
	height: 28px;
	margin: auto;
	border: 3px solid var(--aichat-border);
	border-top-color: var(--aichat-primary);
	border-radius: 50%;
	animation: aichat-spin 0.8s linear infinite;
}

.aichat__consent {
	flex: 1;
	padding: 20px;
	overflow-y: auto;
}

.aichat__consent p {
	margin: 0 0 16px;
}

.aichat__consent-notice {
	padding: 10px 12px;
	border-left: 4px solid var(--aichat-primary);
	background: var(--aichat-bot-bubble);
	font-weight: 600;
}

.aichat .aichat__link {
	padding: 0;
	border: 0;
	background: none;
	color: var(--aichat-primary);
	font-weight: 600;
	text-decoration: underline;
}

.aichat .aichat__button {
	display: inline-block;
	width: 100%;
	padding: 12px 16px;
	border: 0;
	border-radius: 10px;
	background: var(--aichat-primary);
	color: var(--aichat-on-primary);
	font-weight: 600;
	text-align: center;
}

.aichat .aichat__button:hover {
	filter: brightness(1.08);
}

.aichat .aichat__button:disabled {
	opacity: 0.6;
}

.aichat__messages {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.aichat__message {
	display: flex;
	max-width: 85%;
}

.aichat__message--user {
	align-self: flex-end;
}

.aichat__message--assistant {
	align-self: flex-start;
}

.aichat__bubble {
	padding: 10px 14px;
	border-radius: 18px;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.aichat__message--user .aichat__bubble {
	border-bottom-right-radius: 4px;
	background: var(--aichat-primary);
	color: var(--aichat-on-primary);
}

.aichat__message--assistant .aichat__bubble {
	border-bottom-left-radius: 4px;
	background: var(--aichat-bot-bubble);
	color: var(--aichat-text);
}

.aichat__message--assistant .aichat__bubble a {
	color: var(--aichat-primary);
	text-decoration: underline;
}

/* ------------------------------------------------------------------ */
/* Chat buttons (links chosen from the knowledge base)                */
/* ------------------------------------------------------------------ */

.aichat__message--assistant {
	flex-direction: column;
	align-items: flex-start;
}

.aichat__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 8px;
}

.aichat--btn-stacked .aichat__actions {
	flex-direction: column;
	align-self: stretch;
}

.aichat--btn-rounded {
	--aichat-btn-radius: 8px;
}

.aichat--btn-square {
	--aichat-btn-radius: 2px;
}

/* Themes style links heavily: every state is set explicitly. */
.aichat .aichat__action,
.aichat .aichat__action:visited {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-height: 38px;
	max-width: 100%;
	margin: 0;
	padding: 7px 14px;
	border: 1.5px solid var(--aichat-btn-bg);
	border-radius: var(--aichat-btn-radius);
	background: var(--aichat-surface);
	box-shadow: none;
	color: var(--aichat-btn-fg, var(--aichat-btn-bg));
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	transition: background-color 0.15s ease, filter 0.15s ease;
}

.aichat .aichat__action:hover,
.aichat .aichat__action:focus-visible {
	background: color-mix(in srgb, var(--aichat-btn-bg) 10%, var(--aichat-surface));
	color: var(--aichat-btn-fg, var(--aichat-btn-bg));
	text-decoration: none;
}

.aichat--btn-filled .aichat__action,
.aichat--btn-filled .aichat__action:visited,
.aichat--btn-filled .aichat__action:hover,
.aichat--btn-filled .aichat__action:focus-visible {
	background: var(--aichat-btn-bg);
	color: var(--aichat-btn-fg, var(--aichat-on-primary));
}

.aichat--btn-filled .aichat__action:hover {
	filter: brightness(1.1);
}

.aichat--btn-soft .aichat__action,
.aichat--btn-soft .aichat__action:visited {
	border-color: transparent;
	background: color-mix(in srgb, var(--aichat-btn-bg) 12%, var(--aichat-surface));
}

.aichat--btn-soft .aichat__action:hover,
.aichat--btn-soft .aichat__action:focus-visible {
	background: color-mix(in srgb, var(--aichat-btn-bg) 22%, var(--aichat-surface));
}

.aichat__action-icon .aichat__svg {
	width: 18px;
	height: 18px;
}

.aichat__action-label {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

@media (forced-colors: active) {
	.aichat .aichat__action {
		border-color: LinkText;
		color: LinkText;
	}
}

.aichat__message.is-welcome .aichat__bubble {
	border: 1px dashed var(--aichat-border);
	background: var(--aichat-surface);
}

.aichat__dots {
	display: inline-flex;
	gap: 4px;
	padding: 4px 0;
}

.aichat__dots span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--aichat-muted);
	animation: aichat-blink 1.2s infinite ease-in-out;
}

.aichat__dots span:nth-child(2) {
	animation-delay: 0.2s;
}

.aichat__dots span:nth-child(3) {
	animation-delay: 0.4s;
}

.aichat__error,
.aichat__limit {
	flex: none;
	margin: 0 16px 10px;
	padding: 8px 12px;
	border-radius: 8px;
	font-size: 14px;
}

.aichat__error {
	background: var(--aichat-error-bg);
	color: var(--aichat-error-text);
}

.aichat__limit {
	background: var(--aichat-bot-bubble);
	color: var(--aichat-muted);
}

/* ------------------------------------------------------------------ */
/* Input                                                              */
/* ------------------------------------------------------------------ */

.aichat__form {
	position: relative;
	z-index: 2;
	display: flex;
	flex: none;
	gap: 8px;
	align-items: flex-end;
	margin: 0;
	padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
	border-top: 1px solid var(--aichat-border);
	background: var(--aichat-surface);
}

/* Wrapper: a textarea as a flex item often ignores taps on Android Chrome. */
.aichat__composer {
	flex: 1;
	min-width: 0;
}

.aichat .aichat__input {
	display: block;
	width: 100%;
	min-height: 44px;
	max-height: 140px;
	margin: 0;
	padding: 10px 12px;
	border: 1px solid var(--aichat-border);
	border-radius: 12px;
	background: var(--aichat-surface);
	box-shadow: none;
	color: var(--aichat-text);
	/* 16px: no automatic zoom on iOS. */
	font: inherit;
	font-size: 16px;
	line-height: 1.4;
	resize: none;
	touch-action: manipulation;
	-webkit-user-select: text;
	user-select: text;
}

.aichat .aichat__input:disabled {
	background: var(--aichat-bot-bubble);
	cursor: not-allowed;
}

.aichat__send {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--aichat-primary);
	color: var(--aichat-on-primary);
}

.aichat__send:disabled {
	opacity: 0.45;
}

.aichat__send .aichat__svg {
	width: 20px;
	height: 20px;
}

/* ------------------------------------------------------------------ */
/* Privacy popup                                                      */
/* ------------------------------------------------------------------ */

.aichat__modal {
	position: absolute;
	z-index: 2;
	inset: 0;
	display: flex;
	align-items: stretch;
	justify-content: center;
	padding: 12px;
	background: rgba(17, 24, 39, 0.55);
}

.aichat__modal-box {
	display: flex;
	flex: 1;
	flex-direction: column;
	max-width: 640px;
	overflow: hidden;
	border-radius: 12px;
	background: var(--aichat-surface);
	box-shadow: var(--aichat-shadow);
}

.aichat__modal-header {
	display: flex;
	flex: none;
	gap: 8px;
	align-items: center;
	padding: 10px 10px 10px 16px;
	border-bottom: 1px solid var(--aichat-border);
}

.aichat .aichat__modal-title {
	flex: 1;
	margin: 0;
	color: var(--aichat-text);
	font-family: inherit;
	font-size: 16px;
	font-weight: 600;
}

.aichat__modal-content {
	flex: 1;
	padding: 16px;
	overflow-y: auto;
	font-size: 14px;
}

.aichat__modal-content > :first-child {
	margin-top: 0;
}

.aichat__modal-content h3,
.aichat__modal-content h4 {
	margin: 0 0 8px;
	font-size: 15px;
}

.aichat__modal-content p,
.aichat__modal-content ul,
.aichat__modal-content ol {
	margin: 0 0 10px;
}

.aichat__modal-content a,
.aichat__modal-footer a {
	color: var(--aichat-primary);
}

.aichat__modal-code code {
	padding: 1px 4px;
	border-radius: 4px;
	background: var(--aichat-bot-bubble);
	font-size: 12px;
	word-break: break-all;
	user-select: all;
}

.aichat__modal-footer {
	flex: none;
	margin: 0;
	padding: 10px 16px;
	border-top: 1px solid var(--aichat-border);
	font-size: 14px;
}

/* ------------------------------------------------------------------ */
/* Motion                                                             */
/* ------------------------------------------------------------------ */

@keyframes aichat-blink {
	0%,
	80%,
	100% {
		opacity: 0.25;
	}

	40% {
		opacity: 1;
	}
}

@keyframes aichat-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.aichat *,
	.aichat *::before {
		transition: none !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
	}
}

@media print {
	.aichat--floating {
		display: none;
	}
}
