:root {
	--bg: #f6f7f9;
	--surface: #ffffff;
	--text: #1c2128;
	--muted: #5f6b7a;
	--border: #dde1e6;
	--primary: #2f5bd3;
	--primary-text: #ffffff;
	--ok: #1f7a4d;
	--ok-bg: #e6f4ec;
	--bad: #b42318;
	--bad-bg: #fdecea;
	--warn-bg: #fff6e0;
	--warn-text: #7a5200;
	--radius: 10px;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0f1216;
		--surface: #171b21;
		--text: #e6e9ee;
		--muted: #97a2b0;
		--border: #2a313b;
		--primary: #6e8ff0;
		--primary-text: #0b1020;
		--ok: #5fcf95;
		--ok-bg: #12301f;
		--bad: #f28b82;
		--bad-bg: #3a1614;
		--warn-bg: #33270b;
		--warn-text: #f5cf73;
		color-scheme: dark;
	}
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

[hidden] {
	display: none !important;
}

h1,
h2,
h3,
h4 {
	margin: 0 0 4px;
	line-height: 1.25;
}
h1 {
	font-size: 22px;
}
h2 {
	font-size: 18px;
}
h3 {
	font-size: 17px;
}
h4 {
	font-size: 14px;
}
p {
	margin: 0 0 8px;
}
code {
	font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
	font-size: 12.5px;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 4px;
	padding: 0 4px;
}

.muted {
	color: var(--muted);
}
.small {
	font-size: 12.5px;
}
.error {
	color: var(--bad);
	margin: 4px 0 0;
}
.warning {
	background: var(--warn-bg);
	color: var(--warn-text);
	padding: 10px 12px;
	border-radius: 8px;
}

/* ── controls ─────────────────────────────────────────────── */
button {
	font: inherit;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	padding: 7px 14px;
	cursor: pointer;
	white-space: nowrap;
}
button:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}
button.primary {
	background: var(--primary);
	border-color: var(--primary);
	color: var(--primary-text);
	font-weight: 600;
}
button.secondary {
	font-weight: 600;
}
button.ghost {
	background: transparent;
	border-color: transparent;
}
button.ghost:hover {
	border-color: var(--border);
}
button.danger {
	background: var(--bad);
	border-color: var(--bad);
	color: #fff;
	font-weight: 600;
}
.danger-text {
	color: var(--bad);
}
button.block {
	width: 100%;
}

input,
select {
	font: inherit;
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 7px 10px;
	width: 100%;
	min-width: 0;
}
input:focus,
select:focus,
button:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 1px;
}

.field {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0 0 12px;
	border: 0;
	padding: 0;
}
.field > span,
legend {
	font-weight: 600;
	font-size: 13px;
	padding: 0;
	margin-bottom: 4px;
}
.check {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 4px 0 8px;
}
.check input {
	width: auto;
}
.checks {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 18px;
}

.grid-2 {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0 14px;
}
.grid-4 {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 0 10px;
}
.grid-4 .field {
	margin-bottom: 0;
}
.grid-4 .field > span {
	font-weight: 500;
	font-size: 12px;
	color: var(--muted);
}

.inline-form {
	display: flex;
	gap: 8px;
	align-items: center;
	flex-wrap: wrap;
}
.inline-form input {
	flex: 1 1 220px;
	width: auto;
}
.actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 12px;
}
.actions.start {
	justify-content: flex-start;
	margin-top: 6px;
}
/* Borderless buttons align their label, not their padding, with the text above. */
.actions.start > button.ghost:first-child {
	margin-left: -14px;
}
.actions.flush {
	margin-top: 4px;
}

a.button {
	display: inline-block;
	font: inherit;
	font-weight: 600;
	text-decoration: none;
	color: var(--text);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 7px 14px;
	white-space: nowrap;
}
a.button:focus-visible {
	outline: 2px solid var(--primary);
	outline-offset: 1px;
}

.oauth-box {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 14px;
	margin: 8px 0;
}
.oauth-box .step {
	margin: 10px 0 6px;
}
.oauth-box .step:first-child {
	margin-top: 0;
}
.oauth-box .warning {
	margin-bottom: 8px;
}
.oauth-foot {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: 10px;
}

.device-code-row {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
	margin-bottom: 10px;
}
.device-code {
	font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
	font-size: 26px;
	font-weight: 700;
	letter-spacing: 0.12em;
	padding: 6px 14px;
	border: 1px dashed var(--border);
	border-radius: 8px;
	background: var(--surface);
	user-select: all;
}

details.manual {
	margin-top: 12px;
}
details.manual summary {
	cursor: pointer;
	color: var(--muted);
	font-size: 13px;
	margin-bottom: 8px;
}

.badge.warn {
	background: var(--warn-bg);
	color: var(--warn-text);
	border-color: transparent;
}
.expiry-warn {
	color: var(--warn-text);
	background: var(--warn-bg);
	padding: 6px 10px;
	border-radius: 8px;
}

/* ── layout ───────────────────────────────────────────────── */
.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.login {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: 16px;
}
.login-card {
	width: 100%;
	max-width: 360px;
	padding: 28px;
}

.topbar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 12px 24px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}
.brand {
	font-weight: 700;
	font-size: 16px;
}
.topbar-actions {
	display: flex;
	align-items: center;
	gap: 12px;
}

.content {
	max-width: 1180px;
	margin: 0 auto;
	padding: 24px;
}
.section-head {
	display: flex;
	justify-content: space-between;
	align-items: flex-end;
	gap: 16px;
	margin-bottom: 16px;
}

.table-wrap {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	overflow-x: auto;
}
table {
	width: 100%;
	border-collapse: collapse;
	min-width: 760px;
}
th,
td {
	text-align: left;
	padding: 12px 14px;
	border-bottom: 1px solid var(--border);
	vertical-align: top;
}
th {
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--muted);
	font-weight: 600;
}
tbody tr:last-child td {
	border-bottom: 0;
}
td.cell-actions {
	text-align: right;
}
.cell-title {
	font-weight: 600;
}
.empty {
	padding: 28px;
	text-align: center;
	color: var(--muted);
	margin: 0;
}

.badge {
	display: inline-block;
	white-space: nowrap;
	padding: 1px 8px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	background: var(--bg);
	color: var(--muted);
	border: 1px solid var(--border);
}
.badge.ok {
	background: var(--ok-bg);
	color: var(--ok);
	border-color: transparent;
}
.badge.bad {
	background: var(--bad-bg);
	color: var(--bad);
	border-color: transparent;
}

.test-result {
	margin: 0;
}
.test-result.ok {
	color: var(--ok);
}
.test-result.bad {
	color: var(--bad);
}

/* ── dialogs ──────────────────────────────────────────────── */
dialog {
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 0;
	width: min(720px, calc(100vw - 24px));
	max-height: calc(100vh - 24px);
	background: var(--surface);
	color: var(--text);
}
dialog::backdrop {
	background: rgb(10 14 20 / 0.55);
}
.dialog-body {
	padding: 20px 22px;
}
.dialog-head {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 12px;
	margin-bottom: 8px;
}
.panel {
	border-top: 1px solid var(--border);
	padding: 16px 0 4px;
	margin-top: 12px;
}
.danger-zone h4 {
	color: var(--bad);
}

.toast {
	position: fixed;
	left: 50%;
	bottom: 24px;
	transform: translateX(-50%);
	background: var(--text);
	color: var(--bg);
	padding: 10px 16px;
	border-radius: 8px;
	max-width: calc(100vw - 32px);
	z-index: 10;
}

@media (max-width: 640px) {
	.topbar,
	.content {
		padding-left: 14px;
		padding-right: 14px;
	}
	.section-head {
		flex-direction: column;
		align-items: stretch;
	}
	.grid-2 {
		grid-template-columns: minmax(0, 1fr);
	}
	.grid-4 {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 10px;
	}
	.dialog-body {
		padding: 16px;
	}
}
