/**
 * Anak Engage Pro — Chat Widget Styles
 * Premium SaaS aesthetic with Anak blue brand. Glassmorphism + smooth motion.
 */

.aep-chat-root {
	--aep-c-primary: #0066CC;
	--aep-c-primary-2: #00A8FF;
	--aep-c-primary-dark: #004C99;
	--aep-c-bg: #ffffff;
	--aep-c-text: #0f172a;
	--aep-c-muted: #64748b;
	--aep-c-border: #e3e8f0;
	--aep-c-bubble-bot: #f1f5f9;
	position: fixed;
	z-index: 2147483600;
	/* Constrain root to launcher size so it doesn't block page clicks */
	width: 60px;
	height: 60px;
	box-sizing: border-box;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--aep-c-text);
	font-size: 14px;
	/* Prevent theme styles from leaking in */
	line-height: 1.5;
}
/* Scoped box-sizing reset — prevents theme styles from breaking widget layout */
.aep-chat-root *,
.aep-chat-root *::before,
.aep-chat-root *::after {
	box-sizing: border-box;
}

.aep-chat-root.is-dark {
	--aep-c-bg: #0f172a;
	--aep-c-text: #f1f5f9;
	--aep-c-muted: #94a3b8;
	--aep-c-border: #1e293b;
	--aep-c-bubble-bot: #1e293b;
}
.aep-chat-root[data-position="bottom-right"] { bottom: 24px; right: 24px; }
.aep-chat-root[data-position="bottom-left"]  { bottom: 24px; left: 24px; }
.aep-chat-root[data-position="top-right"]    { top: 24px; right: 24px; }
.aep-chat-root[data-position="top-left"]     { top: 24px; left: 24px; }

/* ─── Launcher button ───────────────────────────────────────── */
.aep-chat-launcher {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: none;
	padding: 0;
	margin: 0;
	cursor: pointer;
	background: linear-gradient(135deg, var(--aep-c-primary-2), var(--aep-c-primary), var(--aep-c-primary-dark));
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 6px 20px rgba(0, 102, 204, 0.35), 0 2px 6px rgba(0, 0, 0, 0.08);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	position: relative;
	overflow: hidden;
	flex-shrink: 0;
	text-decoration: none;
	outline: none;
	-webkit-appearance: none;
	appearance: none;
}
.aep-chat-launcher:hover {
	transform: scale(1.06) translateY(-2px);
	box-shadow: 0 10px 28px rgba(0, 102, 204, 0.45), 0 4px 10px rgba(0, 0, 0, 0.12);
}
.aep-chat-launcher:active { transform: scale(0.98); }
.aep-chat-launcher svg {
	width: 28px;
	height: 28px;
	display: block;
	flex-shrink: 0;
	pointer-events: none;
}
.aep-chat-launcher.is-open svg.aep-icon-chat { display: none; }
.aep-chat-launcher:not(.is-open) svg.aep-icon-close { display: none; }
.aep-chat-launcher::after {
	content: '';
	position: absolute;
	top: 8px; right: 8px;
	width: 10px; height: 10px;
	background: #22c55e;
	border: 2px solid #fff;
	border-radius: 50%;
	box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}
.aep-chat-launcher.is-open::after { display: none; }
.aep-chat-badge {
	position: absolute;
	top: -2px; right: -2px;
	min-width: 22px;
	height: 22px;
	border-radius: 999px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 6px;
	box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
	animation: aep-pop 0.3s ease;
}
@keyframes aep-pop { from { transform: scale(0); } to { transform: scale(1); } }

/* ─── Panel ─────────────────────────────────────────────────── */
.aep-chat-panel {
	position: absolute;
	bottom: 76px;
	right: 0;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 120px);
	background: var(--aep-c-bg);
	border-radius: 18px;
	box-shadow: 0 20px 50px rgba(0, 30, 80, 0.18), 0 8px 24px rgba(0, 30, 80, 0.10);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transform: translateY(20px) scale(0.96);
	opacity: 0;
	pointer-events: none;
	transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
	border: 1px solid var(--aep-c-border);
}
.aep-chat-root[data-position="bottom-left"] .aep-chat-panel,
.aep-chat-root[data-position="top-left"]    .aep-chat-panel { right: auto; left: 0; }
.aep-chat-root[data-position="top-right"]   .aep-chat-panel,
.aep-chat-root[data-position="top-left"]    .aep-chat-panel { bottom: auto; top: 76px; }
.aep-chat-panel.is-open {
	transform: translateY(0) scale(1);
	opacity: 1;
	pointer-events: auto;
}

/* ─── Header ────────────────────────────────────────────────── */
.aep-chat-head {
	background: linear-gradient(135deg, var(--aep-c-primary-2) 0%, var(--aep-c-primary) 60%, var(--aep-c-primary-dark) 100%);
	color: #fff;
	padding: 18px 18px 16px;
	display: flex;
	align-items: center;
	gap: 12px;
	position: relative;
	flex-shrink: 0;
}
.aep-chat-head::before {
	content: '';
	position: absolute;
	inset: 0;
	background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="1.5" fill="white" opacity="0.18"/><circle cx="80" cy="40" r="1" fill="white" opacity="0.14"/><circle cx="60" cy="80" r="1.2" fill="white" opacity="0.16"/></svg>') repeat;
	opacity: 0.4;
	pointer-events: none;
}
.aep-chat-brand {
	width: 44px;
	height: 44px;
	border-radius: 12px;
	background: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 5px;
	flex-shrink: 0;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
	position: relative;
	z-index: 1;
}
.aep-chat-brand img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}
.aep-chat-titles {
	flex: 1;
	min-width: 0;
	position: relative;
	z-index: 1;
}
.aep-chat-titles strong {
	display: block;
	font-size: 15px;
	font-weight: 600;
	color: #fff;
	margin: 0;
}
.aep-chat-titles span {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	color: rgba(255, 255, 255, 0.85);
	margin-top: 2px;
}
.aep-chat-status-dot {
	width: 8px; height: 8px;
	border-radius: 50%;
	background: #22c55e;
	box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.4);
	animation: aep-pulse 2s infinite;
}
@keyframes aep-pulse {
	0%, 100% { box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.4); }
	50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}
.aep-chat-close {
	background: rgba(255, 255, 255, 0.18);
	backdrop-filter: blur(6px);
	border: none;
	color: #fff;
	width: 30px; height: 30px;
	border-radius: 8px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s;
	position: relative;
	z-index: 1;
}
.aep-chat-close:hover { background: rgba(255, 255, 255, 0.3); }
.aep-chat-close svg { width: 14px; height: 14px; }

/* ─── Welcome subhead ───────────────────────────────────────── */
.aep-chat-welcome {
	background: linear-gradient(180deg, rgba(0, 102, 204, 0.06), transparent);
	padding: 14px 18px 8px;
	font-size: 13px;
	color: var(--aep-c-muted);
	border-bottom: 1px solid var(--aep-c-border);
}

/* ─── Body / message list ───────────────────────────────────── */
.aep-chat-body {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: linear-gradient(180deg, rgba(0, 168, 255, 0.02) 0%, transparent 40%);
	scrollbar-width: thin;
	scrollbar-color: #cbd5e1 transparent;
}
.aep-chat-body::-webkit-scrollbar { width: 6px; }
.aep-chat-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.aep-msg {
	display: flex;
	gap: 8px;
	max-width: 85%;
	animation: aep-msg-in 0.25s ease;
}
@keyframes aep-msg-in {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: translateY(0); }
}
.aep-msg-visitor { align-self: flex-end; flex-direction: row-reverse; }
.aep-msg-bot, .aep-msg-agent, .aep-msg-system { align-self: flex-start; }

.aep-msg-avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--aep-c-primary-2), var(--aep-c-primary));
	color: #fff;
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 11px;
	font-weight: 700;
}
.aep-msg-visitor .aep-msg-avatar {
	background: #475569;
}

.aep-msg-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	font-size: 14px;
	line-height: 1.45;
	word-wrap: break-word;
}
.aep-msg-visitor .aep-msg-bubble {
	background: linear-gradient(135deg, var(--aep-c-primary-2), var(--aep-c-primary));
	color: #fff;
	border-bottom-right-radius: 4px;
	box-shadow: 0 2px 8px rgba(0, 102, 204, 0.18);
}
.aep-msg-bot .aep-msg-bubble,
.aep-msg-agent .aep-msg-bubble {
	background: var(--aep-c-bubble-bot);
	color: var(--aep-c-text);
	border-bottom-left-radius: 4px;
}
.aep-msg-agent .aep-msg-bubble {
	background: #e0f2fe;
	border: 1px solid #bae6fd;
}
.aep-msg-system .aep-msg-bubble {
	background: transparent;
	color: var(--aep-c-muted);
	font-size: 12px;
	font-style: italic;
	text-align: center;
	width: 100%;
}

/* ─── Typing indicator ──────────────────────────────────────── */
.aep-chat-typing {
	display: flex;
	gap: 4px;
	padding: 8px 16px;
	align-self: flex-start;
}
.aep-chat-typing span {
	width: 7px; height: 7px;
	border-radius: 50%;
	background: var(--aep-c-muted);
	animation: aep-bounce 1.2s infinite ease-in-out;
}
.aep-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.aep-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes aep-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input bar ─────────────────────────────────────────────── */
.aep-chat-input {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--aep-c-border);
	background: var(--aep-c-bg);
	flex-shrink: 0;
	box-sizing: border-box;
}
.aep-chat-input input {
	flex: 1;
	min-width: 0; /* Prevent flex overflow */
	border: 1px solid var(--aep-c-border);
	background: var(--aep-c-bg);
	border-radius: 999px;
	padding: 10px 16px;
	font-size: 14px;
	font-family: inherit;
	line-height: 1.4;
	color: var(--aep-c-text);
	outline: none;
	transition: border-color 0.15s, box-shadow 0.15s;
	box-sizing: border-box;
	-webkit-appearance: none;
	appearance: none;
}
.aep-chat-input input::placeholder { color: var(--aep-c-muted); opacity: 1; }
.aep-chat-input input:focus {
	border-color: var(--aep-c-primary);
	box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.12);
}
.aep-chat-input button {
	background: linear-gradient(135deg, var(--aep-c-primary-2), var(--aep-c-primary));
	border: none;
	padding: 0;
	color: #fff;
	width: 42px;
	height: 42px;
	min-width: 42px; /* Never shrink below this */
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s, box-shadow 0.15s;
	box-shadow: 0 2px 8px rgba(0, 102, 204, 0.25);
	flex-shrink: 0;
	-webkit-appearance: none;
	appearance: none;
}
.aep-chat-input button:hover {
	transform: scale(1.05);
	box-shadow: 0 4px 12px rgba(0, 102, 204, 0.35);
}
.aep-chat-input button:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}
.aep-chat-input button svg { width: 16px; height: 16px; display: block; pointer-events: none; }

/* ─── Footer ────────────────────────────────────────────────── */
.aep-chat-foot {
	background: var(--aep-c-bg);
	border-top: 1px solid var(--aep-c-border);
	padding: 8px;
	text-align: center;
	font-size: 11px;
	color: var(--aep-c-muted);
	flex-shrink: 0;
}
.aep-chat-foot a {
	color: var(--aep-c-primary);
	text-decoration: none;
	font-weight: 500;
}
.aep-chat-foot a:hover { text-decoration: underline; }

/* ─── Mobile ────────────────────────────────────────────────── */
@media (max-width: 480px) {
	.aep-chat-root[data-position] { bottom: 16px !important; right: 16px !important; left: auto !important; top: auto !important; }
	.aep-chat-panel {
		width: calc(100vw - 24px);
		height: calc(100vh - 100px);
		max-height: 600px;
		bottom: 76px;
		right: 0 !important;
		left: auto !important;
	}
}

/* ─── RTL ───────────────────────────────────────────────────── */
.rtl .aep-msg-visitor { align-self: flex-start; flex-direction: row; }
.rtl .aep-msg-bot, .rtl .aep-msg-agent { align-self: flex-end; flex-direction: row-reverse; }
.rtl .aep-msg-visitor .aep-msg-bubble { border-bottom-right-radius: 16px; border-bottom-left-radius: 4px; }
.rtl .aep-msg-bot .aep-msg-bubble, .rtl .aep-msg-agent .aep-msg-bubble { border-bottom-left-radius: 16px; border-bottom-right-radius: 4px; }

/* ─── Inline form (chat→form→thankyou flow) ─────────────── */
.aep-chat-root .aep-msg-form {
	width: 100%;
	max-width: 260px;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 12px;
	padding: 12px;
}
.aep-chat-root .aep-inline-form {
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.aep-chat-root .aep-inline-field {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 12px;
}
.aep-chat-root .aep-inline-field span {
	color: #475569;
	font-weight: 500;
}
.aep-chat-root .aep-inline-field input,
.aep-chat-root .aep-inline-field textarea,
.aep-chat-root .aep-inline-field select {
	width: 100%;
	padding: 7px 9px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	font: inherit;
	font-size: 13px;
	background: #fff;
	color: #1f2937;
	box-sizing: border-box;
}
.aep-chat-root .aep-inline-field input:focus,
.aep-chat-root .aep-inline-field textarea:focus,
.aep-chat-root .aep-inline-field select:focus {
	outline: none;
	border-color: var(--aep-c-primary);
	box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.15);
}
.aep-chat-root .aep-inline-submit {
	margin-top: 4px;
	padding: 8px 12px;
	border: none;
	border-radius: 6px;
	background: linear-gradient(135deg, var(--aep-c-primary-2, var(--aep-c-primary)), var(--aep-c-primary));
	color: #fff;
	font-weight: 600;
	font-size: 13px;
	cursor: pointer;
	transition: opacity 0.2s;
}
.aep-chat-root .aep-inline-submit:hover { opacity: 0.92; }
.aep-chat-root .aep-inline-submit:disabled { opacity: 0.6; cursor: default; }
.aep-chat-root .is-submitted .aep-inline-form input,
.aep-chat-root .is-submitted .aep-inline-form textarea,
.aep-chat-root .is-submitted .aep-inline-form select { pointer-events: none; opacity: 0.6; }

/* Footer "Powered by" — hidden when admin disables it */
.aep-chat-root .aep-chat-foot {
	padding: 8px 16px;
	text-align: center;
	font-size: 11px;
	color: #94a3b8;
	border-top: 1px solid #f1f5f9;
}
.aep-chat-root .aep-chat-foot a {
	color: var(--aep-c-primary);
	text-decoration: none;
}
.aep-chat-root .aep-chat-brand-initial {
	color: var(--aep-c-primary);
	font-weight: 700;
	font-size: 18px;
}
