:root {
	color-scheme: light dark;
	--bg: #f4f4f1;
	--card: #ffffff;
	--fg: #1b1b1f;
	--muted: #686872;
	--line: #e2e0da;
	--soft: #f1f0ec;
	--on: #1f7a4d;
	--on-ink: #ffffff; /* text on a solid --on background */
	--on-soft: #e3f3ea;
	--off: #77777f;
	--off-soft: #ececea;
	--busy: #2457c5;
	--busy-soft: #e6edfb;
	--bad: #b42318;
	--bad-soft: #fbe9e7;
	--warn: #a15c07;
	--warn-soft: #fbf0dc;
	--radius: 12px;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #111113;
		--card: #1a1a1e;
		--fg: #ececf0;
		--muted: #9c9ca6;
		--line: #2b2b31;
		--soft: #222227;
		--on: #4cc38a;
		--on-ink: #0b1f14;
		--on-soft: #15301f;
		--off: #9c9ca6;
		--off-soft: #26262b;
		--busy: #7aa2f7;
		--busy-soft: #18223a;
		--bad: #f27a6b;
		--bad-soft: #3a1a17;
		--warn: #e5a54b;
		--warn-soft: #33260f;
	}
}

* {
	box-sizing: border-box;
}

[hidden] {
	display: none !important;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ------------------------------------------------------------- top bar --- */

.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 16px;
	background: var(--card);
	border-bottom: 1px solid var(--line);
	position: sticky;
	top: 0;
	z-index: 1;
}

.brand {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 600;
}

.topbar-right {
	display: flex;
	align-items: center;
	gap: 12px;
}

.tag {
	font-size: 12px;
	font-weight: 500;
	padding: 2px 8px;
	border-radius: 999px;
	background: var(--warn-soft);
	color: var(--warn);
}

.updated {
	color: var(--muted);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------- layout --- */

.wrap {
	max-width: 1120px;
	margin: 0 auto;
	padding: 16px;
}

.banner {
	margin: 0 0 16px;
	padding: 10px 14px;
	border-radius: var(--radius);
	background: var(--bad-soft);
	color: var(--bad);
}

.box {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 12px;
	margin-bottom: 16px;
}

.stat {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 12px 14px;
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	min-width: 0;
}

.stat-label,
.stat-sub {
	color: var(--muted);
	font-size: 13px;
}

.stat-value {
	font-size: 18px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

/* Two columns on a desktop, not three: at a third of the width the controls
   wrap onto a second row. Phones get one column (see the end of the file). */
.apps {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
	gap: 12px;
}

/* --------------------------------------------------------------- cards --- */

.card {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 14px 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	min-width: 0;
}

.card[data-state='off'],
.card[data-state='missing'] {
	background: color-mix(in srgb, var(--card) 70%, var(--bg));
}

.card-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
}

.card-titles {
	min-width: 0;
}

.card-name {
	margin: 0;
	font-size: 16px;
	line-height: 1.3;
}

.card-url {
	color: var(--muted);
	font-size: 13px;
	text-decoration: none;
	overflow-wrap: anywhere;
}

.card-url:hover {
	text-decoration: underline;
}

.badge {
	flex: none;
	font-size: 12px;
	font-weight: 600;
	padding: 3px 10px;
	border-radius: 999px;
	background: var(--off-soft);
	color: var(--off);
	white-space: nowrap;
}

.badge[data-state='on'] {
	background: var(--on-soft);
	color: var(--on);
}

.badge[data-state='pending'],
.badge[data-state='starting'],
.badge[data-state='stopping'] {
	background: var(--busy-soft);
	color: var(--busy);
}

.badge[data-state='failed'] {
	background: var(--bad-soft);
	color: var(--bad);
}

.badge[data-state='missing'] {
	background: var(--warn-soft);
	color: var(--warn);
}

.flag,
.note {
	margin: 0;
	font-size: 13px;
	padding: 8px 10px;
	border-radius: 8px;
}

.flag {
	background: var(--warn-soft);
	color: var(--warn);
}

.note {
	background: var(--soft);
	color: var(--muted);
}

.metrics {
	display: grid;
	grid-template-columns: 2fr 1fr 1fr 1fr;
	gap: 8px;
	margin: 0;
}

.metric {
	min-width: 0;
}

.metric dt {
	color: var(--muted);
	font-size: 12px;
}

.metric dd {
	margin: 0;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.hint {
	opacity: 0.8;
}

.health[data-health='ok'] {
	color: var(--on);
}

.health[data-health='fail'] {
	color: var(--bad);
}

/* --------------------------------------------------------------- meters --- */

.meter {
	display: block;
	position: relative;
	height: 6px;
	margin-top: 4px;
	border-radius: 999px;
	background: var(--soft);
	overflow: hidden;
}

.meter-fill {
	display: block;
	height: 100%;
	width: 0;
	border-radius: 999px;
	background: var(--on);
	transition: width 0.4s ease;
}

.meter-fill[data-level='warn'] {
	background: var(--warn);
}

.meter-fill[data-level='high'] {
	background: var(--bad);
}

.meter-mark {
	position: absolute;
	top: 0;
	bottom: 0;
	width: 2px;
	background: var(--muted);
	opacity: 0.7;
}

/* ------------------------------------------------------------- controls --- */

.controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.spacer {
	flex: 1;
}

.btn {
	font: inherit;
	font-size: 14px;
	font-weight: 500;
	padding: 6px 12px;
	border-radius: 8px;
	border: 1px solid var(--line);
	background: var(--card);
	color: var(--fg);
	cursor: pointer;
}

.btn:hover:not(:disabled) {
	background: var(--soft);
}

.btn:disabled {
	opacity: 0.55;
	cursor: default;
}

.btn:focus-visible,
select:focus-visible,
input:focus-visible,
.link:focus-visible,
.logs-text:focus-visible {
	outline: 2px solid var(--busy);
	outline-offset: 2px;
}

.btn.primary,
.toggle[data-kind='on'] {
	background: var(--on);
	border-color: var(--on);
	color: var(--on-ink);
}

.btn.primary:hover:not(:disabled),
.toggle[data-kind='on']:hover:not(:disabled) {
	background: color-mix(in srgb, var(--on) 85%, #000);
}

.toggle[data-kind='off'] {
	color: var(--bad);
	border-color: color-mix(in srgb, var(--bad) 45%, var(--line));
}

.btn.ghost {
	background: transparent;
}

.auto {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--muted);
	font-size: 13px;
}

select {
	font: inherit;
	font-size: 13px;
	padding: 5px 8px;
	border-radius: 8px;
	border: 1px solid var(--line);
	background: var(--card);
	color: var(--fg);
}

.link {
	font: inherit;
	font-size: 13px;
	background: none;
	border: 0;
	padding: 0;
	color: var(--busy);
	cursor: pointer;
}

/* ----------------------------------------------------------------- logs --- */

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

.logs-bar {
	display: flex;
	justify-content: space-between;
	color: var(--muted);
	font-size: 12px;
}

.logs-text {
	margin: 0;
	max-height: 320px;
	overflow: auto;
	padding: 10px;
	border-radius: 8px;
	background: var(--soft);
	font: 12px/1.45 var(--mono);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

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

.login-page {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: 16px;
}

.login {
	width: 100%;
	max-width: 360px;
}

.login-card h1 {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0 0 6px;
	font-size: 20px;
}

.login-card label {
	color: var(--muted);
	font-size: 13px;
}

.login-card input {
	font: inherit;
	padding: 9px 12px;
	border-radius: 8px;
	border: 1px solid var(--line);
	background: var(--card);
	color: var(--fg);
}

.login-card .btn {
	padding: 9px 12px;
}

.error {
	margin: 0;
	color: var(--bad);
	font-size: 14px;
}

/* ---------------------------------------------------------------- small --- */

@media (max-width: 760px) {
	.box {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

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

	.updated {
		display: none;
	}
}

@media (max-width: 420px) {
	.stat-value {
		font-size: 15px;
	}

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

	.metric-mem {
		grid-column: 1 / -1;
	}
}
