/**
 * BLNK Chat widget.
 *
 * Reskinned from the original dark indigo/purple prototype onto BLNK's own palette: cream
 * ground, ink text, one orange accent, and the pill geometry (9999px) the site uses everywhere.
 * Microcopy is JetBrains Mono, uppercase and letterspaced, exactly as the site labels its
 * sections; body copy is Archivo.
 *
 * Everything is namespaced under .blnk-chat and scoped tightly, because this drops onto a page
 * whose own styles are almost entirely inline and would otherwise leak in.
 */

.blnk-chat {
	--blnk-cream: #f6f2ee;
	--blnk-ink: #1b1b1b;
	/* The chat runs on purple rather than the site's orange. Defined once here and referenced
	   everywhere, so the accent can be re-pointed without hunting through the file.
	   Measured at hue 271deg, which is unambiguously purple: the first attempt (#6d5efc) sat at
	   246deg and read as blue. Contrast against white text is 5.38:1, comfortably past AA. */
	--blnk-accent: #9333ea;
	--blnk-accent-soft: rgba(147, 51, 234, .16);
	--blnk-accent-shadow: rgba(147, 51, 234, .55);
	--blnk-muted: #a49a90;
	--blnk-line: #e6ded6;
	--blnk-white: #fffdfb;
	--blnk-shadow: 0 24px 60px -18px rgba(27, 27, 27, .35);
	--blnk-sans: "Archivo", "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
	--blnk-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

	position: fixed;
	right: clamp(16px, 4vw, 28px);
	bottom: clamp(16px, 4vw, 28px);
	z-index: 99999;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 14px;
	font-family: var(--blnk-sans);
}

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

/* Bring the real cursor back inside the widget.
 *
 * The BLNK theme hides the native cursor on desktop (`@media (pointer: fine) { body { cursor:
 * none } }`) and draws its own at z-index 10000. This panel sits at 99999, so that custom cursor
 * is painted UNDERNEATH it while the native one is still suppressed, leaving no pointer at all
 * over an open chat.
 *
 * Restoring it here rather than lowering the panel or raising the theme's cursor keeps the fix
 * self-contained: the plugin has to work on any site, including ones with no custom cursor. It
 * also gives the chat the cursors people expect from a chat, a caret in the input and a pointer
 * on the buttons, which a decorative site cursor cannot express.
 */
.blnk-chat,
.blnk-chat * {
	cursor: default;
}

.blnk-chat button,
.blnk-chat a,
.blnk-chat [role="button"] {
	cursor: pointer;
}

.blnk-chat button:disabled {
	cursor: not-allowed;
}

.blnk-chat input,
.blnk-chat textarea {
	cursor: text;
}

/* Message text is selectable, so it gets a caret like any other body copy. */
.blnk-chat__msg {
	cursor: text;
}

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

.blnk-chat__launcher {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 14px 22px;
	border: none;
	border-radius: 9999px;
	background: var(--blnk-accent);
	color: var(--blnk-white);
	font-family: var(--blnk-mono);
	font-size: 12px;
	font-weight: 500;
	letter-spacing: .1em;
	text-transform: uppercase;
	cursor: pointer;
	box-shadow: 0 12px 30px -10px var(--blnk-accent-shadow);
	transition: transform .18s cubic-bezier(.2, .8, .2, 1), box-shadow .18s;
}

.blnk-chat__launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 18px 38px -12px rgba(147, 51, 234, .7);
}

.blnk-chat__launcher:focus-visible {
	outline: 2px solid var(--blnk-ink);
	outline-offset: 3px;
}

.blnk-chat__launcher-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--blnk-white);
	animation: blnk-chat-pulse 2.4s ease-in-out infinite;
}

/* The launcher hides entirely while the panel is open. Keeping it visible put a second close
   affordance directly above one the header already provides, which read as two competing
   controls rather than one. */
.blnk-chat[data-open="true"] .blnk-chat__launcher {
	display: none;
}

@keyframes blnk-chat-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: .35; }
}

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

.blnk-chat__panel {
	width: min(400px, calc(100vw - 32px));
	height: min(620px, calc(100dvh - 130px));
	display: flex;
	flex-direction: column;
	position: relative;
	overflow: hidden;
	border-radius: 26px;
	background: var(--blnk-cream);
	border: 1px solid var(--blnk-line);
	box-shadow: var(--blnk-shadow);
	transform-origin: bottom right;
	animation: blnk-chat-in .32s cubic-bezier(.2, .9, .25, 1) both;
}

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

@keyframes blnk-chat-in {
	from { opacity: 0; transform: translateY(14px) scale(.96); }
	to { opacity: 1; transform: none; }
}

.blnk-chat__header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 16px 18px;
	background: var(--blnk-ink);
	color: var(--blnk-cream);
}

/* The rep's initial. Whoever the visitor is talking to is the first thing in the panel, which
   is the point of naming them at all. */
.blnk-chat__avatar {
	flex: none;
	display: grid;
	place-items: center;
	width: 38px;
	height: 38px;
	border-radius: 9999px;
	background: var(--blnk-accent);
	color: var(--blnk-white);
	font-family: var(--blnk-sans);
	font-size: 16px;
	font-weight: 700;
	line-height: 1;
	text-transform: uppercase;
}

.blnk-chat__who {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
}

.blnk-chat__rep {
	font-family: var(--blnk-sans);
	font-size: 15px;
	font-weight: 600;
	line-height: 1.1;
	letter-spacing: -.01em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Until JS resolves the name there is nothing to show. Collapsing the empty element keeps the
   status line vertically centred against the avatar rather than sitting oddly low. */
.blnk-chat__rep:empty {
	display: none;
}

.blnk-chat__status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-family: var(--blnk-mono);
	font-size: 9.5px;
	letter-spacing: .12em;
	text-transform: uppercase;
	color: rgba(246, 242, 238, .58);
}

.blnk-chat__status-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #4ade80;
	animation: blnk-chat-pulse 2.4s ease-in-out infinite;
}

/* Note: there is deliberately no "a team member has joined" state. A takeover is invisible to
   the visitor, who simply keeps talking to the same named person. */

.blnk-chat__close {
	flex: none;
	margin-left: auto;
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: none;
	border-radius: 9999px;
	background: rgba(246, 242, 238, .12);
	color: var(--blnk-cream);
	cursor: pointer;
	transition: background .16s;
}

.blnk-chat__close:hover {
	background: rgba(246, 242, 238, .24);
}

/* --------------------------------------------------------------- messages */

.blnk-chat__log {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 22px 20px;
	scrollbar-width: thin;
	scrollbar-color: var(--blnk-line) transparent;
}

.blnk-chat__log::-webkit-scrollbar { width: 7px; }
.blnk-chat__log::-webkit-scrollbar-thumb {
	background: var(--blnk-line);
	border-radius: 9999px;
}

.blnk-chat__meta {
	align-self: center;
	margin: 0;
	padding: 7px 16px;
	border-radius: 9999px;
	background: rgba(164, 154, 144, .14);
	font-family: var(--blnk-mono);
	font-size: 10px;
	letter-spacing: .1em;
	text-transform: uppercase;
	color: var(--blnk-muted);
	text-align: center;
}

.blnk-chat__msg {
	max-width: 82%;
	padding: 12px 16px;
	font-size: 14.5px;
	line-height: 1.6;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	animation: blnk-chat-rise .26s cubic-bezier(.2, .8, .2, 1) both;
}

@keyframes blnk-chat-rise {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: none; }
}

.blnk-chat__msg--user {
	align-self: flex-end;
	background: var(--blnk-accent);
	color: var(--blnk-white);
	border-radius: 20px 20px 6px 20px;
}

.blnk-chat__msg--bot {
	align-self: flex-start;
	background: var(--blnk-white);
	color: var(--blnk-ink);
	border: 1px solid var(--blnk-line);
	border-radius: 20px 20px 20px 6px;
}

/* An owner's words render EXACTLY like the bot's. Any visual marker would give away that a
   different person had taken over, which is precisely what should stay hidden. The distinction
   is still kept in the database and shown in the dashboard, where it is useful. */
.blnk-chat__msg--owner {
	/* intentionally identical to .blnk-chat__msg--bot */
}

.blnk-chat__msg[dir="rtl"] {
	text-align: right;
}

.blnk-chat__typing {
	display: inline-flex;
	gap: 4px;
	align-items: center;
	padding: 3px 0;
}

.blnk-chat__typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--blnk-muted);
	animation: blnk-chat-blink 1.4s infinite both;
}

.blnk-chat__typing span:nth-child(2) { animation-delay: .2s; }
.blnk-chat__typing span:nth-child(3) { animation-delay: .4s; }

@keyframes blnk-chat-blink {
	0%, 80%, 100% { opacity: .2; }
	40% { opacity: 1; }
}

/* The booking prompt is its own message, below the reply that offered it. */
.blnk-chat__book {
	align-self: flex-start;
	animation: blnk-chat-rise .26s cubic-bezier(.2, .8, .2, 1) both;
}

.blnk-chat__book-btn {
	display: inline-flex;
	align-items: center;
	gap: 9px;
	padding: 13px 20px;
	border: none;
	border-radius: 9999px;
	background: var(--blnk-ink);
	color: var(--blnk-cream);
	font-family: var(--blnk-mono);
	font-size: 11px;
	font-weight: 500;
	letter-spacing: .08em;
	text-transform: uppercase;
	cursor: pointer;
	transition: transform .16s, background .16s;
}

.blnk-chat__book-btn:hover {
	transform: translateY(-1px);
	background: var(--blnk-accent);
}

/* --------------------------------------------------------------- composer */

.blnk-chat__composer {
	display: flex;
	gap: 8px;
	align-items: center;
	padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
	background: var(--blnk-cream);
	border-top: 1px solid var(--blnk-line);
}

.blnk-chat__input {
	flex: 1;
	min-width: 0;
	padding: 13px 18px;
	border: 1px solid var(--blnk-line);
	border-radius: 9999px;
	background: var(--blnk-white);
	color: var(--blnk-ink);
	font-family: var(--blnk-sans);
	font-size: 14.5px;
	transition: border-color .18s, box-shadow .18s;
}

.blnk-chat__input::placeholder {
	color: var(--blnk-muted);
}

.blnk-chat__input:focus {
	outline: none;
	border-color: var(--blnk-accent);
	box-shadow: 0 0 0 3px var(--blnk-accent-soft);
}

.blnk-chat__send {
	flex: none;
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: none;
	border-radius: 9999px;
	background: var(--blnk-accent);
	color: var(--blnk-white);
	cursor: pointer;
	transition: transform .16s, filter .16s;
}

.blnk-chat__send:hover {
	transform: translateY(-1px);
	filter: brightness(1.06);
}

.blnk-chat__send:disabled {
	opacity: .45;
	cursor: not-allowed;
	transform: none;
}

/* ------------------------------------------------------- pre-chat capture */

.blnk-chat__precap {
	position: absolute;
	inset: 0;
	z-index: 5;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	background: rgba(27, 27, 27, .55);
	backdrop-filter: blur(4px);
}

.blnk-chat__precap[hidden] {
	display: none;
}

.blnk-chat__precap-card {
	width: 100%;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 24px 22px;
	border-radius: 22px;
	background: var(--blnk-cream);
	box-shadow: var(--blnk-shadow);
}

/* Sits over the card's own scroll area, so it stays reachable however far the form is scrolled. */
.blnk-chat__precap-close {
	position: sticky;
	top: 0;
	align-self: flex-end;
	/* Pulled back into the card padding so it hugs the corner without stealing a row of height. */
	margin: -8px -6px -28px 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	padding: 0;
	border: none;
	border-radius: 9999px;
	background: transparent;
	color: var(--blnk-muted);
	cursor: pointer;
	transition: color .16s, background .16s;
}

.blnk-chat__precap-close:hover {
	color: var(--blnk-ink);
	background: rgba(27, 27, 27, .06);
}

.blnk-chat__precap-close:focus-visible {
	outline: none;
	color: var(--blnk-ink);
	box-shadow: 0 0 0 3px var(--blnk-accent-soft);
}

.blnk-chat__precap-card h3 {
	margin: 0;
	padding-right: 28px;
	font-size: 17px;
	font-weight: 700;
	color: var(--blnk-ink);
	line-height: 1.3;
}

.blnk-chat__precap-card p {
	margin: 0 0 4px;
	font-family: var(--blnk-mono);
	font-size: 10.5px;
	line-height: 1.5;
	letter-spacing: .06em;
	text-transform: uppercase;
	color: var(--blnk-muted);
}

/* Six fields have to fit a 400px panel, so the card scrolls rather than growing past it. */
.blnk-chat__precap-card {
	max-height: 100%;
	overflow-y: auto;
}

.blnk-chat__precap-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

.blnk-chat__field {
	display: block;
	min-width: 0;
}

/* Labels exist for screen readers; sighted users get the placeholder, which keeps a six-field
   form from doubling in height. */
.blnk-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;
}

.blnk-chat__precap-card input {
	width: 100%;
	padding: 12px 16px;
	border: 1px solid var(--blnk-line);
	border-radius: 9999px;
	background: var(--blnk-white);
	color: var(--blnk-ink);
	font-family: var(--blnk-sans);
	font-size: 14px;
}

.blnk-chat__precap-card input:focus {
	outline: none;
	border-color: var(--blnk-accent);
	box-shadow: 0 0 0 3px var(--blnk-accent-soft);
}

.blnk-chat__precap-card input.is-invalid {
	border-color: #d64545;
	box-shadow: 0 0 0 3px rgba(214, 69, 69, .14);
}

.blnk-chat__precap-error {
	margin: 2px 0 0;
	padding: 0 4px;
	font-family: var(--blnk-sans);
	font-size: 12.5px;
	line-height: 1.4;
	color: #d64545;
	text-transform: none;
	letter-spacing: 0;
}

.blnk-chat__precap-error[hidden] {
	display: none;
}

.blnk-chat__precap-actions {
	display: flex;
	gap: 8px;
	margin-top: 6px;
}

.blnk-chat__precap-start,
.blnk-chat__precap-skip {
	padding: 12px 18px;
	border-radius: 9999px;
	font-family: var(--blnk-mono);
	font-size: 11px;
	font-weight: 500;
	letter-spacing: .08em;
	text-transform: uppercase;
	cursor: pointer;
	transition: filter .16s, border-color .16s, color .16s;
}

.blnk-chat__precap-start {
	flex: 1;
	border: none;
	background: var(--blnk-accent);
	color: var(--blnk-white);
}

.blnk-chat__precap-start:hover {
	filter: brightness(1.06);
}

.blnk-chat__precap-skip {
	border: 1px solid var(--blnk-line);
	background: transparent;
	color: var(--blnk-muted);
}

.blnk-chat__precap-skip:hover {
	color: var(--blnk-ink);
	border-color: var(--blnk-muted);
}

/* ----------------------------------------------------------------- mobile */

@media (max-width: 480px) {
	.blnk-chat {
		right: 12px;
		bottom: 12px;
		left: 12px;
		align-items: stretch;
	}

	.blnk-chat__launcher {
		align-self: flex-end;
	}

	.blnk-chat__panel {
		width: 100%;
		height: min(560px, calc(100dvh - 110px));
	}

	.blnk-chat__msg {
		max-width: 88%;
	}
}

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