/**
 * Yapper chat on the website (inline block/shortcode and floating panel).
 *
 * Every colour and size is a custom property on .yapper-chat-root, so a theme can retune
 * the chat by overriding a handful of variables. The accent follows the theme's theme.json
 * presets when it has them. Selectors are class-scoped (one class beats a theme's element
 * selectors) and reset what themes commonly restyle, without !important.
 */

.yapper-chat-root {
	--yc-accent: var(--wp--preset--color--primary, var(--wp--preset--color--accent, #2271b1));
	--yc-on-accent: #fff;
	--yc-header-bg: var(--yc-accent);
	--yc-header-bg-end: var(--yc-accent);
	--yc-text: #1e2a3a;
	--yc-muted: #8a94a3;
	--yc-surface: #fff;
	--yc-messages-bg: #f3f6f9;
	--yc-border: #e3e8ef;
	--yc-input-border: #d5dbe3;
	--yc-danger: #b32d2e;
	--yc-danger-bg: #fcf0f1;
	--yc-radius: 14px;
	--yc-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
	--yc-avatar-size: 44px;
	--yc-send-size: 44px;
	/* Widget renderer (cards) follows the same palette. */
	--yw-accent: var(--yc-accent);
	--yw-text: var(--yc-text);
	--yw-surface: var(--yc-surface);
	--yw-border: var(--yc-border);
	--yw-muted: var(--yc-muted);
	--yw-font: inherit;
	font: inherit;
	color: var(--yc-text);
}

/* Lighter tints where color-mix() is supported; the solid values above are the fallback. */
@supports (background: color-mix(in srgb, red 50%, white)) {
	.yapper-chat-root {
		--yc-header-bg-end: color-mix(in srgb, var(--yc-accent) 70%, #fff);
		--yc-messages-bg: color-mix(in srgb, var(--yc-accent) 4%, #f5f7fa);
	}
}

.yapper-chat-root,
.yapper-chat-root *,
.yapper-chat-root *::before,
.yapper-chat-root *::after {
	box-sizing: border-box;
}

.yapper-chat-root button,
.yapper-chat-root textarea {
	font: inherit;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	margin: 0;
}

.yapper-chat-root button {
	cursor: pointer;
	line-height: 1;
	box-shadow: none;
	min-height: 0;
	min-width: 0;
}

.yapper-chat-root button:disabled {
	cursor: default;
	opacity: 0.5;
}

.yapper-chat-root :focus-visible {
	outline: 2px solid var(--yc-accent);
	outline-offset: 2px;
}

.yapper-chat-root .yapper-chat-icon {
	display: block;
	flex: none;
}

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

/* Panel */
.yapper-chat {
	display: flex;
	flex-direction: column;
	background: var(--yc-surface);
	color: var(--yc-text);
	border: 1px solid var(--yc-border);
	border-radius: var(--yc-radius);
	box-shadow: var(--yc-shadow);
	overflow: hidden;
	text-align: left;
}

.yapper-chat-inline {
	height: var(--yapper-chat-height, 520px);
	width: 100%;
}

/* Header */
.yapper-chat-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 16px 18px;
	background: var(--yc-header-bg);
	background-image: linear-gradient(90deg, var(--yc-header-bg), var(--yc-header-bg-end));
	color: var(--yc-on-accent);
}

.yapper-chat-avatar {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--yc-avatar-size);
	height: var(--yc-avatar-size);
	border-radius: 50%;
	background: #fff;
	color: var(--yc-accent);
	overflow: hidden;
	box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.45), 0 2px 6px rgba(0, 0, 0, 0.12);
}

.yapper-chat-root .yapper-chat-avatar img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border-radius: 0;
	object-fit: cover;
}

.yapper-chat-avatar-mark {
	display: block;
	width: 64%;
	height: auto;
}

.yapper-chat-heading {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 2px;
}

.yapper-chat-title {
	font-size: 18px;
	font-weight: 700;
	line-height: 1.25;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.yapper-chat-subtitle {
	font-size: 12px;
	font-weight: 600;
	line-height: 1.3;
	opacity: 0.85;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.yapper-chat-actions {
	flex: none;
	display: flex;
	align-items: center;
	gap: 2px;
}

.yapper-chat-root .yapper-chat-icon-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--yc-on-accent);
	transition: background-color 0.15s ease;
}

.yapper-chat-root .yapper-chat-icon-button:hover {
	background: rgba(255, 255, 255, 0.16);
}

.yapper-chat-root .yapper-chat-icon-button:focus-visible {
	outline: 2px solid var(--yc-on-accent);
	outline-offset: 0;
}

/* Messages */
.yapper-chat-messages {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 12px;
	padding: 16px;
	background: var(--yc-messages-bg);
	scroll-behavior: smooth;
	font-size: 14px;
}

.yapper-chat-bubble {
	max-width: 85%;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
}

.yapper-chat-bubble-bot {
	align-self: flex-start;
	padding: 12px 16px;
	background: var(--yc-surface);
	color: var(--yc-text);
	border: 1px solid var(--yc-border);
	border-radius: 16px;
	line-height: 1.6;
}

.yapper-chat-bubble-user {
	align-self: flex-end;
	padding: 10px 16px;
	background: var(--yc-accent);
	color: var(--yc-on-accent);
	border-radius: 18px;
	font-weight: 600;
	line-height: 1.45;
}

/* Bot text is a markdown widget; inside a bubble it must not look like a card. */
.yapper-chat-bubble-md {
	white-space: normal;
}

.yapper-chat-bubble-md > .yw-md {
	gap: 10px;
	border: 0;
	padding: 0;
	background: none;
	box-shadow: none;
	color: inherit;
	font-size: inherit;
	line-height: inherit;
}

.yapper-chat-bubble-md .yw-md a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.yapper-chat-widgets {
	align-self: stretch;
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-width: 92%;
}

.yapper-chat-bubble-system,
.yapper-chat-bubble-error {
	align-self: center;
	max-width: 92%;
	font-size: 12px;
	text-align: center;
	line-height: 1.4;
}

.yapper-chat-bubble-system {
	padding: 2px 8px;
	color: var(--yc-muted);
}

.yapper-chat-bubble-error {
	padding: 8px 12px;
	color: var(--yc-danger);
	background: var(--yc-danger-bg);
	border: 1px solid var(--yc-danger);
	border-radius: 10px;
}

/* Typing indicator: three dots in a bot bubble */
.yapper-chat-typing {
	display: inline-flex;
	gap: 5px;
	align-items: center;
	padding: 15px 18px;
}

.yapper-chat-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--yc-muted);
	animation: yapper-chat-typing 1.2s infinite ease-in-out;
}

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

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

@keyframes yapper-chat-typing {
	0%, 60%, 100% {
		transform: translateY(0);
		opacity: 0.45;
	}
	30% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

/* Composer */
.yapper-chat-composer {
	display: flex;
	align-items: flex-end;
	gap: 10px;
	margin: 0;
	padding: 12px 14px;
	border-top: 1px solid var(--yc-border);
	background: var(--yc-surface);
}

.yapper-chat-root .yapper-chat-input {
	flex: 1;
	display: block;
	width: auto;
	min-width: 0;
    height: 46px !important;
    padding: 6px 16px;
	resize: none;
	border: 1px solid var(--yc-input-border);
	border-radius: 22px;
	background: var(--yc-surface);
	color: var(--yc-text);
	line-height: 2.2;
	font-size: 14px;
	box-shadow: none;
	overflow: hidden;
}

.yapper-chat-root .yapper-chat-input::placeholder {
	color: var(--yc-muted);
	opacity: 1;
}

.yapper-chat-root .yapper-chat-input:focus {
	border-color: var(--yc-accent);
	outline: none;
	box-shadow: 0 0 0 1px var(--yc-accent);
}

.yapper-chat-root .yapper-chat-send {
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--yc-send-size);
	height: var(--yc-send-size);
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--yc-accent);
	color: var(--yc-on-accent);
	transition: filter 0.15s ease;
}

.yapper-chat-root .yapper-chat-send:hover:not(:disabled) {
	filter: brightness(1.08);
}

.yapper-chat-send .yapper-chat-icon {
	/* The paper plane reads better nudged towards its tip. */
	transform: translate(-1px, 1px);
}

.yapper-chat-disclaimer {
	margin: 0;
	padding: 0 16px 10px;
	background: var(--yc-surface);
	color: var(--yc-muted);
	font-size: 11px;
	line-height: 1.4;
	text-align: center;
}

.yapper-chat-noscript {
	margin: 0;
	padding: 8px 12px;
	font-size: 12px;
}

/* Floating chat */
.yapper-chat-floating {
	position: fixed;
	bottom: 20px;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
}

.yapper-chat-pos-right {
	right: 20px;
}

.yapper-chat-pos-left {
	left: 20px;
	align-items: flex-start;
}

.yapper-chat-panel[hidden] {
	display: none;
}

.yapper-chat-panel {
    width: 100%;
    max-width: 640px;
	height: min(620px, calc(100vh - 120px));
	display: flex;
}

.yapper-chat-box {
	flex: 1;
	min-width: 0;
}

.yapper-chat-root .yapper-chat-launcher {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 999px;
	background: var(--yc-accent);
	color: var(--yc-on-accent);
	font-weight: 600;
	box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
	transition: filter 0.15s ease, transform 0.15s ease;
}

.yapper-chat-root .yapper-chat-launcher.has-label {
	width: auto;
	padding: 0 20px 0 16px;
}

.yapper-chat-root .yapper-chat-launcher:hover {
	filter: brightness(1.08);
	transform: translateY(-1px);
}

.yapper-chat-launcher .yapper-chat-icon {
	width: 24px;
	height: 24px;
}

@media (max-width: 600px) {
	/* Open: the panel takes (almost) the whole screen. */
	.yapper-chat-floating.is-open {
		top: 8px;
		right: 8px;
		bottom: 8px;
		left: 8px;
	}

	.yapper-chat-floating.is-open .yapper-chat-panel {
		width: 100%;
		max-width: none;
		height: auto;
		flex: 1;
		/* Flex items default to min-height: auto (content height), which would let a long
		   conversation grow the panel past the screen and push the composer out of view. */
		min-height: 0;
		/* Hard cap to the visible viewport minus the 8px top/bottom insets, whatever the
		   device height (dvh excludes the mobile browser toolbars; vh is the fallback). */
		max-height: calc(100vh - 16px);
		max-height: calc(100dvh - 16px);
	}
	/* Only while open: the panel's close button takes over and the launcher would cover the
	   composer. Closed, the launcher stays visible in its corner. */
	.yapper-chat-floating.is-open .yapper-chat-launcher {
		display: none;
	}

	.yapper-chat-bubble {
		max-width: 90%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.yapper-chat-typing span {
		animation: none;
	}

	.yapper-chat-messages {
		scroll-behavior: auto;
	}

	.yapper-chat-root .yapper-chat-launcher,
	.yapper-chat-root .yapper-chat-send,
	.yapper-chat-root .yapper-chat-icon-button {
		transition: none;
	}

	.yapper-chat-root .yapper-chat-launcher:hover {
		transform: none;
	}
}
