/*
 * Qwen AI Chat — front-end styles.
 *
 * Layout-shift notes: the inline panel has its height fixed from the server so
 * nothing moves when the script hydrates, and the floating launcher is
 * position:fixed so it is out of document flow entirely.
 */

.qwen-chat {
	/*
	 * Accent comes from the admin colour picker, injected on :root. Consuming
	 * it with var() + fallback rather than redeclaring it here matters: a local
	 * redeclaration would shadow the root value and the setting would do
	 * nothing.
	 */
	--qwen-accent: var(--qwen-primary, #6366f1);
	--qwen-accent-strong: var(--qwen-primary-dark, #4f46e5);
	--qwen-ring: color-mix(in oklch, var(--qwen-accent) 40%, transparent);

	--qwen-r-lg: var(--qwen-radius, 16px);
	--qwen-r-md: 12px;
	--qwen-r-sm: 8px;

	/* Neutrals tinted toward the accent hue; never pure black or white. */
	--qwen-bg: oklch(0.995 0.002 275);
	--qwen-surface: oklch(0.972 0.004 275);
	--qwen-border: oklch(0.918 0.008 275);
	--qwen-text: oklch(0.26 0.018 275);
	--qwen-text-soft: oklch(0.53 0.021 275);
	--qwen-on-accent: oklch(0.99 0.004 275);

	--qwen-ease: cubic-bezier(0.22, 1, 0.36, 1);

	box-sizing: border-box;
	font-family: inherit;
	color: var(--qwen-text);
}

.qwen-chat *,
.qwen-chat *::before,
.qwen-chat *::after {
	box-sizing: border-box;
}

.qwen-chat[data-theme='dark'],
.qwen-chat[data-theme='auto'] {
	color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
	.qwen-chat[data-theme='auto'] {
		--qwen-bg: oklch(0.196 0.011 275);
		--qwen-surface: oklch(0.245 0.014 275);
		--qwen-border: oklch(0.325 0.016 275);
		--qwen-text: oklch(0.945 0.008 275);
		--qwen-text-soft: oklch(0.705 0.014 275);
	}
}

.qwen-chat[data-theme='dark'] {
	--qwen-bg: oklch(0.196 0.011 275);
	--qwen-surface: oklch(0.245 0.014 275);
	--qwen-border: oklch(0.325 0.016 275);
	--qwen-text: oklch(0.945 0.008 275);
	--qwen-text-soft: oklch(0.705 0.014 275);
}

/*
 * The `hidden` attribute is enforced by the user-agent stylesheet, which any
 * author rule outranks. Every `display` declaration below would therefore
 * silently un-hide its element, so restore `hidden` explicitly first.
 */
.qwen-chat [hidden],
.qwen-chat[hidden] {
	display: none !important;
}

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

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

.qwen-chat__panel {
	display: flex;
	flex-direction: column;
	background: var(--qwen-bg);
	border: 1px solid var(--qwen-border);
	border-radius: var(--qwen-r-lg);
	overflow: hidden;
}

.qwen-chat--inline {
	display: block;
	width: 100%;
	margin: 0 auto;
}

.qwen-chat--inline .qwen-chat__panel {
	/* Height comes from the server so hydration causes no shift. */
	height: var(--qwen-h, 600px);
}

.qwen-chat__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--qwen-border);
	background: var(--qwen-surface);
}

.qwen-chat__identity {
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 0;
}

.qwen-chat__dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #22c55e;
	flex: none;
}

.qwen-chat__name {
	font-weight: 600;
	font-size: 0.95rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.qwen-chat__header-actions {
	display: flex;
	gap: 4px;
	flex: none;
}

.qwen-chat__icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--qwen-text-soft);
	cursor: pointer;
}

.qwen-chat__icon-btn:hover,
.qwen-chat__icon-btn:focus-visible {
	background: rgba(127, 127, 127, 0.14);
	color: var(--qwen-text);
}

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

.qwen-chat__log {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 14px;
	background: var(--qwen-bg);
}

.qwen-msg {
	max-width: 92%;
	/* Rendering work scales with DOM size; skip offscreen bubbles. */
	content-visibility: auto;
	contain-intrinsic-size: auto 80px;
}

.qwen-msg--user {
	align-self: flex-end;
}

.qwen-msg--assistant,
.qwen-msg--intro {
	align-self: flex-start;
}

.qwen-msg__body {
	padding: 10px 14px;
	border-radius: 14px;
	background: var(--qwen-surface);
	font-size: 0.95rem;
	line-height: 1.6;
	overflow-wrap: anywhere;
}

.qwen-msg--user .qwen-msg__body {
	background: var(--qwen-accent);
	color: var(--qwen-on-accent);
	white-space: pre-wrap;
}

.qwen-msg__body > *:first-child {
	margin-top: 0;
}

.qwen-msg__body > *:last-child {
	margin-bottom: 0;
}

.qwen-msg__body p {
	margin: 0 0 0.7em;
}

.qwen-msg__body ul,
.qwen-msg__body ol {
	margin: 0 0 0.7em;
	padding-left: 1.3em;
}

.qwen-msg__body pre {
	margin: 0.7em 0;
	padding: 12px;
	border-radius: 10px;
	background: #0f1115;
	color: #e6edf3;
	overflow-x: auto;
	font-size: 0.85rem;
}

.qwen-msg__body code {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.88em;
}

.qwen-msg__body :not(pre) > code {
	padding: 0.15em 0.4em;
	border-radius: 5px;
	background: rgba(127, 127, 127, 0.18);
}

.qwen-msg__streaming {
	white-space: pre-wrap;
	margin: 0;
}

.qwen-msg__image {
	display: block;
	max-width: 220px;
	height: auto;
	margin-bottom: 6px;
	border-radius: 10px;
}

.qwen-msg__tools {
	display: flex;
	gap: 6px;
	margin-top: 6px;
	padding-left: 4px;
}

.qwen-msg__tool {
	border: 0;
	background: transparent;
	padding: 2px 6px;
	border-radius: 6px;
	font-size: 0.78rem;
	color: var(--qwen-text-soft);
	cursor: pointer;
}

.qwen-msg__tool:hover:not(:disabled) {
	background: rgba(127, 127, 127, 0.14);
}

.qwen-msg__tool:disabled {
	cursor: default;
	opacity: 0.55;
}

.qwen-msg__tool.is-selected {
	opacity: 1;
}

/* -------------------------------------------------------------- Related */

.qwen-related {
	margin-top: 10px;
	padding: 10px 14px;
	border: 1px solid var(--qwen-border);
	border-radius: 12px;
}

.qwen-related__label {
	margin: 0 0 6px;
	font-size: 0.78rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--qwen-text-soft);
}

.qwen-related__list {
	margin: 0;
	padding-left: 1.1em;
	font-size: 0.88rem;
}

.qwen-related__list li + li {
	margin-top: 3px;
}

/* ------------------------------------------------------------- Starters */

.qwen-starters__label {
	margin: 4px 0 8px;
	font-size: 0.8rem;
	color: var(--qwen-text-soft);
}

.qwen-starters__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.qwen-starters__btn {
	padding: 7px 12px;
	border: 1px solid var(--qwen-border);
	border-radius: 999px;
	background: var(--qwen-bg);
	color: var(--qwen-text);
	font-size: 0.85rem;
	cursor: pointer;
}

.qwen-starters__btn:hover,
.qwen-starters__btn:focus-visible {
	border-color: var(--qwen-accent);
	color: var(--qwen-accent);
}

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

.qwen-chat__status {
	min-height: 20px;
	padding: 0 16px;
	font-size: 0.82rem;
	color: var(--qwen-text-soft);
}

.qwen-chat__status--error {
	color: #dc2626;
}

.qwen-chat__composer {
	border-top: 1px solid var(--qwen-border);
	padding: 10px 12px 8px;
	background: var(--qwen-bg);
}

.qwen-chat__attachment {
	position: relative;
	display: inline-block;
	margin-bottom: 8px;
}

.qwen-chat__attachment img {
	display: block;
	max-height: 72px;
	width: auto;
	border-radius: 8px;
}

.qwen-chat__attachment button {
	position: absolute;
	top: -6px;
	right: -6px;
	width: 22px;
	height: 22px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: oklch(0.22 0.015 275);
	color: oklch(0.98 0.004 275);
	cursor: pointer;
}

/*
 * The composer is one bordered field that the attach and send controls sit
 * inside, rather than three separate boxes in a row. It reads as a single
 * input, and the send button stops competing with the textarea's border.
 */
.qwen-chat__input-row {
	display: flex;
	align-items: flex-end;
	gap: 6px;
	padding: 6px 6px 6px 8px;
	border: 1px solid var(--qwen-border);
	border-radius: var(--qwen-r-md);
	background: var(--qwen-surface);
	transition: border-color 180ms var(--qwen-ease), box-shadow 180ms var(--qwen-ease);
}

.qwen-chat__input-row:focus-within {
	border-color: var(--qwen-accent);
	box-shadow: 0 0 0 3px var(--qwen-ring);
}

.qwen-chat__input {
	flex: 1 1 auto;
	min-height: 36px;
	max-height: 160px;
	padding: 8px 2px;
	border: 0;
	background: none;
	color: var(--qwen-text);
	font: inherit;
	font-size: 0.95rem;
	line-height: 1.45;
	resize: none;
}

/* The ring lives on the wrapper, so the textarea itself must not draw one. */
.qwen-chat__input:focus,
.qwen-chat__input:focus-visible {
	outline: none;
}

.qwen-chat__input::placeholder {
	color: var(--qwen-text-soft);
}

.qwen-chat__attach {
	flex: none;
	height: 36px;
	width: 36px;
	cursor: pointer;
}

.qwen-chat__send {
	flex: none;
	width: 36px;
	height: 36px;
	padding: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: var(--qwen-r-sm);
	background: var(--qwen-accent);
	color: var(--qwen-on-accent);
	cursor: pointer;
	transition: background-color 160ms var(--qwen-ease), transform 160ms var(--qwen-ease);
}

/*
 * Size and paint the glyph from CSS rather than relying on the element's
 * width/height attributes and inherited `color`. A theme reset such as
 * `img, svg { height: auto }` can otherwise collapse the icon to nothing,
 * which is exactly how it went missing.
 */
.qwen-chat__send svg,
.qwen-chat__icon-btn svg,
.qwen-chat__launcher svg {
	display: block;
	flex: none;
	width: 20px;
	height: 20px;
	fill: currentColor;
	pointer-events: none;
}

.qwen-chat__icon-btn svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
}

.qwen-chat__send:hover:not(:disabled) {
	background: var(--qwen-accent-strong);
}

.qwen-chat__send:active:not(:disabled) {
	transform: scale(0.94);
}

.qwen-chat__send:focus-visible {
	outline: 2px solid var(--qwen-accent);
	outline-offset: 2px;
}

/* Idle until there is something to send: present, but visibly not the action. */
.qwen-chat__send:disabled {
	background: color-mix(in oklch, var(--qwen-accent) 22%, var(--qwen-surface));
	color: var(--qwen-text-soft);
	cursor: default;
}

.qwen-chat__toolbar {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 8px;
	font-size: 0.78rem;
	color: var(--qwen-text-soft);
}

.qwen-chat__select {
	max-width: 190px;
	padding: 4px 8px;
	border: 1px solid var(--qwen-border);
	border-radius: 8px;
	background: var(--qwen-bg);
	color: var(--qwen-text);
	font-size: 0.78rem;
}

.qwen-chat__toggle {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	cursor: pointer;
}

.qwen-chat__quota {
	margin: 0 0 0 auto;
}

.qwen-chat__footnote {
	margin: 0;
	padding: 0 16px 12px;
	font-size: 0.72rem;
	color: var(--qwen-text-soft);
}

/* ------------------------------------------------------------- Floating */

.qwen-chat--floating {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99990;
	/* position:fixed keeps the launcher out of flow, so it cannot shift the
	   page and cannot contribute to CLS. */
}

.qwen-chat__launcher {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 12px 18px;
	border: 0;
	border-radius: 999px;
	background: var(--qwen-accent);
	color: var(--qwen-on-accent);
	font-size: 0.92rem;
	font-weight: 600;
	cursor: pointer;
	box-shadow: 0 6px 20px color-mix(in oklch, var(--qwen-accent) 35%, transparent);
	transition: background-color 160ms var(--qwen-ease), transform 160ms var(--qwen-ease);
}

.qwen-chat__launcher:hover {
	background: var(--qwen-accent-strong);
}

.qwen-chat__launcher:active {
	transform: scale(0.97);
}

.qwen-chat__launcher:focus-visible {
	outline: 2px solid var(--qwen-accent);
	outline-offset: 3px;
}

.qwen-chat--floating .qwen-chat__panel {
	position: absolute;
	right: 0;
	bottom: 62px;
	width: min(var(--qwen-widget-w), calc(100vw - 32px));
	height: min(var(--qwen-widget-h), calc(100vh - 120px));
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
}

@media (max-width: 520px) {
	.qwen-chat--floating {
		right: 12px;
		bottom: 12px;
	}

	.qwen-chat__launcher-text {
		display: none;
	}

	.qwen-chat__launcher {
		padding: 14px;
	}
}

/* --------------------------------------------------------- Model table */

.qwen-models {
	margin: 2rem 0;
}

.qwen-models__scroll {
	overflow-x: auto;
}

.qwen-models__table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.92rem;
}

.qwen-models__caption {
	caption-side: top;
	text-align: left;
	padding-bottom: 0.75rem;
	font-size: 0.88rem;
	color: #5b6472;
}

.qwen-models__table th,
.qwen-models__table td {
	padding: 0.7rem 0.8rem;
	border-bottom: 1px solid #e3e6ea;
	text-align: left;
	vertical-align: top;
}

.qwen-models__table thead th {
	font-size: 0.78rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: #5b6472;
	white-space: nowrap;
}

.qwen-models__name {
	display: block;
	font-weight: 600;
}

.qwen-models__id {
	display: block;
	margin-top: 2px;
	font-size: 0.78rem;
	color: #5b6472;
	overflow-wrap: anywhere;
}

.qwen-models__desc {
	display: block;
	margin-top: 6px;
	max-width: 34ch;
	font-weight: 400;
	font-size: 0.85rem;
	color: #5b6472;
}

.qwen-models__unknown {
	color: #8b95a3;
}

.qwen-models__note {
	margin-top: 0.9rem;
	font-size: 0.82rem;
	color: #5b6472;
}

/* ------------------------------------------------------------- Overview */

.qwen-seo {
	margin: 2rem 0;
}

.qwen-seo__disclaimer {
	padding: 0.9rem 1.1rem;
	border: 1px solid oklch(0.918 0.008 275);
	background: oklch(0.972 0.004 275);
	border-radius: 10px;
	font-size: 0.92rem;
}

.qwen-seo__list {
	padding-left: 1.2em;
}

.qwen-seo__list li {
	margin-bottom: 0.5em;
}

.qwen-faq__item {
	border-bottom: 1px solid #e3e6ea;
}

.qwen-faq__q {
	padding: 0.85rem 0;
	font-weight: 600;
	cursor: pointer;
}

.qwen-faq__a {
	padding-bottom: 0.85rem;
}

.qwen-faq__a p {
	margin: 0;
}

/* -------------------------------------------------------------- Notices */

.qwen-notice {
	padding: 1rem 1.2rem;
	border: 1px solid #e3e6ea;
	border-radius: 10px;
	background: #f6f7f9;
	color: #5b6472;
}

.qwen-notice--admin {
	border-color: #f0b429;
	background: #fff8e6;
	color: #6b4e00;
}

.qwen-notice p {
	margin: 0;
}

@media (prefers-reduced-motion: reduce) {
	.qwen-chat * {
		transition: none !important;
		animation: none !important;
	}
}
