/*!
 * Saad Legal Chatbot — front-end widget styles
 * WhatsApp-inspired, RTL-first, mobile-first, lightweight (no framework).
 */

:root {
	--saad-green: #25D366;
	--saad-green-dark: #128C7E;
	--saad-teal-header: #075E54;
	--saad-bg-chat: #ECE5DD;
	--saad-bubble-bot: #FFFFFF;
	--saad-bubble-user: #DCF8C6;
	--saad-text-dark: #1F2C33;
	--saad-text-muted: #667781;
	--saad-radius: 14px;
	--saad-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

#saad-chatbot-root, #saad-chatbot-root * {
	box-sizing: border-box;
}

#saad-chatbot-root {
	position: fixed;
	bottom: 20px;
	z-index: 999999;
	font-family: "Tahoma", "Segoe UI", "Cairo", -apple-system, sans-serif;
	direction: rtl;
}

#saad-chatbot-root.saad-pos-right { right: 20px; }
#saad-chatbot-root.saad-pos-left  { left: 20px; }

/* ---------- Floating toggle button ---------- */

.saad-chat-toggle {
	position: relative;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: none;
	background: linear-gradient(145deg, var(--saad-green), var(--saad-green-dark));
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	box-shadow: var(--saad-shadow);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	animation: saad-pulse 2.4s infinite;
}

.saad-chat-toggle:hover {
	transform: scale(1.06);
}

.saad-chat-toggle:active {
	transform: scale(0.96);
}

.saad-icon-close { display: none; }

#saad-chatbot-root.saad-open .saad-icon-chat { display: none; }
#saad-chatbot-root.saad-open .saad-icon-close { display: flex; }
#saad-chatbot-root.saad-open .saad-chat-toggle { animation: none; }

.saad-toggle-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	background: #FF3B30;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	min-width: 18px;
	height: 18px;
	border-radius: 9px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 4px;
	border: 2px solid #fff;
}

@keyframes saad-pulse {
	0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.45), var(--saad-shadow); }
	70% { box-shadow: 0 0 0 12px rgba(37, 211, 102, 0), var(--saad-shadow); }
	100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0), var(--saad-shadow); }
}

/* ---------- Chat window ---------- */

.saad-chat-window {
	position: absolute;
	bottom: 76px;
	right: 0;
	width: 360px;
	max-width: calc(100vw - 24px);
	height: 560px;
	max-height: calc(100vh - 120px);
	background: var(--saad-bg-chat);
	border-radius: var(--saad-radius);
	box-shadow: var(--saad-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(16px) scale(0.97);
	pointer-events: none;
	transition: opacity 0.22s ease, transform 0.22s ease;
}

#saad-chatbot-root.saad-pos-left .saad-chat-window {
	right: auto;
	left: 0;
}

#saad-chatbot-root.saad-open .saad-chat-window {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

.saad-chat-window[hidden] { display: none; }

/* ---------- Header ---------- */

.saad-chat-header {
	background: var(--saad-teal-header);
	color: #fff;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	flex-shrink: 0;
}

.saad-chat-avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.15);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 18px;
	flex-shrink: 0;
}

.saad-chat-header-text {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	flex: 1;
}

.saad-chat-title {
	font-size: 13.5px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

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

.saad-status-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4CFF6B;
	display: inline-block;
}

.saad-chat-header-actions {
	display: flex;
	gap: 4px;
}

.saad-icon-btn {
	background: transparent;
	border: none;
	color: #fff;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	opacity: 0.9;
	transition: background 0.15s ease;
}

.saad-icon-btn:hover {
	background: rgba(255, 255, 255, 0.15);
	opacity: 1;
}

/* ---------- Body / messages ---------- */

.saad-chat-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background-image: linear-gradient(rgba(255,255,255,0.4), rgba(255,255,255,0.4)),
		repeating-linear-gradient(45deg, rgba(0,0,0,0.015) 0, rgba(0,0,0,0.015) 2px, transparent 2px, transparent 14px);
}

.saad-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 14px 12px 4px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	scroll-behavior: smooth;
}

.saad-chat-messages::-webkit-scrollbar { width: 6px; }
.saad-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

.saad-msg-row {
	display: flex;
	width: 100%;
	animation: saad-fade-in 0.22s ease both;
}

.saad-msg-row.saad-from-bot { justify-content: flex-start; }
.saad-msg-row.saad-from-user { justify-content: flex-end; }

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

.saad-bubble {
	max-width: 82%;
	padding: 8px 11px;
	border-radius: var(--saad-radius);
	font-size: 13.5px;
	line-height: 1.55;
	white-space: pre-wrap;
	word-wrap: break-word;
	box-shadow: 0 1px 1px rgba(0,0,0,0.08);
	position: relative;
}

.saad-bubble-bot {
	background: var(--saad-bubble-bot);
	color: var(--saad-text-dark);
	border-radius: 4px var(--saad-radius) var(--saad-radius) var(--saad-radius);
}

.saad-bubble-user {
	background: var(--saad-bubble-user);
	color: var(--saad-text-dark);
	border-radius: var(--saad-radius) 4px var(--saad-radius) var(--saad-radius);
}

.saad-bubble a {
	color: var(--saad-green-dark);
	font-weight: 600;
	word-break: break-all;
}

.saad-msg-time {
	display: block;
	font-size: 10px;
	color: var(--saad-text-muted);
	margin-top: 3px;
	text-align: left;
	direction: ltr;
}

/* ---------- Typing indicator ---------- */

.saad-typing-indicator {
	padding: 0 12px 6px;
}

.saad-typing-bubble {
	display: inline-flex;
	gap: 4px;
	padding: 10px 14px;
	align-items: center;
}

.saad-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #9aa3a8;
	animation: saad-blink 1.2s infinite;
}

.saad-dot:nth-child(2) { animation-delay: 0.15s; }
.saad-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes saad-blink {
	0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- Quick replies ---------- */

.saad-quick-replies {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 6px 12px 12px;
}

.saad-quick-replies[hidden] { display: none; }

.saad-quick-reply-btn {
	background: #fff;
	border: 1.5px solid var(--saad-green);
	color: var(--saad-green-dark);
	font-size: 12.5px;
	font-weight: 600;
	padding: 7px 12px;
	border-radius: 999px;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.1s ease;
	white-space: nowrap;
}

.saad-quick-reply-btn:hover {
	background: var(--saad-green);
	color: #fff;
}

.saad-quick-reply-btn:active {
	transform: scale(0.96);
}

/* ---------- Footer / input ---------- */

.saad-chat-footer {
	flex-shrink: 0;
	background: #F0F0F0;
	padding: 8px 10px;
	border-top: 1px solid rgba(0,0,0,0.06);
}

#saad-chat-form {
	display: flex;
	align-items: center;
	gap: 8px;
}

.saad-chat-input {
	flex: 1;
	border: none;
	border-radius: 22px;
	padding: 10px 16px;
	font-size: 13.5px;
	background: #fff;
	outline: none;
	font-family: inherit;
	color: var(--saad-text-dark);
}

.saad-chat-send {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--saad-green);
	border: none;
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.15s ease, transform 0.1s ease;
}

.saad-chat-send:hover { background: var(--saad-green-dark); }
.saad-chat-send:active { transform: scale(0.92); }

/* ---------- Mobile ---------- */

@media (max-width: 480px) {
	#saad-chatbot-root.saad-pos-right,
	#saad-chatbot-root.saad-pos-left {
		right: 12px;
		left: 12px;
		bottom: 12px;
	}

	.saad-chat-window {
		width: auto;
		right: 0;
		left: 0;
		bottom: 76px;
		height: calc(100vh - 100px);
		max-height: none;
	}

	#saad-chatbot-root.saad-pos-left .saad-chat-window {
		left: 0;
	}

	.saad-chat-toggle {
		margin-inline-start: auto;
	}
}
