/**
 * "Let's talk" chat (includes/chat.php, assets/js/chat.js).
 *
 * Bottom-right launcher + panel. Square like the rest of the site (--pk-radius),
 * ink and paper with Peak Blue for the bot's voice and picked chips. Below the
 * site header (z-index 90) so the mobile menu always covers it. Under 600px the
 * panel takes the whole screen.
 */

.pk-chat {
	--pk-chat-w: 380px;
	--pk-chat-edge: clamp(14px, 2vw, 24px);
	position: fixed;
	right: var(--pk-chat-edge);
	bottom: var(--pk-chat-edge);
	z-index: 85;
	display: none;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
	font-family: var(--pk-font);
	color: var(--pk-ink);
}

/* Only once chat.js is running: without it there is nothing to click. */
.pk-chat.is-ready {
	display: flex;
}

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

.pk-chat :where(button, input, textarea) {
	font: inherit;
	color: inherit;
}

/* ---------------------------------------------------------------- Launcher */
.pk-chat__launch {
	display: inline-flex;
	align-items: center;
	gap: 12px;
	min-height: 48px;
	padding: 0 20px 0 18px;
	border: 1px solid var(--pk-ink);
	border-radius: var(--pk-radius);
	background: var(--pk-ink);
	color: #fff;
	font-family: var(--pk-mono);
	font-size: var(--pk-fs-label);
	font-weight: 500;
	letter-spacing: 0.14em;
	line-height: 1;
	text-transform: uppercase;
	cursor: pointer;
	box-shadow: 0 10px 30px -12px rgba(10, 10, 11, 0.45);
	transition:
		background-color var(--pk-fast) ease,
		border-color var(--pk-fast) ease,
		transform var(--pk-fast) ease;
}

.pk-chat__launch:hover {
	background: var(--pk-blue);
	border-color: var(--pk-blue);
}

.pk-chat__launch:active {
	transform: translateY(1px);
}

/* A small blue square that breathes, so the launcher reads as "someone's here". */
.pk-chat__dot {
	position: relative;
	width: 8px;
	height: 8px;
	background: var(--pk-blue);
}

.pk-chat__launch:hover .pk-chat__dot {
	background: #fff;
}

.pk-chat__dot::after {
	content: "";
	position: absolute;
	inset: -4px;
	border: 1px solid var(--pk-blue);
	opacity: 0;
	animation: pk-chat-ping 2.8s var(--pk-ease) infinite;
}

.pk-chat.is-open .pk-chat__dot::after,
.pk-chat__launch:hover .pk-chat__dot::after {
	animation: none;
}

@keyframes pk-chat-ping {
	0% {
		opacity: 0.9;
		transform: scale(0.6);
	}
	60%,
	100% {
		opacity: 0;
		transform: scale(1.6);
	}
}

/* ---------------------------------------------------------------- Panel */
.pk-chat__panel {
	display: flex;
	flex-direction: column;
	width: var(--pk-chat-w);
	max-width: calc(100vw - 2 * var(--pk-chat-edge));
	height: min(600px, calc(100dvh - 120px));
	border: 1px solid var(--pk-ink);
	border-radius: var(--pk-radius);
	background: var(--pk-white);
	box-shadow: 0 24px 60px -24px rgba(10, 10, 11, 0.45);
	overflow: hidden;
	transform-origin: bottom right;
	animation: pk-chat-in var(--pk-med) var(--pk-ease);
}

.pk-chat__panel[hidden] {
	display: none;
}

@keyframes pk-chat-in {
	from {
		opacity: 0;
		transform: translateY(12px) scale(0.98);
	}
}

.pk-chat__head {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 12px 14px 16px;
	background: var(--pk-ink);
	color: #fff;
}

.pk-chat__mark {
	flex: none;
	width: 28px;
	height: 28px;
	padding: 4px;
	background: #fff;
}

.pk-chat__who {
	flex: 1;
	min-width: 0;
}

.pk-chat__title {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 700;
	letter-spacing: -0.01em;
	line-height: 1.2;
}

.pk-chat__status {
	display: flex;
	align-items: center;
	gap: 7px;
	margin: 3px 0 0;
	font-family: var(--pk-mono);
	font-size: 0.625rem;
	letter-spacing: 0.12em;
	line-height: 1.3;
	text-transform: uppercase;
	color: rgba(255, 255, 255, 0.6);
}

.pk-chat__status::before {
	content: "";
	flex: none;
	width: 6px;
	height: 6px;
	background: var(--pk-blue);
}

.pk-chat__close {
	display: grid;
	place-items: center;
	flex: none;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 1px solid transparent;
	background: none;
	color: #fff;
	cursor: pointer;
	transition: border-color var(--pk-fast) ease;
}

.pk-chat__close:hover {
	border-color: var(--pk-line-dark);
}

.pk-chat__close .pk-icon {
	width: 18px;
	height: 18px;
}

/* ---------------------------------------------------------------- Messages */
.pk-chat__log {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin: 0;
	padding: 20px 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
	list-style: none;
	background: var(--pk-paper);
}

.pk-chat__msg {
	max-width: 85%;
	padding: 11px 14px;
	font-size: 0.9375rem;
	line-height: 1.45;
	overflow-wrap: anywhere;
	white-space: pre-line;
	animation: pk-chat-msg 260ms var(--pk-ease);
}

@keyframes pk-chat-msg {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
}

.pk-chat__msg--bot {
	align-self: flex-start;
	border: 1px solid var(--pk-line);
	border-left: 2px solid var(--pk-blue);
	background: var(--pk-white);
}

/* Consecutive bot lines read as one turn. */
.pk-chat__msg--bot + .pk-chat__msg--bot {
	margin-top: -4px;
}

.pk-chat__msg--me {
	align-self: flex-end;
	margin-block: 6px;
	background: var(--pk-ink);
	color: #fff;
}

.pk-chat__msg--typing {
	display: inline-flex;
	gap: 4px;
	padding: 15px 14px;
}

.pk-chat__msg--typing span {
	width: 5px;
	height: 5px;
	background: var(--pk-slate);
	animation: pk-chat-type 1s ease-in-out infinite;
}

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

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

@keyframes pk-chat-type {
	0%,
	60%,
	100% {
		opacity: 0.3;
		transform: none;
	}
	30% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

/* ---------------------------------------------------------------- Reply area */
.pk-chat__reply {
	margin: 0;
	padding: 14px 16px 16px;
	border-top: 1px solid var(--pk-line);
	background: var(--pk-white);
}

.pk-chat__reply:has(.pk-chat__controls:empty) {
	display: none;
}

.pk-chat__hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.pk-chat__controls {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.pk-chat__row {
	display: flex;
	align-items: stretch;
	gap: 8px;
}

.pk-chat__row--end {
	justify-content: flex-end;
	align-items: center;
}

.pk-chat__field {
	flex: 1;
	min-width: 0;
	min-height: 46px;
	padding: 12px 14px;
	border: 1px solid var(--pk-line);
	border-radius: var(--pk-radius);
	background: var(--pk-white);
	/* 16px stops iOS zooming into the field. */
	font-size: 1rem;
	line-height: 1.35;
	resize: none;
	transition: border-color var(--pk-fast) ease;
}

.pk-chat__field::placeholder {
	color: #8b8b92;
}

.pk-chat__field:focus {
	outline: none;
	border-color: var(--pk-ink);
}

.pk-chat__field[aria-invalid="true"] {
	border-color: #c2412d;
}

.pk-chat__send {
	display: grid;
	place-items: center;
	flex: none;
	width: 46px;
	padding: 0;
	border: 1px solid var(--pk-ink);
	border-radius: var(--pk-radius);
	background: var(--pk-ink);
	color: #fff;
	cursor: pointer;
	transition:
		background-color var(--pk-fast) ease,
		border-color var(--pk-fast) ease;
}

.pk-chat__send:hover {
	background: var(--pk-blue);
	border-color: var(--pk-blue);
}

.pk-chat__send .pk-icon,
.pk-chat__go .pk-icon {
	width: 14px;
	height: 14px;
}

.pk-chat__go {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	min-height: 42px;
	padding: 0 18px;
	border: 1px solid var(--pk-ink);
	border-radius: var(--pk-radius);
	background: var(--pk-ink);
	color: #fff;
	font-family: var(--pk-mono);
	font-size: var(--pk-fs-label);
	font-weight: 500;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	cursor: pointer;
	transition:
		background-color var(--pk-fast) ease,
		border-color var(--pk-fast) ease,
		opacity var(--pk-fast) ease;
}

.pk-chat__go:hover:not(:disabled) {
	background: var(--pk-blue);
	border-color: var(--pk-blue);
}

.pk-chat__go:disabled {
	opacity: 0.35;
	cursor: not-allowed;
}

.pk-chat__skip {
	align-self: flex-start;
	padding: 4px 0;
	border: 0;
	background: none;
	color: var(--pk-slate);
	font-family: var(--pk-mono);
	font-size: var(--pk-fs-label);
	letter-spacing: 0.12em;
	text-transform: uppercase;
	text-decoration: underline;
	text-underline-offset: 3px;
	cursor: pointer;
}

.pk-chat__skip:hover {
	color: var(--pk-ink);
}

.pk-chat__row--end .pk-chat__skip {
	margin-right: auto;
	align-self: center;
}

.pk-chat__error {
	margin: 0;
	font-size: var(--pk-fs-small);
	line-height: 1.4;
	color: #c2412d;
}

.pk-chat__error:empty {
	display: none;
}

/* Topic chips: the Contact page's chips (blocks/contact-climb). */
.pk-chat__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.pk-chat__chip {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	min-height: 38px;
	padding: 0.6rem 0.85rem;
	border: 1px solid var(--pk-line);
	border-radius: var(--pk-radius);
	background: var(--pk-white);
	font-family: var(--pk-mono);
	font-size: var(--pk-fs-label);
	font-weight: 500;
	letter-spacing: 0.12em;
	line-height: 1;
	text-transform: uppercase;
	cursor: pointer;
	transition:
		background-color var(--pk-fast) ease,
		border-color var(--pk-fast) ease,
		color var(--pk-fast) ease;
}

.pk-chat__chip::before {
	content: "";
	flex: none;
	width: 8px;
	height: 8px;
	border: 1px solid currentColor;
	transition:
		background-color var(--pk-fast) ease,
		border-color var(--pk-fast) ease;
}

.pk-chat__chip:hover {
	border-color: var(--pk-ink);
}

.pk-chat__chip:active {
	transform: translateY(1px);
}

.pk-chat__chip[aria-pressed="true"] {
	border-color: var(--pk-ink);
	background: var(--pk-ink);
	color: #fff;
}

.pk-chat__chip[aria-pressed="true"]::before {
	border-color: var(--pk-blue);
	background: var(--pk-blue);
}

.pk-chat .pk-form__captcha {
	margin: 0;
	padding: 0 16px 12px;
	background: var(--pk-white);
	font-size: 0.6875rem;
	line-height: 1.4;
	color: var(--pk-slate);
}

.pk-chat .pk-form__captcha a {
	color: inherit;
}

/* ---------------------------------------------------------------- Phones */
@media (max-width: 600px) {
	.pk-chat__launch {
		min-height: 44px;
		padding: 0 16px 0 14px;
	}

	.pk-chat.is-open {
		inset: 0;
		gap: 0;
	}

	.pk-chat.is-open .pk-chat__launch {
		display: none;
	}

	.pk-chat__panel {
		width: 100%;
		max-width: none;
		height: 100%;
		border: 0;
		box-shadow: none;
	}

	.pk-chat__reply {
		padding-bottom: max(16px, env(safe-area-inset-bottom));
	}
}

/* Full-screen chat on phones: stop the page scrolling underneath. */
html.pk-chat-locked,
html.pk-chat-locked body {
	overflow: hidden;
}

@media print {
	.pk-chat {
		display: none !important;
	}
}

@media (prefers-reduced-motion: reduce) {
	.pk-chat__panel,
	.pk-chat__msg,
	.pk-chat__dot::after,
	.pk-chat__msg--typing span {
		animation: none;
	}
}
