/**
 * Ebn Hayan AI Healthcare Assistant – Frontend Styles
 * Phase 3: Full chat widget UI
 *
 * Uses CSS logical properties for RTL/LTR compatibility.
 */

/* ==========================================================================
   CSS Custom Properties (Theme)
   ========================================================================== */
   :root {
	--ebn-ai-primary: #1a7a6d;
	--ebn-ai-primary-dark: #145c53;
	--ebn-ai-primary-light: #e8f5f3;
	--ebn-ai-bg: #ffffff;
	--ebn-ai-bg-alt: #f7f9f9;
	--ebn-ai-text: #2d3436;
	--ebn-ai-text-muted: #636e72;
	--ebn-ai-border: #e0e6e5;
	--ebn-ai-bubble-user: #1a7a6d;
	--ebn-ai-bubble-user-text: #ffffff;
	--ebn-ai-bubble-ai: #f0f4f3;
	--ebn-ai-bubble-ai-text: #2d3436;
	--ebn-ai-error: #d32f2f;
	--ebn-ai-error-bg: #fdecea;
	--ebn-ai-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
	--ebn-ai-radius: 16px;
	--ebn-ai-radius-sm: 10px;
	--ebn-ai-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	--ebn-ai-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--ebn-ai-width: 400px;
	--ebn-ai-height: 560px;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
.ebn-ai-root,
.ebn-ai-root *,
.ebn-ai-root *::before,
.ebn-ai-root *::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

.ebn-ai-root {
	font-family: var(--ebn-ai-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--ebn-ai-text);
}

/* ==========================================================================
   Launcher Button (Floating)
   ========================================================================== */
.ebn-ai-launcher {
	position: fixed;
	bottom: 24px;
	inset-inline-end: 24px;
	z-index: 99999;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--ebn-ai-primary);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--ebn-ai-shadow);
	transition: transform var(--ebn-ai-transition), background var(--ebn-ai-transition);
}

.ebn-ai-launcher:hover {
	background: var(--ebn-ai-primary-dark);
	transform: scale(1.08);
}

.ebn-ai-launcher:focus-visible {
	outline: 3px solid var(--ebn-ai-primary);
	outline-offset: 3px;
}

.ebn-ai-launcher svg {
	width: 28px;
	height: 28px;
	fill: #ffffff;
	transition: transform var(--ebn-ai-transition);
}

.ebn-ai-launcher.is-open svg {
	transform: rotate(45deg);
}

/* Pulse animation to draw initial attention */
@keyframes ebn-ai-pulse {
	0%   { box-shadow: 0 0 0 0 rgba(26, 122, 109, 0.4); }
	70%  { box-shadow: 0 0 0 14px rgba(26, 122, 109, 0); }
	100% { box-shadow: 0 0 0 0 rgba(26, 122, 109, 0); }
}

.ebn-ai-launcher.ebn-ai-pulse {
	animation: ebn-ai-pulse 2s infinite;
}

/* ==========================================================================
   Chat Panel Container
   ========================================================================== */
.ebn-ai-panel {
	position: fixed;
	bottom: 96px;
	inset-inline-end: 24px;
	z-index: 99998;
	width: var(--ebn-ai-width);
	height: var(--ebn-ai-height);
	max-height: calc(100vh - 120px);
	background: var(--ebn-ai-bg);
	border-radius: var(--ebn-ai-radius);
	box-shadow: var(--ebn-ai-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	transform: translateY(16px) scale(0.96);
	transition: opacity var(--ebn-ai-transition), transform var(--ebn-ai-transition), visibility var(--ebn-ai-transition);
}

.ebn-ai-panel.is-open {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

/* ==========================================================================
   Header
   ========================================================================== */
.ebn-ai-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	background: var(--ebn-ai-primary);
	color: #ffffff;
	flex-shrink: 0;
}

.ebn-ai-header-title {
	font-size: 15px;
	font-weight: 600;
	letter-spacing: 0.2px;
}

.ebn-ai-header-close {
	background: none;
	border: none;
	cursor: pointer;
	padding: 4px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s;
}

.ebn-ai-header-close:hover {
	background: rgba(255, 255, 255, 0.2);
}

.ebn-ai-header-close svg {
	width: 20px;
	height: 20px;
	fill: #ffffff;
}

/* ==========================================================================
   Messages Area
   ========================================================================== */
.ebn-ai-messages {
	flex: 1;
	overflow-y: auto;
	padding: 20px 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: var(--ebn-ai-bg-alt);
	scroll-behavior: smooth;
}

/* Scrollbar styling */
.ebn-ai-messages::-webkit-scrollbar {
	width: 6px;
}
.ebn-ai-messages::-webkit-scrollbar-track {
	background: transparent;
}
.ebn-ai-messages::-webkit-scrollbar-thumb {
	background: var(--ebn-ai-border);
	border-radius: 3px;
}

/* ==========================================================================
   Message Bubbles
   ========================================================================== */
.ebn-ai-msg {
	display: flex;
	flex-direction: column;
	max-width: 85%;
	animation: ebn-ai-msg-in 0.25s ease-out;
}

@keyframes ebn-ai-msg-in {
	from { opacity: 0; transform: translateY(8px); }
	to   { opacity: 1; transform: translateY(0); }
}

.ebn-ai-msg--user {
	align-self: flex-end;
}

.ebn-ai-msg--ai {
	align-self: flex-start;
}

.ebn-ai-msg-bubble {
	padding: 10px 14px;
	border-radius: var(--ebn-ai-radius-sm);
	font-size: 14px;
	line-height: 1.55;
	word-wrap: break-word;
	overflow-wrap: break-word;
}

.ebn-ai-msg--user .ebn-ai-msg-bubble {
	background: var(--ebn-ai-bubble-user);
	color: var(--ebn-ai-bubble-user-text);
	border-start-start-radius: 4px;
}

.ebn-ai-msg--ai .ebn-ai-msg-bubble {
	background: var(--ebn-ai-bubble-ai);
	color: var(--ebn-ai-bubble-ai-text);
	border-start-end-radius: 4px;
}

/* Error message bubble */
.ebn-ai-msg--error .ebn-ai-msg-bubble {
	background: var(--ebn-ai-error-bg);
	color: var(--ebn-ai-error);
	border: 1px solid rgba(211, 47, 47, 0.2);
}

/* ==========================================================================
   Loading Indicator (Typing Dots)
   ========================================================================== */
.ebn-ai-typing {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 12px 16px;
	background: var(--ebn-ai-bubble-ai);
	border-radius: var(--ebn-ai-radius-sm);
	border-start-end-radius: 4px;
	width: fit-content;
}

.ebn-ai-typing-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--ebn-ai-text-muted);
	animation: ebn-ai-typing-bounce 1.4s infinite ease-in-out;
}

.ebn-ai-typing-dot:nth-child(2) {
	animation-delay: 0.2s;
}

.ebn-ai-typing-dot:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes ebn-ai-typing-bounce {
	0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
	40%           { transform: translateY(-6px); opacity: 1; }
}

/* ==========================================================================
   Quick Actions
   ========================================================================== */
.ebn-ai-quick-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 16px 12px;
	background: var(--ebn-ai-bg-alt);
}

.ebn-ai-quick-btn {
	padding: 8px 14px;
	border: 1px solid var(--ebn-ai-primary);
	border-radius: 20px;
	background: var(--ebn-ai-primary-light);
	color: var(--ebn-ai-primary);
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	transition: background 0.2s, color 0.2s;
	font-family: var(--ebn-ai-font);
}

.ebn-ai-quick-btn:hover {
	background: var(--ebn-ai-primary);
	color: #ffffff;
}

.ebn-ai-quick-btn:focus-visible {
	outline: 2px solid var(--ebn-ai-primary);
	outline-offset: 2px;
}

/* Hide quick actions after first user message */
.ebn-ai-quick-actions.is-hidden {
	display: none;
}

/* ==========================================================================
   Input Area
   ========================================================================== */
.ebn-ai-input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px;
	background: var(--ebn-ai-bg);
	border-top: 1px solid var(--ebn-ai-border);
	flex-shrink: 0;
}

.ebn-ai-input {
	flex: 1;
	resize: none;
	border: 1px solid var(--ebn-ai-border);
	border-radius: var(--ebn-ai-radius-sm);
	padding: 10px 14px;
	font-size: 14px;
	font-family: var(--ebn-ai-font);
	line-height: 1.4;
	max-height: 80px;
	min-height: 40px;
	transition: border-color 0.2s;
	outline: none;
}

.ebn-ai-input:focus {
	border-color: var(--ebn-ai-primary);
}

.ebn-ai-input::placeholder {
	color: var(--ebn-ai-text-muted);
}

.ebn-ai-send-btn {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: none;
	background: var(--ebn-ai-primary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.2s, transform 0.15s;
}

.ebn-ai-send-btn:hover {
	background: var(--ebn-ai-primary-dark);
	transform: scale(1.05);
}

.ebn-ai-send-btn:focus-visible {
	outline: 2px solid var(--ebn-ai-primary);
	outline-offset: 2px;
}

.ebn-ai-send-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}

.ebn-ai-send-btn svg {
	width: 18px;
	height: 18px;
	fill: #ffffff;
}

/* Rotate send icon for RTL */
.ebn-ai-rtl .ebn-ai-send-btn svg {
	transform: rotate(180deg);
}

/* ==========================================================================
   Footer / Disclaimer
   ========================================================================== */
.ebn-ai-footer {
	padding: 8px 16px 12px;
	background: var(--ebn-ai-bg);
	text-align: center;
	flex-shrink: 0;
}

.ebn-ai-footer p {
	font-size: 11px;
	color: var(--ebn-ai-text-muted);
	line-height: 1.4;
}

/* ==========================================================================
   Mobile Responsive
   ========================================================================== */
@media screen and (max-width: 480px) {
	.ebn-ai-panel {
		inset-inline-start: 0;
		inset-inline-end: 0;
		bottom: 0;
		width: 100%;
		height: 100vh;
		height: 100dvh;
		max-height: 100vh;
		max-height: 100dvh;
		border-radius: 0;
	}

	.ebn-ai-launcher {
		bottom: 16px;
		inset-inline-end: 16px;
		width: 54px;
		height: 54px;
	}

	.ebn-ai-launcher svg {
		width: 24px;
		height: 24px;
	}
}

/* ==========================================================================
   Reduced Motion Preference
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
	.ebn-ai-panel,
	.ebn-ai-launcher,
	.ebn-ai-msg,
	.ebn-ai-typing-dot {
		animation: none !important;
		transition: none !important;
	}
}

/* ==========================================================================
   Print: Hide widget
   ========================================================================== */
@media print {
	.ebn-ai-root {
		display: none !important;
	}
}