/**
 * MTD AI Chatbot widget styles.
 * Everything is namespaced under .mtdchat- and resets inherited theme rules,
 * so the widget looks the same regardless of the active theme.
 */

.mtdchat-root {
	--mtdchat-accent: #2563eb;
	--mtdchat-accent-ink: #ffffff;
	--mtdchat-bg: #ffffff;
	--mtdchat-panel: #f7f8fa;
	--mtdchat-ink: #16181d;
	--mtdchat-ink-soft: #5b6472;
	--mtdchat-line: #e3e6ec;
	--mtdchat-bubble-bot: #f1f3f7;
	--mtdchat-radius: 16px;
	--mtdchat-shadow: 0 18px 48px rgba(16, 24, 40, 0.18);
	--mtdchat-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

	position: fixed;
	bottom: 20px;
	z-index: 999999;
	font-family: var(--mtdchat-font);
	font-size: 15px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

.mtdchat-root.is-right { right: 20px; }
.mtdchat-root.is-left  { left: 20px; }

@media (prefers-color-scheme: dark) {
	.mtdchat-root:not(.is-light) {
		--mtdchat-bg: #16181d;
		--mtdchat-panel: #1d2027;
		--mtdchat-ink: #eceef2;
		--mtdchat-ink-soft: #9aa3b2;
		--mtdchat-line: #2c313a;
		--mtdchat-bubble-bot: #242830;
		--mtdchat-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
	}
}

/* ---------- Launcher ---------- */

.mtdchat-launcher {
	display: inline-flex;
	align-items: center;
	gap: 9px;
	margin: 0;
	padding: 13px 19px;
	border: 0;
	border-radius: 999px;
	background: var(--mtdchat-accent);
	color: var(--mtdchat-accent-ink);
	font: inherit;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	box-shadow: var(--mtdchat-shadow);
	transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.mtdchat-launcher:hover { transform: translateY(-2px); }
.mtdchat-launcher:focus-visible { outline: 3px solid var(--mtdchat-accent); outline-offset: 3px; }
.mtdchat-launcher svg { width: 20px; height: 20px; flex: 0 0 auto; }
.mtdchat-root.is-open .mtdchat-launcher { opacity: 0; pointer-events: none; }

@media (max-width: 480px) {
	.mtdchat-launcher-text { display: none; }
	.mtdchat-launcher { padding: 15px; }
}

/* ---------- Panel ---------- */

.mtdchat-panel {
	position: absolute;
	bottom: 0;
	width: min(400px, calc(100vw - 40px));
	height: min(620px, calc(100vh - 100px));
	display: none;
	flex-direction: column;
	overflow: hidden;
	background: var(--mtdchat-bg);
	color: var(--mtdchat-ink);
	border: 1px solid var(--mtdchat-line);
	border-radius: var(--mtdchat-radius);
	box-shadow: var(--mtdchat-shadow);
}

.mtdchat-root.is-right .mtdchat-panel { right: 0; }
.mtdchat-root.is-left  .mtdchat-panel { left: 0; }
.mtdchat-root.is-open  .mtdchat-panel { display: flex; animation: mtdchat-in .22s ease both; }

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

@media (prefers-reduced-motion: reduce) {
	.mtdchat-root.is-open .mtdchat-panel { animation: none; }
	.mtdchat-launcher { transition: none; }
}

@media (max-width: 520px) {
	.mtdchat-root { bottom: 14px; }
	.mtdchat-root.is-right { right: 14px; }
	.mtdchat-root.is-left { left: 14px; }
	.mtdchat-root.is-open .mtdchat-panel {
		position: fixed;
		inset: 0;
		width: 100vw;
		height: 100dvh;
		border: 0;
		border-radius: 0;
	}
}

/* ---------- Inline (shortcode) ---------- */

.mtdchat-inline { width: 100%; }

.mtdchat-root.is-inline {
	position: relative;
	inset: auto;
	width: 100%;
	height: 100%;
}

.mtdchat-root.is-inline .mtdchat-launcher { display: none; }

.mtdchat-root.is-inline .mtdchat-panel {
	position: relative;
	display: flex;
	width: 100%;
	height: 100%;
	animation: none;
}

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

.mtdchat-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 14px 14px 18px;
	background: var(--mtdchat-accent);
	color: var(--mtdchat-accent-ink);
	flex: 0 0 auto;
}

.mtdchat-title { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .01em; }
.mtdchat-status { margin: 2px 0 0; font-size: 12px; opacity: .85; }
.mtdchat-header-text { flex: 1 1 auto; min-width: 0; }

.mtdchat-iconbtn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, .16);
	color: inherit;
	cursor: pointer;
	flex: 0 0 auto;
}

.mtdchat-iconbtn:hover { background: rgba(255, 255, 255, .28); }
.mtdchat-iconbtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.mtdchat-iconbtn svg { width: 17px; height: 17px; }

/* ---------- Log ---------- */

.mtdchat-log {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 18px 16px;
	background: var(--mtdchat-panel);
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.mtdchat-msg { display: flex; max-width: 88%; }
.mtdchat-msg.is-user { align-self: flex-end; }
.mtdchat-msg.is-bot  { align-self: flex-start; }

.mtdchat-bubble {
	padding: 11px 14px;
	border-radius: 14px;
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.mtdchat-msg.is-user .mtdchat-bubble {
	background: var(--mtdchat-accent);
	color: var(--mtdchat-accent-ink);
	border-bottom-right-radius: 5px;
}

.mtdchat-msg.is-bot .mtdchat-bubble {
	background: var(--mtdchat-bubble-bot);
	color: var(--mtdchat-ink);
	border: 1px solid var(--mtdchat-line);
	border-bottom-left-radius: 5px;
}

.mtdchat-msg.is-error .mtdchat-bubble {
	background: #fdecec;
	color: #8a1c1c;
	border-color: #f5c2c2;
}

.mtdchat-bubble p { margin: 0 0 .6em; }
.mtdchat-bubble p:last-child { margin-bottom: 0; }
.mtdchat-bubble ul, .mtdchat-bubble ol { margin: .3em 0 .6em; padding-left: 1.3em; }
.mtdchat-bubble li { margin: .18em 0; }
.mtdchat-bubble a { color: inherit; text-decoration: underline; }

.mtdchat-bubble code {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: .88em;
	background: rgba(127, 127, 127, .16);
	padding: .12em .38em;
	border-radius: 4px;
}

.mtdchat-bubble pre {
	margin: .5em 0;
	padding: 10px 12px;
	border-radius: 9px;
	background: rgba(127, 127, 127, .16);
	overflow-x: auto;
	white-space: pre;
}

.mtdchat-bubble pre code { background: none; padding: 0; font-size: .85em; }

/* ---------- Reasoning disclosure ---------- */

.mtdchat-reasoning {
	margin: 8px 0 0;
	font-size: 13px;
	color: var(--mtdchat-ink-soft);
}

.mtdchat-reasoning summary { cursor: pointer; font-weight: 600; }

.mtdchat-reasoning div {
	margin-top: 6px;
	padding: 9px 11px;
	border-left: 3px solid var(--mtdchat-line);
	background: rgba(127, 127, 127, .08);
	border-radius: 0 8px 8px 0;
	white-space: pre-wrap;
}

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

.mtdchat-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }

.mtdchat-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--mtdchat-ink-soft);
	animation: mtdchat-blink 1.3s infinite ease-in-out both;
}

.mtdchat-typing span:nth-child(2) { animation-delay: .18s; }
.mtdchat-typing span:nth-child(3) { animation-delay: .36s; }

@keyframes mtdchat-blink {
	0%, 80%, 100% { opacity: .25; transform: scale(.8); }
	40% { opacity: 1; transform: scale(1); }
}

/* ---------- Composer ---------- */

.mtdchat-form {
	flex: 0 0 auto;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	background: var(--mtdchat-bg);
	border-top: 1px solid var(--mtdchat-line);
}

.mtdchat-input {
	flex: 1 1 auto;
	min-height: 42px;
	max-height: 132px;
	padding: 11px 13px;
	border: 1px solid var(--mtdchat-line);
	border-radius: 11px;
	background: var(--mtdchat-panel);
	color: var(--mtdchat-ink);
	font: inherit;
	line-height: 1.45;
	resize: none;
	overflow-y: auto;
	box-sizing: border-box;
}

.mtdchat-input:focus {
	outline: none;
	border-color: var(--mtdchat-accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--mtdchat-accent) 22%, transparent);
}

.mtdchat-input::placeholder { color: var(--mtdchat-ink-soft); opacity: 1; }

.mtdchat-send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	flex: 0 0 auto;
	padding: 0;
	border: 0;
	border-radius: 11px;
	background: var(--mtdchat-accent);
	color: var(--mtdchat-accent-ink);
	cursor: pointer;
	transition: opacity .15s ease;
}

.mtdchat-send:disabled { opacity: .45; cursor: not-allowed; }
.mtdchat-send:focus-visible { outline: 3px solid var(--mtdchat-accent); outline-offset: 2px; }
.mtdchat-send svg { width: 19px; height: 19px; }

.mtdchat-foot {
	flex: 0 0 auto;
	margin: 0;
	padding: 0 12px 10px;
	background: var(--mtdchat-bg);
	color: var(--mtdchat-ink-soft);
	font-size: 11.5px;
	text-align: center;
}

.mtdchat-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
