/**
 * WebSamurai AI Chatbot — frontend styles.
 *
 * Two concerns are handled here:
 *
 * 1. Theme isolation. Themes and Elementor style bare `button`, `textarea`
 *    and `a` elements aggressively, and those rules outrank plain classes.
 *    Every component rule is therefore scoped under the #wsa-chat id, which
 *    outranks any class-based theme rule without needing !important.
 *
 * 2. Theming. Every visual value reads a --wsa-chat-* custom property, so the
 *    admin panel (stage 3) can restyle the widget by overriding variables
 *    instead of touching this file.
 */

#wsa-chat.wsa-chat[data-position="left"] {
	right: auto;
	left: var(--wsa-chat-offset-x);
	align-items: flex-start;
}

#wsa-chat.wsa-chat {
	--wsa-chat-accent: #2c6ecb;
	--wsa-chat-accent-text: #ffffff;
	--wsa-chat-header-bg: #2c6ecb;
	--wsa-chat-header-text: #ffffff;
	--wsa-chat-window-bg: #ffffff;
	--wsa-chat-bot-bg: #f1f3f6;
	--wsa-chat-bot-text: #1c1f24;
	--wsa-chat-user-bg: #2c6ecb;
	--wsa-chat-user-text: #ffffff;
	--wsa-chat-muted: #6b7280;
	--wsa-chat-border: rgba(0, 0, 0, .08);
	--wsa-chat-radius-window: 16px;
	--wsa-chat-radius-bubble: 14px;
	--wsa-chat-radius-launcher: 50%;
	--wsa-chat-shadow: 0 12px 32px rgba(0, 0, 0, .16);
	--wsa-chat-width: 360px;
	--wsa-chat-height: 520px;
	--wsa-chat-font: inherit;
	--wsa-chat-font-size: 14px;
	--wsa-chat-offset-x: 24px;
	--wsa-chat-offset-y: 24px;
	--wsa-chat-launcher-size: 58px;
	--wsa-chat-gap: 10px;

	position: fixed;
	right: var(--wsa-chat-offset-x);
	bottom: var(--wsa-chat-offset-y);
	z-index: 99998;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
	max-width: calc(100vw - (var(--wsa-chat-offset-x) * 2));
	font-family: var(--wsa-chat-font);
	font-size: var(--wsa-chat-font-size);
	line-height: 1.5;
	text-align: left;
}

/* ---------- theme reset ----------
   Neutralises inherited theme styling on the elements themes touch most. */

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

#wsa-chat button,
#wsa-chat textarea {
	-webkit-appearance: none;
	appearance: none;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
	background-image: none;
	box-shadow: none;
	outline: none;
	font: inherit;
	color: inherit;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	white-space: normal;
	overflow-wrap: break-word;
	line-height: 1.4;
	min-height: 0;
	min-width: 0;
	width: auto;
	height: auto;
	transition: none;
}

#wsa-chat button::before,
#wsa-chat button::after {
	content: none;
}

#wsa-chat button:hover,
#wsa-chat button:focus,
#wsa-chat button:active {
	background-image: none;
	box-shadow: none;
	outline: none;
	transform: none;
}

#wsa-chat svg {
	display: block;
	max-width: none;
	fill: none;
}

#wsa-chat a {
	box-shadow: none;
	background: none;
}

/* ---------- launcher ---------- */

#wsa-chat .wsa-chat-bubble {
	width: var(--wsa-chat-launcher-size);
	height: var(--wsa-chat-launcher-size);
	border-radius: var(--wsa-chat-radius-launcher);
	background-color: var(--wsa-chat-accent);
	color: var(--wsa-chat-accent-text);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--wsa-chat-shadow);
	transition: transform .18s ease;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-bubble:hover {
	background-color: var(--wsa-chat-accent);
	transform: scale(1.06);
	box-shadow: var(--wsa-chat-shadow);
}

#wsa-chat[data-open="true"] .wsa-chat-bubble {
	display: none !important;
}

/* ---------- window ---------- */

#wsa-chat .wsa-chat-window {
	width: var(--wsa-chat-width);
	max-width: calc(100vw - 32px);
	height: var(--wsa-chat-height);
	max-height: calc(100vh - 48px);
	background-color: var(--wsa-chat-window-bg);
	border-radius: var(--wsa-chat-radius-window);
	box-shadow: var(--wsa-chat-shadow);
	flex-direction: column;
	overflow: hidden;
	display: none;
}

/*
 * Visibility is driven by data-open rather than the [hidden] attribute:
 * themes commonly ship `[hidden] { display: none !important }` or override
 * it the other way, and either breaks the closed state.
 */
#wsa-chat[data-open="true"] .wsa-chat-window {
	display: flex;
	animation: wsa-chat-in .2s ease;
}

#wsa-chat[data-open="false"] .wsa-chat-window {
	display: none;
}

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

#wsa-chat .wsa-chat-header {
	background-color: var(--wsa-chat-header-bg);
	color: var(--wsa-chat-header-text);
	padding: 12px 14px;
	display: flex;
	align-items: center;
	gap: 10px;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-avatar {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background-color: rgba(255, 255, 255, .22);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 12px;
	font-weight: 600;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-avatar--image {
	background-color: transparent;
	overflow: hidden;
}

#wsa-chat .wsa-chat-avatar--image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	border-radius: 50%;
	max-width: none;
}

#wsa-chat .wsa-chat-titles {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
}

#wsa-chat .wsa-chat-name {
	font-weight: 600;
	font-size: 14px;
	line-height: 1.3;
}

#wsa-chat .wsa-chat-subtitle {
	font-size: 11px;
	opacity: .85;
	line-height: 1.3;
}

#wsa-chat .wsa-chat-close {
	color: inherit;
	cursor: pointer;
	opacity: .85;
	padding: 4px;
	display: flex;
	background-color: transparent;
	border-radius: 4px;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-close:hover {
	opacity: 1;
	background-color: rgba(255, 255, 255, .16);
}

/* ---------- messages ---------- */

#wsa-chat .wsa-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: var(--wsa-chat-gap);
}

#wsa-chat .wsa-chat-msg {
	max-width: 82%;
	padding: 9px 13px;
	border-radius: var(--wsa-chat-radius-bubble);
	white-space: pre-wrap;
	word-wrap: break-word;
	margin: 0;
}

#wsa-chat .wsa-chat-msg--bot {
	background-color: var(--wsa-chat-bot-bg);
	color: var(--wsa-chat-bot-text);
	border-bottom-left-radius: 4px;
	align-self: flex-start;
}

#wsa-chat .wsa-chat-msg--user {
	background-color: var(--wsa-chat-user-bg);
	color: var(--wsa-chat-user-text);
	border-bottom-right-radius: 4px;
	align-self: flex-end;
}

#wsa-chat .wsa-chat-msg--error {
	background-color: #fdecec;
	color: #932121;
	align-self: flex-start;
	border-bottom-left-radius: 4px;
}

/*
 * Links inside a message.
 *
 * The colour is inherited rather than set: a bubble's background is a
 * client-chosen variable, and a fixed link blue vanishes on a dark bot bubble
 * while fighting the palette on a light one. The underline carries the
 * affordance instead, and a long address may break mid-word so it cannot push
 * the bubble past the edge of the window.
 */
#wsa-chat .wsa-chat-msg a,
#wsa-chat .wsa-chat-link {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
	word-break: break-word;
	overflow-wrap: anywhere;
}

#wsa-chat .wsa-chat-msg a:hover,
#wsa-chat .wsa-chat-msg a:focus-visible {
	text-decoration-thickness: 2px;
}

#wsa-chat .wsa-chat-msg a:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 2px;
}

#wsa-chat .wsa-chat-typing {
	display: flex;
	gap: 4px;
	align-items: center;
}

#wsa-chat .wsa-chat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background-color: var(--wsa-chat-muted);
	animation: wsa-chat-dot 1.2s infinite ease-in-out;
}

#wsa-chat .wsa-chat-typing span:nth-child(2) { animation-delay: .15s; }
#wsa-chat .wsa-chat-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes wsa-chat-dot {
	0%, 60%, 100% { opacity: .3; transform: translateY(0); }
	30%           { opacity: 1;  transform: translateY(-3px); }
}

/* ---------- quick replies ---------- */

#wsa-chat .wsa-chat-quick {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 0 14px 10px;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-chip {
	cursor: pointer;
	border: 1px solid var(--wsa-chat-border);
	border-radius: 999px;
	padding: 6px 12px;
	font-size: 13px;
	color: var(--wsa-chat-bot-text);
	background-color: transparent;
	line-height: 1.3;
}

#wsa-chat .wsa-chat-chip:hover {
	background-color: var(--wsa-chat-bot-bg);
}

/* ---------- lead form ---------- */

#wsa-chat .wsa-chat-lead {
	display: none;
	flex-direction: column;
	gap: 8px;
	padding: 12px 14px;
	border-top: 1px solid var(--wsa-chat-border);
	background-color: var(--wsa-chat-bot-bg);
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-lead[data-visible="true"] {
	display: flex;
}

#wsa-chat .wsa-chat-lead-intro {
	margin: 0;
	font-size: 13px;
	color: var(--wsa-chat-bot-text);
	line-height: 1.4;
}

#wsa-chat .wsa-chat-lead input,
#wsa-chat .wsa-chat-lead textarea {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--wsa-chat-border);
	border-radius: 8px;
	background-color: var(--wsa-chat-window-bg);
	color: var(--wsa-chat-bot-text);
	font-size: 13px;
	resize: none;
	box-sizing: border-box;
}

#wsa-chat .wsa-chat-lead input:focus,
#wsa-chat .wsa-chat-lead textarea:focus {
	outline: 2px solid var(--wsa-chat-accent);
	outline-offset: -1px;
}

#wsa-chat .wsa-chat-lead-actions {
	display: flex;
	gap: 8px;
	align-items: center;
}

#wsa-chat .wsa-chat-lead-submit {
	cursor: pointer;
	background-color: var(--wsa-chat-accent);
	color: var(--wsa-chat-accent-text);
	border-radius: 8px;
	padding: 8px 16px;
	font-size: 13px;
	font-weight: 600;
}

#wsa-chat .wsa-chat-lead-submit:disabled {
	opacity: .5;
	cursor: default;
}

#wsa-chat .wsa-chat-lead-cancel {
	cursor: pointer;
	color: var(--wsa-chat-muted);
	font-size: 13px;
	text-decoration: underline;
}

#wsa-chat .wsa-chat-lead-error {
	margin: 0;
	font-size: 12px;
	color: #932121;
}

#wsa-chat .wsa-chat-lead-open {
	color: inherit;
	cursor: pointer;
	opacity: .85;
	padding: 4px;
	display: flex;
	border-radius: 4px;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-lead-open:hover {
	opacity: 1;
	background-color: rgba(255, 255, 255, .16);
}

/* ---------- input ---------- */

#wsa-chat .wsa-chat-input {
	border-top: 1px solid var(--wsa-chat-border);
	padding: 10px 12px;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	flex-shrink: 0;
	margin: 0;
	background: none;
}

#wsa-chat .wsa-chat-input textarea {
	flex: 1;
	resize: none;
	color: var(--wsa-chat-bot-text);
	background-color: transparent;
	max-height: 96px;
	padding: 6px 0;
	font-size: var(--wsa-chat-font-size);
}

#wsa-chat .wsa-chat-input textarea:focus {
	box-shadow: none;
	border: 0;
	outline: none;
	background-color: transparent;
}

#wsa-chat .wsa-chat-input textarea::placeholder {
	color: var(--wsa-chat-muted);
	opacity: 1;
}

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

#wsa-chat .wsa-chat-send:hover {
	background-color: var(--wsa-chat-accent);
	opacity: .9;
}

#wsa-chat .wsa-chat-send:disabled {
	opacity: .45;
	cursor: default;
	background-color: var(--wsa-chat-accent);
}

#wsa-chat .wsa-chat-trap {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

#wsa-chat .wsa-chat-footer {
	padding: 0 14px 10px;
	font-size: 11px;
	color: var(--wsa-chat-muted);
	text-align: center;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-footer a {
	color: inherit;
	text-decoration: underline;
}

/* ---------- teaser ---------- */

#wsa-chat .wsa-chat-teaser {
	display: none;
	align-items: flex-start;
	gap: 6px;
	width: max-content;
	max-width: 240px;
	box-sizing: border-box;
	padding: 10px 10px 10px 14px;
	background-color: var(--wsa-chat-window-bg);
	color: var(--wsa-chat-bot-text);
	border-radius: var(--wsa-chat-radius-bubble);
	box-shadow: var(--wsa-chat-shadow);
	animation: wsa-chat-teaser-in .25s ease;
}

#wsa-chat .wsa-chat-teaser[data-visible="true"] {
	display: flex;
}

#wsa-chat[data-open="true"] .wsa-chat-teaser {
	display: none !important;
}

#wsa-chat .wsa-chat-teaser-text {
	cursor: pointer;
	text-align: left;
	color: inherit;
	font-size: inherit;
	line-height: 1.4;
	white-space: normal;
	overflow-wrap: break-word;
	flex: 1 1 auto;
	min-width: 0;
	width: auto;
}

#wsa-chat .wsa-chat-teaser-close {
	cursor: pointer;
	color: var(--wsa-chat-muted);
	opacity: .7;
	padding: 2px;
	display: flex;
	flex-shrink: 0;
}

#wsa-chat .wsa-chat-teaser-close:hover {
	opacity: 1;
}

@keyframes wsa-chat-teaser-in {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: none; }
}

/* ---------- mobile ----------
   Two layouts, selected by data-mobile: "compact" keeps the window anchored
   to the corner at a configurable size, "fullscreen" fills the viewport. */

@media (max-width: 600px) {
	#wsa-chat.wsa-chat:not(.wsa-chat--inline) {
		right: 16px;
		bottom: 16px;
	}

	#wsa-chat.wsa-chat[data-position="left"]:not(.wsa-chat--inline) {
		left: 16px;
		right: auto;
	}

	#wsa-chat .wsa-chat-teaser {
		max-width: calc(100vw - 48px);
	}

	#wsa-chat.wsa-chat[data-mobile="compact"]:not(.wsa-chat--inline) {
		max-width: calc(100vw - 32px);
	}

	#wsa-chat[data-mobile="compact"][data-position="left"] .wsa-chat-window {
		margin-left: 0;
		margin-right: auto;
	}

	/* compact (default) */

	#wsa-chat[data-mobile="compact"] .wsa-chat-window {
		width: var(--wsa-chat-mobile-width, 92%);
		height: var(--wsa-chat-mobile-height, 80%);
		max-width: calc(100vw - 32px);
		max-height: calc(100vh - 32px);
		margin-left: auto;
	}

	#wsa-chat[data-mobile="compact"][data-open="true"] {
		left: 16px;
		top: auto;
	}

	/* fullscreen */

	#wsa-chat[data-mobile="fullscreen"].wsa-chat[data-open="true"] {
		right: 0;
		bottom: 0;
		left: 0;
		top: 0;
		max-width: none;
	}

	#wsa-chat[data-mobile="fullscreen"][data-open="true"] .wsa-chat-window {
		width: 100%;
		height: 100%;
		max-width: none;
		max-height: none;
		border-radius: 0;
	}
}


/* ---------- inline (Elementor widget) ----------
   Placed last on purpose: the mobile corner rules above must not apply to an
   embedded instance. The widget owns no positioning — the Elementor container
   decides where it sits. */

.wsa-chat-inline {
	width: 100%;
}

#wsa-chat.wsa-chat--inline,
#wsa-chat.wsa-chat--inline[data-position="left"],
#wsa-chat.wsa-chat--inline[data-position="right"] {
	position: static;
	right: auto;
	bottom: auto;
	left: auto;
	top: auto;
	width: 100%;
	max-width: none;
	margin: 0;
	gap: 0;
	align-items: stretch;
	z-index: auto;
}

#wsa-chat.wsa-chat--inline .wsa-chat-bubble,
#wsa-chat.wsa-chat--inline .wsa-chat-teaser,
#wsa-chat.wsa-chat--inline .wsa-chat-close {
	display: none !important;
}

#wsa-chat.wsa-chat--inline .wsa-chat-window,
#wsa-chat.wsa-chat--inline[data-open="true"] .wsa-chat-window {
	display: flex;
	width: 100%;
	max-width: none;
	margin: 0;
	/* Own variable so the Elementor height control is not outranked by the
	   inline style that sets --wsa-chat-height on the id selector. */
	height: var(--wsa-chat-inline-height, var(--wsa-chat-height));
	max-height: none;
	animation: none;
}

@media (max-width: 600px) {
	#wsa-chat.wsa-chat--inline,
	#wsa-chat.wsa-chat--inline[data-mobile="compact"],
	#wsa-chat.wsa-chat--inline[data-mobile="fullscreen"] {
		position: static;
		right: auto;
		bottom: auto;
		left: auto;
		top: auto;
		width: 100%;
		max-width: none;
	}

	#wsa-chat.wsa-chat--inline[data-mobile="compact"] .wsa-chat-window,
	#wsa-chat.wsa-chat--inline[data-mobile="fullscreen"] .wsa-chat-window {
		width: 100%;
		height: var(--wsa-chat-inline-height, var(--wsa-chat-height));
		max-width: none;
		max-height: none;
		border-radius: var(--wsa-chat-radius-window);
	}
}
