/**
 * MrPotter AI Chat Widget – Styles
 * Version: 1.0.0
 */

/* ========================================================
   CSS Custom Properties (overridden by inline style)
   ======================================================== */
:root {
	--mrp-primary: #6366f1;
	--mrp-primary-hover: #6366f1e6;
	--mrp-bg: #ffffff;
	--mrp-bg-msg: #f3f4f6;
	--mrp-text: #1f2937;
	--mrp-text-light: #6b7280;
	--mrp-border: #e5e7eb;
	--mrp-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
	--mrp-radius: 16px;
	--mrp-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Sinhala', 'Noto Sans', sans-serif;
}

/* ========================================================
   Widget Container
   ======================================================== */
.mrp-chat-widget {
	position: fixed;
	bottom: 20px;
	right: 20px;
	z-index: 999999;
	font-family: var(--mrp-font);
	font-size: 14px;
	line-height: 1.5;
	color: var(--mrp-text);
	-webkit-font-smoothing: antialiased;
}

/* ========================================================
   Toggle Button
   ======================================================== */
.mrp-chat-toggle {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--mrp-primary);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
	transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
	position: relative;
	color: #fff;
	outline: none;
}

.mrp-chat-toggle:hover {
	transform: scale(1.08);
	box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.mrp-chat-toggle:focus-visible {
	outline: 2px solid var(--mrp-primary);
	outline-offset: 3px;
}

.mrp-chat-toggle svg {
	width: 28px;
	height: 28px;
	transition: opacity 0.2s ease, transform 0.3s ease;
}

.mrp-icon-close {
	position: absolute;
	opacity: 0;
	transform: rotate(-90deg);
}

.mrp-chat-widget.mrp-open .mrp-icon-chat {
	opacity: 0;
	transform: rotate(90deg);
}

.mrp-chat-widget.mrp-open .mrp-icon-close {
	opacity: 1;
	transform: rotate(0);
}

/* Unread badge */
.mrp-unread-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	min-width: 20px;
	height: 20px;
	border-radius: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 5px;
	line-height: 1;
	animation: mrp-badge-pop 0.3s ease;
}

@keyframes mrp-badge-pop {
	0% { transform: scale(0); }
	60% { transform: scale(1.2); }
	100% { transform: scale(1); }
}

/* ========================================================
   Chat Window
   ======================================================== */
.mrp-chat-window {
	position: absolute;
	bottom: 72px;
	right: 0;
	width: 380px;
	max-height: 560px;
	background: var(--mrp-bg);
	border-radius: var(--mrp-radius);
	box-shadow: var(--mrp-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: mrp-slide-up 0.35s cubic-bezier(0.4, 0, 0.2, 1);
	border: 1px solid var(--mrp-border);
}

@keyframes mrp-slide-up {
	from {
		opacity: 0;
		transform: translateY(16px) scale(0.96);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* ========================================================
   Header
   ======================================================== */
.mrp-chat-header {
	background: var(--mrp-primary);
	color: #fff;
	padding: 16px 18px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}

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

.mrp-avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	overflow: hidden;
	background: rgba(255, 255, 255, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.mrp-avatar-sm {
	width: 28px;
	height: 28px;
}

.mrp-avatar-img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.mrp-avatar-fallback {
	font-size: 18px;
	font-weight: 700;
	color: #fff;
	text-transform: uppercase;
}

.mrp-avatar-sm .mrp-avatar-fallback {
	font-size: 12px;
}

.mrp-chat-header-name {
	font-size: 15px;
	font-weight: 600;
	line-height: 1.3;
}

.mrp-chat-header-status {
	font-size: 12px;
	opacity: 0.85;
	display: flex;
	align-items: center;
	gap: 5px;
}

.mrp-status-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #34d399;
	display: inline-block;
}

.mrp-chat-close {
	background: rgba(255, 255, 255, 0.15);
	border: none;
	color: #fff;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s;
	flex-shrink: 0;
}

.mrp-chat-close:hover {
	background: rgba(255, 255, 255, 0.3);
}

/* ========================================================
   Messages Area
   ======================================================== */
.mrp-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	scroll-behavior: smooth;
	min-height: 200px;
	max-height: 360px;
}

/* Scrollbar styling */
.mrp-chat-messages::-webkit-scrollbar {
	width: 5px;
}

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

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

/* Message bubbles */
.mrp-message {
	display: flex;
	gap: 8px;
	max-width: 85%;
	animation: mrp-fade-in 0.3s ease;
}

@keyframes mrp-fade-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

.mrp-message-bot {
	align-self: flex-start;
}

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

.mrp-message-bubble {
	padding: 10px 14px;
	border-radius: 12px;
	word-wrap: break-word;
	overflow-wrap: break-word;
	hyphens: auto;
}

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

.mrp-message-user .mrp-message-bubble {
	background: var(--mrp-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}

/* Sinhala / Unicode text support */
.mrp-message-bubble {
	unicode-bidi: plaintext;
	direction: auto;
	font-feature-settings: "kern" 1;
}

/* Markdown inside bot messages */
.mrp-message-bot .mrp-message-bubble p {
	margin: 0 0 8px;
}

.mrp-message-bot .mrp-message-bubble p:last-child {
	margin-bottom: 0;
}

.mrp-message-bot .mrp-message-bubble strong {
	font-weight: 600;
}

.mrp-message-bot .mrp-message-bubble a {
	color: var(--mrp-primary);
	text-decoration: underline;
}

.mrp-message-user .mrp-message-bubble a {
	color: #fff;
	text-decoration: underline;
}

.mrp-message-bot .mrp-message-bubble ul,
.mrp-message-bot .mrp-message-bubble ol {
	margin: 6px 0;
	padding-left: 20px;
}

.mrp-message-bot .mrp-message-bubble li {
	margin-bottom: 3px;
}

.mrp-message-bot .mrp-message-bubble code {
	background: rgba(0, 0, 0, 0.06);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: 13px;
}

.mrp-message-bot .mrp-message-bubble pre {
	background: #1f2937;
	color: #e5e7eb;
	padding: 10px 12px;
	border-radius: 8px;
	overflow-x: auto;
	font-size: 13px;
	margin: 8px 0;
}

.mrp-message-bot .mrp-message-bubble pre code {
	background: none;
	padding: 0;
	color: inherit;
}

.mrp-message-time {
	font-size: 11px;
	color: var(--mrp-text-light);
	margin-top: 4px;
	padding: 0 4px;
}

/* Welcome block */
.mrp-welcome {
	text-align: center;
	padding: 10px 0 6px;
}

.mrp-welcome-en {
	font-size: 14px;
	margin-bottom: 4px;
}

.mrp-welcome-si {
	font-size: 13px;
	color: var(--mrp-text-light);
}

/* ========================================================
   Typing Indicator
   ======================================================== */
.mrp-typing-indicator {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 0 16px 8px;
}

.mrp-typing-dots {
	display: flex;
	gap: 4px;
	padding: 8px 14px;
	background: var(--mrp-bg-msg);
	border-radius: 12px;
	border-bottom-left-radius: 4px;
}

.mrp-typing-dots span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9ca3af;
	animation: mrp-typing-bounce 1.4s ease-in-out infinite;
}

.mrp-typing-dots span:nth-child(2) {
	animation-delay: 0.2s;
}

.mrp-typing-dots span:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes mrp-typing-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
	30% { transform: translateY(-6px); opacity: 1; }
}

/* ========================================================
   Input Form
   ======================================================== */
.mrp-chat-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px;
	border-top: 1px solid var(--mrp-border);
	flex-shrink: 0;
}

.mrp-chat-input {
	flex: 1;
	border: 1px solid var(--mrp-border);
	border-radius: 10px;
	padding: 10px 14px;
	font-size: 14px;
	font-family: var(--mrp-font);
	resize: none;
	outline: none;
	max-height: 100px;
	transition: border-color 0.2s;
	background: var(--mrp-bg);
	color: var(--mrp-text);
	line-height: 1.45;
	unicode-bidi: plaintext;
	direction: auto;
}

.mrp-chat-input:focus {
	border-color: var(--mrp-primary);
	box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

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

.mrp-chat-send {
	width: 40px;
	height: 40px;
	border-radius: 10px;
	background: var(--mrp-primary);
	border: none;
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.2s, transform 0.15s;
}

.mrp-chat-send:hover {
	background: var(--mrp-primary-hover);
	transform: scale(1.05);
}

.mrp-chat-send:active {
	transform: scale(0.95);
}

.mrp-chat-send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}

/* ========================================================
   Powered By
   ======================================================== */
.mrp-chat-powered {
	text-align: center;
	font-size: 11px;
	color: var(--mrp-text-light);
	padding: 0 0 10px;
}

/* ========================================================
   Responsive
   ======================================================== */
@media (max-width: 480px) {
	.mrp-chat-widget {
		bottom: 10px;
		right: 10px;
	}

	.mrp-chat-window {
		width: calc(100vw - 20px);
		max-height: calc(100vh - 100px);
		max-height: calc(100dvh - 100px);
		bottom: 68px;
		right: -5px;
		border-radius: 12px;
	}

	.mrp-chat-toggle {
		width: 54px;
		height: 54px;
	}

	.mrp-chat-toggle svg {
		width: 24px;
		height: 24px;
	}

	.mrp-chat-messages {
		max-height: calc(100vh - 280px);
		max-height: calc(100dvh - 280px);
	}
}

@media (max-width: 380px) {
	.mrp-chat-window {
		width: calc(100vw - 10px);
		right: -5px;
	}
}
