/**
 * MD3 AI Connector — visitor chat widget.
 *
 * Everything is scoped under .md3-chat so the widget can drop into any theme
 * without leaking styles.
 */

.md3-chat {
	--md3-chat-accent: #1e5be6;
	--md3-chat-surface: #ffffff;
	--md3-chat-text: #1f2937;
	--md3-chat-muted: #6b7280;
	--md3-chat-border: #e5e7eb;

	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
}

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

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

.md3-chat-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--md3-chat-accent);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 6px 18px rgba(30, 91, 230, 0.25);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.md3-chat-toggle:hover {
	transform: scale(1.05);
	box-shadow: 0 8px 22px rgba(30, 91, 230, 0.35);
}

.md3-chat-toggle:focus-visible {
	outline: 3px solid var(--md3-chat-accent);
	outline-offset: 3px;
}

.md3-chat-icon {
	width: 26px;
	height: 26px;
	fill: currentColor;
}

.md3-chat-icon-close {
	display: none;
}

.md3-chat.is-open .md3-chat-icon-open {
	display: none;
}

.md3-chat.is-open .md3-chat-icon-close {
	display: block;
}

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

.md3-chat-panel {
	position: absolute;
	right: 0;
	bottom: 72px;
	display: flex;
	flex-direction: column;
	width: 370px;
	max-width: calc(100vw - 40px);
	height: 520px;
	max-height: calc(100vh - 120px);
	overflow: hidden;
	border: 1px solid var(--md3-chat-border);
	border-radius: 14px;
	background: var(--md3-chat-surface);
	color: var(--md3-chat-text);
	box-shadow: 0 12px 40px rgba(10, 23, 48, 0.18);
	animation: md3-chat-in 0.18s ease-out;
}

.md3-chat-panel[hidden] {
	display: none;
}

@keyframes md3-chat-in {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.md3-chat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 14px 16px;
	background: var(--md3-chat-accent);
	color: #fff;
}

.md3-chat-title {
	font-weight: 600;
	font-size: 15px;
}

.md3-chat-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
	opacity: 0.85;
}

.md3-chat-close:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.18);
}

.md3-chat-close svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

/* Transcript
   ------------------------------------------------------------------------ */

.md3-chat-log {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	background: #f9fafb;
}

.md3-chat-msg {
	display: flex;
	margin-bottom: 10px;
}

.md3-chat-msg-user {
	justify-content: flex-end;
}

.md3-chat-bubble {
	max-width: 82%;
	padding: 9px 13px;
	border-radius: 14px;
	white-space: pre-wrap;
	overflow-wrap: break-word;
	word-break: break-word;
}

.md3-chat-msg-assistant .md3-chat-bubble {
	border: 1px solid var(--md3-chat-border);
	border-bottom-left-radius: 4px;
	background: #fff;
}

.md3-chat-msg-user .md3-chat-bubble {
	border-bottom-right-radius: 4px;
	background: var(--md3-chat-accent);
	color: #fff;
}

.md3-chat-msg-error .md3-chat-bubble {
	border: 1px solid #fecaca;
	background: #fef2f2;
	color: #b32d2e;
	font-size: 14px;
}

/* WhatsApp handoff
   ------------------------------------------------------------------------ */

.md3-chat-msg-cta {
	justify-content: center;
	margin: 4px 0 12px;
}

.md3-chat-wa {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 10px 16px;
	border-radius: 22px;
	background: #25d366;
	color: #fff !important;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none !important;
	box-shadow: 0 2px 8px rgba(37, 211, 102, 0.35);
	transition: background 0.15s ease, transform 0.15s ease;
}

.md3-chat-wa:hover,
.md3-chat-wa:focus {
	background: #1ebe5b;
	color: #fff !important;
	transform: translateY(-1px);
}

.md3-chat-wa:focus-visible {
	outline: 3px solid var(--md3-chat-accent);
	outline-offset: 2px;
}

.md3-chat-wa svg {
	width: 19px;
	height: 19px;
	flex: 0 0 auto;
	fill: currentColor;
}

/* Typing indicator */

.md3-chat-typing .md3-chat-bubble {
	display: flex;
	gap: 4px;
	padding: 13px;
}

.md3-chat-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--md3-chat-muted);
	animation: md3-chat-bounce 1.2s infinite ease-in-out;
}

.md3-chat-typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.md3-chat-typing span:nth-child(3) {
	animation-delay: 0.3s;
}

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

/* Composer
   ------------------------------------------------------------------------ */

.md3-chat-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--md3-chat-border);
	background: var(--md3-chat-surface);
}

.md3-chat-input {
	flex: 1 1 auto;
	max-height: 120px;
	min-height: 40px;
	padding: 9px 12px;
	border: 1px solid var(--md3-chat-border);
	border-radius: 20px;
	background: #fff;
	color: var(--md3-chat-text);
	font: inherit;
	line-height: 1.4;
	resize: none;
	overflow-y: auto;
}

.md3-chat-input:focus {
	outline: none;
	border-color: var(--md3-chat-accent);
}

.md3-chat-input:disabled {
	opacity: 0.6;
}

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

.md3-chat-send:disabled {
	opacity: 0.5;
	cursor: default;
}

.md3-chat-send svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

/* Honeypot: reachable by bots, invisible and unfocusable for people. */

.md3-chat-hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.md3-chat-disclaimer {
	margin: 0;
	padding: 0 12px 10px;
	background: var(--md3-chat-surface);
	color: var(--md3-chat-muted);
	font-size: 11px;
	text-align: center;
}

/* Themes that don't ship the WordPress helper class. */

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

/* Small screens: the panel takes the viewport. */

@media (max-width: 480px) {
	.md3-chat {
		right: 14px;
		bottom: 14px;
	}

	.md3-chat-panel {
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		max-width: 100%;
		height: 82vh;
		max-height: 82vh;
		border-radius: 14px 14px 0 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.md3-chat-panel,
	.md3-chat-toggle,
	.md3-chat-typing span {
		animation: none;
		transition: none;
	}

	.md3-chat-toggle:hover {
		transform: none;
	}
}
