/* Live Chat - visitor widget. Everything is scoped under #live-chat so theme
   styles do not leak in and ours do not leak out. */

#live-chat {
	--lc-accent: #2563eb;
	--lc-accent-text: #fff;
	--lc-bg: #fff;
	--lc-surface: #f3f4f6;
	--lc-text: #111827;
	--lc-muted: #6b7280;
	--lc-border: #e5e7eb;
	--lc-radius: 16px;
	--lc-shadow: 0 12px 40px rgba( 0, 0, 0, 0.18 );

	position: fixed;
	bottom: 20px;
	z-index: 99999;
	font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: var( --lc-text );
}

#live-chat.lc--right { right: 20px; }
#live-chat.lc--left { left: 20px; }

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

#live-chat [hidden] {
	display: none !important;
}

#live-chat .lc-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	white-space: nowrap;
}

#live-chat .lc-hp {
	position: absolute;
	left: -9999px;
	width: 1px;
	height: 1px;
	opacity: 0;
}

/* Launcher ---------------------------------------------------------------- */

#live-chat .lc-launcher {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var( --lc-accent );
	color: var( --lc-accent-text );
	box-shadow: var( --lc-shadow );
	cursor: pointer;
	transition: transform 0.15s ease;
}

#live-chat .lc-launcher:hover { transform: scale( 1.05 ); }
#live-chat .lc-launcher:focus-visible { outline: 3px solid var( --lc-accent ); outline-offset: 3px; }

#live-chat .lc-icon-close { display: none; }
#live-chat.lc--open .lc-icon-open { display: none; }
#live-chat.lc--open .lc-icon-close { display: block; }

#live-chat .lc-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: 11px;
	background: #dc2626;
	color: #fff;
	font-size: 12px;
	font-weight: 700;
	line-height: 22px;
	text-align: center;
}

/* Panel ------------------------------------------------------------------- */

#live-chat .lc-panel {
	position: absolute;
	bottom: 76px;
	display: flex;
	flex-direction: column;
	width: 370px;
	height: min( 600px, calc( 100vh - 120px ) );
	overflow: hidden;
	border-radius: var( --lc-radius );
	background: var( --lc-bg );
	box-shadow: var( --lc-shadow );
}

#live-chat.lc--right .lc-panel { right: 0; }
#live-chat.lc--left .lc-panel { left: 0; }

#live-chat .lc-header {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 14px 14px 14px 18px;
	background: var( --lc-accent );
	color: var( --lc-accent-text );
}

#live-chat .lc-header-text {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-width: 0;
}

#live-chat .lc-title {
	font-size: 16px;
}

#live-chat .lc-subtitle {
	overflow: hidden;
	font-size: 13px;
	opacity: 0.9;
	text-overflow: ellipsis;
	white-space: nowrap;
}

#live-chat .lc-header-btn {
	margin: 0;
	padding: 4px 10px;
	border: 1px solid rgba( 255, 255, 255, 0.5 );
	border-radius: 8px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 13px;
	cursor: pointer;
}

#live-chat .lc-minimise {
	padding: 0 10px;
	font-size: 20px;
	line-height: 26px;
}

#live-chat .lc-body {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	background: var( --lc-bg );
}

/* Messages ---------------------------------------------------------------- */

#live-chat .lc-messages {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin: 0;
	padding: 0;
	list-style: none;
}

#live-chat .lc-msg {
	display: flex;
	flex-direction: column;
	max-width: 85%;
	margin: 0;
}

#live-chat .lc-msg-author {
	margin: 0 0 2px 4px;
	color: var( --lc-muted );
	font-size: 12px;
}

#live-chat .lc-msg-text {
	padding: 9px 13px;
	border-radius: 14px;
	background: var( --lc-surface );
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

#live-chat .lc-msg--visitor {
	align-self: flex-end;
}

#live-chat .lc-msg--visitor .lc-msg-text {
	border-bottom-right-radius: 4px;
	background: var( --lc-accent );
	color: var( --lc-accent-text );
}

#live-chat .lc-msg--ai .lc-msg-text,
#live-chat .lc-msg--agent .lc-msg-text {
	border-bottom-left-radius: 4px;
}

#live-chat .lc-msg--system {
	align-self: center;
	max-width: 95%;
}

#live-chat .lc-msg--system .lc-msg-text {
	padding: 2px 8px;
	background: none;
	color: var( --lc-muted );
	font-size: 13px;
	text-align: center;
}

#live-chat .lc-typing {
	display: flex;
	align-items: center;
	margin-top: 10px;
}

#live-chat .lc-dots {
	display: inline-flex;
	gap: 4px;
	padding: 12px 14px;
	border-radius: 14px;
	background: var( --lc-surface );
}

#live-chat .lc-dots i {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var( --lc-muted );
	animation: lc-bounce 1.2s infinite ease-in-out;
}

#live-chat .lc-dots i:nth-child( 2 ) { animation-delay: 0.15s; }
#live-chat .lc-dots i:nth-child( 3 ) { animation-delay: 0.3s; }

@keyframes lc-bounce {
	0%, 60%, 100% { transform: translateY( 0 ); opacity: 0.5; }
	30% { transform: translateY( -4px ); opacity: 1; }
}

@media ( prefers-reduced-motion: reduce ) {
	#live-chat .lc-dots i { animation: none; }
	#live-chat .lc-launcher { transition: none; }
}

/* Footer: actions, errors, composer --------------------------------------- */

#live-chat .lc-actions,
#live-chat .lc-ended {
	padding: 6px 16px;
	text-align: center;
}

#live-chat .lc-link {
	margin: 0;
	padding: 4px;
	border: 0;
	background: none;
	color: var( --lc-accent );
	font: inherit;
	font-size: 14px;
	text-decoration: underline;
	cursor: pointer;
}

#live-chat .lc-button {
	margin: 4px 0 12px;
	padding: 9px 18px;
	border: 0;
	border-radius: 10px;
	background: var( --lc-accent );
	color: var( --lc-accent-text );
	font: inherit;
	cursor: pointer;
}

#live-chat .lc-error {
	margin: 0 16px 6px;
	padding: 8px 12px;
	border-radius: 8px;
	background: #fef2f2;
	color: #b91c1c;
	font-size: 13px;
}

#live-chat .lc-compose {
	padding: 10px 12px 12px;
	border-top: 1px solid var( --lc-border );
	background: var( --lc-bg );
}

#live-chat .lc-contact {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	margin-bottom: 8px;
}

#live-chat .lc-field {
	display: flex;
	flex-direction: column;
	margin: 0;
	color: var( --lc-muted );
	font-size: 12px;
}

#live-chat .lc-field input,
#live-chat .lc-compose textarea {
	width: 100%;
	margin: 2px 0 0;
	padding: 8px 10px;
	border: 1px solid var( --lc-border );
	border-radius: 10px;
	background: var( --lc-bg );
	color: var( --lc-text );
	font: inherit;
	font-size: 15px;
	box-shadow: none;
}

#live-chat .lc-field input:focus,
#live-chat .lc-compose textarea:focus {
	border-color: var( --lc-accent );
	outline: none;
}

#live-chat .lc-compose-row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
}

#live-chat .lc-compose textarea {
	flex: 1;
	min-height: 40px;
	max-height: 120px;
	margin: 0;
	resize: none;
}

#live-chat .lc-send {
	display: flex;
	flex: 0 0 40px;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var( --lc-accent );
	color: var( --lc-accent-text );
	cursor: pointer;
}

/* Phones: the panel takes the whole screen. */
@media ( max-width: 480px ) {
	#live-chat.lc--open {
		inset: 0;
	}

	#live-chat.lc--open .lc-launcher {
		display: none;
	}

	#live-chat .lc-panel {
		position: fixed;
		inset: 0;
		width: auto;
		height: auto;
		border-radius: 0;
	}

	#live-chat .lc-contact {
		grid-template-columns: 1fr;
	}

	#live-chat .lc-field input,
	#live-chat .lc-compose textarea {
		font-size: 16px; /* Below 16px, iOS Safari zooms the page on focus. */
	}
}
