/*
 * Chat panel (parts/chat.php, chat.js, plan 23). No design: a Forest A card
 * in the site's palette, 380px wide and up to 620px tall, anchored above the
 * bubbles from 768px; full-screen under the bar on phones, like the menu.
 * The site's lines sit left on a lighter Forest, the visitor's right in Stone
 * on Forest B. z-index 45: above the bubbles (40), under the menu (48).
 */

:root {
	--chat-duration: 0.3s;
}

.chat {
	position: fixed;
	right: var(--gutter);
	bottom: calc(var(--gutter) + 56px + 12px);
	z-index: 45;
	display: flex;
	flex-direction: column;
	width: min(380px, 100vw - var(--gutter) * 2);
	height: min(620px, 100dvh - var(--header-height) - var(--gutter) * 2 - 68px);
	overflow: hidden;
	border-radius: var(--radius);
	background: var(--color-forest-a);
	color: var(--color-stone);
	box-shadow: 0 8px 30px rgb(0 36 30 / 0.35);
	font-family: var(--font-sans);
	font-size: var(--fs-20);
	line-height: var(--lh-sans);
	opacity: 0;
	translate: 0 12px;
	transition: opacity var(--chat-duration) ease, translate var(--chat-duration) ease;
}

.chat[hidden] {
	display: none;
}

/* The bubble's glyph: a little under the WhatsApp one (28px), its shape is fuller. Without a size iOS draws nothing. */
.chat__icon {
	width: 26px;
	height: 26px;
}

.chat.is-open {
	opacity: 1;
	translate: 0 0;
}

/* Phones: the whole screen under the bar, the page locked (chat.js sets the class). */
@media (max-width: 767px) {
	.chat {
		inset: var(--header-height) 0 0;
		right: 0;
		bottom: 0;
		width: auto;
		height: auto;
		border-radius: 0;
		box-shadow: none;
	}

	html.is-chat-open {
		overflow: hidden;
	}
}

.chat__head {
	display: flex;
	gap: var(--space-10);
	align-items: center;
	padding: var(--space-20);
	border-bottom: var(--stroke-hairline) solid rgb(255 255 255 / 0.15);
	color: var(--color-cooper-1);
}

.chat__title {
	flex: 1;
	margin: 0;
	font-family: var(--font-serif);
	font-size: var(--fs-20);
	font-weight: var(--fw-text);
	letter-spacing: var(--ls-nav);
}

.chat__restart,
.chat__close {
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
}

.chat__restart {
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
	font-size: 0.85em;
}

.chat__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	margin: -12px -12px -12px 0;
	font-family: var(--font-serif);
	font-size: 28px;
	line-height: 1;
}

.chat__restart:is(:hover, :focus-visible),
.chat__close:is(:hover, :focus-visible) {
	color: var(--color-cooper-2);
}

.chat__messages {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: var(--space-10);
	margin: 0;
	padding: var(--space-20);
	overflow-y: auto;
	overscroll-behavior: contain;
	list-style: none;
}

.chat__msg {
	max-width: 85%;
	padding: 0.6em 0.9em;
	border-radius: 12px;
	white-space: pre-line;
	overflow-wrap: anywhere;
}

.chat__msg--site {
	align-self: flex-start;
	border-bottom-left-radius: 4px;
	background: rgb(255 255 255 / 0.08);
	color: var(--color-white);
}

.chat__msg--user {
	align-self: flex-end;
	border-bottom-right-radius: 4px;
	background: var(--color-forest-b);
	color: var(--color-stone);
}

.chat__msg--link {
	align-self: flex-start;
}

.chat__msg a {
	color: var(--color-hillside);
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

/* "Typing": three dots that breathe, none with reduced motion. */
.chat__typing {
	display: inline-flex;
	gap: 4px;
	padding: 0.2em 0;
}

.chat__typing > span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.4;
	animation: cliff-chat-dot 1s ease-in-out infinite;
}

.chat__typing > :nth-child(2) {
	animation-delay: 0.15s;
}

.chat__typing > :nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes cliff-chat-dot {
	50% {
		opacity: 1;
	}
}

.chat__form {
	display: grid;
	gap: var(--space-10);
	padding: var(--space-20);
	border-top: var(--stroke-hairline) solid rgb(255 255 255 / 0.15);
}

.chat__row {
	display: flex;
	gap: var(--space-10);
}

.chat__row .chat__input {
	flex: 1;
	min-width: 0;
}

.chat__input {
	width: 100%;
	padding: 0.6em 0.8em;
	border: var(--stroke-hairline) solid rgb(205 215 225 / 0.5);
	border-radius: var(--radius);
	background: rgb(0 0 0 / 0.2);
	color: var(--color-white);
	font: inherit;
}

.chat__input:focus-visible {
	outline: 2px solid var(--color-cooper-2);
	outline-offset: 1px;
}

.chat__fields {
	display: grid;
	gap: var(--space-10);
	margin: 0;
	padding: 0;
	border: 0;
}

.chat__fields[hidden],
.chat__final[hidden],
.chat__row[hidden],
.chat__note[hidden] {
	display: none;
}

.chat__field {
	display: grid;
	gap: 0.3em;
}

.chat__label {
	font-size: 0.8em;
	color: var(--color-stone);
}

.chat__button {
	padding: 0.6em 1em;
	border: var(--stroke-hairline) solid var(--color-cooper-1);
	border-radius: var(--radius);
	background: none;
	color: var(--color-cooper-1);
	font: inherit;
	font-weight: var(--fw-semibold);
	cursor: pointer;
	transition: background-color var(--link-hover-duration) var(--link-hover-ease), color var(--link-hover-duration) var(--link-hover-ease);
}

.chat__button:is(:hover, :focus-visible) {
	background: var(--color-cooper-1);
	color: var(--color-forest-a);
}

.chat__button--quiet {
	border-color: transparent;
	color: var(--color-stone);
}

.chat__button--primary {
	border-color: var(--color-hillside);
	background: var(--color-hillside);
	color: var(--color-forest-a);
}

.chat__button--primary:is(:hover, :focus-visible) {
	background: var(--color-white);
	border-color: var(--color-white);
}

.chat__button:disabled {
	opacity: 0.5;
	cursor: default;
}

.chat__button:focus-visible {
	outline: 2px solid var(--color-cooper-2);
	outline-offset: 2px;
}

.chat__final {
	display: grid;
	gap: var(--space-10);
}

.chat__consent {
	display: flex;
	gap: 0.6em;
	align-items: flex-start;
	font-size: 0.85em;
	color: var(--color-stone);
}

.chat__consent input {
	flex: none;
	width: 18px;
	height: 18px;
	margin: 0.1em 0 0;
	accent-color: var(--color-hillside);
}

.chat__consent a {
	color: var(--color-hillside);
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

.chat__note {
	margin: 0;
	font-size: 0.85em;
	color: var(--color-cooper-2);
}

/* The honeypot stays out of sight and out of the tab order. */
.chat__hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
	.chat,
	.chat__button {
		transition: none;
	}

	.chat__typing > span {
		animation: none;
		opacity: 1;
	}
}
