/**
 * WP AI Chatbot - Frontend styles.
 *
 * @package WP_AI_Chatbot
 */

/* Container */
.wpaic-chatbot {
	display: flex;
	flex-direction: column;
	max-width: 720px;
	height: 600px;
	margin: 1rem auto;
	border: 1px solid #e0e0e0;
	border-radius: 12px;
	background: #ffffff;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
		Ubuntu, Cantarell, sans-serif;
	overflow: hidden;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* Header */
.wpaic-chat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background: #1a1a2e;
	color: #ffffff;
	flex-shrink: 0;
}

.wpaic-chat-title {
	font-size: 15px;
	font-weight: 600;
}

.wpaic-chat-mode {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	padding: 3px 8px;
	background: rgba(255, 255, 255, 0.15);
	border-radius: 4px;
}

/* Messages area */
.wpaic-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #fafafa;
}

.wpaic-chat-messages::-webkit-scrollbar {
	width: 6px;
}

.wpaic-chat-messages::-webkit-scrollbar-track {
	background: transparent;
}

.wpaic-chat-messages::-webkit-scrollbar-thumb {
	background: #ccc;
	border-radius: 3px;
}

/* Messages */
.wpaic-message {
	display: flex;
	gap: 10px;
	max-width: 85%;
	animation: wpaic-fade-in 0.2s ease;
}

.wpaic-message-user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

.wpaic-message-assistant {
	align-self: flex-start;
}

.wpaic-message-avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 12px;
	font-weight: 700;
	flex-shrink: 0;
}

.wpaic-message-user .wpaic-message-avatar {
	background: #4a90d9;
	color: #fff;
}

.wpaic-message-assistant .wpaic-message-avatar {
	background: #1a1a2e;
	color: #fff;
}

.wpaic-message-content {
	padding: 10px 14px;
	border-radius: 12px;
	font-size: 14px;
	line-height: 1.6;
	word-break: break-word;
}

.wpaic-message-user .wpaic-message-content {
	background: #4a90d9;
	color: #fff;
	border-bottom-right-radius: 4px;
}

.wpaic-message-assistant .wpaic-message-content {
	background: #ffffff;
	color: #333;
	border: 1px solid #e0e0e0;
	border-bottom-left-radius: 4px;
}

/* Markdown elements inside assistant messages */
.wpaic-message-assistant .wpaic-message-content p {
	margin: 0 0 8px 0;
}

.wpaic-message-assistant .wpaic-message-content p:last-child {
	margin-bottom: 0;
}

.wpaic-message-assistant .wpaic-message-content code {
	background: #f0f0f0;
	padding: 2px 5px;
	border-radius: 3px;
	font-size: 13px;
	font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

.wpaic-message-assistant .wpaic-message-content pre {
	background: #1e1e1e;
	color: #d4d4d4;
	padding: 12px;
	border-radius: 8px;
	overflow-x: auto;
	margin: 8px 0;
}

.wpaic-message-assistant .wpaic-message-content pre code {
	background: none;
	padding: 0;
	color: inherit;
	font-size: 13px;
}

.wpaic-message-assistant .wpaic-message-content h2,
.wpaic-message-assistant .wpaic-message-content h3,
.wpaic-message-assistant .wpaic-message-content h4 {
	margin: 12px 0 6px 0;
	font-size: 15px;
}

.wpaic-message-assistant .wpaic-message-content ul,
.wpaic-message-assistant .wpaic-message-content ol {
	margin: 4px 0;
	padding-left: 20px;
}

.wpaic-message-assistant .wpaic-message-content li {
	margin-bottom: 4px;
}

.wpaic-message-assistant .wpaic-message-content a {
	color: #4a90d9;
	text-decoration: underline;
}

/* RAG Sources */
.wpaic-sources {
	width: 100%;
	margin-top: 8px;
	padding-left: 42px;
}

.wpaic-sources-toggle {
	background: none;
	border: 1px solid #d0d0d0;
	border-radius: 6px;
	padding: 5px 12px;
	font-size: 12px;
	color: #666;
	cursor: pointer;
	transition: all 0.2s;
}

.wpaic-sources-toggle:hover {
	background: #f5f5f5;
	border-color: #bbb;
}

.wpaic-sources-toggle.wpaic-sources-open {
	background: #f0f0f0;
}

.wpaic-sources-list {
	margin-top: 8px;
	border-left: 3px solid #4a90d9;
	padding-left: 12px;
}

.wpaic-source-item {
	margin-bottom: 10px;
	padding: 8px;
	background: #fff;
	border: 1px solid #eee;
	border-radius: 6px;
	font-size: 12px;
}

.wpaic-source-score {
	display: inline-block;
	background: #e8f4fd;
	color: #2a6fa8;
	padding: 2px 6px;
	border-radius: 3px;
	font-weight: 600;
	font-size: 11px;
	margin-bottom: 4px;
}

.wpaic-source-text {
	margin: 4px 0;
	color: #555;
	line-height: 1.4;
}

.wpaic-source-meta {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	margin-top: 4px;
}

.wpaic-source-meta span {
	font-size: 11px;
	color: #888;
	background: #f5f5f5;
	padding: 1px 5px;
	border-radius: 3px;
}

/* Input area */
.wpaic-chat-input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px;
	border-top: 1px solid #e0e0e0;
	background: #ffffff;
	flex-shrink: 0;
}

.wpaic-chat-input {
	flex: 1;
	border: 1px solid #d0d0d0;
	border-radius: 8px;
	padding: 10px 12px;
	font-size: 14px;
	line-height: 1.4;
	resize: none;
	outline: none;
	font-family: inherit;
	max-height: 120px;
	transition: border-color 0.2s;
}

.wpaic-chat-input:focus {
	border-color: #4a90d9;
	box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.15);
}

.wpaic-chat-input:disabled {
	opacity: 0.6;
}

.wpaic-chat-send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	background: #1a1a2e;
	color: #fff;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	transition: background 0.2s;
	flex-shrink: 0;
}

.wpaic-chat-send:hover {
	background: #2d2d4e;
}

.wpaic-chat-send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* Loading indicator */
.wpaic-loading {
	display: flex;
	align-items: center;
	padding: 8px 0;
}

.wpaic-loading-dots {
	display: flex;
	gap: 4px;
	padding-left: 42px;
}

.wpaic-loading-dots span {
	width: 8px;
	height: 8px;
	background: #aaa;
	border-radius: 50%;
	animation: wpaic-bounce 1.4s infinite ease-in-out both;
}

.wpaic-loading-dots span:nth-child(1) {
	animation-delay: -0.32s;
}

.wpaic-loading-dots span:nth-child(2) {
	animation-delay: -0.16s;
}

/* Error message */
.wpaic-error {
	padding: 8px 12px;
	background: #fef2f2;
	color: #b91c1c;
	border: 1px solid #fecaca;
	border-radius: 6px;
	font-size: 13px;
	transition: opacity 0.5s;
}

.wpaic-error-fade {
	opacity: 0;
}

/* Login required */
.wpaic-login-required {
	max-width: 720px;
	margin: 1rem auto;
	padding: 20px;
	background: #fefce8;
	border: 1px solid #fde68a;
	border-radius: 8px;
	text-align: center;
	color: #92400e;
	font-size: 14px;
}

/* Admin test results */
.wpaic-test-result {
	margin-left: 10px;
	font-size: 13px;
}

.wpaic-test-success {
	color: #16a34a;
	font-weight: 600;
}

.wpaic-test-error {
	color: #dc2626;
	font-weight: 600;
}

/* Animations */
@keyframes wpaic-fade-in {
	from {
		opacity: 0;
		transform: translateY(4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

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

/* =====================================================
   RAG MODE - Wrapper with Sidebar
   ===================================================== */

.wpaic-rag-wrapper {
	display: flex;
	gap: 20px;
	max-width: 1200px;
	margin: 1rem auto;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
		Ubuntu, Cantarell, sans-serif;
}

.wpaic-rag-wrapper .wpaic-chatbot {
	flex: 1;
	max-width: none;
	margin: 0;
}

/* Sidebar */
.wpaic-rag-sidebar {
	width: 300px;
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.wpaic-rag-sidebar h4 {
	margin: 0 0 10px 0;
	font-size: 14px;
	font-weight: 600;
	color: #1a1a2e;
}

/* Status Section */
.wpaic-rag-status {
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 10px;
	padding: 14px;
}

.wpaic-status-item {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 0;
	font-size: 13px;
}

.wpaic-status-indicator {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: #d1d5db;
	flex-shrink: 0;
}

.wpaic-status-indicator.wpaic-status-ok {
	background: #22c55e;
	box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.wpaic-status-indicator.wpaic-status-error {
	background: #ef4444;
	box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.wpaic-status-label {
	font-weight: 500;
	color: #374151;
	min-width: 70px;
}

.wpaic-status-message {
	color: #6b7280;
	font-size: 12px;
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.wpaic-refresh-status {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	width: 100%;
	margin-top: 10px;
	padding: 8px 12px;
	background: #f3f4f6;
	border: 1px solid #e5e7eb;
	border-radius: 6px;
	font-size: 12px;
	color: #374151;
	cursor: pointer;
	transition: all 0.2s;
}

.wpaic-refresh-status:hover {
	background: #e5e7eb;
	border-color: #d1d5db;
}

.wpaic-refresh-status svg {
	flex-shrink: 0;
}

/* Upload Section */
.wpaic-rag-upload {
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 10px;
	padding: 14px;
}

.wpaic-upload-hint {
	margin: 0 0 10px 0;
	font-size: 11px;
	color: #6b7280;
}

.wpaic-upload-dropzone {
	position: relative;
	border: 2px dashed #d1d5db;
	border-radius: 8px;
	padding: 20px;
	text-align: center;
	cursor: pointer;
	transition: all 0.2s;
	background: #fafafa;
}

.wpaic-upload-dropzone:hover,
.wpaic-upload-dropzone.wpaic-dropzone-active {
	border-color: #4a90d9;
	background: #f0f7ff;
}

.wpaic-file-input {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	cursor: pointer;
}

.wpaic-dropzone-content {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	pointer-events: none;
}

.wpaic-dropzone-content svg {
	color: #9ca3af;
}

.wpaic-dropzone-content span {
	font-size: 12px;
	color: #6b7280;
}

/* Upload Progress */
.wpaic-upload-progress {
	margin-top: 12px;
}

.wpaic-progress-bar {
	height: 6px;
	background: #e5e7eb;
	border-radius: 3px;
	overflow: hidden;
}

.wpaic-progress-fill {
	height: 100%;
	background: linear-gradient(90deg, #4a90d9, #3b82f6);
	border-radius: 3px;
	transition: width 0.3s ease;
}

.wpaic-progress-text {
	display: block;
	margin-top: 6px;
	font-size: 11px;
	color: #6b7280;
	text-align: center;
}

/* Upload Result */
.wpaic-upload-result {
	margin-top: 10px;
	padding: 8px 10px;
	border-radius: 6px;
	font-size: 12px;
}

.wpaic-upload-success {
	background: #dcfce7;
	color: #166534;
	border: 1px solid #bbf7d0;
}

.wpaic-upload-error {
	background: #fef2f2;
	color: #b91c1c;
	border: 1px solid #fecaca;
}

/* Documents Section */
.wpaic-rag-documents {
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 10px;
	padding: 14px;
	flex: 1;
	min-height: 150px;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.wpaic-rag-documents h4 {
	display: flex;
	align-items: center;
	gap: 6px;
}

.wpaic-doc-count {
	font-weight: 400;
	color: #6b7280;
	font-size: 12px;
}

.wpaic-documents-list {
	flex: 1;
	overflow-y: auto;
	margin-top: 8px;
}

.wpaic-doc-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 8px 10px;
	background: #f9fafb;
	border-radius: 6px;
	margin-bottom: 6px;
	font-size: 12px;
}

.wpaic-doc-name {
	font-weight: 500;
	color: #374151;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	max-width: 180px;
}

.wpaic-doc-chunks {
	color: #6b7280;
	font-size: 11px;
	flex-shrink: 0;
}

.wpaic-docs-loading,
.wpaic-docs-empty,
.wpaic-docs-error {
	padding: 20px;
	text-align: center;
	color: #6b7280;
	font-size: 12px;
}

.wpaic-docs-error {
	color: #b91c1c;
}

/* Responsive */
@media (max-width: 900px) {
	.wpaic-rag-wrapper {
		flex-direction: column;
		padding: 0 10px;
	}

	.wpaic-rag-sidebar {
		width: 100%;
		flex-direction: row;
		flex-wrap: wrap;
	}

	.wpaic-rag-status,
	.wpaic-rag-upload {
		flex: 1;
		min-width: 200px;
	}

	.wpaic-rag-documents {
		width: 100%;
		min-height: 100px;
	}

	.wpaic-rag-wrapper .wpaic-chatbot {
		height: 450px;
	}
}

@media (max-width: 768px) {
	.wpaic-chatbot {
		height: 500px;
		margin: 0.5rem;
		border-radius: 8px;
	}

	.wpaic-message {
		max-width: 92%;
	}

	.wpaic-chat-messages {
		padding: 12px;
	}

	.wpaic-sources {
		padding-left: 0;
	}

	.wpaic-rag-sidebar {
		flex-direction: column;
	}

	.wpaic-rag-status,
	.wpaic-rag-upload,
	.wpaic-rag-documents {
		width: 100%;
	}
}
