/* ============ Live chat widget ============
   Brand tokens come from base.css. Three screens live inside one panel:
   welcome, details, conversation. */

.mke-chat {
	position: fixed;
	right: 18px;
	bottom: 18px;
	/* Above the sticky site header (900), below the Complianz banner (99999). */
	z-index: 1000;
	font-family: var(--font-sans);
}

/* A class-level display wins over the UA's [hidden] rule, so anything we hide
   with the attribute has to say so at higher specificity or it never closes. */
.mke-chat[hidden],
.mke-chat-panel[hidden],
.mke-chat-thread[hidden],
.mke-chat-intro[hidden],
.mke-chat-welcome[hidden],
.mke-chat-teaser[hidden],
.mke-chat-back[hidden],
.mke-chat-dot[hidden] { display: none; }

/* SVG icons are flex items in several places here, and a flex item may shrink
   below its own width. Without this the launcher icon collapses to 0 and the
   send arrow to 2px, leaving what look like empty buttons. */
.mke-chat svg { flex: 0 0 auto; }

/* Touch details: no grey flash on tap, no 300ms double-tap zoom wait. */
.mke-chat button,
.mke-chat input,
.mke-chat textarea {
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
}

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

.mke-chat-launch {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: .55rem;
	padding: .72rem 1.15rem .72rem .95rem;
	border: 0;
	border-radius: 999px;
	background: var(--bottle);
	color: var(--cream);
	font: inherit;
	font-size: .95rem;
	font-weight: 600;
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(30, 58, 47, .28);
	transition: transform .18s ease, box-shadow .18s ease;
}
.mke-chat-launch:hover {
	transform: translateY(-2px);
	box-shadow: 0 12px 30px rgba(30, 58, 47, .34);
}
.mke-chat-launch:focus-visible {
	outline: 3px solid var(--olive);
	outline-offset: 3px;
}
.mke-chat-launch-icon { display: inline-flex; }
.mke-chat.is-open .mke-chat-launch { transform: scale(.94); opacity: .9; }

.mke-chat-dot {
	position: absolute;
	top: -2px;
	right: -2px;
	width: 13px;
	height: 13px;
	border-radius: 50%;
	background: #C4552F;
	border: 2px solid var(--cream);
}

/* ---------------- teaser ---------------- */

.mke-chat-teaser {
	position: absolute;
	right: 0;
	bottom: calc(100% + 12px);
	width: 258px;
	display: flex;
	background: var(--paper);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: 0 14px 34px rgba(32, 30, 26, .16);
	opacity: 0;
	transform: translateY(8px) scale(.97);
	transform-origin: bottom right;
	transition: opacity .26s ease, transform .26s cubic-bezier(.2, .8, .3, 1);
}
.mke-chat-teaser.is-in { opacity: 1; transform: none; }

.mke-chat-teaser-body {
	flex: 1;
	text-align: left;
	background: none;
	border: 0;
	font: inherit;
	color: var(--ink);
	padding: .8rem .9rem .85rem;
	cursor: pointer;
	border-radius: var(--radius);
}
.mke-chat-teaser-body strong {
	display: block;
	font-size: .92rem;
	font-weight: 700;
	margin-bottom: .12rem;
}
.mke-chat-teaser-body span {
	display: block;
	font-size: .82rem;
	color: var(--muted);
	line-height: 1.4;
}
.mke-chat-teaser-x {
	align-self: flex-start;
	background: none;
	border: 0;
	color: var(--muted);
	font-size: 1.25rem;
	line-height: 1;
	padding: .5rem .55rem;
	cursor: pointer;
}
.mke-chat-teaser-x:hover { color: var(--ink); }
.mke-chat-teaser-body:focus-visible,
.mke-chat-teaser-x:focus-visible { outline: 2px solid var(--olive); outline-offset: -2px; }

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

.mke-chat-panel {
	position: absolute;
	right: 0;
	bottom: calc(100% + 12px);
	width: min(370px, calc(100vw - 36px));
	height: min(580px, calc(100vh - 120px));
	display: flex;
	flex-direction: column;
	background: var(--paper);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: 0 24px 60px rgba(32, 30, 26, .22);
	overflow: hidden;
	animation: mke-chat-in .22s cubic-bezier(.2, .8, .3, 1) both;
	transition: transform .2s ease;
}
@keyframes mke-chat-in {
	from { opacity: 0; transform: translateY(12px) scale(.98); }
	to   { opacity: 1; transform: none; }
}

.mke-chat-head {
	display: flex;
	align-items: center;
	gap: .5rem;
	padding: .8rem .9rem;
	background: var(--bottle);
	color: var(--cream);
}
.mke-chat-head-text { flex: 1; min-width: 0; }
.mke-chat-head strong {
	display: block;
	font-family: var(--font-serif);
	font-size: 1.02rem;
	font-weight: 400;
	color: var(--cream);   /* base.css paints the serif with --ink; unreadable here */
}
.mke-chat-status {
	display: block;
	font-size: .76rem;
	color: rgba(241, 236, 225, .72);
	margin-top: 1px;
}
.mke-chat-status.is-on::before {
	content: "";
	display: inline-block;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #7FB58E;
	margin-right: .4rem;
}
.mke-chat-close,
.mke-chat-back {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	flex: 0 0 auto;
	background: none;
	border: 0;
	border-radius: 50%;
	color: inherit;
	cursor: pointer;
	opacity: .85;
}
.mke-chat-close { font-size: 1.5rem; line-height: 1; }
.mke-chat-close:hover,
.mke-chat-back:hover { opacity: 1; background: rgba(241, 236, 225, .12); }
.mke-chat-close:focus-visible,
.mke-chat-back:focus-visible { outline: 2px solid var(--cream); outline-offset: 1px; }

/* ---------------- welcome ---------------- */

.mke-chat-welcome {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 1.4rem 1.1rem 1.1rem;
	display: flex;
	flex-direction: column;
	text-align: center;
	background:
		radial-gradient(120% 70% at 50% 0%, var(--olive-soft) 0%, rgba(255, 255, 255, 0) 62%),
		var(--paper);
}
.mke-chat-avatar {
	align-self: center;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 54px;
	height: 54px;
	border-radius: 50%;
	background: var(--bottle);
	color: var(--cream);
	margin-bottom: .7rem;
}
.mke-chat-welcome-title {
	font-family: var(--font-serif);
	font-weight: 400;
	font-size: 1.35rem;
	margin: 0 0 .35rem;
	color: var(--ink);
}
.mke-chat-welcome-lede {
	margin: 0 0 1.15rem;
	font-size: .9rem;
	line-height: 1.5;
	color: var(--muted);
}
.mke-chat-chips-label {
	margin: 0 0 .5rem;
	font-size: .68rem;
	letter-spacing: .13em;
	text-transform: uppercase;
	font-weight: 600;
	color: var(--muted);
}
.mke-chat-chips {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: .4rem;
	margin-bottom: 1.15rem;
}
.mke-chat-chip {
	font: inherit;
	font-size: .84rem;
	color: var(--bottle);
	background: var(--cream-light);
	border: 1px solid var(--line);
	border-radius: 999px;
	padding: .42rem .8rem;
	cursor: pointer;
	transition: background .15s ease, border-color .15s ease;
}
.mke-chat-chip:hover { background: var(--olive-soft); border-color: var(--olive); }
.mke-chat-chip:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }

.mke-chat-alt {
	/* A real bottom margin as well as the auto above the button: the auto
	   collapses to nothing when the sheet hugs its content. */
	margin: 0 0 1.1rem;
	font-size: .82rem;
	color: var(--muted);
}
.mke-chat-alt a { color: var(--olive-dark); overflow-wrap: anywhere; }

.mke-chat-begin { width: 100%; margin-top: auto; padding-top: 0; }
.mke-chat-alt + .mke-chat-begin { margin-top: auto; }
.mke-chat-avail {
	margin: .7rem 0 0;
	font-size: .74rem;
	line-height: 1.45;
	color: var(--muted);
}

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

.mke-chat-intro {
	flex: 1;
	min-height: 0;
	padding: 1rem 1rem .85rem;
	overflow-y: auto;
}
.mke-chat-intro label {
	display: block;
	font-size: .74rem;
	letter-spacing: .1em;
	text-transform: uppercase;
	color: var(--muted);
	font-weight: 600;
	margin-bottom: .22rem;
}
.mke-chat-intro input,
.mke-chat-intro textarea,
.mke-chat-reply textarea {
	width: 100%;
	font: inherit;
	font-size: 16px;             /* 16px or iOS zooms the page on focus */
	color: var(--ink);
	background: var(--cream-light);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: .55rem .7rem;
	margin-bottom: .6rem;
	resize: none;
}
.mke-chat-intro input:focus,
.mke-chat-intro textarea:focus,
.mke-chat-reply textarea:focus {
	outline: 2px solid var(--olive);
	outline-offset: 1px;
	background: var(--paper);
}
.mke-chat-intro label.mke-chat-consent,
.mke-chat-intro label.mke-chat-consent span {
	text-transform: none;
	letter-spacing: normal;
	font-weight: 400;
}
.mke-chat-consent {
	display: flex;
	align-items: flex-start;
	gap: .5rem;
	margin: .1rem 0 .7rem;
	cursor: pointer;
	text-transform: none;      /* the label rule above uppercases everything */
	letter-spacing: normal;
	font-weight: 400;
}
.mke-chat-consent input {
	width: auto;
	margin: .15rem 0 0;
	flex: 0 0 auto;
	accent-color: var(--bottle);
}
.mke-chat-consent span {
	font-size: .78rem;
	line-height: 1.4;
	color: var(--muted);
}

/* Blocksy gives every textarea a fixed height through --has-height, which made
   this one 170px tall regardless of rows. Say what we want instead. */
.mke-chat-intro textarea { height: 78px; }

.mke-chat-send { width: 100%; }
.mke-chat-legal {
	margin: .55rem 0 0;
	font-size: .72rem;
	color: var(--muted);
	line-height: 1.45;
}
.mke-chat-error {
	margin: .7rem 0 0;
	font-size: .84rem;
	color: #9C3B33;
}
.mke-hp { position: absolute; left: -9999px; }

/* ---------------- conversation ---------------- */

.mke-chat-thread {
	display: flex;
	flex-direction: column;
	min-height: 0;
	flex: 1;
}
.mke-chat-log {
	flex: 1;
	overflow-y: auto;
	padding: 1rem .9rem;
	display: flex;
	flex-direction: column;
	gap: .5rem;
	background: var(--cream-light);
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
}
.mke-chat-msg {
	max-width: 84%;
	padding: .55rem .75rem;
	border-radius: 12px;
	font-size: .92rem;
	line-height: 1.45;
	animation: mke-msg-in .18s ease both;
}
@keyframes mke-msg-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: none; }
}
.mke-chat-msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.mke-chat-msg time {
	display: block;
	font-size: .68rem;
	opacity: .6;
	margin-top: .2rem;
	font-variant-numeric: lining-nums tabular-nums;
}
.mke-chat-msg.is-visitor {
	align-self: flex-end;
	background: var(--bottle);
	color: var(--cream);
	border-bottom-right-radius: 4px;
}
.mke-chat-msg.is-agent {
	align-self: flex-start;
	background: var(--paper);
	border: 1px solid var(--line);
	border-bottom-left-radius: 4px;
}
.mke-chat-msg.is-system {
	align-self: center;
	max-width: 100%;
	background: transparent;
	color: var(--muted);
	font-size: .8rem;
	text-align: center;
	padding: .2rem .4rem;
}

/* typing dots */
.mke-chat-typing {
	align-self: flex-start;
	display: flex;
	align-items: center;
	gap: 4px;
	background: var(--paper);
	border: 1px solid var(--line);
	border-radius: 12px;
	border-bottom-left-radius: 4px;
	padding: .7rem .8rem;
}
.mke-chat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--muted);
	opacity: .45;
	animation: mke-typing 1.1s infinite ease-in-out;
}
.mke-chat-typing span:nth-child(2) { animation-delay: .16s; }
.mke-chat-typing span:nth-child(3) { animation-delay: .32s; }
@keyframes mke-typing {
	0%, 60%, 100% { transform: none; opacity: .35; }
	30%           { transform: translateY(-4px); opacity: .9; }
}

.mke-chat-reply {
	display: flex;
	align-items: flex-end;
	gap: .5rem;
	padding: .6rem .65rem;
	border-top: 1px solid var(--line);
	background: var(--paper);
}
.mke-chat-reply textarea {
	margin: 0;
	height: 42px;
	min-height: 42px;
	max-height: 110px;
	line-height: 1.4;
}
.mke-chat-submit {
	flex: 0 0 auto;
	width: 42px;
	height: 42px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: var(--bottle);
	color: var(--cream);
	cursor: pointer;
}
.mke-chat-submit:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }

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

@media (max-width: 600px) {
	.mke-chat { right: 12px; bottom: 12px; left: 12px; }
	.mke-chat-launch { position: absolute; right: 0; bottom: 0; padding: .85rem; }
	.mke-chat-launch-label { display: none; }

	.mke-chat-teaser {
		right: 0;
		left: 0;
		width: auto;
		bottom: calc(100% + 62px);
	}

	/* Bottom sheet: full width, rounded top only, sized in dvh so the iOS
	   toolbar collapsing does not clip the composer. */
	.mke-chat-panel {
		position: fixed;
		right: 0;
		left: 0;
		bottom: 0;
		width: auto;
		height: 88vh;
		height: 88dvh;
		max-height: none;
		border-radius: 16px 16px 0 0;
		border-bottom: 0;
		animation-name: mke-sheet-in;
	}
	@keyframes mke-sheet-in {
		from { opacity: 0; transform: translateY(24px); }
		to   { opacity: 1; transform: none; }
	}

	.mke-chat.is-open .mke-chat-launch { display: none; }

	/* The welcome screen is short; a sheet that hugs it looks deliberate, where
	   a full-height one leaves a field of empty cream above the button. The
	   conversation still gets the full sheet. */
	.mke-chat[data-screen="welcome"] .mke-chat-panel {
		height: auto;
		max-height: 88dvh;
	}

	/* Dim the page behind the sheet, and let a tap on it close the chat. */
	.mke-chat.is-open::before {
		content: "";
		position: fixed;
		inset: 0;
		z-index: -1;
		background: rgba(32, 30, 26, .38);
		animation: mke-scrim-in .22s ease both;
	}
	@keyframes mke-scrim-in { from { opacity: 0; } to { opacity: 1; } }

	/* Grab handle, so it reads as a sheet rather than a stuck overlay. */
	.mke-chat-head { position: relative; padding-top: 1.1rem; }
	.mke-chat-head::before {
		content: "";
		position: absolute;
		top: 6px;
		left: 50%;
		transform: translateX(-50%);
		width: 36px;
		height: 4px;
		border-radius: 2px;
		background: rgba(241, 236, 225, .3);
	}

	.mke-chat-close,
	.mke-chat-back { width: 42px; height: 42px; }

	/* The header is the drag handle, so it must not select text under a drag. */
	.mke-chat-head {
		user-select: none;
		-webkit-user-select: none;
		touch-action: none;
	}

	/* Landscape phones are short: let the sheet take what it can get. */
	@media (max-height: 480px) {
		.mke-chat-panel { height: 96dvh; }
		.mke-chat-welcome { padding-top: 1rem; }
		.mke-chat-avatar { display: none; }
		.mke-chat-welcome-lede { margin-bottom: .7rem; }
	}

	.mke-chat-welcome { padding-top: 1.6rem; }
	.mke-chat-chip { padding: .5rem .85rem; font-size: .88rem; }

	/* Home-indicator clearance on the two panes that touch the bottom edge. */
	.mke-chat-reply { padding-bottom: calc(.6rem + env(safe-area-inset-bottom, 0px)); }
	.mke-chat-welcome,
	.mke-chat-intro { padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
}

/* Stop the page scrolling behind the sheet. */
@media (max-width: 600px) {
	body.mke-chat-open { overflow: hidden; }
}

/* The product page keeps a sticky Buy bar down there; sit above it. */
body.has-buybar .mke-chat { bottom: 84px; }
@media (max-width: 600px) {
	body.has-buybar .mke-chat { bottom: 78px; }
	body.has-buybar .mke-chat-panel { bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.mke-chat-launch,
	.mke-chat-teaser { transition: none; }
	.mke-chat-panel,
	.mke-chat-msg { animation: none; }
	.mke-chat.is-open::before { animation: none; }
	.mke-chat-typing span { animation: none; }
}
