/*
 * Chatly for WhatsApp: chat widget.
 * Shared by the front end and the live preview on the settings page.
 * Selectors are scoped under .chatly and set their own box model so theme
 * styles for button/input/dialog don't leak in.
 */

.chatly {
	--chatly-accent: #25d366;
	--chatly-on-accent: #111b21;
	--chatly-ink: #111b21;
	--chatly-muted: #54656f;
	--chatly-wallpaper: #efeae2;
	--chatly-surface: #f0f2f5;
	--chatly-bubble: #fff;
	--chatly-border: #8696a0;
	--chatly-link: #0b6fa4;
	--chatly-focus: #111b21;
	--chatly-gap: 20px;

	position: fixed;
	z-index: 99990;
	right: var(--chatly-gap);
	bottom: var(--chatly-gap);
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 14px;
	max-width: calc(100vw - 2 * var(--chatly-gap));
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: max(16px, 1rem);
	font-weight: 400;
	line-height: 1.4;
	color: var(--chatly-ink);
	text-align: start;
	letter-spacing: normal;
	pointer-events: none;
}

.chatly > * {
	pointer-events: auto;
}

.chatly--left {
	right: auto;
	left: var(--chatly-gap);
	align-items: flex-start;
}

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

.chatly [hidden] {
	display: none !important;
}

.chatly .chatly__sr-only {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.chatly button,
.chatly input {
	margin: 0;
	font: inherit;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	min-width: 0;
	min-height: 0;
}

.chatly svg {
	display: block;
	flex: none;
}

/* Chat window (a non-modal <dialog>) */

.chatly .chatly__window {
	position: static;
	inset: auto;
	width: min(370px, calc(100vw - 2 * var(--chatly-gap)));
	height: min(560px, calc(100vh - 124px));
	height: min(560px, calc(100dvh - 124px));
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border: 0;
	border-radius: 16px;
	background: var(--chatly-wallpaper);
	color: var(--chatly-ink);
	box-shadow: 0 16px 48px rgba(11, 20, 26, 0.24), 0 2px 10px rgba(11, 20, 26, 0.12);
	transform-origin: bottom right;
}

.chatly--left .chatly__window {
	transform-origin: bottom left;
}

.chatly .chatly__window[open] {
	display: flex;
	flex-direction: column;
	animation: chatly-window-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1) backwards;
}

.chatly .chatly__window[open].is-closing {
	animation: chatly-window-out 0.16s ease-in forwards;
}

/* Header */

.chatly .chatly__header {
	display: flex;
	flex: none;
	align-items: center;
	gap: 12px;
	padding: 12px 10px 12px 14px;
	background: var(--chatly-accent);
	color: var(--chatly-on-accent);
}

.chatly .chatly__avatar {
	position: relative;
	display: grid;
	flex: none;
	place-items: center;
	width: 42px;
	height: 42px;
	overflow: hidden;
	border-radius: 50%;
	background: color-mix(in srgb, var(--chatly-on-accent) 16%, transparent);
	font-size: 16px;
	font-weight: 600;
	line-height: 1;
}

.chatly .chatly__avatar-img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	object-fit: cover;
	border-radius: 50%;
}

.chatly .chatly__meta {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-width: 0;
}

.chatly .chatly__name,
.chatly .chatly__status {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.chatly .chatly__name {
	font-size: 1em;
	font-weight: 600;
	line-height: 1.25;
}

.chatly .chatly__status {
	font-size: 0.8125em;
	line-height: 1.35;
}

.chatly .chatly__close {
	display: grid;
	flex: none;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	box-shadow: none;
	cursor: pointer;
}

.chatly .chatly__close:hover {
	background: color-mix(in srgb, currentColor 14%, transparent);
	color: inherit;
}

.chatly .chatly__close svg {
	width: 22px;
	height: 22px;
}

/* Conversation */

.chatly .chatly__body {
	flex: 1;
	min-height: 0;
	padding: 14px 16px 10px;
	overflow-y: auto;
	overscroll-behavior: contain;
	background-color: var(--chatly-wallpaper);
	background-image: radial-gradient(rgba(84, 101, 111, 0.1) 1px, transparent 1.4px);
	background-size: 18px 18px;
	scroll-behavior: smooth;
}

.chatly .chatly__msg {
	display: flex;
	margin: 2px 0 0;
}

.chatly .chatly__msg:first-child {
	margin-top: 0;
}

.chatly .chatly__msg--visitor {
	justify-content: flex-end;
}

.chatly .chatly__msg--bot + .chatly__msg--visitor,
.chatly .chatly__msg--visitor + .chatly__msg--bot {
	margin-top: 10px;
}

.chatly .chatly__bubble {
	position: relative;
	display: flow-root;
	max-width: 85%;
	padding: 6px 9px 7px 10px;
	border-radius: 10px;
	background: var(--chatly-bubble);
	color: var(--chatly-ink);
	box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
	font-size: 0.9375em;
	line-height: 1.4;
	overflow-wrap: anywhere;
	animation: chatly-bubble-in 0.2s ease-out backwards;
}

.chatly .chatly__msg--visitor .chatly__bubble {
	background: var(--chatly-accent);
	color: var(--chatly-on-accent);
}

/* Tail on the first bubble of each run of messages, like WhatsApp. */
.chatly .chatly__bubble::before {
	content: "";
	position: absolute;
	top: 0;
	width: 8px;
	height: 13px;
	background: inherit;
}

.chatly .chatly__msg--bot .chatly__bubble {
	border-top-left-radius: 0;
}

.chatly .chatly__msg--bot .chatly__bubble::before {
	left: -8px;
	clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.chatly .chatly__msg--visitor .chatly__bubble {
	border-top-right-radius: 0;
}

.chatly .chatly__msg--visitor .chatly__bubble::before {
	right: -8px;
	clip-path: polygon(0 0, 100% 0, 0 100%);
}

.chatly .chatly__msg--bot + .chatly__msg--bot .chatly__bubble,
.chatly .chatly__msg--visitor + .chatly__msg--visitor .chatly__bubble {
	border-radius: 10px;
}

.chatly .chatly__msg--bot + .chatly__msg--bot .chatly__bubble::before,
.chatly .chatly__msg--visitor + .chatly__msg--visitor .chatly__bubble::before {
	display: none;
}

.chatly .chatly__text {
	white-space: pre-line;
}

.chatly .chatly__text a {
	color: var(--chatly-link);
	text-decoration: underline;
}

.chatly .chatly__time {
	display: inline-flex;
	float: right;
	align-items: center;
	gap: 3px;
	margin: 8px 0 -5px 12px;
	font-size: 0.6875em;
	line-height: 1;
	color: var(--chatly-muted);
	white-space: nowrap;
}

.chatly .chatly__msg--visitor .chatly__time {
	color: inherit;
	opacity: 0.8;
}

.chatly .chatly__ticks {
	width: 16px;
	height: 11px;
}

.chatly .chatly__handoff {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	margin: 10px 0 3px;
	padding: 10px 16px;
	border: 0;
	border-radius: 999px;
	background: var(--chatly-accent);
	color: var(--chatly-on-accent);
	box-shadow: none;
	font-size: 0.9375em;
	font-weight: 600;
	line-height: 1.25;
	text-align: center;
	text-decoration: none;
}

.chatly .chatly__handoff:hover,
.chatly .chatly__handoff:focus {
	background: color-mix(in srgb, var(--chatly-accent) 88%, #000);
	color: var(--chatly-on-accent);
	text-decoration: none;
}

.chatly .chatly__handoff svg {
	width: 20px;
	height: 20px;
}

.chatly .chatly__typing {
	display: flex;
	align-items: center;
	gap: 4px;
	height: 20px;
	padding: 0 2px;
}

.chatly .chatly__typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #8696a0;
	animation: chatly-typing 1.2s ease-in-out infinite;
}

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

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

/* Composer */

.chatly .chatly__composer {
	display: flex;
	flex: none;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 10px;
	background: var(--chatly-surface);
}

.chatly .chatly__input {
	flex: 1;
	width: auto;
	height: 44px;
	padding: 0 16px;
	border: 1px solid var(--chatly-border);
	border-radius: 22px;
	background: #fff;
	color: var(--chatly-ink);
	box-shadow: none;
	font-size: 16px;
	line-height: normal;
	-webkit-appearance: none;
	appearance: none;
}

.chatly .chatly__input::placeholder {
	color: var(--chatly-muted);
	opacity: 1;
}

.chatly .chatly__send {
	display: grid;
	flex: none;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--chatly-accent);
	color: var(--chatly-on-accent);
	box-shadow: none;
	cursor: pointer;
	transition: transform 0.15s ease;
}

.chatly .chatly__send:hover {
	background: color-mix(in srgb, var(--chatly-accent) 88%, #000);
	color: var(--chatly-on-accent);
}

.chatly .chatly__send:active {
	transform: scale(0.94);
}

.chatly .chatly__send svg {
	width: 21px;
	height: 21px;
}

/* Launcher */

.chatly .chatly__launcher {
	position: relative;
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--chatly-accent);
	color: var(--chatly-on-accent);
	box-shadow: 0 6px 18px rgba(11, 20, 26, 0.26), 0 2px 4px rgba(11, 20, 26, 0.14);
	cursor: pointer;
	transition: transform 0.2s ease;
	animation: chatly-pop 0.36s cubic-bezier(0.2, 0.9, 0.3, 1.3) backwards;
}

.chatly .chatly__launcher:hover {
	transform: scale(1.06);
	background: var(--chatly-accent);
	color: var(--chatly-on-accent);
}

.chatly .chatly__launcher:active {
	transform: scale(0.96);
}

.chatly .chatly__launcher-glyph {
	width: 32px;
	height: 32px;
}

.chatly .chatly__launcher-img {
	width: 60%;
	height: 60%;
	max-width: none;
	margin: 0;
	object-fit: contain;
}

.chatly .chatly__launcher-close {
	display: none;
	width: 28px;
	height: 28px;
}

.chatly.chatly--custom-icon .chatly__launcher-glyph,
.chatly.is-open .chatly__launcher-glyph,
.chatly.is-open .chatly__launcher-img {
	display: none;
}

.chatly.is-open .chatly__launcher-close {
	display: block;
	animation: chatly-turn-in 0.2s ease-out backwards;
}

/* Keyboard focus */

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

.chatly .chatly__launcher:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 7px var(--chatly-focus), 0 6px 18px rgba(11, 20, 26, 0.26);
}

.chatly .chatly__close:focus-visible {
	outline-color: currentColor;
}

.chatly .chatly__input:focus-visible {
	outline-offset: 1px;
}

.chatly .chatly__body:focus-visible {
	outline-offset: -3px;
}

/* Right-to-left sites: mirror bubbles and tails. */

.chatly:dir(rtl) .chatly__msg--bot .chatly__bubble {
	border-radius: 10px 0 10px 10px;
}

.chatly:dir(rtl) .chatly__msg--bot .chatly__bubble::before {
	right: -8px;
	left: auto;
	clip-path: polygon(0 0, 100% 0, 0 100%);
}

.chatly:dir(rtl) .chatly__msg--visitor .chatly__bubble {
	border-radius: 0 10px 10px 10px;
}

.chatly:dir(rtl) .chatly__msg--visitor .chatly__bubble::before {
	right: auto;
	left: -8px;
	clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.chatly:dir(rtl) .chatly__time {
	float: left;
	margin: 8px 12px -5px 0;
}

/* Small screens: the open chat takes almost the whole screen. */

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

	.chatly.is-open:not(.chatly--preview) {
		right: 8px;
		bottom: 8px;
		left: 8px;
		max-width: none;
	}

	.chatly.is-open:not(.chatly--preview) .chatly__window {
		width: 100%;
		height: calc(100vh - 16px);
		height: calc(100dvh - 16px);
	}

	.chatly.is-open:not(.chatly--preview) .chatly__launcher {
		display: none;
	}
}

/* Live preview on the settings page: positioned inside the preview frame. */

.chatly.chatly--preview {
	position: absolute;
	z-index: 1;
	right: 16px;
	bottom: 16px;
	max-width: calc(100% - 32px);
}

.chatly.chatly--preview.chatly--left {
	right: auto;
	left: 16px;
}

.chatly--preview .chatly__window {
	width: min(316px, calc(100cqi - 32px));
	height: 468px;
}

/* Motion */

@keyframes chatly-pop {
	from {
		opacity: 0;
		transform: scale(0.5);
	}
}

@keyframes chatly-window-in {
	from {
		opacity: 0;
		transform: translateY(16px) scale(0.96);
	}
}

@keyframes chatly-window-out {
	to {
		opacity: 0;
		transform: translateY(12px) scale(0.97);
	}
}

@keyframes chatly-bubble-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
}

@keyframes chatly-typing {
	0%,
	60%,
	100% {
		opacity: 0.45;
		transform: translateY(0);
	}

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

@keyframes chatly-turn-in {
	from {
		opacity: 0;
		transform: rotate(-90deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.chatly *,
	.chatly *::before,
	.chatly *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}

	.chatly .chatly__body {
		scroll-behavior: auto;
	}

	.chatly .chatly__typing span {
		animation: none !important;
		opacity: 0.7;
	}

	.chatly .chatly__launcher:hover,
	.chatly .chatly__send:active,
	.chatly .chatly__launcher:active {
		transform: none;
	}
}

@media (forced-colors: active) {
	.chatly .chatly__launcher,
	.chatly .chatly__send,
	.chatly .chatly__handoff {
		border: 2px solid ButtonText;
	}

	.chatly .chatly__window,
	.chatly .chatly__bubble {
		border: 1px solid CanvasText;
	}
}

@media print {
	.chatly {
		display: none !important;
	}
}
