/* WooAI Assistant — chat widget styles.
 * All selectors prefixed with .wooai- to avoid host-theme collisions.
 * Runtime: --wooai-color is set via inline style on .wooai-widget root.
 */

.wooai-widget {
	--wooai-color: #3b82f6;
	--wooai-bg: #ffffff;
	--wooai-fg: #111827;
	--wooai-fg-muted: #6b7280;
	--wooai-user-bg: var(--wooai-color);
	--wooai-user-fg: #ffffff;
	--wooai-assistant-bg: #f3f4f6;
	--wooai-assistant-fg: #111827;
	--wooai-border: #e5e7eb;
	--wooai-radius: 12px;
	--wooai-shadow: 0 8px 32px rgba( 0, 0, 0, 0.12 );

	position: fixed;
	z-index: 999999;
	bottom: 24px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 14px;
	line-height: 1.4;
	color: var( --wooai-fg );
}

.wooai-widget[data-position="bottom-left"] {
	left: 24px;
}
.wooai-widget[data-position="bottom-right"] {
	right: 24px;
}

.wooai-widget *,
.wooai-widget *::before,
.wooai-widget *::after {
	box-sizing: border-box;
}

/* ---------- Bubble ---------- */

.wooai-widget__bubble {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var( --wooai-color );
	color: #ffffff;
	border: none;
	cursor: pointer;
	box-shadow: var( --wooai-shadow );
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: transform 200ms ease;
}

.wooai-widget__bubble:hover,
.wooai-widget__bubble:focus-visible {
	transform: scale( 1.05 );
	outline: none;
}

.wooai-widget.is-open .wooai-widget__bubble {
	transform: scale( 0.95 );
}

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

.wooai-widget__panel[hidden] {
	display: none;
}

.wooai-widget__panel {
	position: absolute;
	bottom: 72px;
	width: 360px;
	height: 520px;
	background: var( --wooai-bg );
	border-radius: var( --wooai-radius );
	box-shadow: var( --wooai-shadow );
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: wooai-slide-up 240ms cubic-bezier( 0.16, 1, 0.3, 1 );
}

.wooai-widget[data-position="bottom-left"] .wooai-widget__panel {
	left: 0;
}
.wooai-widget[data-position="bottom-right"] .wooai-widget__panel {
	right: 0;
}

@keyframes wooai-slide-up {
	from {
		transform: translateY( 8px );
		opacity: 0;
	}
	to {
		transform: translateY( 0 );
		opacity: 1;
	}
}

/* ---------- Header ---------- */

.wooai-widget__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background: var( --wooai-color );
	color: #ffffff;
	flex-shrink: 0;
}

.wooai-widget__title {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
}

.wooai-widget__close {
	background: transparent;
	border: none;
	color: inherit;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	padding: 4px 10px;
	border-radius: 6px;
}

.wooai-widget__close:hover,
.wooai-widget__close:focus-visible {
	background: rgba( 255, 255, 255, 0.15 );
	outline: none;
}

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

.wooai-widget__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: #fafafa;
}

.wooai-message {
	max-width: 80%;
	padding: 8px 12px;
	border-radius: 12px;
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: break-word;
}

.wooai-message--user {
	align-self: flex-end;
	background: var( --wooai-user-bg );
	color: var( --wooai-user-fg );
	border-bottom-right-radius: 4px;
}

.wooai-message--assistant {
	align-self: flex-start;
	background: var( --wooai-assistant-bg );
	color: var( --wooai-assistant-fg );
	border-bottom-left-radius: 4px;
}

/* ---------- Status line (typing / error / countdown) ---------- */

.wooai-widget__status {
	min-height: 24px;
	padding: 4px 16px;
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 12px;
	color: var( --wooai-fg-muted );
	flex-shrink: 0;
}

.wooai-widget__status:empty {
	display: none;
}

.wooai-widget__error {
	color: #b91c1c;
}

.wooai-widget__countdown {
	color: #b45309;
}

.wooai-widget__retry {
	background: transparent;
	border: 1px solid var( --wooai-color );
	color: var( --wooai-color );
	padding: 2px 10px;
	border-radius: 999px;
	cursor: pointer;
	font-size: 12px;
	font-family: inherit;
}

.wooai-widget__retry:hover,
.wooai-widget__retry:focus-visible {
	background: var( --wooai-color );
	color: #ffffff;
	outline: none;
}

/* ---------- Typing indicator ---------- */

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

.wooai-typing span {
	width: 6px;
	height: 6px;
	background: var( --wooai-fg-muted );
	border-radius: 50%;
	animation: wooai-blink 1.4s infinite both;
}

.wooai-typing span:nth-child( 2 ) {
	animation-delay: 0.2s;
}
.wooai-typing span:nth-child( 3 ) {
	animation-delay: 0.4s;
}

@keyframes wooai-blink {
	0%,
	80%,
	100% {
		opacity: 0.25;
	}
	40% {
		opacity: 1;
	}
}

/* ---------- Input form ---------- */

.wooai-widget__form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px;
	border-top: 1px solid var( --wooai-border );
	background: var( --wooai-bg );
	flex-shrink: 0;
}

.wooai-widget__input {
	flex: 1;
	min-height: 40px;
	max-height: 120px;
	padding: 10px 12px;
	border: 1px solid var( --wooai-border );
	border-radius: 8px;
	font: inherit;
	color: inherit;
	resize: none;
	outline: none;
	background: #ffffff;
}

.wooai-widget__input:focus {
	border-color: var( --wooai-color );
	box-shadow: 0 0 0 3px rgba( 59, 130, 246, 0.15 );
}

.wooai-widget__send {
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 8px;
	background: var( --wooai-color );
	color: #ffffff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.wooai-widget__send:hover,
.wooai-widget__send:focus-visible {
	filter: brightness( 0.95 );
	outline: none;
}

.wooai-widget__input:disabled,
.wooai-widget__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* ---------- State modifiers ---------- */

.wooai-widget.is-rate-limited .wooai-widget__input,
.wooai-widget.is-rate-limited .wooai-widget__send {
	opacity: 0.5;
	pointer-events: none;
}

/* ---------- Responsive: full-screen on mobile ---------- */

@media ( max-width: 768px ) {
	.wooai-widget[data-position] {
		bottom: 16px;
	}

	.wooai-widget__panel {
		position: fixed;
		inset: 0;
		width: 100vw;
		height: 100vh;
		height: 100dvh;
		max-width: 100vw;
		border-radius: 0;
		bottom: auto;
	}

	.wooai-widget[data-position="bottom-left"] .wooai-widget__panel,
	.wooai-widget[data-position="bottom-right"] .wooai-widget__panel {
		left: 0;
		right: 0;
	}
}

/* ---------- Reduced motion ---------- */

@media ( prefers-reduced-motion: reduce ) {
	.wooai-widget__bubble,
	.wooai-widget__panel {
		transition: none;
		animation: none;
	}
	.wooai-typing span {
		animation: none;
		opacity: 0.6;
	}
}
