/* ============================================================
   Aitema AI Chat – Frontend Widget Styles
   All selectors are prefixed with .aitema-chat-* to avoid
   conflicts with any theme.
   ============================================================ */

:root {
	--aitema-primary: #2563eb;
	--aitema-text: #ffffff;
	--aitema-radius: 16px;
	--aitema-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
	--aitema-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
	--aitema-z: 999999;
}

/* Root container ─────────────────────────────────────────── */
.aitema-chat-root {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: var(--aitema-z);
	font-family: var(--aitema-font);
	font-size: 15px;
	line-height: 1.5;
	color: #1a1a1a;
}

/* Bubble button ──────────────────────────────────────────── */
.aitema-chat-bubble {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--aitema-primary);
	color: var(--aitema-text);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--aitema-shadow);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	position: relative;
	z-index: calc(var(--aitema-z) + 1);
}

.aitema-chat-bubble:hover,
.aitema-chat-bubble:focus-visible {
	transform: scale(1.08);
	box-shadow: 0 6px 28px rgba(0, 0, 0, 0.24);
	outline: 3px solid #fff;
	outline-offset: 2px;
}

.aitema-chat-bubble__icon,
.aitema-chat-bubble__close {
	width: 26px;
	height: 26px;
	position: absolute;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.aitema-chat-bubble__close {
	opacity: 0;
	transform: rotate(-45deg) scale(0.7);
}

/* When open: swap icons */
.aitema-chat-root--open .aitema-chat-bubble__icon {
	opacity: 0;
	transform: rotate(45deg) scale(0.7);
}
.aitema-chat-root--open .aitema-chat-bubble__close {
	opacity: 1;
	transform: rotate(0deg) scale(1);
}

/* Chat dialog ────────────────────────────────────────────── */
.aitema-chat-dialog {
	position: absolute;
	bottom: 68px;
	right: 0;
	width: 360px;
	max-width: calc(100vw - 48px);
	height: 520px;
	max-height: calc(100vh - 120px);
	background: #fff;
	border-radius: var(--aitema-radius);
	box-shadow: var(--aitema-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;

	/* Slide-up animation */
	opacity: 0;
	transform: translateY(16px) scale(0.97);
	transition: opacity 0.22s ease, transform 0.22s ease;
	pointer-events: none;
}

.aitema-chat-dialog[aria-hidden="false"],
.aitema-chat-root--open .aitema-chat-dialog {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* Header */
.aitema-chat-header {
	background: var(--aitema-primary);
	color: var(--aitema-text);
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}

.aitema-chat-header__title {
	font-weight: 600;
	font-size: 1rem;
}

.aitema-chat-header__close {
	background: none;
	border: none;
	color: var(--aitema-text);
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	display: flex;
	align-items: center;
	opacity: 0.85;
	transition: opacity 0.15s ease;
}
.aitema-chat-header__close:hover,
.aitema-chat-header__close:focus-visible {
	opacity: 1;
	outline: 2px solid rgba(255,255,255,0.7);
	outline-offset: 2px;
}

/* Messages area */
.aitema-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}

/* Individual message bubbles */
.aitema-chat-msg {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: 14px;
	word-break: break-word;
	font-size: 0.9rem;
	line-height: 1.5;
}

.aitema-chat-msg--bot {
	background: #f1f5f9;
	color: #1a1a1a;
	border-bottom-left-radius: 4px;
	align-self: flex-start;
}

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

/* Typing indicator */
.aitema-chat-msg--typing {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 12px 16px;
}

.aitema-chat-msg--typing span {
	width: 7px;
	height: 7px;
	background: #94a3b8;
	border-radius: 50%;
	display: inline-block;
	animation: aitema-bounce 1s infinite;
}
.aitema-chat-msg--typing span:nth-child(2) { animation-delay: 0.15s; }
.aitema-chat-msg--typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes aitema-bounce {
	0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
	40%            { transform: scale(1);   opacity: 1; }
}

/* Input form */
.aitema-chat-form {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #e2e8f0;
	flex-shrink: 0;
	background: #fff;
}

.aitema-chat-input {
	flex: 1;
	border: 1px solid #cbd5e1;
	border-radius: 24px;
	padding: 9px 16px;
	font-size: 0.9rem;
	font-family: var(--aitema-font);
	outline: none;
	transition: border-color 0.15s ease;
	background: #f8fafc;
}
.aitema-chat-input:focus {
	border-color: var(--aitema-primary);
	background: #fff;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--aitema-primary) 15%, transparent);
}

.aitema-chat-send {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--aitema-primary);
	color: var(--aitema-text);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: opacity 0.15s ease;
}
.aitema-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.aitema-chat-send:hover:not(:disabled),
.aitema-chat-send:focus-visible:not(:disabled) {
	opacity: 0.88;
	outline: 3px solid color-mix(in srgb, var(--aitema-primary) 40%, transparent);
	outline-offset: 2px;
}

/* Screen-reader-only utility */
.screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.aitema-chat-dialog,
	.aitema-chat-bubble,
	.aitema-chat-bubble__icon,
	.aitema-chat-bubble__close {
		transition: none;
	}
	.aitema-chat-msg--typing span {
		animation: none;
	}
}

/* Mobile */
@media (max-width: 480px) {
	.aitema-chat-root {
		bottom: 16px;
		right: 16px;
	}
	.aitema-chat-dialog {
		width: calc(100vw - 32px);
		right: -16px;
		bottom: 72px;
		max-height: calc(100vh - 100px);
	}
}

/* ── Inline / shortcode embed mode ──────────────────────────── */
.aitema-chat-root--inline {
	position: relative;
	bottom: auto;
	right: auto;
	z-index: auto;
	display: block;
	width: 100%;
	max-width: 480px;
}

.aitema-chat-root--inline .aitema-chat-dialog {
	position: relative;
	bottom: auto;
	right: auto;
	width: 100%;
	max-width: 100%;
	opacity: 1;
	transform: none;
	pointer-events: auto;
	border-radius: var(--aitema-radius);
	box-shadow: var(--aitema-shadow);
}

/* ── Markdown content inside bot messages ───────────────────── */
.aitema-chat-msg--bot strong { font-weight: 700; }
.aitema-chat-msg--bot em     { font-style: italic; }
.aitema-chat-msg--bot a {
	color: var(--aitema-primary);
	text-decoration: underline;
	word-break: break-all;
}
.aitema-chat-msg--bot a:hover { text-decoration: none; }
