/* The chat screen: sidebar, thread, messages, composer, and the menus and dialogs they open. */

:root {
	--chat-bg: #ffffff;
	--sb-bg: #f9fafb;
	--composer-bg: #ffffff;
	--bubble-user: #f3f4f6;
	--bubble-ai: #f9fafb;
	--bubble-ai-border: #f3f4f6;
	--code-bg: #f6f7f9;
	--menu-shadow: 0 10px 30px rgb(0 0 0 / 0.12), 0 1px 3px rgb(0 0 0 / 0.08);
	--ssb-ball: #000;
	--ssb-ripple: rgb(0 0 0 / 0.35);
	--ssb-idle-bg: #e5e7eb;
	--ssb-idle-fg: #9ca3af;
	--ssb-stop-bg: #fff;
	--ssb-stop-fg: #737373;
	--ssb-stop-border: #e5e5e5;
	--ssb-ring: rgb(31 41 55 / 0.35);
	--rc-bar-bg: rgb(0 0 0 / 0.06);
	--sb-width: 320px;
	--sb-card-bg: #fcfcfd;
	--sb-card-shadow: 0 2px 6px rgb(0 0 0 / 0.04), 0 1px 2px rgb(0 0 0 / 0.03);
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--chat-bg: #111827;
		--sb-bg: #0c111d;
		--composer-bg: #1f2937;
		--bubble-user: rgb(55 65 81 / 0.7);
		--bubble-ai: rgb(31 41 55 / 0.8);
		--bubble-ai-border: #1f2937;
		--code-bg: #0c111d;
		--menu-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
		--ssb-ball: #fff;
		--ssb-ripple: rgb(255 255 255 / 0.45);
		--ssb-idle-bg: #454545;
		--ssb-idle-fg: #a3a3a3;
		--ssb-stop-bg: #454545;
		--ssb-stop-fg: #d4d4d4;
		--ssb-stop-border: transparent;
		--ssb-ring: rgb(255 255 255 / 0.2);
		--rc-bar-bg: rgb(255 255 255 / 0.08);
		--sb-card-bg: #182131;
		--sb-card-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
	}
}

:root[data-theme="dark"] {
	--chat-bg: #111827;
	--sb-bg: #0c111d;
	--composer-bg: #1f2937;
	--bubble-user: rgb(55 65 81 / 0.7);
	--bubble-ai: rgb(31 41 55 / 0.8);
	--bubble-ai-border: #1f2937;
	--code-bg: #0c111d;
	--menu-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
	--ssb-ball: #fff;
	--ssb-ripple: rgb(255 255 255 / 0.45);
	--ssb-idle-bg: #454545;
	--ssb-idle-fg: #a3a3a3;
	--ssb-stop-bg: #454545;
	--ssb-stop-fg: #d4d4d4;
	--ssb-stop-border: transparent;
	--ssb-ring: rgb(255 255 255 / 0.2);
	--rc-bar-bg: rgb(255 255 255 / 0.08);
	--sb-card-bg: #182131;
	--sb-card-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
}

/* ---- shell ---- */

.shell {
	display: flex;
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
	background: var(--chat-bg);
}

.shell-main {
	position: relative; /* the leaving view sits on top while it goes (components/shell.js) */
	display: flex;
	flex: 1;
	min-width: 0;
	overflow: hidden;
}

.icon-btn {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 0;
	border-radius: var(--radius);
	background: none;
	color: var(--muted);
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s, opacity 0.15s;
}

.icon-btn:hover:not(:disabled) {
	background: var(--surface-2);
	color: var(--text-strong);
}

.icon-btn:disabled {
	opacity: 0.35;
	cursor: default;
}

.icon-btn-sm {
	width: 28px;
	height: 28px;
}

/* ---- sidebar ---- */

.sb {
	display: flex;
	flex: none;
	flex-direction: column;
	gap: 10px;
	width: var(--sb-width);
	height: 100%;
	padding: 10px 0 10px 10px;
	background: var(--chat-bg);
	transition: margin-left 0.3s var(--ease);
}

html.sb-collapsed .sb {
	margin-left: calc(-1 * var(--sb-width) - 1px);
}

/* each part of the sidebar floats as a rounded card, like the composer */
.sb-card {
	flex: none;
	border: 1px solid var(--border);
	border-radius: 18px;
	background: var(--sb-card-bg);
	box-shadow: var(--sb-card-shadow);
}

.sb-top {
	padding-bottom: 6px;
}

.sb-convs {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-height: 0;
	overflow: hidden;
}

.sb-pages {
	padding: 6px;
}

.sb-page {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: 10px;
	color: var(--text);
	text-decoration: none;
}

.sb-page:hover {
	background: var(--surface-2);
}

.sb-page svg {
	color: var(--muted);
}

.sb-page .mfd {
	display: flex; /* the icon and its memory-full dot, no baseline gap */
}

.sb-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	min-height: 44px; /* as tall as when the collapse button sat here */
	padding: 10px 8px 2px 16px;
}

.sb-app {
	min-width: 0;
	font-size: calc(15px * var(--ui-scale));
	font-weight: 600;
	color: var(--text-strong);
}

.sb-actions {
	padding: 2px 6px;
}

/* no logo or text above it: as much room above 「新聊天」 as around the other button cards */
.sb-top > .sb-actions:first-child {
	padding-top: 6px;
}

/* ---- the admin's logo or text (lib/branding.js); the logo shows the picture for the current theme ---- */

.brand-text {
	overflow: hidden;
	font-weight: 500;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.brand-text.is-bold {
	font-weight: 700;
}

.brand-text.is-italic {
	font-style: italic;
}

.brand-text.is-underline {
	text-decoration: underline;
	text-decoration-thickness: 0.08em;
	text-underline-offset: 0.18em;
}

.brand-logo {
	display: inline-flex;
	align-items: center;
	min-width: 0;
	max-width: 100%;
}

.brand-logo img {
	display: block;
	max-width: 100%;
	height: 100%;
	object-fit: contain;
	object-position: left center;
}

.brand-logo-dark {
	display: none !important;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .brand-logo-light {
		display: none !important;
	}

	:root:not([data-theme="light"]) .brand-logo-dark {
		display: block !important;
	}
}

:root[data-theme="dark"] .brand-logo-light {
	display: none !important;
}

:root[data-theme="dark"] .brand-logo-dark {
	display: block !important;
}

.sb-app.brand-logo {
	height: 28px;
}

.chat-top-brand.brand-logo {
	justify-content: center;
	height: calc(1.3em + 1px);
	vertical-align: top;
}

.chat-top-brand.brand-logo img {
	object-position: center;
}

.sb-new {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: 10px;
	color: var(--text);
	font-weight: 500;
	text-decoration: none;
}

.sb-new:hover {
	background: var(--surface-2);
}

.sb-list {
	flex: 1;
	overflow-y: auto;
	padding: 0 6px 8px;
}

.sb-group {
	padding: 14px 10px 4px;
	font-size: calc(12px * var(--ui-scale));
	color: var(--faint);
}

.sb-empty {
	padding: 12px 10px;
	color: var(--faint);
}

.sb-item {
	display: flex;
	align-items: center;
	border-radius: var(--radius);
}

.sb-item:hover,
.sb-item.is-current {
	background: var(--surface-2);
}

.sb-item-link {
	display: flex;
	flex: 1;
	align-items: center;
	gap: 6px;
	min-width: 0;
	padding: 7px 4px 7px 10px;
	color: var(--text);
	font-weight: 400;
	text-decoration: none;
}

.sb-item-title {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sb-dot {
	flex: none;
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #3c78d8;
	animation: pulse 1.2s ease-in-out infinite;
}

.sb-item-more {
	width: 28px;
	height: 28px;
	margin-right: 2px;
	opacity: 0;
}

.sb-item:hover .sb-item-more,
.sb-item-more[aria-expanded="true"],
.sb-item-more:focus-visible {
	opacity: 1;
}

@media (hover: none) {
	.sb-item.is-current .sb-item-more {
		opacity: 1;
	}
}

.sb-expand {
	position: fixed;
	top: 10px;
	left: 10px;
	z-index: 5;
	display: none;
	background: var(--chat-bg);
}

html.sb-collapsed .sb-expand {
	display: inline-flex;
}

.sb-backdrop {
	display: none;
}

/* phones and narrow windows: the sidebar is a drawer */
@media (max-width: 767px) {
	.sb {
		position: fixed;
		inset: 0 auto 0 0;
		z-index: 30;
		width: min(86vw, var(--sb-width));
		margin-left: 0 !important;
		padding-right: 10px;
		background: transparent; /* the cards float over the dimmed page */
		transform: translateX(-102%);
		transition: transform 0.3s var(--ease);
	}

	html.sb-drawer-open .sb {
		transform: none;
	}

	.sb-backdrop {
		position: fixed;
		inset: 0;
		z-index: 29;
		display: block;
		background: rgb(0 0 0 / 0.35);
		opacity: 0;
		pointer-events: none;
		transition: opacity 0.3s;
	}

	html.sb-drawer-open .sb-backdrop {
		opacity: 1;
		pointer-events: auto;
	}

	.sb-collapse,
	.sb-expand,
	html.sb-collapsed .sb-expand {
		display: none;
	}
}

/* ---- chat ---- */

.chat {
	position: relative;
	display: flex;
	flex: 1;
	flex-direction: column;
	min-width: 0;
	height: 100%;
}

.chat-top {
	display: none;
}

/* phones: menu · title · +, the same width on both sides so the title sits in the middle;
   the right slot is as wide as the account avatar, which stands there on a new chat */
@media (max-width: 767px) {
	.chat-top {
		display: grid;
		flex: none;
		grid-template-columns: 38px minmax(0, 1fr) 38px;
		grid-template-rows: 38px;
		align-items: center;
		gap: 8px;
		padding: 8px 8px 4px;
	}

	.chat-top-btn {
		justify-self: center;
		width: 34px;
		height: 34px;
		border: 1px solid var(--border);
		border-radius: 50%;
		background: var(--sb-card-bg);
		color: var(--text);
	}

	.chat.is-empty .chat-top-new {
		visibility: hidden;
	}

	/* your own avatar on a message opens the account menu */
	.msg-avatar-btn {
		cursor: pointer;
	}

	/* without names and avatars on messages the corner avatar stays: the + steps left of it */
	html[data-user-identity="off"] .chat-top {
		grid-template-columns: 38px minmax(0, 1fr) 38px 38px;
	}

	html[data-user-identity="off"] .chat.is-empty .chat-top-new {
		visibility: visible;
	}

	/* the account badge, opened, shows your name to the left of its avatar: the title narrows for it */
	.chat-top-title {
		transition: margin-right 0.28s var(--ease);
	}

	/* opened, focused or (with a mouse) hovered: the same 0.28 s as the badge's own growing, so the two meet all the way */
	html:has(.acct-btn:is([aria-expanded="true"], :focus-visible)):not(.acct-in-thread) .chat-top-title,
	html[data-user-identity="off"]:has(.acct-btn:is([aria-expanded="true"], :focus-visible)) .chat-top-title {
		margin-right: var(--acct-name-w, 0px);
	}
}

@media (max-width: 767px) and (hover: hover) {
	html:has(.acct-btn:hover):not(.acct-in-thread) .chat-top-title,
	html[data-user-identity="off"]:has(.acct-btn:hover) .chat-top-title {
		margin-right: var(--acct-name-w, 0px);
	}
}

.chat-top-title {
	justify-self: stretch;
	overflow: hidden;
	padding: 7px 14px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--sb-card-bg);
	font-weight: 500;
	line-height: 1.3;
	text-align: center;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.msg-avatar-btn {
	display: inline-flex;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
}

/* computers keep the account in the corner (setting accountPlace): the avatar on a message is only a
   picture, and the conversation starts lower so your first message is not under the corner badge */
@media (min-width: 768px) {
	html:not([data-account-place="thread"]) .msg-avatar-btn {
		pointer-events: none;
	}

	html[data-account-place="thread"] .msg-avatar-btn {
		cursor: pointer;
	}

	html:not([data-account-place="thread"]) .chat-column,
	html[data-user-identity="off"] .chat-column {
		padding-top: 64px;
	}
}

/* the first message's avatar waits while its twin flies down from the corner */
.chat-thread.is-avatar-flying .msg-avatar-btn {
	visibility: hidden;
}

.chat-scroll {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.chat-column {
	max-width: 768px;
	margin: 0 auto;
	padding: 32px 16px 24px;
}

.chat-intro {
	margin: 0 0 24px;
	font-size: calc(26px * var(--ui-scale));
	font-weight: 600;
	color: var(--text-strong);
	text-align: center;
}

.chat.is-empty .chat-scroll {
	display: flex;
	flex: 1 1 0;
	flex-direction: column;
	justify-content: flex-end;
}

.chat.is-empty .chat-column {
	width: 100%;
	padding-bottom: 8px;
}

.chat.is-empty .chat-bottom {
	flex: 1 1 0;
}

.chat-load-error {
	color: var(--muted);
	text-align: center;
}

.chat-bottom {
	flex: none;
	padding: 0 16px 6px;
}

.chat-bottom-inner {
	position: relative;
	max-width: 768px;
	margin: 0 auto;
}

.chat-to-bottom {
	position: absolute;
	top: -44px;
	left: 50%;
	z-index: 2;
	border: 1px solid var(--border);
	border-radius: 50%;
	background: var(--composer-bg);
	box-shadow: var(--shadow);
	transform: translateX(-50%);
}

.chat-caveat {
	margin: 6px 0 0;
	font-size: calc(12px * var(--ui-scale));
	color: var(--faint);
	text-align: center;
}

/* ---- prompt suggestions above a new chat's composer ---- */
.chat-chips {
	margin-bottom: 10px;
}
.chat-chips[hidden] {
	display: none;
}

/* phones: the prompt row floats above the reasoning row and the input, taking no room,
   so nothing below moves when it folds into the ❝ button beside send */
@media (max-width: 639px) {
	.chat-chips {
		position: absolute;
		right: 0;
		bottom: 100%;
		left: 0;
		z-index: 2; /* over the input, which the round button flies into */
	}

	/* a new chat keeps the row's room under the greeting, open or folded */
	.chat.is-empty .chat-column {
		padding-bottom: 58px;
	}
}

/* ---- composer ---- */

.composer {
	padding: 10px 10px 8px 14px;
	border: 1px solid var(--border);
	border-radius: 24px;
	background: var(--composer-bg);
	box-shadow: 0 1px 6px rgb(0 0 0 / 0.04);
}

.composer:focus-within {
	border-color: var(--border-strong);
}

.composer-notice {
	margin: 0 0 6px;
	font-size: calc(13px * var(--ui-scale));
	color: var(--danger);
}

.composer-input {
	display: block;
	width: 100%;
	max-height: 40vh;
	padding: 4px 2px;
	border: 0;
	outline: none;
	background: none;
	font-size: calc(15px * var(--ui-scale));
	line-height: 1.5;
	resize: none;
}

.composer-input::placeholder {
	color: var(--faint);
}

@media (max-width: 767px) {
	.composer-input {
		font-size: 16px; /* smaller text makes phones zoom in on focus */
	}
}

.composer-row {
	display: flex;
	align-items: center;
	gap: 8px;
	min-height: 32px;
	margin-top: 6px;
}

.composer-spacer {
	flex: 1;
}

.composer-send {
	position: relative;
	flex: none;
	width: 32px;
	height: 32px;
}

.composer-reasoning:empty {
	display: none;
}

.agent-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	max-width: 220px;
	height: 32px;
	padding: 0 8px 0 6px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--composer-bg);
	font-size: calc(13px * var(--ui-scale));
	cursor: pointer;
}

.agent-chip:hover:not(:disabled) {
	background: var(--surface-2);
}

.agent-chip:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.agent-chip-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.agent-chip-arrow {
	display: inline-flex;
	color: var(--faint);
	transition: transform 0.2s var(--ease);
}

.agent-chip[aria-expanded="true"] .agent-chip-arrow {
	transform: rotate(180deg);
}

/* ---- avatars ---- */

.agent-avatar {
	position: relative;
	display: inline-block;
	flex: none;
	overflow: hidden;
	border-radius: 50%;
	background: linear-gradient(145deg, var(--al-c2), var(--al-c3));
}

.agent-avatar svg {
	display: block;
	width: 100%;
	height: 100%;
}
.agent-avatar-img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}
.agent-avatar-text {
	color: #fff;
	font-weight: 600;
	line-height: 1;
}

/* one character, ink-centred (lib/ink-text.js) */
.ink-text-svg {
	display: block;
	width: 100%;
	height: 100%;
}

.user-avatar {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	color: #fff;
	font-weight: 500;
	line-height: 1;
	user-select: none;
}

/* ---- messages ---- */

.msg {
	margin-bottom: 22px;
}

.msg-identity {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 6px;
	font-size: calc(13px * var(--ui-scale));
	color: var(--muted);
}

.msg-identity > :not(.msg-name) {
	flex: none;
}

.msg-name {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-weight: 500;
	color: var(--text);
}

.msg-level {
	padding: 0 6px;
	border-radius: 999px;
	background: var(--surface-2);
	font-size: calc(11px * var(--ui-scale));
}

.msg-user {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
}

.msg-bubble {
	max-width: 85%;
	padding: 10px 16px;
	border-radius: 18px;
	background: var(--bubble-user);
	color: var(--text-strong);
	font-size: calc(15px * var(--ui-scale));
	line-height: 1.55;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.msg-ai .msg-identity {
	margin-left: 2px;
}

.msg-body {
	padding: 12px 20px;
	border: 1px solid var(--bubble-ai-border);
	border-radius: 16px;
	background: linear-gradient(to bottom right, var(--bubble-ai), transparent 70%);
	font-size: calc(15px * var(--ui-scale));
	line-height: 1.55;
	overflow-wrap: anywhere;
}

@media (max-width: 767px) {
	.msg-body {
		padding: 10px 14px;
	}
}

.msg-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	min-height: 28px;
	margin-top: 4px;
	opacity: 0;
	transition: opacity 0.15s;
}

.msg:hover .msg-actions,
.msg:last-child .msg-actions,
.msg-actions:focus-within {
	opacity: 1;
}

@media (hover: none) {
	.msg-actions {
		opacity: 1;
	}
}

.msg-sibs {
	display: inline-flex;
	align-items: center;
	margin-right: 4px;
	font-size: calc(12px * var(--ui-scale));
	color: var(--muted);
}

.msg-sibs-count {
	min-width: 36px;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.msg-edit {
	display: flex;
	flex-direction: column;
	gap: 8px;
	width: 100%;
}

.msg-edit-input {
	min-height: 80px;
	font-size: calc(15px * var(--ui-scale));
	resize: vertical;
}

.msg-edit-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.msg-reasoning {
	margin-bottom: 8px;
	font-size: calc(14px * var(--ui-scale));
	color: var(--muted);
}

.msg-reasoning summary {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	cursor: pointer;
	list-style: none;
	user-select: none;
}

.msg-reasoning summary::-webkit-details-marker {
	display: none;
}

.msg-reasoning summary::after {
	content: "›";
	transition: transform 0.2s;
}

.msg-reasoning[open] summary::after {
	transform: rotate(90deg);
}

.msg-reasoning-text {
	margin: 6px 0 4px;
	padding-left: 12px;
	border-left: 2px solid var(--border);
	white-space: pre-wrap;
}

.msg-error {
	display: flex;
	align-items: flex-start;
	gap: 6px;
	margin-top: 8px;
	padding: 8px 12px;
	border-radius: var(--radius);
	background: var(--danger-bg);
	color: var(--danger);
	font-size: calc(14px * var(--ui-scale));
}

.msg-error svg {
	flex: none;
	margin-top: 3px;
}

.msg-interrupted {
	margin-top: 6px;
	font-size: calc(12px * var(--ui-scale));
	color: var(--faint);
}

.typing {
	display: inline-flex;
	gap: 4px;
	padding: 6px 0;
}

.typing i {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--faint);
	animation: typing 1.2s ease-in-out infinite;
}

.typing i:nth-child(2) {
	animation-delay: 0.15s;
}

.typing i:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes typing {
	0%,
	60%,
	100% {
		transform: translateY(0);
		opacity: 0.5;
	}
	30% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

@keyframes pulse {
	50% {
		opacity: 0.3;
	}
}

.shimmer {
	background: linear-gradient(90deg, var(--muted) 30%, var(--text-strong) 50%, var(--muted) 70%) 0 0 / 200% 100%;
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
	animation: shimmer 1.6s linear infinite;
}

@keyframes shimmer {
	to {
		background-position: -200% 0;
	}
}

/* ---- markdown ---- */

.md > :first-child {
	margin-top: 0;
}

.md > :last-child {
	margin-bottom: 0;
}

.md p,
.md ul,
.md ol,
.md blockquote,
.md .md-table,
.md .md-code {
	margin: 0 0 12px;
}

.md h1,
.md h2,
.md h3,
.md h4,
.md h5,
.md h6 {
	margin: 18px 0 8px;
	color: var(--text-strong);
	line-height: 1.3;
}

.md h1 {
	font-size: 1.5em;
}

.md h2 {
	font-size: 1.3em;
}

.md h3 {
	font-size: 1.15em;
}

.md h4,
.md h5,
.md h6 {
	font-size: 1em;
}

.md ul,
.md ol {
	padding-left: 1.6em;
}

.md li + li {
	margin-top: 4px;
}

.md li > ul,
.md li > ol {
	margin: 4px 0 0;
}

.md a {
	color: #2563eb;
	font-weight: 400;
}

.md blockquote {
	padding-left: 12px;
	border-left: 3px solid var(--border-strong);
	color: var(--muted);
}

.md hr {
	margin: 16px 0;
	border: 0;
	border-top: 1px solid var(--border);
}

.md img {
	max-width: 100%;
	border-radius: var(--radius);
}

.md :not(pre) > code {
	padding: 1px 5px;
	border-radius: 5px;
	background: var(--surface-2);
	font-family: var(--mono);
	font-size: 0.88em;
}

.md-code {
	overflow: hidden;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: var(--code-bg);
}

.md-code-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 2px 4px 2px 12px;
	border-bottom: 1px solid var(--border);
	font-size: calc(12px * var(--ui-scale));
	color: var(--muted);
}

.md-code pre {
	margin: 0;
	padding: 12px 14px;
	overflow-x: auto;
	font-family: var(--mono);
	font-size: calc(13px * var(--ui-scale));
	line-height: 1.5;
}

.md-table {
	overflow-x: auto;
}

.md table {
	border-collapse: collapse;
	font-size: calc(14px * var(--ui-scale));
}

.md th,
.md td {
	padding: 6px 12px;
	border: 1px solid var(--border);
}

.md th {
	background: var(--surface-2);
	font-weight: 600;
}

/* the allowed HTML (settings: allowHtml) */
.md-html {
	margin: 0 0 12px;
	overflow-x: auto;
}

.md kbd {
	padding: 1px 6px;
	border: 1px solid var(--border-strong);
	border-bottom-width: 2px;
	border-radius: 5px;
	background: var(--surface);
	font-family: var(--mono);
	font-size: 0.85em;
}

.md mark {
	padding: 0 2px;
	border-radius: 3px;
	background: #fef08a;
	color: #111827;
}

.md details {
	margin: 0 0 12px;
	padding: 8px 12px;
	border: 1px solid var(--border);
	border-radius: 10px;
}

.md details > summary {
	cursor: pointer;
	font-weight: 500;
}

.md details[open] > summary {
	margin-bottom: 8px;
}

.md details > :last-child {
	margin-bottom: 0;
}

/* ---- menus, dialogs, toasts ---- */

.menu {
	position: fixed;
	z-index: 50;
	min-width: 180px;
	max-width: min(320px, calc(100vw - 16px));
	max-height: 320px;
	padding: 4px;
	overflow-y: auto;
	border: 1px solid var(--border);
	border-radius: 12px;
	background: var(--surface);
	box-shadow: var(--menu-shadow);
}

.menu-fade {
	animation: menu-in 0.12s ease-out;
}

.menu-leaving {
	opacity: 0;
	transition: opacity 0.12s;
}

@keyframes menu-in {
	from {
		opacity: 0;
		transform: scale(0.97);
	}
}

.menu-item {
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	min-height: 32px;
	padding: 0 8px;
	border: 0;
	border-radius: var(--radius);
	background: none;
	font-size: calc(14px * var(--ui-scale));
	text-align: left;
	cursor: pointer;
}

.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
	background: var(--surface-2);
	outline: none;
}

.menu-item:disabled {
	opacity: 0.5;
	cursor: default;
}

.menu-item-danger {
	color: var(--danger);
}

.menu-icon {
	display: inline-flex;
	color: var(--muted);
}

.menu-item-danger .menu-icon {
	color: inherit;
}

.menu-label {
	flex: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.menu-check {
	display: inline-flex;
	color: var(--muted);
}

.menu-hint {
	padding: 4px 8px 6px;
	font-size: calc(11px * var(--ui-scale));
	color: var(--muted);
}

.menu-sep {
	height: 1px;
	margin: 4px 0;
	background: var(--border);
}

.modal-backdrop {
	position: fixed;
	inset: 0;
	z-index: 60;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: rgb(0 0 0 / 0.4);
	animation: fade-in 0.15s;
}

.modal-leaving {
	opacity: 0;
	transition: opacity 0.15s;
}

@keyframes fade-in {
	from {
		opacity: 0;
	}
}

.modal {
	width: min(440px, 100%);
	padding: 24px;
	border-radius: var(--radius-lg);
	background: var(--surface);
	box-shadow: var(--menu-shadow);
}

.modal-title {
	margin: 0 0 12px;
	font-size: calc(18px * var(--ui-scale));
	font-weight: 600;
	color: var(--text-strong);
}

.modal-body {
	margin: 0 0 16px;
	color: var(--muted);
}

.modal-check {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 16px;
	color: var(--muted);
}

.modal-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.btn-danger-solid {
	background: var(--danger);
	color: #fff;
}

.btn-danger-solid:hover {
	filter: brightness(0.92);
}

.toast {
	position: fixed;
	bottom: 24px;
	left: 50%;
	z-index: 70;
	max-width: min(480px, calc(100vw - 32px));
	padding: 10px 16px;
	border-radius: 12px;
	background: var(--text-strong);
	color: var(--bg);
	box-shadow: var(--menu-shadow);
	transform: translateX(-50%);
	animation: fade-in 0.2s;
}

.toast-leaving {
	opacity: 0;
	transition: opacity 0.3s;
}

/* ---- send / stop button (from the old app's SendStopButton) ---- */

.ssb {
	position: absolute;
	inset: 0;
	display: block;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.ssb:disabled {
	cursor: default;
}

.ssb.is-busy {
	pointer-events: none;
}

.ssb-face {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 1px solid transparent;
	border-radius: 50%;
	transform: scale(1);
	transition: transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1), background-color 200ms ease, color 200ms ease,
		border-color 200ms ease;
}

.ssb-face .ssb-icon {
	transition: opacity 150ms ease;
}

.ssb-face.ssb-launched {
	overflow: hidden;
}

.ssb-face.ssb-launched .ssb-icon {
	transform: translateY(-150%);
	transition: transform 170ms cubic-bezier(0.55, 0, 0.9, 0.4);
}

.ssb-face--send-idle {
	background: var(--ssb-idle-bg);
	color: var(--ssb-idle-fg);
}

.ssb-face--send-ready {
	border-color: #e5e5e5;
	background: #fff;
	color: #000;
	box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}

.ssb-face--stop {
	border-color: var(--ssb-stop-border);
	background: var(--ssb-stop-bg);
	color: var(--ssb-stop-fg);
	box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

.ssb-face--stop::after {
	content: "";
	position: absolute;
	inset: -2px;
	border-radius: inherit;
	background: conic-gradient(from 0deg, transparent 0deg 240deg, var(--ssb-ring) 240deg 360deg);
	-webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
	mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
	pointer-events: none;
	animation: ssb-rotate 1.2s linear infinite;
}

.ssb-face.ssb-phase--shrink {
	border-color: transparent;
	background: var(--ssb-ball);
	box-shadow: none;
	transform: scale(0.3);
	transition: transform 200ms cubic-bezier(0.55, 0, 1, 0.45), background-color 120ms ease, border-color 120ms ease;
}

.ssb-face.ssb-phase--shrink::after {
	opacity: 0;
}

.ssb-face.ssb-phase--shrink .ssb-icon {
	opacity: 0;
	transition-duration: 80ms;
}

.ssb-face.ssb-phase--grow .ssb-icon {
	animation: ssb-icon-in 320ms ease both;
}

.ssb-ripple {
	position: absolute;
	inset: 0;
	border: 1.5px solid var(--ssb-ripple);
	border-radius: 50%;
	opacity: 0;
	pointer-events: none;
}

@media (hover: hover) {
	.ssb:enabled:hover .ssb-ripple {
		animation: ssb-ripple 1.6s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
	}

	.ssb:enabled:hover .ssb-ripple--late {
		animation-delay: 0.8s;
	}
}

@media (hover: none) {
	.ssb--content .ssb-ripple {
		animation: ssb-ripple 1.6s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
	}

	.ssb--content .ssb-ripple--late {
		animation-delay: 0.8s;
	}
}

@keyframes ssb-ripple {
	0% {
		transform: scale(1);
		opacity: 0.9;
	}
	100% {
		transform: scale(1.4);
		opacity: 0;
	}
}

@keyframes ssb-icon-in {
	0%,
	30% {
		opacity: 0;
	}
	100% {
		opacity: 1;
	}
}

@keyframes ssb-rotate {
	to {
		transform: rotate(360deg);
	}
}

/* ---- reasoning control (from the old app's ReasoningControl) ---- */

.rc {
	display: flex;
	flex: none;
	align-items: center;
	gap: 4px;
	height: 32px;
	padding: 2px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--composer-bg);
}

.seg-compact .seg-option {
	min-height: 0;
	padding: 2px 8px;
	font-size: calc(12px * var(--ui-scale));
}

.rc-bar {
	position: relative;
	flex: none;
	width: 112px;
	height: 100%;
	overflow: hidden;
	border-radius: 999px;
	background: var(--rc-bar-bg);
}

/* the three tubes side by side; the bar shows one (reasoning-control.js slides them) */
.rc-strip {
	--rc-tube-gap: 8px;
	position: absolute;
	inset: 0;
	display: flex;
	gap: var(--rc-tube-gap);
}

.rc-face {
	position: relative;
	flex: 0 0 100%;
	height: 100%;
	overflow: hidden;
	border-radius: 999px;
}

.rc-track {
	background: linear-gradient(90deg, var(--rc-c2), var(--rc-c3), var(--rc-c4), var(--rc-c1));
}

.rc-progress {
	background: linear-gradient(90deg, var(--rc-c4), var(--rc-c2), var(--rc-c4)) 0 0 / 12rem 100% repeat-x;
	animation: rc-roll-progress 7.2s linear infinite;
}

@keyframes rc-roll-progress {
	to {
		background-position: -12rem 0;
	}
}

.rc-hazard {
	background: linear-gradient(45deg, var(--rc-c4) 25%, var(--rc-c2) 25% 50%, var(--rc-c4) 50% 75%, var(--rc-c2) 75%) 0 0 /
		0.875rem 0.875rem;
	animation: rc-roll-hazard 0.9s linear infinite;
}

@keyframes rc-roll-hazard {
	to {
		background-position: -0.875rem 0;
	}
}

.rc-grid {
	position: relative;
	display: grid;
	height: 100%;
	touch-action: pan-y;
}

.rc-stop {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
}

.rc-stop.is-current {
	cursor: grab;
}

.rc-stop.is-current:active {
	cursor: grabbing;
}

.rc-dot {
	width: 4px;
	height: 4px;
	border-radius: 50%;
	background: rgb(255 255 255 / 0.8);
}

.rc-thumb {
	position: absolute;
	top: 2px;
	bottom: 2px;
	left: 0;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 999px;
	background: #fff;
	box-shadow: 0 1px 2px rgb(0 0 0 / 0.15);
	color: #1f2937;
	font-size: calc(11px * var(--ui-scale));
	font-weight: 500;
	pointer-events: none;
	/* always on the manual tube, so it slides in with the tube already in place */
	transition: transform 300ms var(--ease);
}

.rc-thumb--drag {
	transition: none;
}

/* the agent pill keeps its size beside the reasoning control (which goes outside when they do not fit);
   alone in the row (phones, or the control outside) it shrinks rather than pushing anything onto a new line */
.composer-picker {
	flex: none;
	min-width: 0;
}

.composer-row:not(:has(> .composer-reasoning:not([hidden], :empty))) .composer-picker {
	flex: 0 1 auto;
}

.composer-row:not(:has(> .composer-reasoning:not([hidden], :empty))) .agent-chip {
	max-width: 100%;
}

@media (max-width: 767px) {
	.rc-bar {
		width: 88px;
	}
}

/* ---- tool calls and the agent's questions ---- */

.composer-plus {
	border: 1px solid var(--border);
	border-radius: 50%;
	background: var(--composer-bg);
}

.composer-plus[aria-expanded="true"] {
	background: var(--surface-2);
}

.tool-row {
	margin: 6px 0 10px;
	font-size: calc(13px * var(--ui-scale));
	color: var(--muted);
}

.tool-row summary {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	max-width: 100%;
	padding: 3px 10px 3px 6px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--surface);
	cursor: pointer;
	list-style: none;
	user-select: none;
}

.tool-row summary::-webkit-details-marker {
	display: none;
}

.tool-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 16px;
	height: 16px;
}

.tool-ok .tool-icon {
	color: var(--ok);
}

.tool-error .tool-icon {
	color: var(--danger);
}

.tool-name {
	font-weight: 500;
	color: var(--text);
}

.tool-ms {
	color: var(--faint);
	font-variant-numeric: tabular-nums;
}

.tool-detail {
	margin-top: 6px;
	padding: 8px 12px;
	border-radius: var(--radius);
	background: var(--code-bg);
}

.tool-detail-label {
	margin-top: 4px;
	font-size: calc(11px * var(--ui-scale));
	color: var(--faint);
}

.tool-detail pre {
	max-height: 240px;
	margin: 2px 0 6px;
	overflow: auto;
	font-family: var(--mono);
	font-size: calc(12px * var(--ui-scale));
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.spinner {
	width: 12px;
	height: 12px;
	border: 2px solid var(--border-strong);
	border-top-color: var(--muted);
	border-radius: 50%;
	animation: ssb-rotate 0.8s linear infinite;
}

.ask-card {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin: 8px 0;
	padding: 14px 16px;
	border: 1px solid var(--border-strong);
	border-radius: 14px;
	background: var(--surface);
	box-shadow: var(--shadow);
}

.ask-head {
	font-size: calc(12px * var(--ui-scale));
	color: var(--muted);
}

.ask-question {
	margin: 0;
	font-weight: 500;
	color: var(--text-strong);
	white-space: pre-wrap;
}

.ask-options {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.ask-option {
	display: flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
}

.ask-status {
	margin: 0;
	font-size: calc(13px * var(--ui-scale));
	color: var(--muted);
}

.ask-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

/* ---- attachments ---- */

.attach-strip {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 8px;
}

.attach-chip {
	position: relative;
	display: flex;
	align-items: center;
	gap: 8px;
	max-width: 220px;
	height: 44px;
	padding: 4px 28px 4px 4px;
	border: 1px solid var(--border);
	border-radius: 10px;
	background: var(--surface-2);
	font-size: calc(13px * var(--ui-scale));
}

.attach-chip img {
	width: 36px;
	height: 36px;
	border-radius: 6px;
	object-fit: cover;
}

.attach-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 6px;
	background: var(--surface);
	color: var(--muted);
}

.attach-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.attach-chip.is-error {
	border-color: var(--danger);
}

.attach-chip .spinner {
	flex: none;
}

.attach-remove {
	position: absolute;
	top: 4px;
	right: 4px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 20px;
	height: 20px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--surface);
	color: var(--muted);
	cursor: pointer;
}

.attach-remove:hover {
	color: var(--text-strong);
}

.msg-files {
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 8px;
	max-width: 85%;
	margin-bottom: 6px;
}

.file-thumb img {
	display: block;
	max-width: 240px;
	max-height: 180px;
	border: 1px solid var(--border);
	border-radius: 12px;
	object-fit: cover;
}

.file-card {
	display: flex;
	align-items: center;
	gap: 10px;
	max-width: 260px;
	padding: 8px 12px 8px 8px;
	border: 1px solid var(--border);
	border-radius: 12px;
	background: var(--surface);
	color: var(--text);
	font-weight: 400;
	text-decoration: none;
}

.file-card:hover {
	background: var(--surface-2);
}

.file-card-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 8px;
	background: var(--surface-2);
	color: var(--muted);
}

.file-card[data-type="word"] .file-card-icon {
	background: color-mix(in srgb, #2563eb 14%, transparent);
	color: #2563eb;
}

.file-card[data-type="excel"] .file-card-icon {
	background: color-mix(in srgb, #16a34a 14%, transparent);
	color: #16a34a;
}

.file-card[data-type="powerpoint"] .file-card-icon {
	background: color-mix(in srgb, #ea580c 14%, transparent);
	color: #ea580c;
}

.file-card[data-type="pdf"] .file-card-icon {
	background: color-mix(in srgb, #dc2626 14%, transparent);
	color: #dc2626;
}

/* files the agent made sit under its answer, on the left */
.msg-ai .msg-files {
	justify-content: flex-start;
	max-width: 100%;
	margin: 10px 0 0;
}

.file-card-text {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.file-card-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.file-card-size {
	font-size: calc(12px * var(--ui-scale));
	color: var(--faint);
}

.drop-hint {
	position: absolute;
	inset: 8px;
	z-index: 20;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2px dashed var(--border-strong);
	border-radius: 16px;
	background: color-mix(in srgb, var(--chat-bg) 85%, transparent);
	color: var(--muted);
	text-align: center;
	pointer-events: none;
}

/* ---- display settings (data-* on <html>, from the user's settings) ---- */

html[data-sidebar-width="narrow"] {
	--sb-width: 260px;
}

html[data-sidebar-width="wider"] {
	--sb-width: 380px;
}

html[data-user-align="left"] .msg-user {
	align-items: flex-start;
}

html[data-user-align="left"] .msg-user .msg-identity {
	flex-direction: row-reverse;
}

html[data-user-align="left"] .msg-user .msg-files {
	justify-content: flex-start;
}

html[data-user-bubble="off"] .msg-bubble {
	padding: 0;
	border-radius: 0;
	background: none;
}

html[data-ai-bubble="off"] .msg-body {
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
}

html[data-user-identity="off"] .msg-user .msg-identity,
html[data-ai-identity="off"] .msg-ai .msg-identity {
	display: none;
}

.user-avatar-img {
	object-fit: cover;
	background: var(--surface-2);
}

/* the sidebar's edge switch (desktop): a bookmark tab or a thin handle in place of the buttons */
.sb-edge {
	display: none;
}

@media (min-width: 768px) {
	html:not([data-sidebar-toggle="none"]) .sb-collapse,
	html:not([data-sidebar-toggle="none"]).sb-collapsed .sb-expand {
		display: none;
	}

	html[data-sidebar-toggle="tab"] .sb-edge,
	html[data-sidebar-toggle="handle"] .sb-edge {
		position: fixed;
		top: 50%;
		left: var(--sb-width);
		z-index: 6;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0;
		border: 0;
		color: var(--muted);
		cursor: pointer;
		transform: translateY(-50%);
		transition:
			left 0.3s var(--ease),
			width 0.15s,
			background 0.15s,
			transform 0.42s var(--ease),
			opacity 0.3s var(--ease);
	}

	/* a settings card stands in for the chats card: the bookmark steps out to the left with it */
	.sb-wrap.has-panel .sb-edge {
		opacity: 0;
		pointer-events: none;
		transform: translate(calc(-1 * var(--sb-width) - 40px), -50%);
	}

	html.sb-collapsed .sb-edge {
		left: 0 !important;
	}

	html[data-sidebar-toggle="tab"] .sb-edge {
		width: 22px;
		height: 72px;
		border: 1px solid var(--border);
		border-left: 0;
		border-radius: 0 10px 10px 0;
		background: var(--sb-card-bg);
		transform-origin: left center;
	}

	html[data-sidebar-toggle="tab"] .sb-edge:hover {
		color: var(--text-strong);
	}

	html[data-sidebar-toggle="tab"] .sb-edge svg {
		transition: transform 0.3s var(--ease);
	}

	html[data-sidebar-toggle="tab"].sb-collapsed .sb-edge svg {
		transform: rotate(180deg);
	}

	html[data-sidebar-toggle="handle"] .sb-edge {
		width: 14px;
		height: 72px;
		margin-left: 2px;
		background: none;
	}

	html[data-sidebar-toggle="handle"] .sb-edge::before {
		content: "";
		width: 4px;
		height: 44px;
		border-radius: 999px;
		background: var(--border-strong);
		transition: height 0.15s, background 0.15s;
	}

	html[data-sidebar-toggle="handle"] .sb-edge:hover::before {
		height: 60px;
		background: var(--muted);
	}

	html[data-sidebar-toggle="handle"] .sb-edge svg {
		display: none;
	}
}

/* an animated agent avatar (components/agent-face.js): the loader's frame is larger than the face and centred on it */
.agent-face {
	position: relative;
	display: inline-block;
	flex: none;
}

.agent-face > .al {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
}

/* the send button pressed: by the pointer, or by Enter (lib/enter-key.js) */
.ssb:active:not(:disabled) .ssb-face--send-ready,
.ssb.is-key-down .ssb-face--send-ready {
	scale: 0.9;
	transition-duration: 80ms;
}
