/* ==========================================================================
   AI Chat Assistant — widget styles
   Every color / size comes from CSS variables set by the plugin settings.
   ========================================================================== */

.aica-root,
.aica-root * {
	box-sizing: border-box;
}

.aica-root {
	--aica-primary: #2563eb;
	--aica-primary-dark: #1e4fc0;
	--aica-primary-soft: rgba(37, 99, 235, 0.14);
	--aica-header-text: #ffffff;
	--aica-bot-bg: #ffffff;
	--aica-bot-text: #1f2937;
	--aica-user-bg: #2563eb;
	--aica-user-bg-dark: #1f55ca;
	--aica-user-text: #ffffff;
	--aica-window-bg: #f4f6fb;
	--aica-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	--aica-font-size: 15px;
	--aica-width: 400px;
	--aica-height: 680px;
	--aica-launcher: 64px;
	--aica-radius: 20px;
	--aica-off-b: 24px;
	--aica-off-s: 24px;
	--aica-off-b-m: 16px;
	--aica-off-s-m: 16px;
	--aica-z: 99999;

	position: fixed;
	z-index: var(--aica-z);
	bottom: var(--aica-off-b);
	font-family: var(--aica-font);
	font-size: var(--aica-font-size);
	line-height: 1.5;
	color: #111827;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-align: left;
	direction: ltr;
}

.aica-root.aica-pos-bottom-right { right: var(--aica-off-s); }
.aica-root.aica-pos-bottom-left  { left:  var(--aica-off-s); }

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

.aica-launcher {
	position: relative;
	width: var(--aica-launcher);
	height: var(--aica-launcher);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--aica-primary) 0%, var(--aica-primary-dark) 100%);
	color: var(--aica-header-text);
	cursor: pointer;
	display: grid;
	place-items: center;
	box-shadow: 0 10px 28px -6px rgba(0, 0, 0, 0.35), 0 0 0 0 var(--aica-primary-soft);
	transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
	-webkit-tap-highlight-color: transparent;
	animation: aica-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
	outline: none;
	overflow: visible;
	line-height: 0;
}

.aica-launcher:hover {
	transform: scale(1.07);
	box-shadow: 0 14px 34px -6px rgba(0, 0, 0, 0.4), 0 0 0 10px var(--aica-primary-soft);
}

.aica-launcher:active { transform: scale(0.96); }
.aica-launcher:focus-visible { box-shadow: 0 10px 28px -6px rgba(0, 0, 0, 0.35), 0 0 0 4px #fff, 0 0 0 7px var(--aica-primary); }

.aica-launcher-icon {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}

.aica-launcher-icon svg {
	width: 46%;
	height: 46%;
	display: block;
}

.aica-launcher-img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 50%;
	display: block;
}

.aica-icon-close {
	opacity: 0;
	transform: rotate(-90deg) scale(0.4);
}

.aica-root.is-open .aica-icon-open  { opacity: 0; transform: rotate(90deg) scale(0.4); }
.aica-root.is-open .aica-icon-close { opacity: 1; transform: none; }

/* Attention badge + pulse ring */
.aica-launcher-badge {
	position: absolute;
	top: -3px;
	right: -3px;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: 11px;
	background: #ef4444;
	color: #fff;
	font-size: 12px;
	font-weight: 700;
	line-height: 22px;
	text-align: center;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25), 0 0 0 2px #fff;
	animation: aica-badge-in 0.4s 1s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.aica-launcher-badge[hidden] { display: none; }

.aica-root.has-badge:not(.is-open) .aica-launcher::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	box-shadow: 0 0 0 0 var(--aica-primary);
	animation: aica-pulse 2.2s ease-out 1.2s infinite;
	pointer-events: none;
}

/* Optional label next to the bubble */
.aica-launcher-label {
	position: absolute;
	bottom: calc(var(--aica-launcher) / 2 - 19px);
	right: calc(var(--aica-launcher) + 14px);
	padding: 9px 15px;
	border-radius: 999px;
	background: #fff;
	color: #111827;
	font-size: 0.92em;
	font-weight: 600;
	white-space: nowrap;
	box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.04);
	pointer-events: none;
	animation: aica-label-in 0.5s 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.aica-launcher-label::after {
	content: "";
	position: absolute;
	top: 50%;
	right: -5px;
	width: 10px;
	height: 10px;
	background: #fff;
	transform: translateY(-50%) rotate(45deg);
}

.aica-pos-bottom-left .aica-launcher-label {
	right: auto;
	left: calc(var(--aica-launcher) + 14px);
	animation-name: aica-label-in-left;
}

.aica-pos-bottom-left .aica-launcher-label::after {
	right: auto;
	left: -5px;
}

.aica-root.is-open .aica-launcher-label,
.aica-root.label-dismissed .aica-launcher-label { display: none; }

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

.aica-window {
	position: absolute;
	bottom: calc(var(--aica-launcher) + 16px);
	right: 0;
	width: var(--aica-width);
	max-width: calc(100vw - (var(--aica-off-s) * 2));
	height: var(--aica-height);
	max-height: calc(100vh - var(--aica-launcher) - var(--aica-off-b) - 32px);
	max-height: calc(100dvh - var(--aica-launcher) - var(--aica-off-b) - 32px);
	display: flex;
	flex-direction: column;
	background: var(--aica-window-bg);
	border-radius: var(--aica-radius);
	box-shadow: 0 24px 64px -12px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.05);
	overflow: hidden;
	transform-origin: bottom right;
	opacity: 0;
	visibility: hidden;
	transform: translateY(18px) scale(0.92);
	transition: transform 0.38s cubic-bezier(0.2, 0.9, 0.3, 1.12), opacity 0.25s ease, visibility 0s linear 0.38s;
}

.aica-pos-bottom-left .aica-window {
	right: auto;
	left: 0;
	transform-origin: bottom left;
}

.aica-root.is-open .aica-window {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition-delay: 0s;
}

/* Header */
.aica-header {
	position: relative;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 14px 14px 16px;
	background: linear-gradient(135deg, var(--aica-primary) 0%, var(--aica-primary-dark) 100%);
	color: var(--aica-header-text);
	flex: none;
	overflow: hidden;
}

.aica-header::before {
	content: "";
	position: absolute;
	inset: -40% -20% auto auto;
	width: 60%;
	aspect-ratio: 1;
	border-radius: 50%;
	background: radial-gradient(circle, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 70%);
	pointer-events: none;
}

.aica-header-id {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
	flex: 1;
	position: relative;
}

.aica-avatar {
	width: 42px;
	height: 42px;
	flex: none;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.92);
	color: var(--aica-primary);
	display: grid;
	place-items: center;
	overflow: hidden;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18), 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.aica-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aica-avatar svg { width: 60%; height: 60%; display: block; }

.aica-header-text { min-width: 0; }

.aica-name {
	font-weight: 700;
	font-size: 1.06em;
	line-height: 1.25;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.aica-status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 0.8em;
	opacity: 0.88;
	line-height: 1.3;
	margin-top: 2px;
}

.aica-status[hidden] { display: none; }

.aica-status-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6);
	animation: aica-dot 2s ease-out infinite;
}

.aica-header-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	position: relative;
}

.aica-hbtn {
	width: 36px;
	height: 36px;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
	opacity: 0.85;
	transition: background 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
	text-decoration: none;
	padding: 0;
	margin: 0;
	line-height: 0;
}

.aica-hbtn:hover { background: rgba(255, 255, 255, 0.18); opacity: 1; }
.aica-hbtn:active { transform: scale(0.92); }
.aica-hbtn svg { width: 20px; height: 20px; }
.aica-hbtn.aica-whatsapp svg { width: 22px; height: 22px; }

/* Messages */
.aica-messages {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 18px 14px 6px;
	scroll-behavior: smooth;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}

.aica-messages::-webkit-scrollbar { width: 6px; }
.aica-messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.18); border-radius: 3px; }

.aica-msg {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin: 0 0 10px;
	animation: aica-msg-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.aica-msg-user { flex-direction: row-reverse; }

.aica-msg-avatar {
	width: 28px;
	height: 28px;
	flex: none;
	border-radius: 50%;
	background: var(--aica-primary-soft);
	color: var(--aica-primary);
	display: grid;
	place-items: center;
	overflow: hidden;
}

.aica-msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aica-msg-avatar svg { width: 62%; height: 62%; }
.aica-root.no-msg-avatar .aica-msg-avatar { display: none; }

.aica-bubble {
	max-width: 82%;
	padding: 11px 15px;
	border-radius: 18px;
	font-size: 1em;
	line-height: 1.5;
	overflow-wrap: anywhere;
	word-break: break-word;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
	position: relative;
}

.aica-msg-bot .aica-bubble {
	background: var(--aica-bot-bg);
	color: var(--aica-bot-text);
	border-bottom-left-radius: 6px;
}

.aica-msg-user .aica-bubble {
	background: var(--aica-user-bg);
	background: linear-gradient(135deg, var(--aica-user-bg), var(--aica-user-bg-dark));
	color: var(--aica-user-text);
	border-bottom-right-radius: 6px;
}

/* Bubble content (markdown-lite) */
.aica-bubble p { margin: 0 0 0.6em; color: inherit; font: inherit; }
.aica-bubble p:last-child { margin-bottom: 0; }
.aica-bubble ul,
.aica-bubble ol { margin: 0.3em 0 0.6em; padding-left: 1.25em; }
.aica-bubble li { margin: 0.15em 0; }
.aica-bubble strong { font-weight: 700; color: inherit; }
.aica-bubble em { font-style: italic; }
.aica-bubble a {
	color: inherit;
	text-decoration: underline;
	text-decoration-thickness: 1.5px;
	text-underline-offset: 2px;
	font-weight: 600;
}
.aica-msg-bot .aica-bubble a { color: var(--aica-primary); }
.aica-bubble code {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.88em;
	padding: 1px 5px;
	border-radius: 5px;
	background: rgba(0, 0, 0, 0.07);
}
.aica-msg-user .aica-bubble code { background: rgba(255, 255, 255, 0.18); }
.aica-bubble h4 { margin: 0.4em 0 0.3em; font-size: 1em; font-weight: 700; }

/* Typing indicator */
.aica-typing {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 14px 16px;
	min-height: 44px;
}

.aica-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.45;
	animation: aica-bounce 1.2s ease-in-out infinite;
}

.aica-typing span:nth-child(2) { animation-delay: 0.15s; }
.aica-typing span:nth-child(3) { animation-delay: 0.3s; }

/* Error bubble */
.aica-msg-error .aica-bubble {
	background: #fff1f2;
	color: #9f1239;
	border: 1px solid #fecdd3;
}

/* Suggestion chips */
.aica-suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 14px;
	flex: none;
}

.aica-suggestions:not(:empty) { padding-bottom: 10px; }

.aica-chip {
	--i: 0;
	margin: 0;
	padding: 7px 13px;
	border: 1.5px solid var(--aica-primary);
	border-radius: 999px;
	background: var(--aica-bot-bg);
	color: var(--aica-primary);
	font: inherit;
	font-size: 0.86em;
	font-weight: 600;
	line-height: 1.3;
	cursor: pointer;
	text-align: left;
	transition: background 0.2s ease, color 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
	animation: aica-chip-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
	animation-delay: calc(var(--i) * 70ms);
}

.aica-chip:hover {
	background: var(--aica-primary);
	color: var(--aica-header-text);
	transform: translateY(-1px);
	box-shadow: 0 6px 16px -6px var(--aica-primary);
}

.aica-chip:active { transform: scale(0.97); }

/* Composer */
.aica-composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 10px 10px 16px;
	margin: 0;
	background: var(--aica-bot-bg);
	border-top: 1px solid rgba(0, 0, 0, 0.06);
	flex: none;
}

.aica-input {
	flex: 1 1 auto;
	min-width: 0;
	min-height: 42px;
	max-height: 130px;
	margin: 0;
	padding: 10px 0;
	border: 0;
	outline: 0;
	resize: none;
	background: transparent;
	color: var(--aica-bot-text);
	font: inherit;
	font-size: 1em;
	line-height: 1.45;
	box-shadow: none;
}

.aica-input::placeholder { color: var(--aica-bot-text); opacity: 0.45; }
.aica-input:focus { outline: 0; box-shadow: none; }

.aica-send {
	width: 42px;
	height: 42px;
	flex: none;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--aica-primary), var(--aica-primary-dark));
	color: var(--aica-header-text);
	display: grid;
	place-items: center;
	cursor: pointer;
	box-shadow: 0 6px 16px -6px var(--aica-primary);
	transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, box-shadow 0.2s ease;
	line-height: 0;
}

.aica-send svg { width: 20px; height: 20px; margin-left: 2px; }
.aica-send:hover { transform: scale(1.07); box-shadow: 0 8px 20px -6px var(--aica-primary); }
.aica-send:active { transform: scale(0.92); }
.aica-send:disabled { opacity: 0.45; cursor: default; transform: none; box-shadow: none; }

/* --------------------------------------------------------------------------
   Mobile: full-screen sheet
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
	.aica-root { bottom: var(--aica-off-b-m); }
	.aica-root.aica-pos-bottom-right { right: var(--aica-off-s-m); }
	.aica-root.aica-pos-bottom-left  { left:  var(--aica-off-s-m); }

	.aica-window,
	.aica-pos-bottom-left .aica-window {
		position: fixed;
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: none;
		border-radius: 0;
		transform-origin: bottom center;
		transform: translateY(40px) scale(0.98);
	}

	.aica-root.is-open .aica-window { transform: none; }
	.aica-root.is-open .aica-launcher,
	.aica-root.is-open .aica-launcher-label { display: none; }

	.aica-header { padding-top: calc(14px + env(safe-area-inset-top)); }
	.aica-composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
	.aica-bubble { max-width: 86%; }
}

body.aica-lock {
	overflow: hidden !important;
	touch-action: none;
}

/* --------------------------------------------------------------------------
   Admin live preview (inline, not fixed)
   -------------------------------------------------------------------------- */

.aica-root.aica-preview {
	position: relative;
	bottom: auto;
	right: auto;
	left: auto;
	z-index: 1;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 16px;
	width: 100%;
}

.aica-root.aica-preview.aica-pos-bottom-left { align-items: flex-start; }

.aica-root.aica-preview .aica-window,
.aica-root.aica-preview.aica-pos-bottom-left .aica-window {
	position: relative;
	inset: auto;
	bottom: auto;
	right: auto;
	left: auto;
	max-width: 100%;
	max-height: 560px;
	order: 1;
	opacity: 1;
	visibility: visible;
	transform: none;
	transition: none;
}

.aica-root.aica-preview .aica-launcher { animation: none; display: grid; order: 2; }
.aica-root.aica-preview .aica-icon-open { opacity: 1; transform: none; }
.aica-root.aica-preview .aica-icon-close { opacity: 0; }
.aica-root.aica-preview .aica-launcher-label { display: none; }
.aica-root.aica-preview .aica-msg { animation: none; }
.aica-root.aica-preview .aica-chip { animation: none; }

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */

@keyframes aica-pop {
	0%   { transform: scale(0.3); opacity: 0; }
	100% { transform: scale(1);   opacity: 1; }
}

@keyframes aica-badge-in {
	0%   { transform: scale(0); }
	100% { transform: scale(1); }
}

@keyframes aica-pulse {
	0%   { box-shadow: 0 0 0 0 var(--aica-primary); opacity: 0.7; }
	100% { box-shadow: 0 0 0 22px var(--aica-primary); opacity: 0; }
}

@keyframes aica-label-in {
	0%   { opacity: 0; transform: translateX(12px) scale(0.9); }
	100% { opacity: 1; transform: none; }
}

@keyframes aica-label-in-left {
	0%   { opacity: 0; transform: translateX(-12px) scale(0.9); }
	100% { opacity: 1; transform: none; }
}

@keyframes aica-msg-in {
	0%   { opacity: 0; transform: translateY(10px) scale(0.97); }
	100% { opacity: 1; transform: none; }
}

@keyframes aica-chip-in {
	0%   { opacity: 0; transform: translateY(8px); }
	100% { opacity: 1; transform: none; }
}

@keyframes aica-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
	30%           { transform: translateY(-5px); opacity: 1; }
}

@keyframes aica-dot {
	0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
	100% { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); }
}

@media (prefers-reduced-motion: reduce) {
	.aica-root *,
	.aica-root *::before,
	.aica-root *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}
