/**
 * ACS AI Customer Assistant — widget styles.
 *
 * Scoped entirely to .mr-assistant and built from the tokens theme.json
 * already defines, so the assistant reads as part of this site rather than a
 * widget bolted onto it. No new colours, no new radii, no new font: if the
 * design system changes, this file follows.
 *
 * Nothing here is fixed-position except the launcher and the panel themselves,
 * so the widget cannot shift the page's layout — the thing that would show up
 * as a Core Web Vitals regression on every page it appears on.
 *
 * @package malardalenrent
 */

.mr-assistant {
	--mr-assistant-gap: 24px;
	--mr-assistant-bubble: var(--wp--preset--color--primary-subtle);
	--mr-assistant-border: var(--wp--custom--color--card-border);

	/*
	 * --mr-assistant-consent is the height of the cookie banner where it
	 * overlaps this corner, measured by the script while the banner is up and
	 * zero otherwise. Without it the two collide on a phone: the banner is
	 * nearly full width at the bottom-left, the launcher sits bottom-right,
	 * and the banner wins the click — so a visitor cannot open the assistant
	 * at all until they have answered the cookie dialog. That is a real
	 * blocker, and it only appears below the width where the two meet, which
	 * is exactly why it is worth measuring rather than assuming.
	 */
	bottom: calc(var(--mr-assistant-gap) + var(--mr-assistant-consent, 0px));
	inset-inline-end: var(--mr-assistant-gap);
	position: fixed;

	/*
	 * Below the cookie banner's 60 on purpose. Consent is a legal control and
	 * the assistant is a convenience; where the two still overlap, the banner
	 * must be the one the visitor can reach.
	 */
	z-index: 55;
}

/*
 * Set when the cookie banner covers the launcher and leaves no room above it
 * for a conversation. The assistant steps out of the way rather than sitting
 * behind the banner as an invisible click target, and comes back the moment
 * the banner is answered. See syncConsentOffset() in assistant.js.
 */
.mr-assistant--yield {
	display: none;
}

/* ---- Launcher -------------------------------------------------------- */

.mr-assistant__teaser {
	background: var(--wp--preset--color--surface);
	border: 1px solid var(--mr-assistant-border);
	border-radius: var(--wp--custom--radius--md);
	bottom: calc(100% + 12px);
	box-shadow: 0 12px 32px rgb(26 46 35 / 14%);
	color: var(--wp--preset--color--foreground);
	cursor: pointer;
	font-family: inherit;
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	inset-inline-end: 0;
	line-height: 1.45;
	max-width: min(300px, calc(100vw - 32px));
	opacity: 0;
	padding: 12px 16px;
	position: absolute;
	text-align: start;
	transform: translateY(8px) scale(0.97);
	transform-origin: bottom right;
	transition:
		opacity 0.32s ease,
		transform 0.48s cubic-bezier(0.16, 1, 0.3, 1);
	width: max-content;
}

.mr-assistant__teaser span,
.mr-assistant__teaser strong {
	display: block;
}

.mr-assistant__teaser strong {
	color: var(--wp--preset--color--primary);
	font-size: 0.92em;
	font-weight: 700;
	margin-top: 3px;
}

.mr-assistant__teaser[hidden] {
	display: none;
}

.mr-assistant--teaser-visible .mr-assistant__teaser {
	opacity: 1;
	transform: translateY(0) scale(1);
}

.mr-assistant__teaser:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}

.mr-assistant__launcher {
	align-items: center;
	background-color: var(--wp--preset--color--primary);
	border: 0;
	border-radius: var(--wp--custom--radius--pill);
	box-shadow: var(--wp--custom--shadow--cta);
	color: var(--wp--preset--color--surface);
	cursor: pointer;
	display: flex;
	font-family: inherit;
	font-size: var(--wp--preset--font-size--md);
	font-weight: 600;
	gap: 10px;
	line-height: 1;
	margin-inline-start: auto;
	min-height: 52px;
	padding: 0 20px 0 18px;
	transition:
		background-color 0.18s ease,
		box-shadow 0.25s ease,
		padding 0.5s cubic-bezier(0.16, 1, 0.3, 1),
		transform 0.18s ease;
}

.mr-assistant__launcher:hover {
	background-color: var(--wp--preset--color--primary-accent);
	box-shadow:
		var(--wp--custom--shadow--cta),
		0 0 0 7px rgb(47 104 55 / 10%);
	transform: scale(1.03);
}

.mr-assistant__launcher:active {
	transform: scale(0.97);
}

.mr-assistant--smart-invite:not(.mr-assistant--pill-visible) .mr-assistant__launcher {
	padding-inline: 13px;
}

.mr-assistant--smart-invite:not(.mr-assistant--pill-visible) .mr-assistant__launcher-label {
	max-width: 0;
	opacity: 0;
	overflow: hidden;
	white-space: nowrap;
}

.mr-assistant__launcher-label {
	max-width: 160px;
	opacity: 1;
	transition:
		max-width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
		opacity 0.3s ease 0.08s;
}

.mr-assistant--smart-invite .mr-assistant__launcher {
	animation: mr-assistant-smart-enter 0.82s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.mr-assistant--smart-invite .mr-assistant__launcher::after {
	animation: mr-assistant-glow-wave 0.9s ease-out 0.2s both;
}

.mr-assistant__launcher::after {
	border: 1px solid rgb(47 104 55 / 28%);
	border-radius: inherit;
	box-shadow: 0 0 20px rgb(47 104 55 / 18%);
	content: '';
	inset: 0;
	opacity: 0;
	pointer-events: none;
	position: absolute;
}

.mr-assistant__launcher {
	position: relative;
}

.mr-assistant--invite-waves .mr-assistant__launcher::after {
	animation: mr-assistant-two-waves 2.35s ease-in-out both;
}

.mr-assistant--launcher-react .mr-assistant__launcher {
	animation: mr-assistant-launcher-react 0.38s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes mr-assistant-smart-enter {
	0% {
		opacity: 0;
		transform: translateY(14px) scale(0.7);
	}
	68% {
		opacity: 1;
		transform: translateY(-1px) scale(1.08);
	}
	100% {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

@keyframes mr-assistant-glow-wave {
	0% { opacity: 0.35; transform: scale(0.9); }
	100% { opacity: 0; transform: scale(1.42); }
}

@keyframes mr-assistant-two-waves {
	0%, 46%, 100% {
		opacity: 0;
		transform: scale(1);
	}
	18%, 64% {
		opacity: 0.28;
		transform: scale(1.3);
	}
}

@keyframes mr-assistant-launcher-react {
	0% { transform: scale(1); }
	45% { transform: scale(0.92); }
	100% { transform: scale(1); }
}

.mr-assistant__launcher:focus-visible,
.mr-assistant__close:focus-visible,
.mr-assistant__send:focus-visible,
.mr-assistant__input:focus-visible,
.mr-assistant__quick:focus-visible,
.mr-assistant__cta:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}

.mr-assistant__glyph {
	display: block;
	flex: none;
}

.mr-assistant__panel .mr-assistant__close:focus-visible,
.mr-assistant__panel .mr-assistant__send:focus-visible {
	outline-color: var(--wp--preset--color--surface);
}

/* The panel carries the title once it is open; repeating it here is noise. */
.mr-assistant__launcher[aria-expanded="true"] .mr-assistant__launcher-label {
	display: none;
}

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

.mr-assistant__panel {
	background-color: var(--wp--preset--color--surface);
	border-radius: var(--wp--custom--radius--lg);
	box-shadow:
		inset 0 0 0 1px var(--mr-assistant-border),
		0 18px 48px rgb(26 46 35 / 18%);
	bottom: calc(100% + 14px);
	display: flex;
	flex-direction: column;
	inset-inline-end: 0;

	/* Whatever the consent offset took from the bottom, the panel gives back
	   at the top, so it never grows past the viewport on a short screen. */
	max-height: min(
		620px,
		calc(100vh - 140px - var(--mr-assistant-consent, 0px))
	);
	overflow: hidden;
	position: absolute;
	opacity: 0;
	transform: translateY(14px) scale(0.92);
	transform-origin: bottom right;
	transition:
		opacity 0.22s ease,
		transform 0.42s cubic-bezier(0.16, 1, 0.3, 1);
	width: min(384px, calc(100vw - 48px));
}

.mr-assistant--panel-visible .mr-assistant__panel {
	opacity: 1;
	transform: translateY(0) scale(1);
}

.mr-assistant--panel-closing .mr-assistant__panel {
	opacity: 0;
	transform: translateY(8px) scale(0.96);
}

.mr-assistant__panel[hidden] {
	display: none;
}

.mr-assistant__header {
	align-items: center;
	background-color: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--surface);
	display: flex;
	flex: none;
	gap: 12px;
	justify-content: space-between;
	padding: 14px 16px;
}

.mr-assistant__title {
	color: inherit;
	font-size: var(--wp--preset--font-size--lg);
	font-weight: 700;
	line-height: 1.2;
	margin: 0;
}

.mr-assistant__subtitle {
	color: var(--wp--custom--color--onGreenBody);
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.3;
	margin: 2px 0 0;
}

.mr-assistant__close {
	align-items: center;
	background-color: rgb(255 255 255 / 12%);
	border: 0;
	border-radius: var(--wp--custom--radius--pill);
	color: inherit;
	cursor: pointer;
	display: flex;
	flex: none;
	height: 34px;
	justify-content: center;
	width: 34px;
}

.mr-assistant__close:hover {
	background-color: rgb(255 255 255 / 22%);
}

/* ---- Conversation ---------------------------------------------------- */

.mr-assistant__log {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	gap: 10px;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px;
	scrollbar-width: thin;
}

.mr-assistant__row {
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-width: 100%;
}

.mr-assistant__message {
	border-radius: var(--wp--custom--radius--md);
	font-size: var(--wp--preset--font-size--md);
	line-height: 1.5;
	margin: 0;
	max-width: 88%;
	overflow-wrap: anywhere;
	padding: 10px 14px;
	white-space: pre-wrap;
}

.mr-assistant__message--assistant {
	align-self: flex-start;
	background-color: var(--mr-assistant-bubble);
	color: var(--wp--preset--color--heading);
}

.mr-assistant__message--visitor {
	align-self: flex-end;
	background-color: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--surface);
}

.mr-assistant__message--error {
	align-self: flex-start;
	background-color: var(--wp--custom--color--errorSurface);
	border: 1px solid var(--wp--custom--color--errorBorder);
	color: var(--wp--custom--color--errorText);
}

/* ---- Quick actions and CTAs ------------------------------------------ */

.mr-assistant__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.mr-assistant__quick,
.mr-assistant__cta {
	background-color: transparent;
	border: 0;
	border-radius: var(--wp--custom--radius--pill);
	cursor: pointer;
	font-family: inherit;
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.3;
	padding: 8px 14px;
	text-align: start;
	text-decoration: none;
}

.mr-assistant__quick {
	background-color: var(--wp--preset--color--surface);
	box-shadow:
		inset 0 0 0 1.5px var(--wp--preset--color--primary),
		0 3px 9px rgb(26 46 35 / 7%);
	color: var(--wp--preset--color--primary);
	font-weight: 600;
	min-height: 38px;
	transition: background-color 0.18s ease, transform 0.18s ease;
}

.mr-assistant--panel-visible .mr-assistant__quick {
	animation: mr-assistant-action-in 0.38s ease both;
}

.mr-assistant--panel-visible .mr-assistant__quick:nth-child(2) { animation-delay: 45ms; }
.mr-assistant--panel-visible .mr-assistant__quick:nth-child(3) { animation-delay: 90ms; }
.mr-assistant--panel-visible .mr-assistant__quick:nth-child(4) { animation-delay: 135ms; }

@keyframes mr-assistant-action-in {
	from { opacity: 0; transform: translateY(5px); }
	to { opacity: 1; transform: translateY(0); }
}

.mr-assistant__quick:hover {
	background-color: var(--wp--preset--color--primary-subtle);
	transform: translateY(-1px);
}

.mr-assistant__cta {
	background-color: var(--wp--preset--color--primary);
	color: var(--wp--preset--color--surface);
	display: inline-block;
	font-weight: 600;
	box-shadow: var(--wp--custom--shadow--cta);
	padding: 10px 16px;
}

.mr-assistant__cta:hover {
	background-color: var(--wp--preset--color--primary-accent);
}

.mr-assistant__cta--outline {
	background-color: transparent;
	box-shadow: inset 0 0 0 1.5px var(--wp--preset--color--primary);
	color: var(--wp--preset--color--primary);
}

/* ---- Typing indicator ------------------------------------------------ */

.mr-assistant__typing {
	align-items: center;
	align-self: flex-start;
	background-color: var(--mr-assistant-bubble);
	border-radius: var(--wp--custom--radius--md);
	display: flex;
	gap: 5px;
	padding: 13px 16px;
}

.mr-assistant__typing span {
	animation: mr-assistant-dot 1.1s infinite ease-in-out;
	background-color: var(--wp--preset--color--primary);
	border-radius: 50%;
	height: 6px;
	width: 6px;
}

.mr-assistant__typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.mr-assistant__typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes mr-assistant-dot {
	0%,
	60%,
	100% {
		opacity: 0.35;
		transform: translateY(0);
	}

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

/* ---- Composer -------------------------------------------------------- */

.mr-assistant__form {
	align-items: flex-end;
	border-top: 1px solid var(--mr-assistant-border);
	display: flex;
	flex: none;
	gap: 8px;
	padding: 12px;
}

.mr-assistant__input {
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--mr-assistant-border);
	border-radius: var(--wp--custom--radius--md);
	color: var(--wp--preset--color--heading);
	flex: 1 1 auto;
	font-family: inherit;
	font-size: var(--wp--preset--font-size--md);
	line-height: 1.4;
	max-height: 120px;
	min-height: 44px;
	padding: 11px 12px;
	resize: none;
}

.mr-assistant__input::placeholder {
	color: var(--wp--preset--color--muted);
}

.mr-assistant__send {
	align-items: center;
	background-color: var(--wp--preset--color--primary);
	border: 0;
	border-radius: var(--wp--custom--radius--pill);
	color: var(--wp--preset--color--surface);
	cursor: pointer;
	display: flex;
	flex: none;
	height: 44px;
	justify-content: center;
	width: 44px;
}

.mr-assistant__send:hover {
	background-color: var(--wp--preset--color--primary-accent);
}

.mr-assistant__send[disabled] {
	cursor: default;
	opacity: 0.5;
}

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

.mr-assistant__lead {
	background-color: var(--wp--preset--color--base);
	border-top: 1px solid var(--mr-assistant-border);
	display: flex;
	flex-direction: column;
	flex: none;
	gap: 10px;
	padding: 14px 12px;
}

.mr-assistant__lead[hidden] {
	display: none;
}

.mr-assistant__lead-title {
	color: var(--wp--preset--color--heading);
	font-size: var(--wp--preset--font-size--md);
	font-weight: 700;
	margin: 0;
}

.mr-assistant__lead-intro {
	color: var(--wp--preset--color--body);
	font-size: var(--wp--preset--font-size--sm);
	line-height: 1.4;
	margin: 0;
}

.mr-assistant__field {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.mr-assistant__field label {
	color: var(--wp--preset--color--body);
	font-size: var(--wp--preset--font-size--sm);
}

.mr-assistant__field input,
.mr-assistant__field textarea {
	background-color: var(--wp--preset--color--surface);
	border: 1px solid var(--mr-assistant-border);
	border-radius: var(--wp--custom--radius--md);
	color: var(--wp--preset--color--heading);
	font-family: inherit;
	font-size: var(--wp--preset--font-size--md);
	min-height: 40px;
	padding: 8px 10px;
}

.mr-assistant__consent {
	align-items: flex-start;
	color: var(--wp--preset--color--body);
	display: flex;
	font-size: var(--wp--preset--font-size--sm);
	gap: 8px;
	line-height: 1.4;
}

.mr-assistant__consent input {
	margin-top: 2px;
}

.mr-assistant__lead-actions {
	display: flex;
	gap: 8px;
}

.mr-assistant__lead-error {
	color: var(--wp--custom--color--errorText);
	font-size: var(--wp--preset--font-size--sm);
	margin: 0;
}

.mr-assistant__lead-error[hidden] {
	display: none;
}

/*
 * The honeypot. Hidden from people, present for bots that fill every field
 * they find. Not `display: none`, which some of them skip.
 */
.mr-assistant__trap {
	height: 0;
	inset-inline-start: -9999px;
	position: absolute;
	width: 0;
}

/* ---- Small screens --------------------------------------------------- */

@media (max-width: 480px) {
	.mr-assistant {
		--mr-assistant-gap: 16px;
	}

	.mr-assistant__panel {
		bottom: calc(100% + 12px);
		max-height: min(560px, calc(100vh - 110px));
		width: calc(100vw - 32px);
	}

	.mr-assistant__launcher {
		min-height: 48px;
		padding: 0 16px;
	}

	.mr-assistant__teaser {
		font-size: 13px;
		max-width: min(260px, calc(100vw - 32px));
		padding: 10px 13px;
	}

	.mr-assistant__message {
		max-width: 94%;
	}
}

/* ---- Motion and print ------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.mr-assistant__launcher,
	.mr-assistant__launcher::after,
	.mr-assistant__launcher .mr-assistant__glyph,
	.mr-assistant__launcher-label,
	.mr-assistant__panel,
	.mr-assistant__teaser,
	.mr-assistant__quick,
	.mr-assistant__typing span {
		animation: none;
		transition: none;
	}
}

@media print {
	.mr-assistant {
		display: none;
	}
}
