/*
 * Mahad AI Assistant — self-contained widget styling.
 * Brand: deep blue #39477e, green #92c024, orange #c94711.
 * Fonts: Poppins (headings/UI), Open Sans (body) — loaded by the theme,
 * with safe system fallbacks so the widget never depends on theme CSS.
 */

.mahad-ai {
	--mai-blue: #39477e;
	--mai-green: #92c024;
	--mai-orange: #c94711;
	--mai-navy: #141b2e;
	--mai-accent: #39477e;
	--mai-accent-ink: #ffffff;
	--mai-bg: #ffffff;
	--mai-surface: #f5f7fb;
	--mai-line: #e5e8f0;
	--mai-text: #1f2430;
	--mai-muted: #6b7280;
	--mai-radius: 16px;
	--mai-shadow: 0 18px 48px rgba(20, 27, 46, .22);
	--mai-font: "Poppins", "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

	position: fixed;
	bottom: 22px;
	z-index: 99990;
	font-family: var(--mai-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--mai-text);
}

.mahad-ai[data-position="bottom-right"] { right: 22px; }
.mahad-ai[data-position="bottom-left"]  { left: 22px; }

.mahad-ai[data-accent="blue"]   { --mai-accent: var(--mai-blue);   --mai-accent-ink: #fff; }
.mahad-ai[data-accent="green"]  { --mai-accent: var(--mai-green);  --mai-accent-ink: #14320a; }
.mahad-ai[data-accent="orange"] { --mai-accent: var(--mai-orange); --mai-accent-ink: #fff; }

.mahad-ai *,
.mahad-ai *::before,
.mahad-ai *::after { box-sizing: border-box; }

/* ---- Launcher ---- */
.mahad-ai__launcher {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	border: 0;
	cursor: pointer;
	padding: 14px 20px 14px 16px;
	border-radius: 999px;
	background: var(--mai-accent);
	color: var(--mai-accent-ink);
	font-family: var(--mai-font);
	font-size: 15px;
	font-weight: 600;
	box-shadow: var(--mai-shadow);
	transition: transform .18s ease, box-shadow .18s ease;
}
.mahad-ai__launcher:hover { transform: translateY(-2px); }
.mahad-ai__launcher:focus-visible { outline: 3px solid var(--mai-navy); outline-offset: 3px; }
.mahad-ai__launcher-label { white-space: nowrap; }
.mahad-ai.is-open .mahad-ai__launcher { display: none; }

/* ---- Panel ---- */
.mahad-ai__panel {
	position: absolute;
	bottom: 0;
	width: 380px;
	height: 560px;
	max-height: calc(100vh - 44px);
	display: flex;
	flex-direction: column;
	background: var(--mai-bg);
	border: 1px solid var(--mai-line);
	border-radius: var(--mai-radius);
	box-shadow: var(--mai-shadow);
	overflow: hidden;
	transform-origin: bottom right;
	animation: mahad-ai-in .2s ease;
}
.mahad-ai[data-position="bottom-right"] .mahad-ai__panel { right: 0; }
.mahad-ai[data-position="bottom-left"]  .mahad-ai__panel { left: 0; transform-origin: bottom left; }
.mahad-ai__panel[hidden] { display: none; }

@keyframes mahad-ai-in {
	from { opacity: 0; transform: translateY(14px) scale(.98); }
	to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Header ---- */
.mahad-ai__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 14px 14px 14px 16px;
	background: var(--mai-accent);
	color: var(--mai-accent-ink);
}
.mahad-ai__brandwrap { display: flex; align-items: center; gap: 10px; }
.mahad-ai__avatar {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 10px;
	background: rgba(255, 255, 255, .18);
}
.mahad-ai__titles { display: flex; flex-direction: column; line-height: 1.15; }
.mahad-ai__brand { font-weight: 700; font-size: 15px; }
.mahad-ai__subtitle { font-size: 12px; opacity: .85; }
.mahad-ai__close {
	border: 0;
	background: transparent;
	color: inherit;
	cursor: pointer;
	padding: 6px;
	border-radius: 8px;
	display: inline-flex;
}
.mahad-ai__close:hover { background: rgba(255, 255, 255, .18); }
.mahad-ai__close:focus-visible,
.mahad-ai__chip:focus-visible,
.mahad-ai__send:focus-visible,
.mahad-ai__human:focus-visible,
.mahad-ai__input:focus-visible {
	outline: 3px solid var(--mai-navy);
	outline-offset: 2px;
}

/* ---- Messages ---- */
.mahad-ai__messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--mai-surface);
}
.mahad-ai__bubble {
	max-width: 84%;
	padding: 10px 13px;
	border-radius: 14px;
	font-size: 14px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
.mahad-ai__bubble p { margin: 0; }
.mahad-ai__bubble--assistant {
	align-self: flex-start;
	background: #fff;
	border: 1px solid var(--mai-line);
	border-bottom-left-radius: 4px;
}
.mahad-ai__bubble--user {
	align-self: flex-end;
	background: var(--mai-accent);
	color: var(--mai-accent-ink);
	border-bottom-right-radius: 4px;
}
.mahad-ai__automated-tag {
	display: inline-block;
	margin-bottom: 5px;
	font-size: 10.5px;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: var(--mai-orange);
}

/* ---- Link cards ---- */
.mahad-ai__cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.mahad-ai__card {
	display: block;
	padding: 9px 12px;
	border: 1px solid var(--mai-line);
	border-left: 3px solid var(--mai-accent);
	border-radius: 10px;
	background: #fff;
	text-decoration: none;
	color: var(--mai-blue);
	font-weight: 600;
	font-size: 13.5px;
	transition: border-color .15s ease, transform .15s ease;
}
.mahad-ai__card:hover { transform: translateX(2px); border-color: var(--mai-accent); }
.mahad-ai__card-type {
	display: block;
	font-size: 10.5px;
	font-weight: 700;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: var(--mai-muted);
	margin-bottom: 2px;
}

/* ---- Typing indicator ---- */
.mahad-ai__typing {
	align-self: flex-start;
	display: inline-flex;
	gap: 4px;
	padding: 12px 14px;
	background: #fff;
	border: 1px solid var(--mai-line);
	border-radius: 14px;
	border-bottom-left-radius: 4px;
}
.mahad-ai__typing span {
	width: 7px; height: 7px;
	border-radius: 50%;
	background: var(--mai-muted);
	animation: mahad-ai-blink 1.2s infinite ease-in-out both;
}
.mahad-ai__typing span:nth-child(2) { animation-delay: .18s; }
.mahad-ai__typing span:nth-child(3) { animation-delay: .36s; }
@keyframes mahad-ai-blink {
	0%, 80%, 100% { opacity: .3; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-3px); }
}

/* ---- Quick actions ---- */
.mahad-ai__quick {
	display: flex;
	flex-wrap: wrap;
	gap: 7px;
	padding: 10px 14px 4px;
	border-top: 1px solid var(--mai-line);
}
.mahad-ai__chip {
	border: 1px solid var(--mai-line);
	background: #fff;
	color: var(--mai-blue);
	font-family: var(--mai-font);
	font-size: 12.5px;
	font-weight: 600;
	padding: 7px 12px;
	border-radius: 999px;
	cursor: pointer;
	transition: background .15s ease, border-color .15s ease;
}
.mahad-ai__chip:hover { background: var(--mai-surface); border-color: var(--mai-accent); }

/* ---- Lead form ---- */
.mahad-ai__lead {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-top: 8px;
	padding: 12px;
	background: #fff;
	border: 1px solid var(--mai-line);
	border-radius: 12px;
}
.mahad-ai__lead input,
.mahad-ai__lead textarea {
	width: 100%;
	font-family: var(--mai-font);
	font-size: 13.5px;
	padding: 9px 11px;
	border: 1px solid var(--mai-line);
	border-radius: 9px;
	color: var(--mai-text);
}
.mahad-ai__lead textarea { resize: vertical; min-height: 60px; }
.mahad-ai__lead button {
	border: 0;
	background: var(--mai-green);
	color: #14320a;
	font-family: var(--mai-font);
	font-weight: 700;
	font-size: 13.5px;
	padding: 10px 12px;
	border-radius: 9px;
	cursor: pointer;
}
.mahad-ai__lead button:hover { filter: brightness(.96); }

/* ---- Consent notice ---- */
.mahad-ai__consent {
	margin: 0;
	padding: 6px 14px 8px;
	font-size: 11px;
	line-height: 1.4;
	color: var(--mai-muted);
}

/* ---- Input bar ---- */
.mahad-ai__inputbar {
	display: flex;
	gap: 8px;
	align-items: center;
	padding: 10px 12px;
	border-top: 1px solid var(--mai-line);
	background: #fff;
}
.mahad-ai__input {
	flex: 1 1 auto;
	border: 1px solid var(--mai-line);
	border-radius: 999px;
	padding: 11px 15px;
	font-family: var(--mai-font);
	font-size: 14px;
	color: var(--mai-text);
	background: var(--mai-surface);
}
.mahad-ai__send {
	flex: 0 0 auto;
	border: 0;
	width: 42px; height: 42px;
	border-radius: 50%;
	background: var(--mai-accent);
	color: var(--mai-accent-ink);
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.mahad-ai__send:hover { filter: brightness(.96); }

/* ---- Footer ---- */
.mahad-ai__footer {
	padding: 8px 14px 12px;
	text-align: center;
	background: #fff;
}
.mahad-ai__human {
	font-size: 12.5px;
	font-weight: 600;
	color: var(--mai-orange);
	text-decoration: none;
}
.mahad-ai__human:hover { text-decoration: underline; }

.mahad-ai .screen-reader-text {
	position: absolute !important;
	width: 1px; height: 1px;
	padding: 0; margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ---- Mobile: full screen ---- */
@media (max-width: 600px) {
	.mahad-ai { bottom: 16px; }
	.mahad-ai[data-position="bottom-right"] { right: 16px; }
	.mahad-ai[data-position="bottom-left"]  { left: 16px; }
	.mahad-ai__launcher-label { display: none; }
	.mahad-ai__launcher { padding: 15px; }

	.mahad-ai.is-open .mahad-ai__panel,
	.mahad-ai__panel {
		position: fixed;
		inset: 0;
		width: 100vw;
		height: 100vh;
		height: 100dvh;
		max-height: none;
		border: 0;
		border-radius: 0;
	}
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
	.mahad-ai__panel { animation: none; }
	.mahad-ai__launcher,
	.mahad-ai__card { transition: none; }
	.mahad-ai__typing span { animation: none; }
}
