/**
 * AI Virtual Assistant Frontend Stylesheet
 * Scoped strictly to avoid interfering with any theme.
 */

:root {
	--aiva-primary: #0066cc;
	--aiva-secondary: #004c99;
	--aiva-header-bg: #0066cc;
	--aiva-header-text: #ffffff;
	--aiva-user-msg-bg: #0066cc;
	--aiva-user-msg-color: #ffffff;
	--aiva-bot-msg-bg: #f1f5f9;
	--aiva-bot-msg-color: #1e293b;
	--aiva-window-bg: #ffffff;
	--aiva-chat-width: 390px;
	--aiva-chat-height: 600px;
	--aiva-border-radius: 18px;
	--aiva-font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	--aiva-font-size: 14px;
	--aiva-btn-size: 60px;
	--aiva-pos-x: 24px;
	--aiva-pos-y: 24px;
	--aiva-shadow: 0 12px 36px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.08);
}

.aiva-root {
	position: fixed;
	z-index: 999999;
	font-family: var(--aiva-font-family);
	font-size: var(--aiva-font-size);
	line-height: 1.5;
	box-sizing: border-box;
	color: #334155;
	-webkit-font-smoothing: antialiased;
}

.aiva-root *,
.aiva-root *::before,
.aiva-root *::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

/* Positions */
.aiva-pos-bottom-right {
	bottom: var(--aiva-pos-y);
	right: var(--aiva-pos-x);
}

.aiva-pos-bottom-left {
	bottom: var(--aiva-pos-y);
	left: var(--aiva-pos-x);
}

/* Welcome Tooltip Bubble */
.aiva-welcome-bubble {
	position: absolute;
	bottom: calc(var(--aiva-btn-size) + 14px);
	right: 0;
	background: #ffffff;
	border-radius: 12px;
	padding: 12px 32px 12px 14px;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
	max-width: 250px;
	animation: aivaFadeUp 0.3s ease-out;
	cursor: pointer;
	border: 1px solid rgba(0, 0, 0, 0.06);
	z-index: 10;
}

.aiva-pos-bottom-left .aiva-welcome-bubble {
	right: auto;
	left: 0;
}

.aiva-bubble-content {
	display: block;
}

.aiva-bubble-text {
	display: block;
	width: 100%;
	font-size: 13px;
	font-weight: 500;
	line-height: 1.4;
	color: #1e293b;
	white-space: normal;
	word-break: normal;
	overflow-wrap: break-word;
}

.aiva-bubble-close {
	all: unset;
	box-sizing: border-box;
	position: absolute;
	top: 10px;
	right: 10px;
	width: 18px;
	height: 18px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 15px;
	line-height: 1;
	color: #94a3b8;
	cursor: pointer;
}

.aiva-bubble-close:hover {
	color: #475569;
}

.aiva-bubble-arrow {
	position: absolute;
	bottom: -6px;
	right: 22px;
	width: 12px;
	height: 12px;
	background: #ffffff;
	transform: rotate(45deg);
	border-right: 1px solid rgba(0, 0, 0, 0.06);
	border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.aiva-pos-bottom-left .aiva-bubble-arrow {
	right: auto;
	left: 22px;
}

/* Floating Launcher Button */
.aiva-launcher {
	width: var(--aiva-btn-size);
	height: var(--aiva-btn-size);
	border-radius: 50%;
	background: var(--aiva-primary);
	color: #ffffff;
	border: none;
	box-shadow: 0 6px 20px rgba(0, 102, 204, 0.35);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
	outline: none;
}

.aiva-launcher:hover {
	transform: scale(1.08);
	box-shadow: 0 8px 24px rgba(0, 102, 204, 0.45);
}

.aiva-launcher:active {
	transform: scale(0.96);
}

.aiva-launcher-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.aiva-launcher .aiva-icon-close {
	display: none;
}

.aiva-root.aiva-is-open .aiva-launcher .aiva-icon-chat {
	display: none;
}

.aiva-root.aiva-is-open .aiva-launcher .aiva-icon-close {
	display: flex;
}

.aiva-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	background: #ef4444;
	color: #ffffff;
	font-size: 11px;
	font-weight: 700;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2px solid #ffffff;
}

/* Chat Window */
.aiva-window {
	position: absolute;
	bottom: calc(var(--aiva-btn-size) + 16px);
	right: 0;
	width: var(--aiva-chat-width);
	height: var(--aiva-chat-height);
	max-width: calc(100vw - 32px);
	max-height: calc(100vh - 100px);
	background: var(--aiva-window-bg);
	border-radius: var(--aiva-border-radius);
	box-shadow: var(--aiva-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: aivaScaleUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
	border: 1px solid rgba(0, 0, 0, 0.08);
}

.aiva-pos-bottom-left .aiva-window {
	right: auto;
	left: 0;
}

/* Header */
.aiva-header {
	background: var(--aiva-header-bg);
	color: var(--aiva-header-text);
	padding: 14px 18px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.aiva-header-info {
	display: flex;
	align-items: center;
	gap: 12px;
}

.aiva-avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	color: #ffffff;
	flex-shrink: 0;
}

.aiva-avatar img {
	width: 100%;
	height: 100%;
	border-radius: 50%;
	object-fit: cover;
}

.aiva-online-dot {
	position: absolute;
	bottom: 0;
	right: 0;
	width: 10px;
	height: 10px;
	background: #10b981;
	border: 2px solid var(--aiva-header-bg);
	border-radius: 50%;
}

.aiva-header-titles {
	display: flex;
	flex-direction: column;
}

.aiva-title {
	font-size: 15px;
	font-weight: 600;
	color: inherit;
	line-height: 1.2;
}

.aiva-status {
	font-size: 11px;
	opacity: 0.88;
}

.aiva-header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
}

.aiva-btn-icon {
	background: rgba(255, 255, 255, 0.15);
	border: none;
	color: inherit;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease;
}

.aiva-btn-icon:hover {
	background: rgba(255, 255, 255, 0.3);
}

/* Medical / Disclaimer Banner */
.aiva-disclaimer-banner {
	background: #fffbeb;
	color: #92400e;
	border-bottom: 1px solid #fef3c7;
	padding: 8px 12px;
	font-size: 11px;
	line-height: 1.35;
	display: flex;
	align-items: flex-start;
	gap: 8px;
	flex-shrink: 0;
}

.aiva-disclaimer-banner svg {
	flex-shrink: 0;
	margin-top: 2px;
	color: #d97706;
}

/* Messages Area */
.aiva-messages-area {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 14px;
	background: #f8fafc;
	scroll-behavior: smooth;
}

/* Message Bubbles */
.aiva-msg-row {
	display: flex;
	gap: 10px;
	max-width: 86%;
	animation: aivaFadeIn 0.2s ease-out;
}

.aiva-msg-user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

.aiva-msg-assistant {
	align-self: flex-start;
}

.aiva-msg-bubble {
	padding: 11px 15px;
	font-size: var(--aiva-font-size);
	line-height: 1.48;
	word-break: break-word;
}

.aiva-msg-user .aiva-msg-bubble {
	background: var(--aiva-user-msg-bg);
	color: var(--aiva-user-msg-color);
	border-radius: 16px 16px 4px 16px;
}

.aiva-msg-assistant .aiva-msg-bubble {
	background: var(--aiva-bot-msg-bg);
	color: var(--aiva-bot-msg-color);
	border-radius: 16px 16px 16px 4px;
	border: 1px solid rgba(0, 0, 0, 0.04);
}

/* Markdown formatting within messages */
.aiva-msg-bubble p {
	margin-bottom: 8px;
}
.aiva-msg-bubble p:last-child {
	margin-bottom: 0;
}
.aiva-msg-bubble strong {
	font-weight: 600;
}
.aiva-msg-bubble em {
	font-style: italic;
}
.aiva-msg-bubble ul,
.aiva-msg-bubble ol {
	margin: 6px 0 8px 18px;
}
.aiva-msg-bubble li {
	margin-bottom: 4px;
}
.aiva-msg-bubble a {
	color: var(--aiva-primary);
	text-decoration: underline;
	font-weight: 500;
}
.aiva-msg-user .aiva-msg-bubble a {
	color: #ffffff;
}
.aiva-msg-bubble h1,
.aiva-msg-bubble h2,
.aiva-msg-bubble h3,
.aiva-msg-bubble h4 {
	font-size: 14px;
	font-weight: 700;
	margin: 8px 0 4px 0;
}

/* Source Citations */
.aiva-sources-block {
	margin-top: 8px;
	padding-top: 6px;
	border-top: 1px solid rgba(0, 0, 0, 0.08);
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	align-items: center;
}

.aiva-sources-tag {
	font-size: 11px;
	font-weight: 600;
	color: #64748b;
	margin-right: 2px;
}

.aiva-source-pill {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: #ffffff;
	border: 1px solid #cbd5e1;
	border-radius: 12px;
	padding: 3px 8px;
	font-size: 11px;
	color: #2563eb;
	text-decoration: none;
	transition: background 0.15s ease, border-color 0.15s ease;
}

.aiva-source-pill:hover {
	background: #eff6ff;
	border-color: #93c5fd;
	text-decoration: none;
}

/* Message Feedback */
.aiva-msg-feedback {
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 4px;
	font-size: 11px;
	color: #94a3b8;
}

.aiva-btn-feedback {
	background: none;
	border: none;
	color: #94a3b8;
	cursor: pointer;
	padding: 2px;
	border-radius: 4px;
	transition: color 0.15s ease;
}

.aiva-btn-feedback:hover {
	color: #475569;
}

.aiva-btn-feedback.aiva-feedback-active {
	color: var(--aiva-primary);
}

/* Typing / Thinking Indicator */
.aiva-typing-indicator {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 8px 12px;
	background: #e2e8f0;
	border-radius: 14px;
	width: fit-content;
}

.aiva-typing-dot {
	width: 6px;
	height: 6px;
	background: #64748b;
	border-radius: 50%;
	animation: aivaBounce 1.4s infinite ease-in-out both;
}

.aiva-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.aiva-typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* Suggested Questions Chips */
.aiva-suggested-container {
	padding: 8px 14px 10px;
	background: #f8fafc;
	border-top: 1px solid rgba(0, 0, 0, 0.05);
	flex-shrink: 0;
}

.aiva-suggested-label {
	font-size: 11px;
	font-weight: 600;
	color: #64748b;
	margin-bottom: 6px;
}

.aiva-chips-scroll {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	max-height: 80px;
	overflow-y: auto;
}

.aiva-chip {
	background: #ffffff;
	border: 1px solid #cbd5e1;
	border-radius: 16px;
	padding: 5px 11px;
	font-size: 12px;
	color: #334155;
	cursor: pointer;
	transition: all 0.15s ease;
	text-align: left;
	line-height: 1.25;
}

.aiva-chip:hover {
	background: #f1f5f9;
	border-color: var(--aiva-primary);
	color: var(--aiva-primary);
}

/* Escalation Action Bar */
.aiva-escalation-bar {
	display: flex;
	gap: 6px;
	padding: 6px 14px;
	background: #f1f5f9;
	border-top: 1px solid rgba(0, 0, 0, 0.06);
	flex-shrink: 0;
	overflow-x: auto;
}

.aiva-btn-escalation {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: #ffffff;
	border: 1px solid #94a3b8;
	border-radius: 6px;
	padding: 5px 10px;
	font-size: 11px;
	font-weight: 500;
	color: #1e293b;
	text-decoration: none;
	white-space: nowrap;
	transition: all 0.15s ease;
}

.aiva-btn-escalation:hover {
	background: var(--aiva-primary);
	border-color: var(--aiva-primary);
	color: #ffffff;
}

/* Lead Capture Form Modal */
.aiva-lead-card {
	position: absolute;
	bottom: 60px;
	left: 12px;
	right: 12px;
	background: #ffffff;
	border-radius: 14px;
	padding: 16px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
	border: 1px solid rgba(0, 0, 0, 0.1);
	z-index: 20;
	animation: aivaFadeUp 0.25s ease-out;
}

.aiva-lead-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 4px;
}

.aiva-lead-header h4 {
	font-size: 14px;
	font-weight: 600;
	color: #1e293b;
}

.aiva-btn-close-lead {
	background: none;
	border: none;
	font-size: 18px;
	color: #94a3b8;
	cursor: pointer;
}

.aiva-lead-subtitle {
	font-size: 12px;
	color: #64748b;
	margin-bottom: 12px;
}

.aiva-form-group {
	margin-bottom: 8px;
}

.aiva-form-group input,
.aiva-form-group textarea {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid #cbd5e1;
	border-radius: 8px;
	font-size: 12px;
	font-family: inherit;
	color: #1e293b;
	outline: none;
	transition: border-color 0.15s ease;
}

.aiva-form-group input:focus,
.aiva-form-group textarea:focus {
	border-color: var(--aiva-primary);
	box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.15);
}

.aiva-btn-submit-lead {
	width: 100%;
	padding: 9px;
	background: var(--aiva-primary);
	color: #ffffff;
	border: none;
	border-radius: 8px;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease;
}

.aiva-btn-submit-lead:hover {
	background: var(--aiva-secondary);
}

/* Footer & Input */
.aiva-footer {
	background: #ffffff;
	border-top: 1px solid rgba(0, 0, 0, 0.08);
	padding: 10px 14px 8px;
	flex-shrink: 0;
}

.aiva-input-container {
	display: flex;
	align-items: center;
	gap: 8px;
	background: #f1f5f9;
	border-radius: 24px;
	padding: 4px 6px 4px 14px;
	border: 1px solid transparent;
	transition: border-color 0.15s ease, background 0.15s ease;
}

.aiva-input-container:focus-within {
	background: #ffffff;
	border-color: var(--aiva-primary);
	box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.15);
}

.aiva-input {
	flex: 1;
	border: none;
	background: transparent;
	font-family: inherit;
	font-size: var(--aiva-font-size);
	color: #1e293b;
	outline: none;
	resize: none;
	max-height: 90px;
	padding: 6px 0;
	line-height: 1.35;
}

.aiva-send-btn {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: var(--aiva-primary);
	color: #ffffff;
	border: none;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: opacity 0.15s ease, transform 0.15s ease;
	flex-shrink: 0;
}

.aiva-send-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.aiva-send-btn:not(:disabled):hover {
	transform: scale(1.06);
}

.aiva-powered-by {
	text-align: center;
	font-size: 10px;
	color: #94a3b8;
	margin-top: 6px;
}

.aiva-powered-by a {
	color: inherit;
	text-decoration: none;
}

.aiva-powered-by a:hover {
	text-decoration: underline;
}

/* Layout Variations */
.aiva-layout-minimal .aiva-window {
	border-radius: 8px;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.aiva-layout-minimal .aiva-header {
	background: #ffffff;
	color: #1e293b;
	border-bottom: 1px solid #e2e8f0;
}
.aiva-layout-minimal .aiva-avatar {
	background: #e2e8f0;
	color: #475569;
}
.aiva-layout-minimal .aiva-btn-icon {
	background: #f1f5f9;
	color: #475569;
}

.aiva-layout-corporate-professional .aiva-window {
	border-radius: 12px;
	border: 1px solid #0f172a;
}
.aiva-layout-corporate-professional .aiva-header {
	background: #0f172a;
}

/* Responsive & Fullscreen Mobile */
@media (max-width: 768px) {
	.aiva-window,
	.aiva-layout-fullscreen-mobile .aiva-window {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100vw !important;
		height: 100vh !important;
		max-width: 100vw !important;
		max-height: 100vh !important;
		border-radius: 0 !important;
		z-index: 1000000;
	}

	.aiva-welcome-bubble {
		display: none !important;
	}
}

/* Keyframes */
@keyframes aivaFadeIn {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: translateY(0); }
}

@keyframes aivaFadeUp {
	from { opacity: 0; transform: translateY(12px); }
	to { opacity: 1; transform: translateY(0); }
}

@keyframes aivaScaleUp {
	from { opacity: 0; transform: scale(0.92) translateY(16px); }
	to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes aivaBounce {
	0%, 80%, 100% { transform: scale(0); }
	40% { transform: scale(1); }
}
