/* Kitengela Terrazzo Assistant — chat widget (spec section 6). Mobile first. */

.kt-chat-root {
	--kt-chat-red: #D62A1C;
	--kt-chat-red-dark: #A81F14;
	--kt-chat-charcoal: #272F32;
	--kt-chat-stone: #F6F3EE;
	--kt-chat-sand: #E6E0D6;
	--kt-chat-muted: #5E5852;
	--kt-chat-white: #FFFFFF;
	--kt-chat-heading: var(--wp--preset--font-family--jost, Jost, sans-serif);
	--kt-chat-body: var(--wp--preset--font-family--manrope, Manrope, sans-serif);
	font-family: var(--kt-chat-body);
	font-size: 15px;
	line-height: 1.5;
	color: var(--kt-chat-charcoal);
}

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

.kt-chat-sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Launcher */
.kt-chat-launcher {
	position: fixed;
	right: calc(20px + env(safe-area-inset-right, 0px));
	bottom: calc(20px + env(safe-area-inset-bottom, 0px));
	z-index: 9990;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--kt-chat-red);
	color: var(--kt-chat-white);
	box-shadow: 0 6px 18px rgba(39, 47, 50, .28);
	cursor: pointer;
	transition: background-color .15s ease, transform .15s ease;
}
.kt-chat-launcher:hover { background: var(--kt-chat-red-dark); transform: translateY(-1px); }
.kt-chat-launcher svg { width: 26px; height: 26px; }

/* Panel — full screen on mobile */
.kt-chat-panel {
	position: fixed;
	inset: 0;
	z-index: 100000; /* above the WP admin bar */
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100vh;
	height: 100dvh;
	background: var(--kt-chat-white);
	padding-bottom: env(safe-area-inset-bottom, 0px);
}
.kt-chat-panel[hidden] { display: none; }

.kt-chat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 12px 14px 18px;
	padding-top: calc(14px + env(safe-area-inset-top, 0px));
	background: var(--kt-chat-charcoal);
	color: var(--kt-chat-white);
}
.kt-chat-title {
	margin: 0;
	font-family: var(--kt-chat-heading);
	font-size: 17px;
	font-weight: 500;
	line-height: 1.2;
	letter-spacing: 0;
	color: var(--kt-chat-white);
}
.kt-chat-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--kt-chat-white);
	cursor: pointer;
}
.kt-chat-close:hover { background: rgba(255, 255, 255, .12); }

.kt-chat-log {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	background: var(--kt-chat-stone);
}

.kt-chat-msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 16px;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}
.kt-chat-msg--assistant {
	align-self: flex-start;
	background: var(--kt-chat-white);
	border: 1px solid var(--kt-chat-sand);
	border-bottom-left-radius: 4px;
}
.kt-chat-msg--user {
	align-self: flex-end;
	background: var(--kt-chat-red);
	color: var(--kt-chat-white);
	border-bottom-right-radius: 4px;
}
.kt-chat-msg--failed { opacity: .6; }
.kt-chat-msg--error { border-color: var(--kt-chat-red); }

/* Typing indicator */
.kt-chat-typing {
	display: flex;
	gap: 5px;
	padding: 0 16px 12px 30px;
	background: var(--kt-chat-stone);
}
.kt-chat-typing[hidden] { display: none; }
.kt-chat-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--kt-chat-muted);
	animation: kt-chat-bounce 1.2s infinite ease-in-out;
}
.kt-chat-dot:nth-child(3) { animation-delay: .15s; }
.kt-chat-dot:nth-child(4) { animation-delay: .3s; }
@keyframes kt-chat-bounce {
	0%, 80%, 100% { opacity: .3; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-3px); }
}

/* Input */
.kt-chat-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--kt-chat-sand);
	background: var(--kt-chat-white);
}
.kt-chat-input {
	flex: 1 1 auto;
	min-height: 44px;
	max-height: 140px;
	margin: 0;
	padding: 10px 12px;
	border: 1px solid var(--kt-chat-sand);
	border-radius: 12px;
	background: var(--kt-chat-white);
	color: var(--kt-chat-charcoal);
	font: inherit;
	font-size: 16px; /* prevents iOS zoom on focus */
	line-height: 1.4;
	resize: none;
}
.kt-chat-input:disabled { background: var(--kt-chat-stone); }
.kt-chat-send {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--kt-chat-red);
	color: var(--kt-chat-white);
	cursor: pointer;
}
.kt-chat-send:hover { background: var(--kt-chat-red-dark); }
.kt-chat-send:disabled { opacity: .5; cursor: default; }
.kt-chat-send svg { width: 20px; height: 20px; }

.kt-chat-notice {
	margin: 0;
	padding: 0 14px 10px;
	background: var(--kt-chat-white);
	font-size: 12px;
	line-height: 1.4;
	color: var(--kt-chat-muted);
}
.kt-chat-notice a { color: var(--kt-chat-red); font-weight: 600; text-decoration: underline; white-space: nowrap; }
.kt-chat-notice a:hover { color: var(--kt-chat-red-dark); }

/* Turnstile check (managed mode; often invisible, may show a checkbox) */
.kt-chat-turnstile {
	display: flex;
	justify-content: center;
	padding: 8px 12px 0;
	background: var(--kt-chat-white);
	border-top: 1px solid var(--kt-chat-sand);
}
.kt-chat-turnstile[hidden] { display: none; }

/* Rate-limit message link */
.kt-chat-msg--limit a { color: var(--kt-chat-red); font-weight: 600; text-decoration: underline; }
.kt-chat-msg--limit a:hover { color: var(--kt-chat-red-dark); }

/* Focus */
.kt-chat-root :focus-visible {
	outline: 3px solid var(--kt-chat-red);
	outline-offset: 2px;
}
.kt-chat-header :focus-visible,
.kt-chat-launcher:focus-visible { outline-color: var(--kt-chat-white); box-shadow: 0 0 0 5px var(--kt-chat-red); }
.kt-chat-input:focus-visible { outline-offset: 0; }

/* Mobile: hide launcher while full-screen panel is open; lock page scroll */
.kt-chat-root--open .kt-chat-launcher { display: none; }
html.kt-chat-lock,
html.kt-chat-lock body { overflow: hidden; }

/* Keep the fixed button clear of the footer contact links at the end of the page */
/* (footer bottom padding 28px + 64px = 92px > 76px button + offset) */
body.kt-chat-on .kt-footer .kt-footer__bottom { padding-bottom: 64px; }

/* Desktop / tablet: floating panel */
@media (min-width: 640px) {
	.kt-chat-panel {
		inset: auto;
		right: 20px;
		bottom: 88px;
		z-index: 9991;
		width: 380px;
		height: min(600px, calc(100vh - 120px));
		border-radius: 16px;
		overflow: hidden;
		box-shadow: 0 16px 48px rgba(39, 47, 50, .25);
		padding-bottom: 0;
	}
	.kt-chat-header { padding-top: 14px; }
	.kt-chat-root--open .kt-chat-launcher { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
	.kt-chat-launcher,
	.kt-chat-dot { transition: none; animation: none; }
	.kt-chat-launcher:hover { transform: none; }
}
