:root {
	--bg: #faf9f5;
	--panel: #f0eee6;
	--card: #ffffff;
	--text: #29261b;
	--muted: #77736a;
	--border: #e3dfd3;
	--accent: #c96442;
	--accent-text: #ffffff;
	--user-bubble: #f0eee6;
	--code-bg: #f3f1ea;
	--ok: #4c8a52;
	--danger: #b3402b;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #262624;
		--panel: #1f1e1d;
		--card: #30302e;
		--text: #ece9e1;
		--muted: #a09d94;
		--border: #3d3c38;
		--user-bubble: #141413;
		--code-bg: #1c1b1a;
	}
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
code, pre { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: 13px; }

.login {
	max-width: 320px;
	margin: 18vh auto 0;
	padding: 0 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}
.login h1 { font-family: Georgia, serif; font-weight: 400; text-align: center; }
.login input, .login button {
	padding: 10px 12px;
	border-radius: 10px;
	border: 1px solid var(--border);
	background: var(--card);
}
.login button { background: var(--accent); color: var(--accent-text); border: none; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

.app { display: flex; height: 100dvh; }

.sidebar {
	width: 270px;
	flex-shrink: 0;
	background: var(--panel);
	border-right: 1px solid var(--border);
	padding: 12px;
	display: flex;
	flex-direction: column;
	overflow-y: auto;
}
.sidebar h2 {
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--muted);
	margin: 18px 8px 6px;
}
.new-chat {
	padding: 9px 12px;
	border-radius: 10px;
	border: 1px solid var(--border);
	background: var(--card);
	text-align: left;
}
.list { list-style: none; margin: 0; padding: 0; }
.list li {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 7px 8px;
	border-radius: 8px;
	cursor: pointer;
	white-space: nowrap;
	overflow: hidden;
}
.list li span.name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.list li:hover { background: var(--border); }
.list li.active { background: var(--card); }
.list li .delete { visibility: hidden; border: none; background: none; color: var(--muted); padding: 0 4px; }
.list li:hover .delete { visibility: visible; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.dot.busy { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }
.hint { color: var(--muted); font-size: 13px; margin: 2px 8px; }
.logout { margin-top: auto; border: none; background: none; color: var(--muted); text-align: left; padding: 8px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 16px;
	border-bottom: 1px solid var(--border);
}
.menu { display: none; border: none; background: none; font-size: 20px; }
.title-box { flex: 1; min-width: 0; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { color: var(--muted); font-size: 13px; }

.messages {
	flex: 1;
	overflow-y: auto;
	padding: 24px 16px 8px;
}
.messages > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; color: var(--muted); font-family: Georgia, serif; font-size: 26px; margin-top: 20vh; }

.msg { margin-bottom: 18px; overflow-wrap: anywhere; }
.msg.user {
	background: var(--user-bubble);
	border-radius: 14px;
	padding: 10px 14px;
	width: fit-content;
	max-width: min(85%, 760px);
	margin-right: max(0px, calc((100% - 760px) / 2));
	margin-left: auto;
	white-space: pre-wrap;
}
.msg.assistant pre { background: var(--code-bg); padding: 12px; border-radius: 10px; overflow-x: auto; }
.msg.assistant :not(pre) > code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.msg.assistant p:first-child { margin-top: 0; }
.msg.error-text { color: var(--danger); }
.msg.system { color: var(--muted); font-size: 13px; white-space: pre-wrap; }

details.tool {
	border: 1px solid var(--border);
	border-radius: 10px;
	margin: 6px 0;
	background: var(--card);
	font-size: 13px;
}
details.tool summary { padding: 6px 10px; cursor: pointer; color: var(--muted); }
details.tool summary b { color: var(--text); font-weight: 600; }
details.tool.failed summary b { color: var(--danger); }
details.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); white-space: pre-wrap; max-height: 360px; overflow: auto; }
details.thinking { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
details.thinking pre { white-space: pre-wrap; }

.composer {
	max-width: 760px;
	width: calc(100% - 32px);
	margin: 0 auto 16px;
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 18px;
	padding: 10px 12px 8px;
	box-shadow: 0 2px 10px rgb(0 0 0 / .04);
}
.composer textarea {
	width: 100%;
	border: none;
	outline: none;
	resize: none;
	background: transparent;
	max-height: 240px;
}
.composer-bar { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.composer select { border: none; background: transparent; color: var(--muted); max-width: 60%; margin-right: auto; }
.send, .stop { border: none; border-radius: 10px; padding: 6px 12px; background: var(--accent); color: var(--accent-text); }
.stop { background: var(--border); color: var(--text); }
.send:disabled { opacity: .4; cursor: default; }

@media (max-width: 760px) {
	.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
	.sidebar.open { transform: none; box-shadow: 0 0 30px rgb(0 0 0 / .25); }
	.menu { display: block; }
}
