:root {
	--bg: #f7f7f5;
	--surface: #ffffff;
	--text: #1c1d1f;
	--muted: #6a6d73;
	--border: #e2e2de;
	--accent: #1f5fd1;
	--accent-text: #ffffff;
	--ok: #1d7a46;
	--warn: #a15c00;
	--bad: #b42318;
	--code-bg: #f0f0ec;
	--prompt-bg: #eef3fd;
	--radius: 8px;
	--font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #151618;
		--surface: #1d1f22;
		--text: #e6e6e3;
		--muted: #9a9ca1;
		--border: #303237;
		--accent: #5b8ff0;
		--accent-text: #0d1117;
		--ok: #4cc38a;
		--warn: #e0a24a;
		--bad: #f07167;
		--code-bg: #26282c;
		--prompt-bg: #1f2a40;
		color-scheme: dark;
	}
}

:root[data-theme="dark"] {
	--bg: #151618;
	--surface: #1d1f22;
	--text: #e6e6e3;
	--muted: #9a9ca1;
	--border: #303237;
	--accent: #5b8ff0;
	--accent-text: #0d1117;
	--ok: #4cc38a;
	--warn: #e0a24a;
	--bad: #f07167;
	--code-bg: #26282c;
	--prompt-bg: #1f2a40;
	color-scheme: dark;
}

* { box-sizing: border-box; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.55 var(--font);
}

a { color: var(--accent); }
code, pre { font-family: var(--mono); font-size: 0.88em; }
code { background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; }
.muted { color: var(--muted); }
.bad { color: var(--bad); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0.2em 0 0.5em; }
h2 { font-size: 1.1rem; margin: 1.8em 0 0.6em; }

button, .button {
	font: inherit;
	font-size: 0.92rem;
	display: inline-block;
	padding: 0.45em 0.95em;
	border-radius: var(--radius);
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
	text-decoration: none;
	white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.big { font-size: 1.05rem; padding: 0.7em 1.4em; }
button.small { font-size: 0.82rem; padding: 0.25em 0.7em; }
button.danger { border-color: var(--bad); color: var(--bad); }
button:disabled { opacity: 0.6; cursor: default; }

input, textarea {
	font: inherit;
	padding: 0.45em 0.6em;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--text);
	min-width: 0;
}

.spinner {
	display: inline-block;
	width: 1em;
	height: 1em;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	border-radius: 50%;
	vertical-align: -0.15em;
	animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- candidate pages ---- */

main.narrow { max-width: 720px; margin: 0 auto; padding: 48px 16px 64px; }
main.center { text-align: center; padding-top: 25vh; }
.eyebrow { color: var(--muted); font-size: 0.85rem; letter-spacing: 0.02em; margin: 0; }
.lead { font-size: 1.1rem; }
ul.record li { margin: 0.25em 0; }
form.start { margin-top: 2em; padding: 1.2em; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
label.check { display: flex; gap: 0.6em; align-items: flex-start; margin-bottom: 1em; }
label.check input { margin-top: 0.35em; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.3em 1.2em; margin: 1em 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
body.dark { background: #1f1f1f; color: #cccccc; }
form.register label { display: block; margin-bottom: 1em; font-weight: 600; }
form.register label .muted { font-weight: 400; }
form.register input { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
.error { padding: 10px 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.save-link { margin: 1.2em 0; padding: 4px 16px 12px; border: 1px solid var(--accent); border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.invite input { flex: 1; min-width: 220px; font-family: var(--mono); font-size: 0.85rem; }

/* ---- workspace page ---- */

body.shell {
	height: 100vh;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: #181818;
	color: #cccccc;
	color-scheme: dark;
}
.bar {
	display: flex;
	align-items: center;
	gap: 16px;
	padding: 6px 12px;
	background: #1f1f1f;
	border-bottom: 1px solid #2b2b2b;
	font-size: 0.9rem;
	flex: none;
}
.bar .brand { font-weight: 600; color: #e6e6e6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .muted { color: #8b8b8b; font-weight: 400; }
.bar nav { margin-left: auto; display: flex; gap: 8px; }
.bar button, .bar a {
	font-size: 0.85rem;
	padding: 0.3em 0.8em;
	background: #2b2b2b;
	border: 1px solid #3c3c3c;
	color: #e6e6e6;
	border-radius: 6px;
	text-decoration: none;
	cursor: pointer;
}
.bar button.primary { background: #2a6ee8; border-color: #2a6ee8; color: #fff; }
.timer { font-family: var(--mono); font-variant-numeric: tabular-nums; color: #e6e6e6; padding: 0.15em 0.6em; border-radius: 6px; background: #2b2b2b; }
.timer.warn { background: #5c4100; color: #ffd27a; }
.timer.over { background: #6b1d1d; color: #ffb4ab; }
.banner { background: #6b1d1d; color: #ffe1dd; padding: 6px 12px; font-size: 0.9rem; flex: none; }
#ide { flex: 1; width: 100%; border: 0; background: #1f1f1f; }

.drawer {
	position: fixed;
	top: 42px;
	right: 0;
	bottom: 0;
	width: min(560px, 100vw);
	background: #fbfbfa;
	color: #1c1d1f;
	color-scheme: light;
	box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
	display: flex;
	flex-direction: column;
	z-index: 10;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid #e2e2de; }
.drawer-head button { border: 0; background: none; font-size: 1rem; }
.drawer-body { overflow: auto; padding: 4px 20px 24px; }
.markdown h1 { font-size: 1.3rem; }
.markdown pre { background: #f0f0ec; padding: 10px; border-radius: 6px; overflow: auto; }

dialog {
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 20px 24px;
	max-width: min(560px, calc(100vw - 32px));
	background: var(--surface);
	color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin-top: 0; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
ul.checks { list-style: none; padding: 0; }
ul.checks li { padding-left: 1.6em; position: relative; margin: 0.35em 0; }
ul.checks li::before { position: absolute; left: 0; font-weight: 700; }
ul.checks li.ok::before { content: "✓"; color: var(--ok); }
ul.checks li.warn::before { content: "!"; color: var(--warn); left: 0.3em; }

/* ---- admin ---- */

.admin-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.admin-bar .brand { font-weight: 700; color: var(--text); text-decoration: none; }
main.wide { max-width: 1180px; margin: 0 auto; padding: 16px 16px 64px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 16px 16px; margin-top: 16px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); gap: 4px; }
.inline-form label.grow { flex: 1; min-width: 200px; }
.invite-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.invite-cards .card { margin-top: 0; }
.invite-cards p.muted { font-size: 0.88rem; margin-top: 0; }
.stack-form { display: flex; flex-direction: column; gap: 10px; }
.stack-form textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 0.85rem; }
ul.links { list-style: none; padding: 0; margin: 14px 0 0; border-top: 1px solid var(--border); }
ul.links li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
ul.links li:last-child { border-bottom: 0; }
.link-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 0 24px; }
pre.message { white-space: pre-wrap; font-family: var(--font); font-size: 0.9rem; max-height: none; }
form.settings { display: flex; flex-direction: column; gap: 14px; padding: 16px; margin-top: 0; }
form.settings > label:not(.check) { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.9rem; }
form.settings > label .muted { font-weight: 400; font-size: 0.82rem; }
form.settings > label.check { margin: 0; }
form.settings input:not([type="checkbox"]) { max-width: 320px; }
form.settings textarea { font-family: var(--mono); font-size: 0.85rem; resize: vertical; }
#search { width: 220px; }
code.link { word-break: break-all; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
td.right { text-align: right; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 0.15em 0.6em; border-radius: 99px; background: var(--code-bg); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.pill.active, .pill.provisioning, .pill.submitting { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.pill.submitted { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.failed { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.pill.open { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
h1 .pill { font-size: 0.8rem; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.head-row h2 { margin-bottom: 0.3em; }
.head-row.toolbar { align-items: center; margin: 1.8em 0 0.6em; }
.head-row.toolbar h2 { margin: 0; }
.card h2 { margin-top: 0.9em; }
.notice { margin-top: 12px; padding: 10px 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.notice.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.notice.bad-notice { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.actions.left { justify-content: flex-start; margin: 12px 0; }
.invite { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.invite code { word-break: break-all; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; }
.stat .value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { font-size: 0.82rem; color: var(--muted); }
.stat .hint { font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; }
.filters { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 12px; font-size: 0.88rem; }
ol.timeline { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
li.ev { display: grid; grid-template-columns: 76px 74px 1fr; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--border); font-size: 0.9rem; align-items: baseline; }
li.ev[hidden] { display: none; }
li.ev:last-child { border-bottom: 0; }
li.ev.ai { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.when { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.src { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.what { min-width: 0; overflow-wrap: anywhere; }
.what summary { cursor: pointer; }
pre.prompt, pre.reply { white-space: pre-wrap; word-break: break-word; margin: 6px 0 2px; padding: 8px 10px; border-radius: 6px; max-height: 420px; overflow: auto; }
pre.prompt { background: var(--prompt-bg); font-family: var(--font); font-size: 0.92rem; }
pre.reply { background: var(--code-bg); }
ul.tools { margin: 6px 0; padding-left: 1.2em; }
code.cmd { white-space: pre-wrap; }
.danger-zone { margin-top: 40px; font-size: 0.9rem; }
.danger-zone summary { cursor: pointer; color: var(--bad); }
pre.patch { margin: 0; padding: 16px; white-space: pre-wrap; word-break: break-word; font-size: 0.82rem; }

@media (max-width: 640px) {
	li.ev { grid-template-columns: 1fr; gap: 2px; }
	.bar .brand .muted { display: none; }
	table.list th:nth-child(3), table.list td:nth-child(3), table.list th:nth-child(4), table.list td:nth-child(4) { display: none; }
}
