/**
 * Wiz Core CRM — visitor chat widget.
 *
 * The accent colour is injected per render as the --wiz-chat-accent custom
 * property, so a site can rebrand the widget without touching this file. Two
 * readable variants are injected alongside it — --wiz-chat-on-accent for text
 * drawn on the accent, and --wiz-chat-accent-text for the accent used as text
 * or as a line on white — because a light accent such as amber fails contrast
 * in both of those places.
 */

.wiz-chat {
	--wiz-chat-accent: #2563eb;
	--wiz-chat-on-accent: #ffffff;
	--wiz-chat-accent-text: var(--wiz-chat-accent);
	display: flex;
	flex-direction: column;
	width: 360px;
	height: 520px;
	max-height: calc(100vh - 120px);
	background: #ffffff;
	border-radius: 12px;
	box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
	overflow: hidden;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 14px;
	line-height: 1.5;
	color: #0f172a;
	box-sizing: border-box;
}

.wiz-chat *,
.wiz-chat *::before,
.wiz-chat *::after {
	box-sizing: border-box;
}

.wiz-chat--inline {
	width: 100%;
	max-width: 420px;
	height: 460px;
	margin: 0 auto;
	border: 1px solid #e2e8f0;
	box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.08);
}

/* Header */
.wiz-chat__header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	background: var(--wiz-chat-accent);
	color: var(--wiz-chat-on-accent);
	flex: 0 0 auto;
}

.wiz-chat__avatar {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.22);
	font-weight: 700;
	flex: 0 0 auto;
}

.wiz-chat__name {
	font-weight: 600;
	flex: 1 1 auto;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.wiz-chat__close {
	background: transparent;
	border: 0;
	color: var(--wiz-chat-on-accent);
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
	opacity: 0.85;
}

.wiz-chat__close:hover {
	opacity: 1;
}

.wiz-chat--inline .wiz-chat__close {
	display: none;
}

/* Log */
.wiz-chat__log {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 14px;
	background: #f8fafc;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.wiz-chat__msg {
	display: flex;
}

.wiz-chat__msg--visitor {
	justify-content: flex-end;
}

.wiz-chat__bubble {
	max-width: 82%;
	padding: 9px 12px;
	border-radius: 12px;
	background: #ffffff;
	border: 1px solid #e2e8f0;
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.wiz-chat__msg--visitor .wiz-chat__bubble {
	background: var(--wiz-chat-accent);
	border-color: transparent;
	color: var(--wiz-chat-on-accent);
}

.wiz-chat__msg--system .wiz-chat__bubble {
	background: #fef3c7;
	border-color: #fde68a;
	color: #92400e;
	font-size: 13px;
}

.wiz-chat__msg--agent .wiz-chat__bubble {
	border-color: var(--wiz-chat-accent-text);
}

.wiz-chat__whatsapp {
	align-self: center;
	margin: 4px 0;
	font-weight: 600;
	color: var(--wiz-chat-accent-text);
	text-decoration: underline;
}

/* Form */
.wiz-chat__form {
	display: flex;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #e2e8f0;
	background: #ffffff;
	flex: 0 0 auto;
}

.wiz-chat__input {
	flex: 1 1 auto;
	min-width: 0;
	padding: 9px 11px;
	border: 1px solid #cbd5e1;
	border-radius: 8px;
	font-size: 14px;
	font-family: inherit;
	color: inherit;
}

.wiz-chat__input:focus {
	outline: 2px solid var(--wiz-chat-accent);
	outline-offset: 1px;
}

.wiz-chat__send {
	flex: 0 0 auto;
	padding: 9px 16px;
	border: 0;
	border-radius: 8px;
	background: var(--wiz-chat-accent);
	color: var(--wiz-chat-on-accent);
	font-weight: 600;
	font-family: inherit;
	cursor: pointer;
}

.wiz-chat__send:disabled,
.wiz-chat__input:disabled {
	opacity: 0.6;
	cursor: default;
}

.wiz-chat__privacy {
	margin: 0;
	padding: 0 12px 10px;
	background: #ffffff;
	color: #64748b;
	font-size: 11px;
	flex: 0 0 auto;
}

/* Floating launcher */
.wiz-chat-launcher {
	position: fixed;
	bottom: 20px;
	z-index: 999990;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 12px 18px;
	border-radius: 999px;
	background: var(--wiz-chat-accent, #2563eb);
	color: var(--wiz-chat-on-accent, #ffffff);
	font-weight: 600;
	cursor: pointer;
	box-shadow: 0 8px 20px rgba(15, 23, 42, 0.22);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.wiz-chat-launcher--right {
	right: 20px;
}

.wiz-chat-launcher--left {
	left: 20px;
}

.wiz-chat-launcher:focus-visible {
	outline: 3px solid #ffffff;
	outline-offset: 2px;
}

.wiz-chat-launcher__panel {
	position: fixed;
	bottom: 82px;
	z-index: 999991;
}

/* Without this the panel is centred on the left edge, because neither side is set. */
.wiz-chat-launcher__panel--right {
	right: 20px;
}

.wiz-chat-launcher__panel--left {
	left: 20px;
}

.wiz-chat-launcher__panel[hidden] {
	display: none;
}

.wiz-chat-launcher__panel + .wiz-chat {
	position: static;
}

.wiz-chat-launcher__panel .wiz-chat {
	box-shadow: 0 16px 40px rgba(15, 23, 42, 0.28);
}

/* Small screens: turn the panel into a bottom sheet. */
@media (max-width: 480px) {
	.wiz-chat-launcher__panel {
		left: 0;
		right: 0;
		bottom: 0;
	}

	.wiz-chat {
		width: 100%;
		height: 80vh;
		max-height: 80vh;
		border-radius: 12px 12px 0 0;
	}
}

/* ---------------------------------------------------------------------------
 * Conversation feel
 *
 * Deliberately WhatsApp-shaped: the visitor's own line carries a clock and then
 * two ticks once the server has it, the other side shows three typing dots before
 * a line lands, and each bubble rises into place rather than appearing.
 * ------------------------------------------------------------------------- */

@keyframes wiz-chat-in {
	from {
		opacity: 0;
		transform: translateY(8px) scale(0.98);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

@keyframes wiz-chat-dot {
	0%,
	60%,
	100% {
		opacity: 0.5;
		transform: translateY(0);
	}

	30% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

@keyframes wiz-chat-panel {
	from {
		opacity: 0;
		transform: translateY(10px) scale(0.98);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

.wiz-chat__msg.is-entering {
	animation: wiz-chat-in 260ms ease-out both;
}

/* The bubble tail, at the foot of the bubble as WhatsApp draws it. */
.wiz-chat__bubble {
	position: relative;
}

.wiz-chat__msg--visitor .wiz-chat__bubble {
	border-bottom-right-radius: 0;
}

.wiz-chat__msg--visitor .wiz-chat__bubble::after {
	position: absolute;
	right: -6px;
	bottom: 0;
	width: 0;
	height: 0;
	border-right: 7px solid transparent;
	border-bottom: 8px solid var(--wiz-chat-accent);
	content: "";
}

.wiz-chat__msg--bot .wiz-chat__bubble {
	border-bottom-left-radius: 0;
}

.wiz-chat__msg--bot .wiz-chat__bubble::after {
	position: absolute;
	left: -6px;
	bottom: 0;
	width: 0;
	height: 0;
	border-bottom: 8px solid #ffffff;
	border-left: 7px solid transparent;
	content: "";
}

/* Time and delivery ticks, floated so they sit at the end of the last line. */
.wiz-chat__meta {
	float: right;
	display: inline-flex;
	align-items: center;
	gap: 3px;
	margin: 5px -2px -3px 8px;
	font-size: 10px;
	line-height: 1;
	opacity: 0.62;
}

.wiz-chat__msg--visitor .wiz-chat__meta {
	opacity: 0.8;
}

.wiz-chat__ticks {
	font-size: 11px;
	letter-spacing: -1px;
}

.wiz-chat__msg.is-pending .wiz-chat__ticks {
	opacity: 0.6;
}

.wiz-chat__bubble--typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 12px 14px;
}

/* Quick replies, the way a chat app offers a tappable answer to its own question. */
.wiz-chat__quick {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	padding: 2px 0 6px;
	animation: wiz-chat-in 260ms ease-out both;
}

.wiz-chat__quick-skip {
	padding: 8px 18px;
	border: 1px solid var(--wiz-chat-accent-text);
	border-radius: 999px;
	background: #ffffff;
	color: var(--wiz-chat-accent-text);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.wiz-chat__quick-skip:hover,
.wiz-chat__quick-skip:focus-visible {
	background: var(--wiz-chat-accent);
	color: var(--wiz-chat-on-accent);
}

.wiz-chat__dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #94a3b8;
	animation: wiz-chat-dot 1.2s ease-in-out infinite;
}

.wiz-chat__dot:nth-child(2) {
	animation-delay: 0.15s;
}

.wiz-chat__dot:nth-child(3) {
	animation-delay: 0.3s;
}

/* Header identity: the name over a presence line. */
.wiz-chat__id {
	display: flex;
	flex-direction: column;
	gap: 2px;
	flex: 1 1 auto;
	min-width: 0;
}

.wiz-chat__presence {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 11px;
	line-height: 1.2;
	opacity: 0.92;
}

.wiz-chat__presence-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
	flex: 0 0 auto;
}

/* The conversation is with the team rather than with the bot, so a green "we are
   here right now" light would be a promise nobody is holding open. */
.wiz-chat__presence[data-base="handoff"] .wiz-chat__presence-dot {
	background: #fbbf24;
	box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.3);
}

.wiz-chat-launcher {
	animation: wiz-chat-panel 320ms ease-out both;
}

.wiz-chat-launcher__panel:not([hidden]) {
	animation: wiz-chat-panel 220ms ease-out both;
}

@media (prefers-reduced-motion: reduce) {

	.wiz-chat__msg.is-entering,
	.wiz-chat__quick,
	.wiz-chat__dot,
	.wiz-chat-launcher,
	.wiz-chat-launcher__panel:not([hidden]) {
		animation: none;
	}
}

/* Screen-reader-only text, mirroring WordPress core's .screen-reader-text. */
.wiz-chat .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
