/* Components. Colors, type and shape come from tokens.css. */

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

html,
body {
	margin: 0;
	height: 100%;
}

body {
	background: var(--bg);
	color: var(--ink);
	font-family: var(--font-sans);
	font-size: var(--text-md);
	line-height: var(--leading);
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}

#app {
	height: 100%;
}

[hidden] {
	display: none !important;
}

h1,
h2,
h3 {
	line-height: 1.25;
	letter-spacing: -0.01em;
}

a {
	color: var(--accent);
}

:focus-visible {
	outline: none;
	box-shadow: var(--focus);
	border-radius: var(--radius-sm);
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.icon {
	width: 1.25em;
	height: 1.25em;
	flex: none;
	stroke: currentColor;
	fill: none;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* ---------------------------------------------------------------------------
 * Buttons and form controls
 * ------------------------------------------------------------------------ */

button,
.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	min-height: 2.75rem;
	padding: 0 var(--space-4);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--ink);
	font: inherit;
	font-size: var(--text-sm);
	font-weight: 550;
	text-decoration: none;
	cursor: pointer;
	transition:
		background 150ms var(--ease),
		border-color 150ms var(--ease),
		transform 100ms var(--ease),
		color 150ms var(--ease);
}

button:hover,
.button:hover {
	background: var(--surface-2);
}

button:active {
	transform: scale(0.98);
}

button:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}

button.primary {
	background: var(--accent);
	border-color: transparent;
	color: var(--accent-ink);
}

button.primary:hover {
	background: var(--accent-strong);
}

button.ghost {
	border-color: transparent;
	background: transparent;
	color: var(--ink-2);
}

button.ghost:hover {
	background: var(--surface-3);
	color: var(--ink);
}

button.icon-only {
	width: 2.75rem;
	padding: 0;
}

button.danger {
	color: var(--danger);
}

button.danger.armed {
	background: var(--danger);
	border-color: transparent;
	color: oklch(0.99 0 0);
}

button.link {
	min-height: auto;
	padding: 0;
	border: 0;
	background: none;
	color: var(--accent);
	font-weight: 500;
}

button.block {
	width: 100%;
}

input,
select,
textarea {
	width: 100%;
	min-height: 2.875rem;
	padding: var(--space-2) var(--space-3);
	border: 1px solid var(--border-strong);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--ink);
	font: inherit;
	transition:
		border-color 150ms var(--ease),
		box-shadow 150ms var(--ease);
}

input:focus,
select:focus,
textarea:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: var(--focus);
}

label {
	display: block;
	margin-bottom: var(--space-1);
	color: var(--ink-2);
	font-size: var(--text-sm);
	font-weight: 600;
}

.field {
	margin-bottom: var(--space-4);
}

.hint {
	color: var(--ink-3);
	font-size: var(--text-sm);
}

.row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-3);
}

.notice,
.error {
	margin-bottom: var(--space-4);
	padding: var(--space-3) var(--space-4);
	border-radius: var(--radius);
	font-size: var(--text-sm);
}

.notice {
	background: var(--accent-soft);
	color: var(--ink);
}

.error {
	background: var(--danger-soft);
	color: var(--danger);
}

.badge {
	display: inline-block;
	padding: 0.1rem 0.6rem;
	border-radius: 999px;
	background: var(--surface-3);
	color: var(--ink-2);
	font-size: var(--text-xs);
	font-weight: 600;
}

.badge.danger {
	background: var(--danger-soft);
	color: var(--danger);
}

.badge.ok {
	background: oklch(from var(--ok) l c h / 0.15);
	color: var(--ok);
}

.status-dot {
	display: inline-block;
	width: 0.6rem;
	height: 0.6rem;
	border-radius: 50%;
	background: var(--border-strong);
	flex: none;
}

.status-dot.on {
	background: var(--ok);
}

.status-dot.busy {
	background: var(--accent);
	animation: pulse 1.2s ease-in-out infinite;
}

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

@keyframes rise {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
}

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

.spinner {
	width: 1rem;
	height: 1rem;
	border: 2px solid var(--border-strong);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
	flex: none;
}

/* ---------------------------------------------------------------------------
 * Sign-in pages
 * ------------------------------------------------------------------------ */

.auth {
	display: grid;
	place-items: center;
	min-height: 100%;
	padding: var(--space-5) var(--space-4);
	background:
		radial-gradient(60rem 30rem at 50% -10%, var(--accent-soft), transparent 70%),
		var(--bg);
}

.auth .card {
	width: min(100%, 26rem);
	padding: var(--space-6);
	box-shadow: var(--shadow-lg);
}

.auth .brand {
	margin-bottom: var(--space-5);
}

.auth h1 {
	margin: 0 0 var(--space-5);
	font-size: var(--text-xl);
}

.card {
	padding: var(--space-5);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background: var(--surface);
	box-shadow: var(--shadow-sm);
}

.card + .card {
	margin-top: var(--space-4);
}

.card h2 {
	margin: 0 0 var(--space-4);
	font-size: var(--text-lg);
}

/* ---------------------------------------------------------------------------
 * Brand
 * ------------------------------------------------------------------------ */

.brand {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	min-width: 0;
	font-weight: 700;
	font-size: var(--text-md);
	letter-spacing: -0.01em;
}

.brand img {
	height: 1.75rem;
	width: auto;
	max-width: 9rem;
}

.brand img.wordmark {
	height: 2.25rem;
	max-width: 13rem;
}

.auth .brand img.wordmark {
	height: 3rem;
	max-width: 100%;
}

.brand .mark {
	display: grid;
	place-items: center;
	width: 2rem;
	height: 2rem;
	border-radius: 0.6rem;
	background: linear-gradient(135deg, var(--accent), oklch(from var(--accent) calc(l - 0.08) c calc(h + 40)));
	color: var(--accent-ink);
	font-size: var(--text-sm);
	flex: none;
}

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

/* ---------------------------------------------------------------------------
 * Shell: sidebar + main
 * ------------------------------------------------------------------------ */

.shell {
	display: grid;
	grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
	height: 100%;
}

.sidebar {
	display: flex;
	flex-direction: column;
	min-height: 0;
	border-right: 1px solid var(--border);
	background: var(--sidebar);
}

.sidebar-top {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	padding: var(--space-4) var(--space-3) var(--space-3);
}

.sidebar-top .brand {
	padding: 0 var(--space-2);
	min-height: 2.75rem;
}

.search {
	position: relative;
}

.search .icon {
	position: absolute;
	left: var(--space-3);
	top: 50%;
	transform: translateY(-50%);
	color: var(--ink-3);
	pointer-events: none;
}

.search input {
	padding-left: 2.5rem;
	min-height: 2.5rem;
	background: var(--surface);
	font-size: var(--text-sm);
}

.conversation-list {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 0 var(--space-3) var(--space-3);
}

.conversation-list h3 {
	margin: var(--space-4) var(--space-2) var(--space-1);
	color: var(--ink-3);
	font-size: var(--text-xs);
	font-weight: 650;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.conversation-list ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.conversation-list a {
	display: block;
	padding: var(--space-2) var(--space-3);
	border-radius: var(--radius-sm);
	color: var(--ink);
	font-size: var(--text-sm);
	text-decoration: none;
	transition: background 120ms var(--ease);
}

.conversation-list a:hover {
	background: var(--surface-3);
}

.conversation-list a.active {
	background: var(--surface);
	box-shadow: var(--shadow-sm);
	font-weight: 600;
}

.conversation-list .title {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.conversation-list .meta {
	display: block;
	color: var(--ink-3);
	font-size: var(--text-xs);
}

.conversation-list .empty-list {
	padding: var(--space-4) var(--space-2);
	color: var(--ink-3);
	font-size: var(--text-sm);
}

.sidebar-nav {
	padding: var(--space-2) var(--space-3);
	border-top: 1px solid var(--border);
}

.sidebar-nav a {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	min-height: 2.5rem;
	padding: 0 var(--space-3);
	border-radius: var(--radius-sm);
	color: var(--ink-2);
	font-size: var(--text-sm);
	font-weight: 550;
	text-decoration: none;
}

.sidebar-nav a:hover {
	background: var(--surface-3);
	color: var(--ink);
}

.sidebar-nav a.active {
	background: var(--surface);
	color: var(--ink);
	box-shadow: var(--shadow-sm);
}

.avatar {
	display: grid;
	place-items: center;
	width: 1.75rem;
	height: 1.75rem;
	border-radius: 50%;
	background: var(--accent-soft);
	color: var(--accent-strong);
	font-size: var(--text-xs);
	font-weight: 700;
	flex: none;
}

.main {
	display: flex;
	flex-direction: column;
	min-width: 0;
	min-height: 0;
	background: var(--bg);
}

.main-header {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	min-height: 3.75rem;
	padding: var(--space-2) var(--space-4);
	border-bottom: 1px solid var(--border);
	background: oklch(from var(--bg) l c h / 0.85);
	backdrop-filter: blur(8px);
}

.main-header .menu {
	display: none;
}

.main-header h1 {
	flex: 1;
	min-width: 0;
	margin: 0;
	font-size: var(--text-md);
	font-weight: 650;
}

.title-button {
	display: inline-flex;
	max-width: 100%;
	min-height: 2.25rem;
	padding: 0 var(--space-2);
	border-color: transparent;
	background: transparent;
	font-size: var(--text-md);
	font-weight: 650;
}

.title-button span {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.title-button .icon {
	opacity: 0;
	color: var(--ink-3);
	transition: opacity 150ms;
}

.title-button:hover .icon,
.title-button:focus-visible .icon {
	opacity: 1;
}

.title-input {
	max-width: 30rem;
	min-height: 2.25rem;
	font-weight: 650;
}

.working {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	color: var(--ink-2);
	font-size: var(--text-sm);
}

.scrim {
	display: none;
}

/* ---------------------------------------------------------------------------
 * Chat
 * ------------------------------------------------------------------------ */

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

.messages {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: var(--space-6) var(--space-4) var(--space-4);
}

.thread {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	max-width: var(--column);
	margin: 0 auto;
}

/* Entry animation runs once: `.enter` is removed when it ends, so re-inserting a cached node
 * during a re-render does not replay it. */
.enter {
	animation: rise 260ms var(--ease);
}

.msg.user {
	align-self: flex-end;
	max-width: 85%;
}

.msg.user .bubble {
	padding: var(--space-3) var(--space-4);
	border-radius: var(--radius-lg) var(--radius-lg) var(--space-1) var(--radius-lg);
	background: var(--user-bubble);
	color: var(--user-ink);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.msg.user .files {
	justify-content: flex-end;
}

.msg.assistant {
	display: grid;
	grid-template-columns: 2rem minmax(0, 1fr);
	gap: var(--space-3);
}

.msg.assistant .mark {
	display: grid;
	place-items: center;
	width: 2rem;
	height: 2rem;
	border-radius: 0.6rem;
	background: var(--surface-3);
	color: var(--accent);
}

.msg.assistant.error .body {
	padding: var(--space-3) var(--space-4);
	border-radius: var(--radius);
	background: var(--danger-soft);
	color: var(--danger);
}

.msg.assistant.stopped .body {
	color: var(--ink-3);
	font-style: italic;
}

.msg .time {
	margin-top: var(--space-1);
	color: var(--ink-3);
	font-size: var(--text-xs);
	opacity: 0;
	transition: opacity 150ms;
}

.msg:hover .time {
	opacity: 1;
}

.msg.user .time {
	text-align: right;
}

.cursor::after {
	content: "";
	display: inline-block;
	width: 0.5em;
	height: 1.1em;
	margin-left: 0.1em;
	vertical-align: text-bottom;
	border-radius: 2px;
	background: var(--accent);
	animation: pulse 1s ease-in-out infinite;
}

/* Tool steps */

.steps {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
	margin-left: calc(2rem + var(--space-3));
}

.step {
	border-radius: var(--radius);
	font-size: var(--text-sm);
}

.step summary {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	min-height: 2.25rem;
	padding: var(--space-1) var(--space-3);
	border-radius: var(--radius);
	color: var(--ink-2);
	cursor: pointer;
	list-style: none;
	transition: background 120ms var(--ease);
}

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

.step summary:hover {
	background: var(--surface-2);
}

.step summary .label {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.step summary .label strong {
	color: var(--ink);
	font-weight: 600;
}

.step summary .extra {
	color: var(--ink-3);
	white-space: nowrap;
}

.step summary .meta {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	margin-left: auto;
	white-space: nowrap;
}

.step summary .status {
	display: inline-grid;
	place-items: center;
	width: 1.25rem;
	height: 1.25rem;
	border-radius: 50%;
}

.step summary .status .icon {
	width: 0.85rem;
	height: 0.85rem;
	stroke-width: 2.6;
}

.step summary .status.ok {
	background: oklch(from var(--ok) l c h / 0.14);
	color: var(--ok);
}

.step summary .status.failed {
	background: var(--danger-soft);
	color: var(--danger);
}

.step summary .error-text {
	color: var(--danger);
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 16rem;
}

.step.live summary {
	background: var(--surface-2);
	cursor: default;
}

.step.live summary .slow {
	color: var(--warn);
}

.step summary .chevron {
	margin-left: 0;
	color: var(--ink-3);
	transition: transform 150ms var(--ease);
}

.step[open] summary .chevron {
	transform: rotate(90deg);
}

.step.failed summary {
	color: var(--danger);
}

.step .detail {
	margin: var(--space-1) 0 var(--space-2) calc(1.25em + var(--space-3) + var(--space-2));
	padding: var(--space-3);
	border-left: 2px solid var(--border);
	color: var(--ink-2);
	font-family: var(--font-mono);
	font-size: var(--text-xs);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	max-height: 18rem;
	overflow-y: auto;
}

.step .detail .args {
	margin-bottom: var(--space-2);
	color: var(--ink-3);
}

/* Files */

.files {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	gap: var(--space-2);
	margin-top: var(--space-2);
}

.file-card {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	max-width: 20rem;
	padding: var(--space-2) var(--space-3);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--ink);
	text-decoration: none;
	box-shadow: var(--shadow-sm);
	transition:
		border-color 150ms var(--ease),
		transform 150ms var(--ease);
}

.file-card:hover {
	border-color: var(--accent);
	transform: translateY(-1px);
}

.file-card .kind {
	display: grid;
	place-items: center;
	width: 2.25rem;
	height: 2.25rem;
	border-radius: var(--radius-sm);
	background: var(--accent-soft);
	color: var(--accent-strong);
	flex: none;
}

.file-card .info {
	min-width: 0;
}

.file-card .name {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: var(--text-sm);
	font-weight: 600;
}

.file-card .size {
	display: block;
	color: var(--ink-3);
	font-size: var(--text-xs);
}

.file-image {
	display: block;
	overflow: hidden;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface-2);
}

.file-image img {
	display: block;
	max-width: min(100%, 24rem);
	max-height: 18rem;
	object-fit: contain;
}

/* Empty state */

.welcome {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: 100%;
	padding: var(--space-6) 0;
	text-align: center;
	animation: rise 400ms var(--ease);
}

.welcome .mark {
	display: grid;
	place-items: center;
	width: 3.5rem;
	height: 3.5rem;
	margin-bottom: var(--space-4);
	border-radius: 1rem;
	background: linear-gradient(135deg, var(--accent), oklch(from var(--accent) calc(l - 0.08) c calc(h + 40)));
	color: var(--accent-ink);
	box-shadow: var(--shadow);
}

.welcome h2 {
	margin: 0 0 var(--space-2);
	font-size: var(--text-xl);
}

.welcome p {
	margin: 0 0 var(--space-5);
	color: var(--ink-2);
}

.suggestions {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--space-3);
	width: 100%;
	max-width: 36rem;
}

.suggestions button {
	justify-content: flex-start;
	min-height: 3.5rem;
	padding: var(--space-3) var(--space-4);
	border-color: var(--border);
	border-radius: var(--radius);
	text-align: left;
	font-weight: 500;
	color: var(--ink-2);
	box-shadow: var(--shadow-sm);
}

.suggestions button:hover {
	border-color: var(--accent);
	color: var(--ink);
	background: var(--surface);
}

.suggestions .icon {
	color: var(--accent);
}

/* Jump to latest */

.jump {
	position: absolute;
	left: 50%;
	bottom: calc(100% + var(--space-3));
	transform: translateX(-50%);
	min-height: 2.25rem;
	border-radius: 999px;
	box-shadow: var(--shadow);
	font-size: var(--text-xs);
}

/* Composer */

.composer-wrap {
	position: relative;
	padding: 0 var(--space-4) var(--space-4);
}

.composer {
	max-width: var(--column);
	margin: 0 auto;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-lg);
	background: var(--surface);
	box-shadow: var(--shadow);
	transition:
		border-color 150ms var(--ease),
		box-shadow 150ms var(--ease);
}

.composer:focus-within {
	border-color: var(--accent);
	box-shadow: var(--shadow), var(--focus);
}

.composer.dragging {
	border-color: var(--accent);
	border-style: dashed;
	background: var(--accent-soft);
}

.composer textarea {
	display: block;
	min-height: 3.25rem;
	max-height: 14rem;
	padding: var(--space-4) var(--space-4) var(--space-2);
	border: 0;
	background: transparent;
	resize: none;
	box-shadow: none;
}

.composer textarea:focus {
	box-shadow: none;
}

.composer-bar {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	padding: var(--space-2);
}

.composer-bar .spacer {
	flex: 1;
}

.composer-bar .hint {
	font-size: var(--text-xs);
}

.composer .send {
	width: 2.75rem;
	padding: 0;
	border-radius: var(--radius);
}

.chips {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2);
	padding: var(--space-3) var(--space-3) 0;
}

.chips:empty {
	display: none;
}

.chip {
	position: relative;
	display: flex;
	align-items: center;
	gap: var(--space-2);
	max-width: 16rem;
	min-height: 2.5rem;
	padding: var(--space-1) var(--space-1) var(--space-1) var(--space-2);
	overflow: hidden;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface-2);
	font-size: var(--text-xs);
}

.chip img {
	width: 2rem;
	height: 2rem;
	border-radius: 0.35rem;
	object-fit: cover;
}

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

.chip button {
	width: 2rem;
	min-height: 2rem;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--ink-3);
}

.chip .progress {
	position: absolute;
	left: 0;
	bottom: 0;
	height: 3px;
	background: var(--accent);
	transition: width 150ms linear;
}

.chip.failed {
	border-color: var(--danger);
	color: var(--danger);
}

.composer-note {
	max-width: var(--column);
	margin: var(--space-2) auto 0;
	text-align: center;
	color: var(--ink-3);
	font-size: var(--text-xs);
}

.composer-error {
	max-width: var(--column);
	margin: 0 auto var(--space-2);
}

.readonly {
	max-width: var(--column);
	margin: 0 auto;
	padding: var(--space-4);
	border: 1px dashed var(--border-strong);
	border-radius: var(--radius-lg);
	color: var(--ink-2);
	text-align: center;
	font-size: var(--text-sm);
}

/* ---------------------------------------------------------------------------
 * Markdown
 * ------------------------------------------------------------------------ */

.md {
	overflow-wrap: anywhere;
}

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

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

.md p,
.md ul,
.md ol,
.md blockquote,
.md pre,
.md table {
	margin: 0 0 var(--space-3);
}

.md h1,
.md h2,
.md h3,
.md h4 {
	margin: var(--space-5) 0 var(--space-2);
}

.md h1 {
	font-size: var(--text-xl);
}

.md h2 {
	font-size: var(--text-lg);
}

.md h3,
.md h4 {
	font-size: var(--text-md);
}

.md ul,
.md ol {
	padding-left: 1.5rem;
}

.md li + li {
	margin-top: var(--space-1);
}

.md li > p {
	margin: 0;
}

.md blockquote {
	padding: var(--space-1) var(--space-4);
	border-left: 3px solid var(--accent);
	color: var(--ink-2);
}

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

.md a {
	text-decoration-thickness: 1px;
	text-underline-offset: 2px;
}

.md code {
	padding: 0.1em 0.35em;
	border-radius: 0.35rem;
	background: var(--code-bg);
	color: var(--code-ink);
	font-family: var(--font-mono);
	font-size: 0.88em;
}

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

.codeblock {
	position: relative;
	margin: 0 0 var(--space-3);
	overflow: hidden;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--code-bg);
}

.codeblock .codebar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	min-height: 2.25rem;
	padding: 0 var(--space-2) 0 var(--space-3);
	border-bottom: 1px solid var(--border);
	color: var(--ink-3);
	font-size: var(--text-xs);
	font-family: var(--font-mono);
}

.codeblock .codebar button {
	min-height: 1.75rem;
	padding: 0 var(--space-2);
	border: 0;
	background: transparent;
	color: var(--ink-3);
	font-size: var(--text-xs);
}

.codeblock .codebar button:hover {
	color: var(--ink);
	background: var(--surface-3);
}

.md pre {
	margin: 0;
	padding: var(--space-3) var(--space-4);
	overflow-x: auto;
}

.md pre code {
	padding: 0;
	background: none;
	font-size: var(--text-sm);
	line-height: 1.55;
	overflow-wrap: normal;
}

.table-scroll {
	margin: 0 0 var(--space-3);
	overflow-x: auto;
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.md table {
	width: 100%;
	margin: 0;
	border-collapse: collapse;
	font-size: var(--text-sm);
}

.md th,
.md td {
	padding: var(--space-2) var(--space-3);
	border-bottom: 1px solid var(--border);
	text-align: left;
	vertical-align: top;
}

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

.md tr:last-child td {
	border-bottom: 0;
}

/* highlight.js classes mapped to tokens */
.hljs-keyword,
.hljs-selector-tag,
.hljs-built_in,
.hljs-type {
	color: var(--hl-keyword);
}

.hljs-string,
.hljs-regexp,
.hljs-symbol,
.hljs-meta .hljs-string {
	color: var(--hl-string);
}

.hljs-number,
.hljs-literal {
	color: var(--hl-number);
}

.hljs-comment,
.hljs-quote {
	color: var(--hl-comment);
	font-style: italic;
}

.hljs-title,
.hljs-section,
.hljs-function .hljs-title {
	color: var(--hl-title);
}

.hljs-attr,
.hljs-attribute,
.hljs-property,
.hljs-variable,
.hljs-params {
	color: var(--hl-attr);
}

/* ---------------------------------------------------------------------------
 * Pages (admin, account)
 * ------------------------------------------------------------------------ */

.page {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: var(--space-6) var(--space-4);
}

.page-inner {
	max-width: 60rem;
	margin: 0 auto;
	animation: rise 300ms var(--ease);
}

.page-head {
	margin-bottom: var(--space-5);
}

.page-head h1 {
	margin: 0 0 var(--space-1);
	font-size: var(--text-xl);
}

.page-head p {
	margin: 0;
	color: var(--ink-2);
}

.grid-form {
	display: grid;
	grid-template-columns: 1fr 1fr 10rem auto;
	align-items: end;
	gap: var(--space-3);
}

.grid-form.three {
	grid-template-columns: 1fr 1.4fr auto;
}

.grid-form .field {
	margin: 0;
}

.table-wrap {
	padding: 0;
	overflow-x: auto;
}

table.data {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--text-sm);
}

table.data th,
table.data td {
	padding: var(--space-3) var(--space-4);
	border-bottom: 1px solid var(--border);
	text-align: left;
	vertical-align: middle;
}

table.data th {
	color: var(--ink-3);
	font-size: var(--text-xs);
	font-weight: 650;
	letter-spacing: 0.05em;
	text-transform: uppercase;
}

table.data tr:last-child td {
	border-bottom: 0;
}

table.data select {
	min-height: 2.25rem;
	width: auto;
}

table.data .person {
	display: flex;
	align-items: center;
	gap: var(--space-3);
}

.secret {
	margin: var(--space-2) 0;
	padding: var(--space-2) var(--space-3);
	border-radius: var(--radius-sm);
	background: var(--surface);
	font-family: var(--font-mono);
	font-size: var(--text-lg);
	letter-spacing: 0.04em;
}

pre.code {
	margin: var(--space-2) 0;
	padding: var(--space-3);
	overflow-x: auto;
	border-radius: var(--radius-sm);
	background: var(--code-bg);
	font-family: var(--font-mono);
	font-size: var(--text-xs);
}

.loading-screen {
	display: grid;
	place-items: center;
	height: 100%;
	color: var(--ink-3);
}

/* ---------------------------------------------------------------------------
 * Phone
 * ------------------------------------------------------------------------ */

@media (max-width: 860px) {
	.shell {
		grid-template-columns: minmax(0, 1fr);
	}

	.sidebar {
		position: fixed;
		inset: 0 auto 0 0;
		z-index: 20;
		width: min(85vw, var(--sidebar-width));
		transform: translateX(-100%);
		transition: transform 250ms var(--ease);
		box-shadow: var(--shadow-lg);
	}

	.shell.drawer-open .sidebar {
		transform: none;
	}

	.shell.drawer-open .scrim {
		display: block;
		position: fixed;
		inset: 0;
		z-index: 10;
		background: oklch(0 0 0 / 0.35);
	}

	.main-header .menu {
		display: inline-flex;
	}

	.messages {
		padding: var(--space-4) var(--space-3) var(--space-3);
	}

	.composer-wrap {
		padding: 0 var(--space-2) var(--space-2);
	}

	.msg.user {
		max-width: 92%;
	}

	.msg.assistant {
		grid-template-columns: minmax(0, 1fr);
	}

	.msg.assistant .mark {
		display: none;
	}

	.steps {
		margin-left: 0;
	}

	.suggestions {
		grid-template-columns: minmax(0, 1fr);
	}

	.grid-form,
	.grid-form.three {
		grid-template-columns: minmax(0, 1fr);
	}

	.composer-bar .hint {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation: none !important;
		transition: none !important;
		scroll-behavior: auto !important;
	}
}

.row .spacer {
	flex: 1;
}

.table-wrap > .hint {
	margin: 0;
	padding: var(--space-4) var(--space-5);
}

/* ---------------------------------------------------------------------------
 * Live feedback
 * ------------------------------------------------------------------------ */

.spinner.small {
	width: 0.75rem;
	height: 0.75rem;
	border-width: 1.5px;
}

.status-dot.warn {
	background: var(--warn);
	animation: pulse 1.2s ease-in-out infinite;
}

/* Thinking */

.thinking-row {
	margin-left: calc(2rem + var(--space-3));
}

.thinking {
	margin-bottom: var(--space-2);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface-2);
	font-size: var(--text-sm);
}

.thinking summary {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	min-height: 2.25rem;
	padding: var(--space-1) var(--space-3);
	color: var(--ink-2);
	cursor: pointer;
	list-style: none;
}

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

.thinking summary .label {
	font-weight: 600;
	white-space: nowrap;
}

.thinking summary .preview {
	min-width: 0;
	overflow: hidden;
	color: var(--ink-3);
	font-style: italic;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.thinking summary .chevron {
	margin-left: auto;
	color: var(--ink-3);
	transition: transform 150ms var(--ease);
}

.thinking[open] summary .chevron {
	transform: rotate(90deg);
}

.thinking[open] summary .preview {
	display: none;
}

.thinking-body {
	max-height: 16rem;
	overflow-y: auto;
	padding: 0 var(--space-4) var(--space-3);
	color: var(--ink-2);
	white-space: pre-wrap;
	font-style: italic;
}

.msg.assistant .body > .thinking {
	margin-bottom: var(--space-3);
}

/* Turn status bar */

.turn-status {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	max-width: var(--column);
	min-height: 2.5rem;
	margin: 0 auto var(--space-2);
	padding: var(--space-1) var(--space-2) var(--space-1) var(--space-4);
	border-radius: 999px;
	font-size: var(--text-sm);
	animation: rise 200ms var(--ease);
}

.turn-status.running {
	border: 1px solid var(--border);
	background: var(--surface);
	box-shadow: var(--shadow-sm);
	color: var(--ink);
}

.turn-status.done {
	justify-content: center;
	min-height: 2rem;
	color: var(--ink-3);
	font-size: var(--text-xs);
}

.turn-status.done .icon {
	color: var(--ok);
}

.turn-status .phase {
	min-width: 0;
	overflow: hidden;
	font-weight: 600;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.turn-status .elapsed,
.turn-status .dim {
	color: var(--ink-3);
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

.turn-status .spacer {
	flex: 1;
}

.turn-status .stop {
	min-height: 2rem;
	padding: 0 var(--space-3);
	border-radius: 999px;
	font-size: var(--text-xs);
}

.turn-status .stop .icon {
	width: 0.9rem;
	height: 0.9rem;
	fill: currentColor;
}

/* Message lifecycle */

.msg .time.visible {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: var(--space-2);
	opacity: 1;
}

.msg .time .sent {
	display: inline-flex;
	align-items: center;
	gap: 0.15rem;
	color: var(--ok);
}

.msg .time .sent .icon {
	width: 0.9em;
	height: 0.9em;
	stroke-width: 2.5;
}

.msg.user.pending.sending .bubble {
	opacity: 0.7;
}

.msg.user.pending.failed .bubble {
	border: 1px solid var(--danger);
	background: var(--danger-soft);
}

.send-failed {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-end;
	gap: var(--space-1) var(--space-3);
	margin-top: var(--space-1);
	color: var(--danger);
	font-size: var(--text-sm);
}

.send-failed > span:first-child {
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
}

.row.tight {
	gap: var(--space-3);
}

button.link.muted {
	color: var(--ink-3);
}

.error-card {
	padding: var(--space-3) var(--space-4);
	border: 1px solid oklch(from var(--danger) l c h / 0.35);
	border-radius: var(--radius);
	background: var(--danger-soft);
}

.error-card .error-title {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	margin-bottom: var(--space-1);
	color: var(--danger);
	font-weight: 650;
}

.error-card .error-text {
	margin-bottom: var(--space-2);
	color: var(--ink-2);
	font-size: var(--text-sm);
	overflow-wrap: anywhere;
}

.error-card .row {
	margin-top: var(--space-2);
}

/* Connection */

.conn {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	padding: 0.15rem var(--space-3);
	border-radius: 999px;
	background: oklch(from var(--warn) l c h / 0.15);
	color: var(--ink-2);
	font-size: var(--text-xs);
	font-weight: 600;
	white-space: nowrap;
}

.offline-banner {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	padding: var(--space-2) var(--space-4);
	background: oklch(from var(--warn) l c h / 0.18);
	color: var(--ink);
	font-size: var(--text-sm);
	font-weight: 550;
}

/* Upload chips */

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

.chip-error {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 0.72rem;
}

.chip .percent {
	min-width: 2.5rem;
	color: var(--ink-3);
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.chip .ok {
	display: inline-grid;
	place-items: center;
	color: var(--ok);
}

.chip.failed {
	background: var(--danger-soft);
}

.chip .chip-action {
	width: 2rem;
	min-height: 2rem;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--ink-3);
}

.chip .chip-action:hover {
	color: var(--ink);
}

.send-wrap {
	display: inline-flex;
}

/* Toasts */

.toasts {
	position: fixed;
	left: 50%;
	top: 4.5rem;
	z-index: 50;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-2);
	transform: translateX(-50%);
	pointer-events: none;
}

.toast {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	padding: var(--space-2) var(--space-4);
	border-radius: 999px;
	background: var(--ink);
	color: var(--bg);
	box-shadow: var(--shadow-lg);
	font-size: var(--text-sm);
	font-weight: 550;
	animation: rise 200ms var(--ease);
	transition:
		opacity 220ms var(--ease),
		transform 220ms var(--ease);
}

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

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

.toast.leaving {
	opacity: 0;
	transform: translateY(-6px);
}

@media (max-width: 860px) {
	.thinking-row {
		margin-left: 0;
	}

	.turn-status .count {
		display: none;
	}
}

.turn-status.done.failed .icon {
	color: var(--danger);
}

/* Three dots while the reply has not started */
.typing {
	display: inline-flex;
	gap: 0.3rem;
	margin: 0.6rem 0;
}

.typing span {
	width: 0.45rem;
	height: 0.45rem;
	border-radius: 50%;
	background: var(--ink-3);
	animation: typing 1.2s ease-in-out infinite;
}

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

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

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