:root {
	color-scheme: dark;
	--bg: #0e1116;
	--panel: #151a21;
	--panel-2: #1b222b;
	--line: #28313d;
	--text: #e6edf3;
	--muted: #8b98a9;
	--accent: #7c9cff;
	--accent-2: #4f6ef7;
	--danger: #ff6b6b;
	--ok: #3ddc97;
	--radius: 14px;
	--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* {
	box-sizing: border-box;
}

html,
body {
	height: 100%;
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: var(--font);
	font-size: 15px;
	-webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
}

.muted {
	color: var(--muted);
}
.small {
	font-size: 12px;
}
.error {
	color: var(--danger);
}
[hidden] {
	display: none !important;
}

/* ------------------------------------------------------------------ login */

.login {
	min-height: 100%;
	display: grid;
	place-items: center;
	padding: 24px;
	background:
		radial-gradient(1200px 600px at 50% -10%, rgba(124, 156, 255, 0.16), transparent 60%),
		var(--bg);
}

.login-card {
	width: min(360px, 100%);
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 20px;
	padding: 28px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.login-card h1 {
	margin: 0;
	font-size: 22px;
}

.login-card label {
	margin-top: 10px;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--muted);
}

.login-card input,
.composer textarea {
	background: var(--panel-2);
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 11px 12px;
	outline: none;
}

.login-card input:focus,
.composer textarea:focus {
	border-color: var(--accent-2);
	box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.18);
}

.login-card button {
	margin-top: 8px;
	background: var(--accent-2);
	border: 0;
	border-radius: 10px;
	padding: 12px;
	font-weight: 600;
}

.login-card button:disabled {
	opacity: 0.6;
}

.logo {
	width: 44px;
	height: 44px;
	border-radius: 12px;
	display: grid;
	place-items: center;
	background: linear-gradient(135deg, var(--accent-2), #9d7cff);
	font-size: 24px;
	font-weight: 700;
}

/* -------------------------------------------------------------------- app */

.app {
	height: 100%;
	display: grid;
	grid-template-columns: 280px 1fr;
	grid-template-rows: 56px auto 1fr;
	grid-template-areas:
		"topbar topbar"
		"banner banner"
		"sidebar main";
}

.topbar {
	grid-area: topbar;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 0 12px;
	border-bottom: 1px solid var(--line);
	background: rgba(14, 17, 22, 0.9);
	backdrop-filter: blur(12px);
	padding-top: env(safe-area-inset-top);
}

.title {
	flex: 1;
	text-align: left;
	background: none;
	border: 0;
	font-weight: 600;
	font-size: 15px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	padding: 8px;
}

.icon-button {
	background: none;
	border: 1px solid transparent;
	border-radius: 10px;
	width: 38px;
	height: 38px;
	display: grid;
	place-items: center;
	font-size: 18px;
	color: var(--muted);
}
.icon-button:hover {
	background: var(--panel-2);
	color: var(--text);
}

.status {
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: var(--muted);
	flex: none;
}
.status.online {
	background: var(--ok);
}
.status.busy {
	background: var(--accent);
	animation: pulse 1.4s ease-in-out infinite;
}
.status.offline {
	background: var(--danger);
}

@keyframes pulse {
	0%,
	100% {
		opacity: 1;
	}
	50% {
		opacity: 0.35;
	}
}

.banner {
	grid-area: banner;
	padding: 10px 16px;
	background: rgba(255, 180, 84, 0.12);
	color: #ffcc80;
	border-bottom: 1px solid rgba(255, 180, 84, 0.25);
	font-size: 13px;
}

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

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

.sidebar-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 12px 6px 16px;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	color: var(--muted);
}

#close-menu {
	display: none;
}

.sessions {
	flex: 1;
	overflow-y: auto;
	padding: 4px 8px 12px;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.session {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px;
	border-radius: 10px;
	border: 1px solid transparent;
	cursor: pointer;
	text-align: left;
	background: none;
	color: var(--text);
}
.session:hover {
	background: var(--panel-2);
}
.session.active {
	background: var(--panel-2);
	border-color: var(--line);
}

.session .dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: transparent;
	flex: none;
}
.session.busy .dot {
	background: var(--accent);
	animation: pulse 1.4s ease-in-out infinite;
}

.session .name {
	flex: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-size: 14px;
}

.session .when {
	font-size: 11px;
	color: var(--muted);
	flex: none;
}

.sidebar-foot {
	border-top: 1px solid var(--line);
	padding: 12px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.link-button {
	background: none;
	border: 0;
	color: var(--muted);
	font-size: 12px;
	padding: 4px;
}
.link-button:hover {
	color: var(--text);
}

/* ------------------------------------------------------------------- main */

.main {
	grid-area: main;
	display: flex;
	flex-direction: column;
	min-height: 0;
	min-width: 0;
}

.messages {
	flex: 1;
	overflow-y: auto;
	padding: 22px 16px 8px;
	display: flex;
	flex-direction: column;
	gap: 14px;
	scroll-behavior: smooth;
}

.message {
	max-width: 820px;
	width: 100%;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.message .who {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--muted);
}

.bubble {
	padding: 12px 14px;
	border-radius: var(--radius);
	border: 1px solid var(--line);
	background: var(--panel);
	line-height: 1.55;
	overflow-wrap: anywhere;
}

.message.user .bubble {
	background: linear-gradient(135deg, rgba(79, 110, 247, 0.22), rgba(124, 156, 255, 0.1));
	border-color: rgba(124, 156, 255, 0.35);
}

.message.assistant .bubble {
	background: var(--panel);
}

.message.system {
	opacity: 0.75;
}
.message.system .bubble {
	background: transparent;
	border-style: dashed;
	font-size: 13px;
	padding: 8px 12px;
}

.bubble p {
	margin: 0 0 8px;
}
.bubble p:last-child {
	margin-bottom: 0;
}
.bubble pre.code {
	background: #0a0d12;
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 12px;
	overflow-x: auto;
	margin: 8px 0;
	font-family: var(--mono);
	font-size: 13px;
	line-height: 1.45;
}
.bubble code {
	font-family: var(--mono);
	font-size: 0.92em;
	background: rgba(255, 255, 255, 0.06);
	padding: 1px 5px;
	border-radius: 5px;
}
.bubble pre.code code {
	background: none;
	padding: 0;
}
.bubble a {
	color: var(--accent);
}

.thinking {
	border-left: 2px solid var(--line);
	padding-left: 10px;
	color: var(--muted);
	font-size: 13px;
}
.thinking summary {
	cursor: pointer;
	color: var(--muted);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

.tool {
	border: 1px solid var(--line);
	border-radius: 10px;
	background: #10151b;
	font-size: 13px;
}
.tool summary {
	cursor: pointer;
	padding: 8px 11px;
	color: var(--muted);
	display: flex;
	gap: 8px;
	align-items: center;
}
.tool summary .name {
	color: var(--text);
	font-family: var(--mono);
	font-size: 12px;
}
.tool pre {
	margin: 0;
	padding: 10px 12px;
	border-top: 1px solid var(--line);
	overflow-x: auto;
	max-height: 340px;
	white-space: pre-wrap;
	font-family: var(--mono);
	font-size: 12px;
	line-height: 1.45;
	color: #c9d4e2;
}
.tool.error summary {
	color: var(--danger);
}

.tool-calls {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: 8px;
}

.live {
	max-width: 820px;
	margin: 0 auto;
	width: 100%;
	display: flex;
	flex-direction: column;
	gap: 8px;
	color: var(--muted);
	font-size: 14px;
}
.live .bubble {
	background: rgba(124, 156, 255, 0.06);
	border-style: dashed;
	color: var(--text);
}
.live .pulse-dot {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--accent);
	margin-right: 8px;
	animation: pulse 1.2s ease-in-out infinite;
}

.empty {
	margin: auto;
	max-width: 520px;
	text-align: center;
	color: var(--muted);
	padding: 40px 16px;
}
.empty h2 {
	color: var(--text);
	font-size: 20px;
	margin: 0 0 8px;
}

.failure {
	color: var(--danger);
	font-size: 13px;
	border: 1px solid rgba(255, 107, 107, 0.3);
	background: rgba(255, 107, 107, 0.07);
	border-radius: 10px;
	padding: 10px 12px;
}

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

.composer {
	border-top: 1px solid var(--line);
	padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
	display: flex;
	gap: 10px;
	align-items: flex-end;
	background: rgba(14, 17, 22, 0.92);
	backdrop-filter: blur(12px);
}

.composer textarea {
	flex: 1;
	resize: none;
	max-height: 200px;
	line-height: 1.45;
	font-size: 15px;
	padding: 11px 13px;
}

.composer-actions {
	display: flex;
	gap: 8px;
}

.send,
.stop {
	border: 0;
	border-radius: 10px;
	padding: 11px 16px;
	font-weight: 600;
}
.send {
	background: var(--accent-2);
	color: white;
}
.send:disabled {
	opacity: 0.5;
}
.stop {
	background: rgba(255, 107, 107, 0.12);
	color: var(--danger);
	border: 1px solid rgba(255, 107, 107, 0.3);
}

/* ---------------------------------------------------------------- mobile */

.scrim {
	display: none;
}

@media (max-width: 820px) {
	.app {
		grid-template-columns: 1fr;
		grid-template-areas:
			"topbar"
			"banner"
			"main";
	}

	.sidebar {
		position: fixed;
		inset: 0 auto 0 0;
		width: min(84vw, 320px);
		z-index: 40;
		transform: translateX(-102%);
		transition: transform 0.2s ease;
		box-shadow: 20px 0 60px rgba(0, 0, 0, 0.5);
	}

	.sidebar.open {
		transform: translateX(0);
	}

	#close-menu {
		display: grid;
	}

	.scrim {
		display: block;
		position: fixed;
		inset: 0;
		background: rgba(0, 0, 0, 0.55);
		z-index: 30;
	}

	.messages {
		padding: 16px 10px 8px;
	}

	.composer {
		padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
	}

	.bubble {
		padding: 11px 12px;
	}
}

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