.mgs-chat-bubble,
.mgs-chat-panel {
	font-family: var(--font-body);
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 100000; /* the site's fixed header sits very high */
}

.mgs-chat-bubble[hidden],
.mgs-chat-panel[hidden] {
	display: none;
}

.mgs-chat-bubble {
	align-items: center;
	background: var(--accent);
	border: 0;
	border-radius: 999px;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
	color: var(--accent-ink);
	cursor: pointer;
	display: flex;
	font-size: 15px;
	font-weight: 600;
	gap: 8px;
	padding: 11px 18px 11px 14px;
}

.mgs-chat-bubble:hover {
	background: #ffe07a;
}

.mgs-chat-panel {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: 12px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
	color: var(--text-soft);
	display: flex;
	flex-direction: column;
	height: min(560px, calc(100vh - 40px));
	overflow: hidden;
	width: 380px;
}

.mgs-chat-header {
	align-items: center;
	background: var(--surface-2);
	border-bottom: 1px solid var(--line);
	display: flex;
	justify-content: space-between;
	padding: 10px 8px 10px 16px;
}

.mgs-chat-header h2 {
	color: #fff;
	font-family: var(--font-heading);
	font-size: 19px;
	font-weight: 700;
	margin: 0;
}

.mgs-chat-close {
	background: none;
	border: 0;
	border-radius: 6px;
	color: var(--text);
	cursor: pointer;
	font-size: 24px;
	line-height: 1;
	padding: 2px 10px 5px;
}

.mgs-chat-close:hover {
	background: var(--line);
}

.mgs-chat-thread {
	flex: 1;
	font-size: 15px;
	line-height: 1.45;
	overflow-y: auto;
	padding: 14px;
}

.mgs-chat-welcome p {
	color: var(--text-soft);
	margin: 0 0 12px;
}

.mgs-chat-chip {
	background: var(--surface-2);
	border: 1px solid var(--line);
	border-radius: 8px;
	color: var(--text);
	cursor: pointer;
	display: block;
	font-size: 14px;
	margin-bottom: 8px;
	padding: 8px 11px;
	text-align: left;
	width: 100%;
}

.mgs-chat-chip:hover {
	border-color: var(--accent);
}

.mgs-chat-message {
	margin-bottom: 14px;
}

.mgs-chat-user {
	background: var(--surface-2);
	border-radius: 12px 12px 3px 12px;
	color: var(--text);
	margin-left: auto;
	overflow-wrap: anywhere;
	padding: 7px 12px;
	white-space: pre-wrap;
	width: fit-content;
}

.mgs-chat-answer p {
	margin: 0 0 8px;
}

.mgs-chat-answer ul {
	margin: 0 0 8px;
	padding-left: 20px;
}

.mgs-chat-answer > :last-child {
	margin-bottom: 0;
}

.mgs-chat-answer a {
	color: var(--accent);
	text-decoration: underline;
	text-underline-offset: 3px;
}

.mgs-chat-answer a:hover {
	color: #fff;
}

.mgs-chat-thinking {
	color: var(--muted);
	font-style: italic;
}

.mgs-chat-error {
	color: #ff8f7a;
}

.mgs-chat-form {
	align-items: flex-end;
	border-top: 1px solid var(--line);
	display: flex;
	gap: 8px;
	margin: 0;
	padding: 10px 10px 4px;
}

.mgs-chat-form textarea {
	background: var(--bg);
	border: 1px solid var(--line);
	border-radius: 6px;
	color: var(--text);
	flex: 1;
	font: 16px/1.3 var(--font-body);
	min-width: 0;
	padding: 7px 9px;
	resize: none;
}

.mgs-chat-form textarea::placeholder {
	color: var(--muted);
}

.mgs-chat-send {
	background: var(--accent);
	border: 0;
	border-radius: 6px;
	color: var(--accent-ink);
	cursor: pointer;
	font-size: 15px;
	font-weight: 600;
	padding: 8px 14px;
}

.mgs-chat-send:hover {
	background: #ffe07a;
}

.mgs-chat-send:disabled {
	background: var(--accent);
	cursor: default;
	opacity: 0.55;
}

.mgs-chat-fine-print {
	color: var(--muted);
	font-size: 11px;
	margin: 0;
	padding: 3px 10px 8px;
	text-align: center;
}

.mgs-chat-bubble:focus-visible,
.mgs-chat-close:focus-visible,
.mgs-chat-chip:focus-visible,
.mgs-chat-send:focus-visible,
.mgs-chat-form textarea:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

@media (max-width: 500px) {
	.mgs-chat-bubble {
		bottom: 14px;
		right: 14px;
	}

	.mgs-chat-panel {
		border: 0;
		border-radius: 0;
		bottom: 0;
		height: 100dvh;
		right: 0;
		width: 100%;
	}
}
