/**
 * W51 AI Chat — front-end widget styles.
 *
 * Deliberately theme-agnostic: every colour and metric is a custom property,
 * the defaults below are only a fallback, and nothing here touches global
 * element selectors. A theme can restyle the widget by overriding the
 * variables on `.w51ai-root`.
 */

.w51ai-root {
	--w51ai-primary: #1e6ef5;
	--w51ai-header-bg: #0b1f45;
	--w51ai-header-text: #ffffff;
	--w51ai-bot-bg: #f2f5fa;
	--w51ai-text: #0f172a;
	--w51ai-muted: #64748b;
	--w51ai-line: rgba(15, 23, 42, 0.1);
	--w51ai-surface: #ffffff;
	--w51ai-radius: 14px;
	--w51ai-offset-x: 24px;
	--w51ai-offset-y: 24px;
	--w51ai-size: 56px;

	position: fixed;
	inset-inline-end: var(--w51ai-offset-x);
	bottom: var(--w51ai-offset-y);
	z-index: 2147483000;

	font-family: inherit;
	font-size: 14px;
	line-height: 1.5;
	color: var(--w51ai-text);
	direction: ltr;
	text-align: start;
}

.w51ai-root[data-position="left"] {
	inset-inline-end: auto;
	inset-inline-start: var(--w51ai-offset-x);
}

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

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

.w51ai-launcher {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--w51ai-size);
	height: var(--w51ai-size);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--w51ai-primary);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
	transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.w51ai-launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 12px 28px rgba(15, 23, 42, 0.28);
}

.w51ai-launcher:focus-visible,
.w51ai-icon-btn:focus-visible,
.w51ai-send:focus-visible,
.w51ai-inline-trigger:focus-visible {
	outline: 2px solid var(--w51ai-primary);
	outline-offset: 3px;
}

.w51ai-root[data-launcher="0"] .w51ai-launcher {
	display: none;
}

.w51ai-launcher .w51ai-icon {
	width: calc(var(--w51ai-size) * 0.45);
	height: calc(var(--w51ai-size) * 0.45);
}

.w51ai-launcher-hint {
	position: absolute;
	inset-inline-end: calc(100% + 12px);
	top: 50%;
	transform: translateY(-50%);
	padding: 8px 12px;
	border-radius: 999px;
	background: var(--w51ai-surface);
	color: var(--w51ai-text);
	font-size: 13px;
	white-space: nowrap;
	box-shadow: 0 6px 18px rgba(15, 23, 42, 0.16);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.18s ease;
}

.w51ai-root[data-position="left"] .w51ai-launcher-hint {
	inset-inline-end: auto;
	inset-inline-start: calc(100% + 12px);
}

.w51ai-root[data-hint="1"] .w51ai-launcher-hint {
	opacity: 1;
}

.w51ai-launcher-badge {
	position: absolute;
	top: -2px;
	inset-inline-end: -2px;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 999px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	line-height: 18px;
	text-align: center;
}

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

.w51ai-panel {
	position: fixed;
	inset-inline-end: var(--w51ai-offset-x);
	bottom: calc(var(--w51ai-offset-y) + var(--w51ai-size) + 12px);
	display: flex;
	flex-direction: column;
	width: 380px;
	max-width: calc(100vw - (var(--w51ai-offset-x) * 2));
	height: 580px;
	max-height: calc(100vh - var(--w51ai-offset-y) - var(--w51ai-size) - 40px);
	overflow: hidden;
	border-radius: var(--w51ai-radius);
	background: var(--w51ai-surface);
	box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
	opacity: 0;
	transform: translateY(8px);
	pointer-events: none;
	transition: opacity 0.18s ease, transform 0.18s ease;
}

.w51ai-root[data-position="left"] .w51ai-panel {
	inset-inline-end: auto;
	inset-inline-start: var(--w51ai-offset-x);
}

.w51ai-root[data-open="1"] .w51ai-panel {
	opacity: 1;
	transform: translateY(0);
	pointer-events: auto;
}

.w51ai-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 16px;
	background: var(--w51ai-header-bg);
	color: var(--w51ai-header-text);
}

.w51ai-header-text {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.w51ai-title {
	font-size: 15px;
	font-weight: 600;
	line-height: 1.3;
}

.w51ai-subtitle {
	font-size: 12px;
	opacity: 0.78;
}

.w51ai-header-actions {
	display: flex;
	gap: 4px;
	flex-shrink: 0;
}

.w51ai-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.12);
	color: inherit;
	cursor: pointer;
	transition: background 0.15s ease;
}

.w51ai-icon-btn:hover {
	background: rgba(255, 255, 255, 0.22);
}

.w51ai-log {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px;
	background: var(--w51ai-surface);
}

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

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

.w51ai-bubble {
	max-width: 86%;
	padding: 10px 13px;
	border-radius: var(--w51ai-radius);
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.w51ai-msg-bot .w51ai-bubble {
	background: var(--w51ai-bot-bg);
	color: var(--w51ai-text);
	border-start-start-radius: 4px;
}

.w51ai-msg-user .w51ai-bubble {
	background: var(--w51ai-primary);
	color: #fff;
	border-start-end-radius: 4px;
}

.w51ai-msg-note .w51ai-bubble {
	background: transparent;
	color: var(--w51ai-muted);
	font-size: 12px;
	padding: 0 4px;
}

.w51ai-typing {
	display: inline-flex;
	gap: 4px;
	align-items: center;
}

.w51ai-typing i {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--w51ai-muted);
	opacity: 0.5;
	animation: w51ai-blink 1.2s infinite ease-in-out;
}

.w51ai-typing i:nth-child(2) {
	animation-delay: 0.15s;
}

.w51ai-typing i:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes w51ai-blink {
	0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
	40% { opacity: 0.9; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
	.w51ai-typing i {
		animation: none;
	}

	.w51ai-panel,
	.w51ai-launcher {
		transition: none;
	}
}

/* Lead capture --------------------------------------------------------- */

.w51ai-lead {
	margin: 12px 0 4px;
	padding: 14px;
	border: 1px solid var(--w51ai-line);
	border-radius: calc(var(--w51ai-radius) - 2px);
	background: var(--w51ai-bot-bg);
}

.w51ai-lead strong {
	display: block;
	margin-bottom: 4px;
	font-size: 13px;
}

.w51ai-lead p {
	margin: 0 0 10px;
	font-size: 12px;
	color: var(--w51ai-muted);
}

.w51ai-lead-row {
	display: flex;
	gap: 8px;
}

.w51ai-lead input {
	flex: 1 1 auto;
	min-width: 0;
	padding: 9px 11px;
	border: 1px solid var(--w51ai-line);
	border-radius: 9px;
	background: var(--w51ai-surface);
	color: var(--w51ai-text);
	font: inherit;
	font-size: 13px;
}

.w51ai-lead button {
	flex: 0 0 auto;
	padding: 9px 16px;
	border: 0;
	border-radius: 9px;
	background: var(--w51ai-primary);
	color: #fff;
	font: inherit;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
}

.w51ai-lead-error {
	margin: 8px 0 0;
	color: #dc2626;
	font-size: 12px;
}

/* Contact card --------------------------------------------------------- */

.w51ai-contact-card {
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	padding: 16px;
	background: var(--w51ai-surface);
	border-top: 1px solid var(--w51ai-line);
	box-shadow: 0 -12px 30px rgba(15, 23, 42, 0.08);
}

.w51ai-contact-card strong {
	display: block;
	margin-bottom: 10px;
	font-size: 13px;
}

.w51ai-contact-list {
	margin: 0;
	padding: 0;
	list-style: none;
	display: grid;
	gap: 8px;
	font-size: 13px;
}

.w51ai-contact-list a {
	color: var(--w51ai-primary);
	text-decoration: none;
	word-break: break-all;
}

.w51ai-contact-label {
	display: inline-block;
	min-width: 76px;
	color: var(--w51ai-muted);
	font-size: 12px;
}

.w51ai-contact-qr {
	display: block;
	width: 140px;
	height: 140px;
	margin-top: 4px;
	object-fit: contain;
	border-radius: 8px;
}

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

.w51ai-composer {
	position: relative;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--w51ai-line);
	background: var(--w51ai-surface);
}

.w51ai-input {
	flex: 1 1 auto;
	min-width: 0;
	max-height: 120px;
	padding: 10px 12px;
	border: 1px solid var(--w51ai-line);
	border-radius: calc(var(--w51ai-radius) - 2px);
	background: var(--w51ai-surface);
	color: var(--w51ai-text);
	font: inherit;
	font-size: 14px;
	line-height: 1.45;
	resize: none;
	overflow-y: auto;
}

.w51ai-input:focus {
	outline: none;
	border-color: var(--w51ai-primary);
}

.w51ai-send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 38px;
	height: 38px;
	padding: 0;
	border: 0;
	border-radius: calc(var(--w51ai-radius) - 2px);
	background: var(--w51ai-primary);
	color: #fff;
	cursor: pointer;
}

.w51ai-send[disabled] {
	opacity: 0.5;
	cursor: default;
}

.w51ai-footnote {
	padding: 0 12px 10px;
	color: var(--w51ai-muted);
	font-size: 11px;
	line-height: 1.4;
}

/* Inline trigger ------------------------------------------------------- */

.w51ai-inline-trigger {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 10px 18px;
	border: 0;
	border-radius: var(--w51ai-radius, 14px);
	background: var(--w51ai-primary, #1e6ef5);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

/* Breakpoints ---------------------------------------------------------- */

@media (max-width: 1024px) {
	.w51ai-root {
		inset-inline-end: var(--w51ai-offset-x-tablet, 20px);
		bottom: var(--w51ai-offset-y-tablet, 20px);
		--w51ai-size: var(--w51ai-size-tablet, 52px);
	}

	.w51ai-root[data-position="left"] {
		inset-inline-end: auto;
		inset-inline-start: var(--w51ai-offset-x-tablet, 20px);
	}
}

@media (max-width: 600px) {
	.w51ai-root {
		inset-inline-end: var(--w51ai-offset-x-mobile, 16px);
		bottom: var(--w51ai-offset-y-mobile, 16px);
		--w51ai-size: var(--w51ai-size-mobile, 48px);
	}

	.w51ai-root[data-position="left"] {
		inset-inline-end: auto;
		inset-inline-start: var(--w51ai-offset-x-mobile, 16px);
	}

	.w51ai-panel {
		inset-inline: 0;
		bottom: 0;
		width: 100%;
		max-width: 100%;
		height: 88vh;
		max-height: 88vh;
		border-end-start-radius: 0;
		border-end-end-radius: 0;
	}

	.w51ai-launcher-hint {
		display: none;
	}
}
