/**
 * Richie's assistant: the "Ask a question" launcher and the chat panel.
 *
 * Flat colours from the Richie's identity (forest green, ivory, cream, sage), read from the
 * theme's tokens with the same values as fallbacks, so it also looks right on any other theme.
 * Loaded only on pages that show the widget.
 */

.rs-ai {
	--rs-ai-green: var(--green, #12392c);
	--rs-ai-green-deep: var(--green-deep, #0b251d);
	--rs-ai-ivory: var(--ivory, #f5f0e7);
	--rs-ai-cream: var(--cream, #eae1d2);
	--rs-ai-sage: var(--sage, #d4d9c4);
	--rs-ai-ink: var(--ink, #0a1812);
	--rs-ai-muted: var(--muted, #49574d);
	--rs-ai-white: #fff;
	--rs-ai-line: rgba(10, 24, 18, 0.14);
	--rs-ai-font: Lato, "Helvetica Neue", Arial, sans-serif;

	font-family: var(--rs-ai-font);
	font-size: 16px;
	line-height: 1.5;
	color: var(--rs-ai-ink);
}

.rs-ai[hidden],
.rs-ai [hidden] {
	display: none !important;
}

.rs-ai *,
.rs-ai *::before,
.rs-ai *::after {
	box-sizing: border-box;
}

/* ------------------------------------------------------------------ launcher */

.rs-ai .rs-ai__launcher {
	position: fixed;
	right: 16px;
	bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	z-index: 90;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 48px;
	margin: 0;
	padding: 0 20px 0 16px;
	border: 0;
	border-radius: 999px;
	background: var(--rs-ai-green);
	color: var(--rs-ai-ivory);
	/* A flat ivory ring keeps the button visible on the dark green bands. */
	box-shadow: 0 0 0 2px var(--rs-ai-ivory);
	font: 700 15px/1 var(--rs-ai-font);
	letter-spacing: 0.01em;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.rs-ai .rs-ai__launcher:hover {
	background: var(--rs-ai-green-deep);
}

.rs-ai .rs-ai__launcher:focus-visible {
	outline: 3px solid var(--rs-ai-green);
	outline-offset: 3px;
	border-radius: 999px;
	box-shadow: 0 0 0 2px var(--rs-ai-ivory);
}

.rs-ai .rs-ai__paw {
	flex: 0 0 auto;
	display: block;
}

/* The personalise page's buy bar (phones) sits at the bottom of the screen: stay above it. */
body.has-buy-bar .rs-ai .rs-ai__launcher {
	bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

.rs-ai.is-open .rs-ai__launcher {
	display: none;
}

/* --------------------------------------------------------------------- panel */

.rs-ai .rs-ai__panel {
	position: fixed;
	right: 16px;
	bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	z-index: 98;
	display: flex;
	flex-direction: column;
	width: min(400px, calc(100vw - 32px));
	max-height: min(640px, calc(100vh - 32px));
	max-height: min(640px, calc(100dvh - 32px));
	margin: 0;
	overflow: hidden;
	background: var(--rs-ai-ivory);
	border: 1px solid var(--rs-ai-line);
	border-radius: 20px;
	box-shadow: var(--lift, 0 12px 32px -20px rgba(10, 24, 18, 0.25));
	/* The panel takes focus on touch screens so the keyboard stays down; it is not a control. */
	outline: none;
}

body.admin-bar .rs-ai .rs-ai__panel {
	max-height: min(640px, calc(100vh - 80px));
	max-height: min(640px, calc(100dvh - 80px));
}

.rs-ai .rs-ai__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 10px 14px 18px;
	background: var(--rs-ai-green);
	color: var(--rs-ai-ivory);
}

.rs-ai .rs-ai__heading {
	min-width: 0;
}

.rs-ai .rs-ai__title {
	margin: 0;
	padding: 0;
	font-family: "DM Serif Display", Georgia, serif;
	font-size: 22px;
	font-weight: 400;
	line-height: 1.15;
	letter-spacing: 0;
	text-transform: none;
	color: var(--rs-ai-ivory);
}

.rs-ai .rs-ai__badge {
	display: inline-block;
	margin: 6px 0 0;
	padding: 3px 9px;
	font-size: 11px;
	font-weight: 700;
	line-height: 1.3;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--rs-ai-green-deep);
	background: var(--rs-ai-sage);
	border-radius: 999px;
}

.rs-ai .rs-ai__tools {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	gap: 2px;
}

.rs-ai .rs-ai__restart,
.rs-ai .rs-ai__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	margin: 0;
	padding: 0 10px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--rs-ai-ivory);
	font: 700 13px/1 var(--rs-ai-font);
	cursor: pointer;
}

.rs-ai .rs-ai__restart {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.rs-ai .rs-ai__close {
	padding: 0;
}

.rs-ai .rs-ai__restart:hover,
.rs-ai .rs-ai__close:hover {
	background: var(--rs-ai-green-deep);
}

.rs-ai .rs-ai__head :focus-visible {
	outline: 3px solid var(--rs-ai-ivory);
	outline-offset: -3px;
	border-radius: 999px;
	box-shadow: none;
}

/* ----------------------------------------------------------------- the talk */

.rs-ai .rs-ai__body {
	flex: 1 1 auto;
	min-height: 140px;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px 16px 8px;
}

.rs-ai .rs-ai__intro p {
	margin: 0 0 12px;
	font-size: 15px;
	color: var(--rs-ai-muted);
}

.rs-ai .rs-ai__starters {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.rs-ai .rs-ai__starters li {
	margin: 0;
	padding: 0;
}

.rs-ai .rs-ai__starter {
	min-height: 44px;
	margin: 0;
	padding: 10px 16px;
	border: 1px solid var(--rs-ai-green);
	border-radius: 999px;
	background: var(--rs-ai-white);
	color: var(--rs-ai-green);
	font: 700 14px/1.2 var(--rs-ai-font);
	text-align: left;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease;
}

.rs-ai .rs-ai__starter:hover {
	background: var(--rs-ai-green);
	color: var(--rs-ai-ivory);
}

.rs-ai .rs-ai__log {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.rs-ai .rs-ai__msg {
	max-width: 88%;
	margin: 0;
	padding: 10px 14px;
	border-radius: 16px;
	font-size: 15px;
	line-height: 1.5;
	overflow-wrap: anywhere;
}

.rs-ai .rs-ai__msg--user {
	align-self: flex-end;
	background: var(--rs-ai-green);
	color: var(--rs-ai-ivory);
	border-bottom-right-radius: 6px;
}

.rs-ai .rs-ai__msg--assistant {
	align-self: flex-start;
	background: var(--rs-ai-white);
	border: 1px solid var(--rs-ai-line);
	border-bottom-left-radius: 6px;
}

.rs-ai .rs-ai__msg--notice {
	align-self: stretch;
	max-width: none;
	background: var(--rs-ai-cream);
	color: var(--rs-ai-ink);
}

.rs-ai .rs-ai__msg p,
.rs-ai .rs-ai__msg ul {
	margin: 0 0 8px;
}

.rs-ai .rs-ai__msg p:last-child,
.rs-ai .rs-ai__msg ul:last-child {
	margin-bottom: 0;
}

.rs-ai .rs-ai__msg ul {
	padding-left: 20px;
	list-style: disc;
}

.rs-ai .rs-ai__msg li {
	margin: 0 0 4px;
}

.rs-ai .rs-ai__msg a {
	color: var(--rs-ai-green);
	font-weight: 700;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.rs-ai .rs-ai__msg a:focus-visible,
.rs-ai .rs-ai__note a:focus-visible,
.rs-ai .rs-ai__starter:focus-visible,
.rs-ai .rs-ai__send:focus-visible {
	outline: 3px solid var(--rs-ai-green);
	outline-offset: 2px;
	box-shadow: none;
}

.rs-ai .rs-ai__starter:focus-visible,
.rs-ai .rs-ai__send:focus-visible {
	border-radius: 999px;
}

.rs-ai .rs-ai__sr,
.rs-ai .rs-ai__live {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.rs-ai .rs-ai__typing {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 12px 0 4px;
	font-size: 14px;
	color: var(--rs-ai-muted);
}

.rs-ai .rs-ai__dots {
	display: inline-flex;
	gap: 4px;
}

.rs-ai .rs-ai__dots span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--rs-ai-green);
	opacity: 0.4;
}

/* ---------------------------------------------------------------------- form */

.rs-ai .rs-ai__form {
	margin: 0;
	padding: 12px 16px 4px;
	border-top: 1px solid var(--rs-ai-line);
	background: var(--rs-ai-ivory);
}

.rs-ai .rs-ai__label {
	display: block;
	margin: 0 0 6px;
	font-size: 13px;
	font-weight: 700;
	color: var(--rs-ai-ink);
}

.rs-ai .rs-ai__row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
}

.rs-ai .rs-ai__input {
	flex: 1 1 auto;
	min-width: 0;
	min-height: 48px;
	max-height: 128px;
	margin: 0;
	padding: 12px 14px;
	border: 1px solid rgba(10, 24, 18, 0.4);
	border-radius: 14px;
	background: var(--rs-ai-white);
	color: var(--rs-ai-ink);
	font: 400 16px/1.4 var(--rs-ai-font);
	resize: none;
	box-shadow: none;
}

.rs-ai .rs-ai__input:focus-visible {
	outline: 3px solid var(--rs-ai-green);
	outline-offset: 1px;
	border-radius: 14px;
	box-shadow: none;
}

.rs-ai .rs-ai__send {
	flex: 0 0 auto;
	min-height: 48px;
	margin: 0;
	padding: 0 18px;
	border: 0;
	border-radius: 999px;
	background: var(--rs-ai-green);
	color: var(--rs-ai-ivory);
	font: 700 15px/1 var(--rs-ai-font);
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.rs-ai .rs-ai__send:hover {
	background: var(--rs-ai-green-deep);
}

.rs-ai .rs-ai__send[disabled] {
	opacity: 0.6;
	cursor: progress;
}

.rs-ai .rs-ai__hint {
	margin: 6px 0 0;
	font-size: 12.5px;
	line-height: 1.4;
	color: var(--rs-ai-muted);
}

.rs-ai .rs-ai__note {
	margin: 0;
	padding: 8px 16px 14px;
	font-size: 12.5px;
	line-height: 1.45;
	color: var(--rs-ai-muted);
	background: var(--rs-ai-ivory);
}

.rs-ai .rs-ai__note a {
	color: var(--rs-ai-green);
	font-weight: 700;
	overflow-wrap: anywhere;
}

/* -------------------------------------------------------------------- motion */

@media (prefers-reduced-motion: no-preference) {
	.rs-ai .rs-ai__panel {
		animation: rs-ai-in 0.2s ease-out;
	}

	.rs-ai .rs-ai__dots span {
		animation: rs-ai-dot 1.2s ease-in-out infinite;
	}

	.rs-ai .rs-ai__dots span:nth-child(2) {
		animation-delay: 0.15s;
	}

	.rs-ai .rs-ai__dots span:nth-child(3) {
		animation-delay: 0.3s;
	}
}

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

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

@keyframes rs-ai-dot {
	0%,
	80%,
	100% {
		opacity: 0.4;
		transform: translateY(0);
	}

	40% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

/* -------------------------------------------------------------------- phones */

@media (max-width: 599px) {
	.rs-ai .rs-ai__launcher {
		right: 12px;
		bottom: calc(12px + env(safe-area-inset-bottom, 0px));
	}

	body.has-buy-bar .rs-ai .rs-ai__launcher {
		bottom: calc(80px + env(safe-area-inset-bottom, 0px));
	}

	/* A full width bottom sheet. */
	.rs-ai .rs-ai__panel,
	body.admin-bar .rs-ai .rs-ai__panel {
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		max-height: 85vh;
		max-height: 85dvh;
		border-width: 1px 0 0;
		border-radius: 20px 20px 0 0;
		padding-bottom: env(safe-area-inset-bottom, 0px);
	}
}

@media print {
	.rs-ai {
		display: none !important;
	}
}
