/**
 * Chat Widget CSS v12.7.0 - Modern AI Chat Interface with Dynamic Colors
 * Inspired by ChatGPT, Gemini, and modern chat interfaces
 */

/* CSS Custom Properties for Dynamic Theming */
:root {
	--aisa-primary-color: #667eea;
	--aisa-secondary-color: #764ba2;
	--aisa-header-bg: #1a202c;
	--aisa-user-msg-bg: #667eea;
	--aisa-user-msg-text: #ffffff;
	--aisa-ai-msg-bg: #2d3748;
	--aisa-ai-msg-text: #e2e8f0;
	--aisa-button-color: #667eea;
	--aisa-button-text: #ffffff;
	--aisa-input-bg: #2d3748;
	--aisa-input-text: #e2e8f0;
	--aisa-input-border: #4a5568;
}

/* Reset & Base */
* {
	box-sizing: border-box;
}

/* Main Widget Container */
.aisa-chat-widget {
	position: fixed;
	bottom: 100px;
	right: 20px;
	width: 350px;
	height: 500px;
	border-radius: 12px;
	box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
	display: flex;
	flex-direction: column;
	background: #ffffff;
	z-index: 99999;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
	font-size: 14px;
	color: #374151;
	animation: slideInUp 0.3s ease-out;
	transition: all 0.3s ease;
	overflow: hidden;
	pointer-events: auto;
}

/* Force fixed positioning - never change on scroll */
html.aisa-chat-fixed .aisa-chat-widget {
	position: fixed !important;
	bottom: 100px !important;
	right: 20px !important;
	will-change: transform;
}

/* Minimized State */
.aisa-chat-widget.minimized {
	height: 60px;
	width: 60px;
	bottom: 100px;
	right: 20px;
	border-radius: 50%;
	box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
	animation: minimizedBounce 2s ease-in-out infinite;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	overflow: hidden;
	display: flex !important;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.aisa-chat-widget.minimized .aisa-chat-body {
	display: none !important;
	visibility: hidden !important;
	height: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
}

.aisa-chat-widget.minimized .aisa-chat-input {
	display: none !important;
	visibility: hidden !important;
	height: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
}

/* When NOT minimized (expanded), show them */
.aisa-chat-widget:not(.minimized) .aisa-chat-body {
	display: flex !important;
	visibility: visible !important;
	height: auto !important;
}

.aisa-chat-widget:not(.minimized) .aisa-chat-input {
	display: flex !important;
	visibility: visible !important;
	height: auto !important;
}

@keyframes minimizedBounce {
	0%, 100% {
		transform: translateY(0);
		box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
	}
	50% {
		transform: translateY(-8px);
		box-shadow: 0 8px 20px rgba(102, 126, 234, 0.6);
	}
}

/* Hidden State */
.aisa-chat-widget.hidden {
	display: none;
}

/* Animations */
@keyframes slideInUp {
	from {
		opacity: 0;
		transform: translateY(20px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@keyframes fadeIn {
	from { opacity: 0; }
	to { opacity: 1; }
}

/* ===========================
   HEADER SECTION
   =========================== */

.aisa-chat-header {
	background: linear-gradient(135deg, var(--aisa-primary-color) 0%, var(--aisa-secondary-color) 100%);
	color: white;
	padding: 16px;
	border-radius: 12px 12px 0 0;
	font-weight: 600;
	font-size: 15px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	flex-shrink: 0;
	transition: all 0.3s ease;
}

.aisa-chat-widget.minimized .aisa-chat-header {
	border-radius: 50%;
	width: 60px;
	height: 60px;
	padding: 0;
	justify-content: center;
	align-items: center;
	cursor: pointer;
	flex-direction: column;
	background: linear-gradient(135deg, var(--aisa-primary-color) 0%, var(--aisa-secondary-color) 100%);
	box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
	overflow: hidden;
}

.aisa-chat-widget.minimized .aisa-chat-header-title {
	display: none !important;
	visibility: hidden !important;
	width: 0;
	height: 0;
	margin: 0;
	padding: 0;
}

.aisa-chat-widget.minimized .aisa-chat-controls {
	display: none !important;
	visibility: hidden !important;
	width: 0;
	height: 0;
	margin: 0;
	padding: 0;
}

/* Show only the chat icon when minimized */
.aisa-chat-widget.minimized .aisa-chat-header {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
}

.aisa-chat-widget.minimized .aisa-chat-header::before {
	content: '💬';
	font-size: 28px;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: 100%;
	height: 100%;
	line-height: 1 !important;
	text-align: center;
	margin: 0 !important;
	padding: 0 !important;
	animation: chatIconPulse 2.5s ease-in-out infinite;
	position: relative;
	top: 0;
	left: 0;
}

@keyframes chatIconPulse {
	0%, 100% {
		transform: scale(1);
		opacity: 1;
	}
	50% {
		transform: scale(1.15);
		opacity: 0.8;
	}
}

/* Behavior Badge - HIDE IN MINIMIZED STATE */
.aisa-behavior-badge {
	display: none !important;
	visibility: hidden !important;
	width: 0 !important;
	height: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	overflow: hidden !important;
	font-size: 0 !important;
}

.aisa-chat-header-title {
	display: flex;
	align-items: center;
	gap: 8px;
	flex: 1;
	font-weight: 600;
	font-size: 15px;
}

.aisa-chat-header-title::before {
	content: '💬';
	font-size: 18px;
}

.aisa-chat-widget.minimized .aisa-chat-header-title {
	display: none;
}

.aisa-chat-widget.minimized .aisa-chat-header-title.icon-only {
	display: flex;
	justify-content: center;
	align-items: center;
}

.aisa-chat-widget.minimized .aisa-chat-header-title.icon-only::before {
	font-size: 28px;
	content: '💬';
}

/* Control Buttons */
.aisa-chat-controls {
	display: flex;
	gap: 6px;
	align-items: center;
}

.aisa-chat-btn {
	background: rgba(255, 255, 255, 0.2);
	border: none;
	color: white;
	cursor: pointer;
	padding: 6px 10px;
	border-radius: 6px;
	font-size: 14px;
	font-weight: 600;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 28px;
	height: 28px;
}

.aisa-chat-btn:hover {
	background: rgba(255, 255, 255, 0.3);
	transform: scale(1.05);
}

.aisa-chat-btn:active {
	transform: scale(0.95);
}

.aisa-chat-widget.minimized .aisa-chat-controls {
	display: none;
}

/* ===========================
   CHAT MESSAGES AREA
   =========================== */

.aisa-chat-body {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #ffffff;
	animation: fadeIn 0.3s ease;
}

.aisa-chat-body::-webkit-scrollbar {
	width: 6px;
}

.aisa-chat-body::-webkit-scrollbar-track {
	background: #f3f4f6;
	border-radius: 10px;
}

.aisa-chat-body::-webkit-scrollbar-thumb {
	background: #d1d5db;
	border-radius: 10px;
	transition: background 0.2s;
}

.aisa-chat-body::-webkit-scrollbar-thumb:hover {
	background: #9ca3af;
}

/* Message Container */
.aisa-message {
	display: flex;
	gap: 8px;
	animation: slideInUp 0.3s ease;
	animation-fill-mode: both;
}

.aisa-message.user {
	justify-content: flex-end;
	animation-delay: 0s;
}

.aisa-message.assistant {
	justify-content: flex-start;
	animation-delay: 0.05s;
}

/* Message Bubble */
.aisa-message-bubble {
	max-width: 75%;
	padding: 10px 14px;
	border-radius: 12px;
	word-wrap: break-word;
	line-height: 1.4;
	font-size: 14px;
}

.aisa-message.user .aisa-message-bubble {
	background: linear-gradient(135deg, var(--aisa-user-msg-bg) 0%, var(--aisa-secondary-color) 100%);
	color: var(--aisa-user-msg-text);
	border-bottom-right-radius: 4px;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.aisa-message.assistant .aisa-message-bubble {
	background: var(--aisa-ai-msg-bg);
	color: var(--aisa-ai-msg-text);
	border-bottom-left-radius: 4px;
	border: 1px solid #4a5568;
}

.aisa-message-bubble p {
	margin: 0;
	white-space: pre-wrap;
}

.aisa-message-bubble p:not(:last-child) {
	margin-bottom: 8px;
}

/* Loading Indicator */
.aisa-message-loading {
	display: flex;
	gap: 4px;
	align-items: center;
	padding: 10px 14px;
	background: #f3f4f6;
	border-radius: 12px;
	border-bottom-left-radius: 4px;
}

.aisa-loading-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #9ca3af;
	animation: bounce 1.4s infinite;
}

.aisa-loading-dot:nth-child(2) {
	animation-delay: 0.2s;
}

.aisa-loading-dot:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes bounce {
	0%, 80%, 100% { opacity: 0.5; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-6px); }
}

/* ===========================
   INPUT AREA
   =========================== */

.aisa-chat-input {
	display: flex;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid #e5e7eb;
	background: #ffffff;
	flex-shrink: 0;
}

.aisa-chat-input input {
	flex: 1;
	border: 1px solid #d1d5db;
	border-radius: 8px;
	padding: 10px 14px;
	font-size: 14px;
	font-family: inherit;
	color: #374151;
	transition: all 0.2s ease;
	outline: none;
}

.aisa-chat-input input::placeholder {
	color: #9ca3af;
}

.aisa-chat-input input:focus {
	border-color: var(--aisa-primary-color);
	box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
	background: #f9fafb;
}

.aisa-send-btn {
	width: 36px;
	height: 36px;
	border: none;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: white;
	border-radius: 8px;
	cursor: pointer;
	font-size: 16px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s ease;
	flex-shrink: 0;
}

.aisa-send-btn::after {
	content: '→';
	font-weight: 600;
}

.aisa-send-btn:hover:not(:disabled) {
	transform: translateY(-2px);
	box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.aisa-send-btn:active:not(:disabled) {
	transform: translateY(0);
}

.aisa-send-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* ===========================
   LEAD FORM
   =========================== */

.aisa-lead-form {
	padding: 16px;
	background: #f9fafb;
	border-top: 1px solid #e5e7eb;
	border-radius: 0 0 12px 12px;
	animation: slideInUp 0.3s ease;
}

.aisa-lead-form h3 {
	margin: 0 0 12px 0;
	font-size: 14px;
	font-weight: 600;
	color: #374151;
}

.aisa-form-group {
	margin-bottom: 10px;
}

.aisa-form-group:last-child {
	margin-bottom: 0;
}

.aisa-form-group label {
	display: block;
	font-size: 12px;
	font-weight: 500;
	color: #6b7280;
	margin-bottom: 4px;
}

.aisa-form-group input,
.aisa-form-group textarea {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	font-size: 13px;
	font-family: inherit;
	color: #374151;
	transition: all 0.2s ease;
	outline: none;
}

.aisa-form-group input::placeholder,
.aisa-form-group textarea::placeholder {
	color: #9ca3af;
}

.aisa-form-group input:focus,
.aisa-form-group textarea:focus {
	border-color: #667eea;
	box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
	background: white;
}

.aisa-form-submit {
	width: 100%;
	padding: 10px;
	background: linear-gradient(135deg, var(--aisa-primary-color) 0%, var(--aisa-secondary-color) 100%);
	color: white;
	border: none;
	border-radius: 6px;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.2s ease;
	margin-top: 8px;
}

.aisa-form-submit:hover {
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.aisa-form-submit:active {
	transform: translateY(0);
}

/* ===========================
   MOBILE RESPONSIVE
   =========================== */

@media (max-width: 480px) {
	.aisa-chat-widget {
		width: 100vw;
		height: 100vh;
		bottom: 0;
		right: 0;
		left: 0;
		top: 0;
		border-radius: 0;
		max-width: 100vw;
		max-height: 100vh;
		position: fixed;
		display: flex;
		flex-direction: column;
		z-index: 999999;
	}

	.aisa-chat-widget.minimized {
		width: 60px;
		height: 60px;
		bottom: 20px;
		right: 20px;
		left: auto;
		top: auto;
		border-radius: 50%;
		max-width: 60px;
		max-height: 60px;
		display: flex !important;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.aisa-chat-widget.minimized .aisa-chat-body {
		display: none !important;
	}

	.aisa-chat-widget.minimized .aisa-chat-input {
		display: none !important;
	}

	.aisa-chat-body {
		padding: 12px;
		gap: 10px;
		flex: 1;
		overflow-y: auto;
	}

	.aisa-message-bubble {
		max-width: 85%;
	}

	.aisa-chat-input {
		padding: 10px;
		gap: 6px;
		border-top: 1px solid #e5e7eb;
	}

	.aisa-chat-input input {
		padding: 9px 12px;
		font-size: 13px;
	}

	.aisa-send-btn {
		width: 32px;
		height: 32px;
	}

	.aisa-chat-header {
		padding: 12px;
		font-size: 14px;
		border-radius: 0;
		flex-shrink: 0;
	}

	.aisa-chat-widget.minimized .aisa-chat-header {
		border-radius: 50%;
		width: 60px;
		height: 60px;
		padding: 0;
	}

	.aisa-chat-header-title::before {
		font-size: 16px;
	}
}

/* ===========================
   DARK MODE SUPPORT
   =========================== */

@media (prefers-color-scheme: dark) {
	.aisa-chat-widget {
		background: #1f2937;
		color: #e5e7eb;
	}

	.aisa-chat-header {
		background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	}

	.aisa-chat-body {
		background: #1f2937;
	}

	.aisa-chat-body::-webkit-scrollbar-track {
		background: #374151;
	}

	.aisa-chat-body::-webkit-scrollbar-thumb {
		background: #6b7280;
	}

	.aisa-chat-body::-webkit-scrollbar-thumb:hover {
		background: #9ca3af;
	}

	.aisa-message.assistant .aisa-message-bubble {
		background: #374151;
		color: #e5e7eb;
		border-color: #4b5563;
	}

	.aisa-message-loading {
		background: #374151;
	}

	.aisa-loading-dot {
		background: #6b7280;
	}

	.aisa-chat-input {
		border-top-color: #4b5563;
		background: #1f2937;
	}

	.aisa-chat-input input {
		border-color: #4b5563;
		background: #374151;
		color: #e5e7eb;
	}

	.aisa-chat-input input::placeholder {
		color: #9ca3af;
	}

	.aisa-chat-input input:focus {
		border-color: #667eea;
		box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
		background: #4b5563;
	}

	.aisa-lead-form {
		background: #374151;
		border-top-color: #4b5563;
	}

	.aisa-lead-form h3 {
		color: #e5e7eb;
	}

	.aisa-form-group label {
		color: #9ca3af;
	}

	.aisa-form-group input,
	.aisa-form-group textarea {
		background: #4b5563;
		border-color: #6b7280;
		color: #e5e7eb;
	}

	.aisa-form-group input::placeholder,
	.aisa-form-group textarea::placeholder {
		color: #9ca3af;
	}

	.aisa-form-group input:focus,
	.aisa-form-group textarea:focus {
		border-color: #667eea;
		box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
		background: #374151;
	}
}

/* ===========================
   ACCESSIBILITY
   =========================== */

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

/* Focus Visible for Keyboard Navigation */
.aisa-chat-btn:focus-visible,
.aisa-send-btn:focus-visible,
.aisa-chat-input input:focus-visible {
	outline: 2px solid #667eea;
	outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: more) {
	.aisa-message.user .aisa-message-bubble {
		border: 2px solid #667eea;
	}

	.aisa-message.assistant .aisa-message-bubble {
		border: 2px solid #374151;
	}

	.aisa-chat-input input {
		border-width: 2px;
	}

	.aisa-chat-btn,
	.aisa-send-btn {
		border: 2px solid currentColor;
	}
}
