/* KTL AI Chat — front-end widget
   Palette: deep navy (trust, freight-industry seriousness) + amber accent
   (a nod to route markers on a shipping map, echoing the site's "Pick Path"
   visual language). Open Sans to match the KTL brand typeface, with a
   solid system-font fallback if it isn't already loaded on the page. */

#ktl-chat-root {
	--ktl-primary: #0f2942;
	--ktl-accent: #e8944a;
	--ktl-bg: #ffffff;
	--ktl-msg-bg: #f1f4f7;
	--ktl-text: #1f2937;
	--ktl-text-muted: #6b7280;
	--ktl-border: #e5e9ee;
	--ktl-radius: 16px;
	--ktl-font: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

	position: fixed;
	z-index: 2147483000;
	right: 22px;
	bottom: 22px;
	font-family: var(--ktl-font);
	line-height: 1.4;
}

#ktl-chat-root *,
#ktl-chat-root *::before,
#ktl-chat-root *::after {
	box-sizing: border-box;
}

/* ---------------------------------------------------------------- */
/* Launcher                                                          */
/* ---------------------------------------------------------------- */
.ktl-chat-launcher {
	width: 58px;
	height: 58px;
	border-radius: 50%;
	background: var(--ktl-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	box-shadow: 0 10px 28px rgba(15, 41, 66, 0.32);
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	transition: transform 0.15s ease, filter 0.15s ease;
}
.ktl-chat-launcher:hover {
	filter: brightness(0.85);
	transform: translateY(-1px);
}
.ktl-chat-launcher:focus-visible {
	outline: 2px solid var(--ktl-accent);
	outline-offset: 3px;
}
.ktl-chat-launcher svg {
	width: 26px;
	height: 26px;
	position: absolute;
	transition: opacity 0.15s ease, transform 0.15s ease;
}
.ktl-chat-launcher-icon-close {
	opacity: 0;
	transform: scale(0.7);
}
#ktl-chat-root.is-open .ktl-chat-launcher-icon-open {
	opacity: 0;
	transform: scale(0.7);
}
#ktl-chat-root.is-open .ktl-chat-launcher-icon-close {
	opacity: 1;
	transform: scale(1);
}
.ktl-chat-launcher-dot {
	position: absolute;
	top: 2px;
	right: 2px;
	width: 13px;
	height: 13px;
	border-radius: 50%;
	background: var(--ktl-accent);
	border: 2px solid #fff;
}
@keyframes ktl-launcher-pulse {
	0% { box-shadow: 0 0 0 0 rgba(232, 148, 74, 0.55); }
	100% { box-shadow: 0 0 0 14px rgba(232, 148, 74, 0); }
}
.ktl-chat-launcher.ktl-pulse-once::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	animation: ktl-launcher-pulse 1.4s ease-out 1;
}

/* ---------------------------------------------------------------- */
/* Window                                                             */
/* ---------------------------------------------------------------- */
.ktl-chat-window {
	position: absolute;
	right: 0;
	bottom: 74px;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 570px;
	max-height: calc(100vh - 120px);
	background: var(--ktl-bg);
	border-radius: var(--ktl-radius);
	box-shadow: 0 18px 50px rgba(15, 41, 66, 0.28);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	transform-origin: bottom right;
	pointer-events: none;
	transition: opacity 0.18s ease, transform 0.18s ease;
}
#ktl-chat-root.is-open .ktl-chat-window {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

.ktl-chat-header {
	background: var(--ktl-primary);
	color: #fff;
	padding: 16px 16px 14px;
	display: flex;
	flex-direction: column;
	gap: 2px;
	flex-shrink: 0;
}
.ktl-chat-header-title {
	font-weight: 600;
	font-size: 15px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.ktl-chat-header-status {
	font-size: 11.5px;
	color: rgba(255, 255, 255, 0.68);
}
.ktl-chat-send:focus-visible,
.ktl-chat-input:focus-visible {
	outline: 2px solid var(--ktl-accent);
	outline-offset: 2px;
}

/* ---------------------------------------------------------------- */
/* Messages                                                           */
/* ---------------------------------------------------------------- */
.ktl-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--ktl-bg);
}

.ktl-msg {
	max-width: 82%;
	padding: 9px 13px;
	border-radius: 14px;
	font-size: 13.5px;
	color: var(--ktl-text);
	white-space: pre-wrap;
	word-wrap: break-word;
	animation: ktl-msg-in 0.18s ease;
}
@keyframes ktl-msg-in {
	from { opacity: 0; transform: translateY(4px); }
	to { opacity: 1; transform: translateY(0); }
}
.ktl-msg-bot,
.ktl-msg-agent {
	align-self: flex-start;
	background: var(--ktl-msg-bg);
	border-bottom-left-radius: 4px;
}
.ktl-msg-agent-label {
	display: block;
	font-size: 10.5px;
	font-weight: 700;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	color: var(--ktl-accent);
	margin-bottom: 3px;
}
.ktl-msg-visitor {
	align-self: flex-end;
	background: var(--ktl-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}
.ktl-msg-system {
	align-self: center;
	max-width: 92%;
	background: transparent;
	color: var(--ktl-text-muted);
	font-size: 11.5px;
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 4px 6px;
	text-align: center;
}
.ktl-msg-system svg {
	flex-shrink: 0;
	width: 14px;
	height: 14px;
}
.ktl-msg-system circle {
	animation: ktl-route-pulse 1.8s ease-in-out infinite;
}
@keyframes ktl-route-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.35; }
}

.ktl-chat-typing {
	padding: 0 16px 8px;
	display: flex;
	gap: 4px;
	align-items: center;
}
.ktl-chat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--ktl-text-muted);
	animation: ktl-typing-bounce 1s infinite ease-in-out;
}
.ktl-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ktl-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ktl-typing-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------------------------------------------------------------- */
/* Input                                                              */
/* ---------------------------------------------------------------- */
.ktl-chat-form {
	flex-shrink: 0;
	display: flex;
	gap: 8px;
	align-items: flex-end;
	padding: 10px 12px;
	border-top: 1px solid var(--ktl-border);
}
.ktl-chat-input {
	flex: 1;
	resize: none;
	border: 1px solid var(--ktl-border);
	border-radius: 12px;
	padding: 9px 12px;
	font-family: var(--ktl-font);
	font-size: 13.5px;
	max-height: 90px;
	color: var(--ktl-text);
}
.ktl-chat-input:focus {
	outline: none;
	border-color: var(--ktl-primary);
}
.ktl-chat-send {
	flex-shrink: 0;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	border: none;
	background: var(--ktl-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: filter 0.15s ease;
}
.ktl-chat-send:hover {
	filter: brightness(0.94);
}
.ktl-chat-send svg {
	width: 17px;
	height: 17px;
}
.ktl-chat-footer-note {
	flex-shrink: 0;
	font-size: 10.5px;
	color: var(--ktl-text-muted);
	text-align: center;
	padding: 0 10px 10px;
}

/* ---------------------------------------------------------------- */
/* Responsive + motion                                                */
/* ---------------------------------------------------------------- */
@media (max-width: 480px) {
	#ktl-chat-root {
		right: 14px;
		bottom: 14px;
	}
	.ktl-chat-window {
		width: calc(100vw - 24px);
		height: calc(100vh - 110px);
		bottom: 70px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ktl-chat-launcher.ktl-pulse-once::after,
	.ktl-msg-system circle,
	.ktl-chat-typing span,
	.ktl-msg {
		animation: none !important;
	}
	.ktl-chat-window,
	.ktl-chat-launcher svg {
		transition: none !important;
	}
}
