/* ============================================================
   Math Question Widget
   ============================================================ */

/* Wrapper */
.mqw-wrapper {
	background-color: #eeeef8;
	border-radius: 16px;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	width: 100%;
	font-family: inherit;
	box-sizing: border-box;
}

/* ── Input Bar ─────────────────────────────────────────── */
.mqw-input-bar {
	display: flex;
	align-items: center;
	background: #ffffff;
	border-radius: 50px;
	padding: 6px 6px 6px 12px;
	gap: 8px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.mqw-icon-btn {
	background: none;
	border: none;
	cursor: pointer;
	padding: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #a0a0c0;
	flex-shrink: 0;
	border-radius: 50%;
	transition: color 0.2s;
}

.mqw-icon-btn:hover {
	color: #6060a0;
}

.mqw-divider {
	width: 1px;
	height: 22px;
	background: #ddddef;
	flex-shrink: 0;
}

.mqw-text-input {
	flex: 1;
	border: none;
	outline: none;
	background: transparent;
	font-size: 15px;
	color: #5a5a7a;
	padding: 6px 0;
	min-width: 0;
}

.mqw-text-input::placeholder {
	color: #b0b0cc;
}

.mqw-submit-btn {
	background-color: #c8c8e0;
	border: none;
	border-radius: 50%;
	width: 38px;
	height: 38px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	color: #ffffff;
	transition: background-color 0.2s, transform 0.15s;
}

.mqw-submit-btn:hover {
	background-color: #9090c0;
	transform: scale(1.05);
}

/* ── Upload Area ───────────────────────────────────────── */
.mqw-upload-area {
	background: #ffffff;
	border: 2px dashed #c8c8e8;
	border-radius: 14px;
	padding: 36px 24px;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.2s, background-color 0.2s;
	position: relative;
	box-sizing: border-box;
}

.mqw-upload-area:hover,
.mqw-upload-area.mqw-drag-over {
	border-color: #8080c0;
	background-color: #f6f6ff;
}

/* Icon + Plus badge */
.mqw-upload-icon {
	position: relative;
	display: inline-block;
	margin-bottom: 12px;
	color: #c0c0d8;
}

.mqw-upload-plus {
	position: absolute;
	top: -4px;
	right: -8px;
	background: #c0c0d8;
	color: #ffffff;
	border-radius: 50%;
	width: 18px;
	height: 18px;
	font-size: 14px;
	line-height: 18px;
	text-align: center;
	font-weight: 700;
}

/* Labels */
.mqw-upload-label {
	margin: 0 0 6px;
	font-size: 14px;
	color: #7070a0;
	line-height: 1.5;
}

.mqw-upload-label strong {
	font-weight: 700;
	color: #5050a0;
}

.mqw-paste-hint {
	margin: 0;
	font-size: 12px;
	color: #a0a0c0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 5px;
}

.mqw-kbd {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: #ebebf5;
	border: 1px solid #d0d0e8;
	border-radius: 4px;
	padding: 1px 5px;
	font-size: 11px;
	color: #8080b0;
	font-family: system-ui, sans-serif;
}

/* ── Image Preview ─────────────────────────────────────── */
/* Hide upload labels once an image is loaded */
.mqw-upload-area.mqw-has-image .mqw-upload-icon,
.mqw-upload-area.mqw-has-image .mqw-upload-label,
.mqw-upload-area.mqw-has-image .mqw-paste-hint {
	display: none;
}

.mqw-preview {
	position: relative;
	display: inline-block;
	background: #8B88F51C;
	border-radius: 8px;
}

.mqw-preview-img {
	max-width: 100%;
	max-height: 160px;
	border-radius: 8px;
	display: block;
	margin: 0 auto;
	border: 1px solid #e0e0f0;
}

/* Upload progress bar */
.mqw-upload-progress {
	width: 100%;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 40px;
}

.mqw-upload-progress-track {
	flex: 1;
	height: 8px;
	background: #e8e8f4;
	border-radius: 20px;
	overflow: hidden;
}

.mqw-upload-progress-bar {
	height: 100%;
	width: 0%;
	background: #7070d0;
	border-radius: 20px;
	transition: width 0.3s ease;
}

.mqw-upload-progress-pct {
	font-size: 12px;
	font-weight: 600;
	color: #5050a0;
	min-width: 32px;
	text-align: right;
}

.mqw-remove-img {
	position: absolute;
	top: -8px;
	right: -8px;
	background: #e05050;
	color: #fff;
	border: none;
	border-radius: 50%;
	width: 22px;
	height: 22px;
	font-size: 11px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

/* Answer loader (bouncing dots before stream) */
.mqw-answer-loader {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	padding: 12px 0;
}

/* ── Submit loading state ──────────────────────────────── */
.mqw-submit-btn.mqw-loading {
	opacity: 0.6;
	cursor: not-allowed;
}

/* ── Streaming live indicator (pulsing dot in header) ──── */
.mqw-streaming-dot {
	display: none;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #7070d0;
	animation: mqw-pulse 1s infinite ease-in-out;
	margin-left: auto;
	margin-right: 8px;
}

@keyframes mqw-pulse {
	0%, 100% { opacity: 0.3; transform: scale(0.8); }
	50%       { opacity: 1;   transform: scale(1.2); }
}

/* ── Spinner (three bouncing dots) ─────────────────────── */
.mqw-spinner {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 20px 0;
}

.mqw-spinner span {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #9090c0;
	animation: mqw-bounce 1.2s infinite ease-in-out;
}

.mqw-spinner span:nth-child(1) { animation-delay: 0s;    }
.mqw-spinner span:nth-child(2) { animation-delay: 0.2s;  }
.mqw-spinner span:nth-child(3) { animation-delay: 0.4s;  }

@keyframes mqw-bounce {
	0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
	40%           { transform: scale(1.0); opacity: 1;   }
}

/* ── Answer Panel ──────────────────────────────────────── */
.mqw-answer-wrap {
	display: none;
	background: #ffffff;
	border-radius: 14px;
	border: 1px solid #e0e0f0;
	overflow: hidden;
}

.mqw-answer-wrap.mqw-answer-visible {
	display: block;
}

.mqw-answer-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 16px;
	background: #f4f4fc;
	border-bottom: 1px solid #e8e8f4;
}

.mqw-answer-label {
	font-size: 12px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: #8080b0;
}

.mqw-answer-close {
	background: none;
	border: none;
	cursor: pointer;
	color: #b0b0cc;
	font-size: 14px;
	line-height: 1;
	padding: 2px 4px;
	border-radius: 4px;
	transition: color 0.15s;
}

.mqw-answer-close:hover {
	color: #6060a0;
}

/* ── Markdown body ─────────────────────────────────────── */
.mqw-answer-body {
	padding: 20px 22px;
	font-size: 15px;
	line-height: 1.7;
	color: #3a3a5c;
	overflow-x: auto;
}

/* Headings */
.mqw-md h1, .mqw-md h2, .mqw-md h3,
.mqw-md h4, .mqw-md h5, .mqw-md h6 {
	margin: 1.4em 0 0.5em;
	font-weight: 700;
	color: #2a2a4a;
	line-height: 1.3;
}
.mqw-md h1 { font-size: 1.45em; }
.mqw-md h2 { font-size: 1.25em; }
.mqw-md h3 { font-size: 1.1em;  }

/* Paragraphs */
.mqw-md p { margin: 0 0 1em; }

/* Bold / Italic */
.mqw-md strong { font-weight: 700; color: #2a2a4a; }
.mqw-md em     { font-style: italic; }

/* Lists */
.mqw-md ul, .mqw-md ol {
	margin: 0 0 1em 1.5em;
	padding: 0;
}
.mqw-md li { margin-bottom: 0.35em; }

/* Blockquote */
.mqw-md blockquote {
	margin: 1em 0;
	padding: 10px 16px;
	border-left: 4px solid #c0c0e8;
	background: #f6f6ff;
	border-radius: 0 8px 8px 0;
	color: #6060a0;
}

/* Code inline */
.mqw-md code {
	background: #f0f0fa;
	border: 1px solid #e0e0f0;
	border-radius: 4px;
	padding: 1px 5px;
	font-size: 0.88em;
	font-family: 'Fira Code', 'Consolas', monospace;
	color: #5050a0;
}

/* Code block */
.mqw-md pre {
	background: #1e1e3a;
	border-radius: 10px;
	padding: 16px 20px;
	overflow-x: auto;
	margin: 1em 0;
}
.mqw-md pre code {
	background: none;
	border: none;
	padding: 0;
	font-size: 0.9em;
	color: #d0d0ff;
}

/* Horizontal rule */
.mqw-md hr {
	border: none;
	border-top: 1px solid #e0e0f0;
	margin: 1.5em 0;
}

/* Links */
.mqw-md a {
	color: #5555cc;
	text-decoration: underline;
}
.mqw-md a:hover { color: #3333aa; }

/* ── Answer meta bar ───────────────────────────────────── */
.mqw-answer-meta {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 22px 14px;
	border-top: 1px solid #eeeef8;
}

.mqw-answer-badge {
	font-size: 12px;
	font-weight: 600;
	color: #00a050;
	background: #eaffea;
	border: 1px solid #b0e8b0;
	border-radius: 20px;
	padding: 3px 10px;
}

.mqw-answer-link {
	font-size: 13px;
	color: #5555cc;
	text-decoration: none;
	font-weight: 500;
}
.mqw-answer-link:hover { text-decoration: underline; }

/* ── Access / Login toast ──────────────────────────────── */
.mqw-access-toast {
	position: fixed;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%) translateY(20px);
	z-index: 999999;
	padding: 14px 24px;
	font-size: 14px;
	color: #3a3a5c;
	background: #fff;
	border: 1px solid #e0e0f0;
	border-left: 3px solid #8080c0;
	border-radius: 8px;
	box-shadow: 0 8px 24px rgba(0,0,0,.12);
	line-height: 1.6;
	opacity: 0;
	transition: opacity .3s ease, transform .3s ease;
	pointer-events: auto;
	max-width: 90vw;
}
.mqw-access-toast.mqw-toast-visible {
	opacity: 1;
	transform: translateX(-50%) translateY(0);
}
.mqw-access-toast a {
	color: #5050b0;
	text-decoration: underline;
}

/* ── Error / Warning ───────────────────────────────────── */
.mqw-answer-error {
	margin: 0;
	padding: 16px 20px;
	color: #c03030;
	font-size: 14px;
	background: #fff5f5;
}

.mqw-answer-warning {
	margin: 0;
	padding: 10px 20px 14px;
	font-size: 13px;
	color: #a06000;
	background: #fffbe6;
	border-top: 1px solid #ffe88a;
}

/* ── Rating Display Badge ─────────────────────────────────── */
.mqw-rating-badge {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	background-color: #eeeef8;
	border-radius: 20px;
	padding: 8px 16px;
	font-size: 14px;
	font-weight: 600;
	color: #3a3a5c;
	line-height: 1;
}

.mqw-rating-icon {
	display: block;
	flex-shrink: 0;
	width: 15px;
	height: 15px;
}

.mqw-rating-percent {
	font-weight: 700;
	color: #2a2a4a;
}

.mqw-rating-count {
	font-weight: 400;
	color: #8080a0;
	font-size: 13px;
}

/* ── Helpful Buttons ──────────────────────────────────────── */
.mqw-helpful-wrap {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	width: 100%;
}

.mqw-helpful-spacer {
	flex: 1;
}

.mqw-copy-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	border: 1px solid #e0e0f0;
	border-radius: 10px;
	background: #ffffff;
	color: #8080a0;
	cursor: pointer;
	transition: border-color 0.2s, color 0.2s;
	flex-shrink: 0;
	padding: 0;
}

.mqw-copy-btn:hover {
	border-color: #9090c0;
	color: #5050a0;
}

.mqw-vote-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	border: 1px solid #e0e0f0;
	border-radius: 12px;
	background: #ffffff;
	color: #5a5a7a;
	font-size: 14px;
	font-weight: 500;
	padding: 11px 22px;
	cursor: pointer;
	transition: background-color 0.2s, border-color 0.2s, color 0.2s;
	line-height: 1;
}

.mqw-vote-btn:hover:not(:disabled) {
	border-color: #9090c0;
	color: #3a3a5c;
}

.mqw-vote-btn.mqw-voted {
	background-color: #eeeef8;
	border-color: #9090c0;
	color: #3a3a5c;
}

/* Fill the SVG icon solid when the button is in the voted state */
.mqw-vote-btn.mqw-voted .mqw-vote-icon {
	fill: currentColor;
	stroke: none;
}

.mqw-vote-btn:disabled {
	cursor: default;
	opacity: 0.75;
}

.mqw-vote-icon {
	display: block;
	flex-shrink: 0;
}

/* ── Follow-up Input Bar ──────────────────────────────────── */
.mqw-followup-wrap {
	width: 100%;
}

.mqw-followup-bar {
	display: flex;
	align-items: center;
	gap: 8px;
	background-color: #f5f5fa;
	border-radius: 50px;
	padding: 10px 10px 10px 20px;
	width: 100%;
	box-sizing: border-box;
}

.mqw-followup-icon {
	display: flex;
	align-items: center;
	flex-shrink: 0;
	color: #9090b0;
}

.mqw-followup-input {
	flex: 1;
	border: none;
	background: transparent;
	outline: none;
	font-size: 14px;
	color: #3a3a5c;
	min-width: 0;
	padding: 0;
}

.mqw-followup-input::placeholder {
	color: #a0a0c0;
}

.mqw-followup-chips {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-shrink: 0;
	flex-wrap: nowrap;
}

.mqw-followup-chip {
	display: inline-flex;
	align-items: center;
	border: none;
	border-radius: 50px;
	background: #ffffff;
	color: #5a5a7a;
	font-size: 13px;
	font-weight: 500;
	padding: 8px 14px;
	cursor: pointer;
	white-space: nowrap;
	transition: background-color 0.2s, color 0.2s;
	line-height: 1;
}

.mqw-followup-chip:hover {
	background-color: #ebebf8;
	color: #3a3a5c;
}

.mqw-followup-submit {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: #3a3a5c;
	color: #ffffff;
	border: none;
	cursor: pointer;
	flex-shrink: 0;
	padding: 0;
	transition: opacity 0.2s;
}

.mqw-followup-submit:hover {
	opacity: 0.85;
}

.mqw-followup-submit:disabled {
	opacity: 0.5;
	cursor: default;
}

.mqw-followup-answer {
	margin-top: 12px;
}

/* ── Submit button: gray by default, dark when ready ─────────── */
.mqw-followup-submit {
	background: #c0c0d0; /* gray — no text in field */
}
.mqw-followup-submit.mqw-submit-ready {
	background: #3a3a5c; /* dark — field has text */
}

/* ── Sidebar overlay ─────────────────────────────────────────── */
.mqw-sidebar-overlay {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.35);
	z-index: 99998;
}
.mqw-sidebar-overlay.mqw-sidebar-overlay-visible {
	display: block;
}

/* ── Sidebar panel ───────────────────────────────────────────── */
.mqw-sidebar {
	position: fixed;
	top: 5vh;
	right: -100%;
	width: 440px;
	max-width: calc(100vw - 70px);
	height: 95vh; /* fills from 5vh top to bottom edge */
	background: #ffffff;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	border-radius: 16px 16px 0 0; /* top corners rounded, bottom flush */
	box-shadow: 0 8px 40px rgba(0, 0, 0, 0.14);
	transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.mqw-sidebar.mqw-sidebar-open {
	right: 50px; /* 50px gap from right edge of screen */
}

/* Lock page scroll when sidebar is open */
body.mqw-sidebar-active {
	overflow: hidden;
}

/* Header */
.mqw-sidebar-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	border-bottom: 1px solid #eeeef8;
	flex-shrink: 0;
}
.mqw-sidebar-title {
	font-size: 15px;
	font-weight: 700;
	color: #2a2a4a;
}
.mqw-sidebar-close {
	background: none;
	border: none;
	cursor: pointer;
	color: #b0b0cc;
	font-size: 16px;
	padding: 4px 6px;
	border-radius: 6px;
	line-height: 1;
	transition: color 0.15s;
}
.mqw-sidebar-close:hover {
	color: #5050a0;
}

/* Chips row */
.mqw-sidebar-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 12px 20px;
	border-bottom: 1px solid #f0f0f8;
	flex-shrink: 0;
}
.mqw-sidebar-chips:empty {
	display: none;
}

/* Conversation body */
.mqw-sidebar-body {
	flex: 1;
	overflow-y: auto;
	padding: 20px 20px 12px;
	display: flex;
	flex-direction: column;
	gap: 20px;
}

/* User bubble */
.mqw-chat-user {
	display: flex;
	justify-content: flex-end;
}
.mqw-chat-user-bubble {
	background: #eeeef8;
	border-radius: 18px 18px 4px 18px;
	padding: 11px 16px;
	font-size: 14px;
	color: #2a2a4a;
	max-width: 85%;
	line-height: 1.55;
	word-break: break-word;
}

/* AI response */
.mqw-chat-ai {
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.mqw-chat-ai-body {
	font-size: 15px;
	line-height: 1.7;
	color: #3a3a5c;
}

/* Sidebar input row */
.mqw-sidebar-input-row {
	padding: 14px 16px 18px;
	border-top: 1px solid #eeeef8;
	flex-shrink: 0;
}

/* ── Hide chips when input is focused ───────────────────── */
.mqw-followup-bar.mqw-input-focused .mqw-followup-chips {
	display: none;
}

/* Mobile: reduce right gap so sidebar fits small screens */
@media ( max-width: 540px ) {
	.mqw-sidebar.mqw-sidebar-open {
		right: 16px;
	}
}

/* Mobile: show only the first chip */
@media ( max-width: 768px ) {
	.mqw-followup-chip:not(:first-child) {
		display: none;
	}
}
