/**
 * Self-contained default styling for the chat widget, written entirely
 * against CSS custom properties (see class-ca-ai-chat-public.php) so
 * re-theming per site is a settings change, never a CSS edit. Every
 * property has a literal fallback too, so the widget still looks
 * reasonable even before the inline :root override loads.
 *
 * Uses the .ca-chat/.ca-msg/.ca-chat-row/.ca-chat-send class names the
 * cawt-2026 theme's own hero demo already established, so on that site
 * this widget drops into the existing .panel-ai container without any
 * theme-side CSS changes — but every rule here is self-sufficient, since
 * this plugin also needs to work standalone on any other WordPress site.
 */

.ca-ai-chat-widget {
	font-family: var( --ca-ai-chat-font-body, inherit );
}

.ca-ai-chat-widget .ca-chat {
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-height: 320px;
	overflow-y: auto;
	margin-bottom: 12px;
}

.ca-ai-chat-widget .ca-msg {
	max-width: 85%;
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 14px;
	line-height: 1.45;
	word-break: break-word;
}

.ca-ai-chat-widget .ca-msg-them {
	align-self: flex-start;
	background: rgba( 0, 0, 0, 0.06 );
	color: var( --color-dark-text, #232936 ) !important;
}

/* Root cause, found while chasing this same readability problem across
   several rounds: cawt-2026's parent theme ("Improvise") has a global
   `p, li, pre { color; font-family; font-size; line-height; }` rule
   (improvise/style.css) that targets those bare elements directly. CSS
   only falls back to inheriting a property from an ancestor when nothing
   targets the element itself — so that rule always wins over whatever
   .ca-msg-them's own color/font-size resolves to, regardless of
   selector specificity or !important on the ancestor rule, for any
   property it sets. Assistant replies are real markup (see
   renderMarkdown() in chat-widget.js) — p/ul/ol/li/strong tags — so they
   get caught by it; the visitor's own message (.ca-msg-me below) is
   plain text with no such tags, so it was never affected. This one rule
   explains every readability report so far (color, and now font-size)
   — fixed once, here, for every property that rule sets, rather than
   chasing them one at a time. Margins are trimmed from browser defaults
   to read as one continuous chat bubble, not a spaced-out document, and
   the first/last child's margin is zeroed so the bubble's own padding is
   the only space above/below the text. */
.ca-ai-chat-widget .ca-msg-them p,
.ca-ai-chat-widget .ca-msg-them ul,
.ca-ai-chat-widget .ca-msg-them ol,
.ca-ai-chat-widget .ca-msg-them li,
.ca-ai-chat-widget .ca-msg-them strong {
	color: inherit !important;
	font-family: inherit !important;
	font-size: inherit !important;
	line-height: inherit !important;
}

.ca-ai-chat-widget .ca-msg-them p,
.ca-ai-chat-widget .ca-msg-them ul,
.ca-ai-chat-widget .ca-msg-them ol {
	margin: 0 0 8px;
}

.ca-ai-chat-widget .ca-msg-them p:last-child,
.ca-ai-chat-widget .ca-msg-them ul:last-child,
.ca-ai-chat-widget .ca-msg-them ol:last-child {
	margin-bottom: 0;
}

.ca-ai-chat-widget .ca-msg-them ul,
.ca-ai-chat-widget .ca-msg-them ol {
	padding-left: 20px;
}

.ca-ai-chat-widget .ca-msg-them li {
	margin-bottom: 2px;
}

.ca-ai-chat-widget .ca-msg-them a {
	color: var( --ca-ai-chat-color-primary, #2c6e8a );
	text-decoration: underline;
}

/* "AI is thinking" indicator — a real bubble in the thread (not just the
   send button dimming) so waiting reads as active, not stalled. Shown
   between the visitor's message and the real reply, then removed. */
.ca-ai-chat-widget .ca-ai-chat-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 14px 16px;
}

.ca-ai-chat-widget .ca-ai-chat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.4;
	animation: ca-ai-chat-typing-bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes ca-ai-chat-typing-bounce {
	0%, 60%, 100% {
		opacity: 0.4;
		transform: translateY( 0 );
	}
	30% {
		opacity: 1;
		transform: translateY( -3px );
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.ca-ai-chat-widget .ca-ai-chat-typing span {
		animation: none;
		opacity: 0.8;
	}
}

.ca-ai-chat-widget .ca-msg-me {
	align-self: flex-end;
	background: var( --ca-ai-chat-color-primary, #2c6e8a );
	color: var( --ca-ai-chat-color-accent, #ffffff );
	white-space: pre-wrap;
}

.ca-ai-chat-widget .ca-chat-row {
	display: flex;
	gap: 2%;
	align-items: center;
}

.ca-ai-chat-widget .ca-ai-chat-input {
	flex: 1;
	padding: 11px 13px;
	border: 1.5px solid rgba( 0, 0, 0, 0.15 );
	border-radius: 9px;
	font-size: 14px;
	font-family: inherit;
}

.ca-ai-chat-widget .ca-ai-chat-input:focus {
	outline: none;
	border-color: var( --ca-ai-chat-color-primary, #2c6e8a );
}

.ca-ai-chat-widget .ca-chat-send {
	flex: none;
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 50%;
	background: var( --ca-ai-chat-color-primary, #2c6e8a );
	color: var( --ca-ai-chat-color-accent, #ffffff );
	font-size: 15px;
	cursor: pointer;
	transition: opacity 0.15s;
}

.ca-ai-chat-widget .ca-chat-send:hover {
	opacity: 0.88;
}

.ca-ai-chat-widget .ca-chat-send:disabled {
	opacity: 0.6;
	cursor: default;
}

.ca-ai-chat-widget .ca-ai-chat-lead {
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px dashed rgba( 0, 0, 0, 0.15 );
}

.ca-ai-chat-widget .ca-ai-chat-hint {
	font-size: 13px;
	margin: 0 0 8px;
}

.ca-ai-chat-widget .ca-ai-chat-lead-form {
	display: flex;
	flex-wrap: wrap;
	gap: 2%;
}

.ca-ai-chat-widget .ca-ai-chat-lead-form input {
	flex: 1 1 45%;
	padding: 8px 10px;
	border: 1.5px solid rgba( 0, 0, 0, 0.15 );
	border-radius: 8px;
	font-size: 13px;
	font-family: inherit;
}

.ca-ai-chat-widget .ca-ai-chat-lead-form button {
	flex: none;
	padding: 8px 16px;
	border: none;
	border-radius: 99px;
	background: var( --ca-ai-chat-color-primary, #2c6e8a );
	color: var( --ca-ai-chat-color-accent, #ffffff );
	font-size: 13px;
	cursor: pointer;
}

/**
 * Floating launcher bubble (display_mode "floating" — see
 * render_floating_widget() in class-ca-ai-chat-public.php), the
 * alternative to placing the .ca-ai-chat-widget block inline. The panel
 * wraps that same widget markup unchanged, so everything above this
 * point already styles its contents correctly.
 */
.ca-ai-chat-floating {
	position: fixed;
	bottom: 20px;
	z-index: 999999;
	font-family: var( --ca-ai-chat-font-body, inherit );
}

.ca-ai-chat-floating--right {
	right: 20px;
}

.ca-ai-chat-floating--left {
	left: 20px;
}

.ca-ai-chat-floating-launcher {
	width: 60px;
	height: 60px;
	border: none;
	border-radius: 50%;
	background: var( --ca-ai-chat-color-primary, #2c6e8a );
	color: var( --ca-ai-chat-color-accent, #ffffff );
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 6px 20px rgba( 0, 0, 0, 0.25 );
	transition: transform 0.15s;
}

.ca-ai-chat-floating-launcher:hover {
	transform: scale( 1.06 );
}

.ca-ai-chat-floating-icon-close {
	display: none;
}

.ca-ai-chat-floating-open .ca-ai-chat-floating-icon-chat {
	display: none;
}

.ca-ai-chat-floating-open .ca-ai-chat-floating-icon-close {
	display: block;
}

.ca-ai-chat-floating-panel {
	position: absolute;
	bottom: 76px;
	width: min( 360px, calc( 100vw - 40px ) );
	max-height: min( 70vh, 560px );
	background: #ffffff;
	border-radius: 16px;
	box-shadow: 0 12px 40px rgba( 0, 0, 0, 0.22 );
	padding: 16px;
	overflow-y: auto;
}

.ca-ai-chat-floating--right .ca-ai-chat-floating-panel {
	right: 0;
}

.ca-ai-chat-floating--left .ca-ai-chat-floating-panel {
	left: 0;
}

@media ( max-width: 480px ) {
	.ca-ai-chat-floating-panel {
		width: calc( 100vw - 24px );
	}
}
