:root {
	--bg: #f5f6f8;
	--surface: #ffffff;
	--surface-2: #f0f2f5;
	--border: #dde1e7;
	--border-strong: #c3cad4;
	--text: #1b2028;
	--muted: #5b6676;
	--accent: #3b5bdb;
	--accent-hover: #2f4ac0;
	--accent-soft: #edf1ff;
	--on-accent: #ffffff;
	--danger: #c22727;
	--danger-soft: #fdecec;
	--ok: #24783a;
	--ok-soft: #e7f6eb;
	--warn: #9a5b00;
	--warn-soft: #fff3dc;
	--shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
	--shadow-lg: 0 12px 32px rgb(16 24 40 / 18%);
	--radius: 10px;
	--radius-sm: 6px;
	--mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
	--sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0e1115;
		--surface: #161a20;
		--surface-2: #1d232b;
		--border: #29313b;
		--border-strong: #3a4552;
		--text: #e7eaee;
		--muted: #98a4b3;
		--accent: #8098f9;
		--accent-hover: #9aaefb;
		--accent-soft: #1b2342;
		--on-accent: #0e1115;
		--danger: #ff8a8a;
		--danger-soft: #3b1b1b;
		--ok: #6fd583;
		--ok-soft: #132c1a;
		--warn: #f5bd6b;
		--warn-soft: #37280f;
		--shadow: 0 1px 2px rgb(0 0 0 / 40%);
		--shadow-lg: 0 12px 32px rgb(0 0 0 / 55%);
	}
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
}

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

h1,
h2,
h3,
p {
	margin: 0;
}

a {
	color: var(--accent);
}

code,
.mono {
	font-family: var(--mono);
	font-size: 0.92em;
}

[hidden] {
	display: none !important;
}

.noscript {
	padding: 2rem;
	text-align: center;
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

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

.topbar {
	position: sticky;
	top: 0;
	z-index: 10;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}

.topbar-inner {
	display: flex;
	align-items: center;
	gap: 16px;
	max-width: 1120px;
	margin: 0 auto;
	padding: 0 20px;
	min-height: 56px;
}

.brand {
	display: flex;
	align-items: center;
	gap: 10px;
	font-weight: 650;
	white-space: nowrap;
}

.brand img {
	width: 24px;
	height: 24px;
}

.brand-domain {
	color: var(--muted);
	font-weight: 400;
}

.nav {
	display: flex;
	gap: 2px;
	margin-left: 8px;
	flex: 1;
	overflow-x: auto;
}

.nav a {
	padding: 17px 12px 15px;
	border-bottom: 2px solid transparent;
	color: var(--muted);
	text-decoration: none;
	font-weight: 500;
	white-space: nowrap;
}

.nav a:hover {
	color: var(--text);
}

.nav a[aria-current='page'] {
	color: var(--accent);
	border-bottom-color: var(--accent);
}

.account {
	display: flex;
	align-items: center;
	gap: 10px;
	color: var(--muted);
	font-size: 14px;
	white-space: nowrap;
}

.page {
	max-width: 1120px;
	margin: 0 auto;
	padding: 28px 20px 64px;
}

/* Each view renders into one container. Its direct children are spaced evenly. */
.page > div {
	display: flex;
	flex-direction: column;
	gap: 20px;
}

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

.page-head h1 {
	font-size: 22px;
	line-height: 1.25;
}

.page-head p {
	margin-top: 4px;
	color: var(--muted);
	max-width: 68ch;
}

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.card-body > .section,
.kv.section {
	margin-top: 16px;
}

.card-body {
	padding: 18px 20px;
}

.card-title {
	font-size: 16px;
	font-weight: 650;
}

.card-sub {
	margin-top: 2px;
	color: var(--muted);
	font-size: 14px;
}

.muted {
	color: var(--muted);
}

.small {
	font-size: 13px;
}

.stack {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.row {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

.grow {
	flex: 1;
	min-width: 0;
}

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

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 7px 13px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font: inherit;
	font-weight: 550;
	line-height: 1.3;
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
}

.btn:hover {
	background: var(--surface-2);
}

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

.btn-primary {
	border-color: var(--accent);
	background: var(--accent);
	color: var(--on-accent);
}

.btn-primary:hover {
	border-color: var(--accent-hover);
	background: var(--accent-hover);
}

.btn-quiet {
	border-color: transparent;
	background: transparent;
	color: var(--muted);
	padding: 6px 9px;
}

.btn-quiet:hover {
	color: var(--text);
}

.btn-danger {
	color: var(--danger);
}

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

.btn-lg {
	padding: 10px 18px;
	font-size: 16px;
}

label,
.label {
	display: block;
	margin-bottom: 5px;
	font-weight: 600;
	font-size: 14px;
}

.hint {
	margin-top: 5px;
	color: var(--muted);
	font-size: 13px;
}

.error {
	margin-top: 5px;
	color: var(--danger);
	font-size: 13px;
	font-weight: 500;
}

input[type='text'],
input[type='email'],
input[type='search'],
input[type='number'],
select,
textarea {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font: inherit;
}

textarea {
	min-height: 96px;
	resize: vertical;
	font-family: var(--mono);
	font-size: 14px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 0;
	border-color: var(--accent);
}

input[aria-invalid='true'],
textarea[aria-invalid='true'] {
	border-color: var(--danger);
}

.field + .field {
	margin-top: 16px;
}

.affix {
	display: flex;
	align-items: stretch;
}

.affix input {
	border-top-right-radius: 0;
	border-bottom-right-radius: 0;
	min-width: 0;
}

.affix span {
	display: flex;
	align-items: center;
	padding: 0 10px;
	border: 1px solid var(--border-strong);
	border-left: 0;
	border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
	background: var(--surface-2);
	color: var(--muted);
	font-family: var(--mono);
	font-size: 14px;
	white-space: nowrap;
}

.choices {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.choice {
	position: relative;
	margin: 0;
	font-weight: 500;
}

.choice input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.choice span {
	display: block;
	padding: 7px 13px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	cursor: pointer;
}

.choice input:checked + span {
	border-color: var(--accent);
	background: var(--accent-soft);
	color: var(--accent);
}

.choice input:focus-visible + span {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.check {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	font-weight: 500;
	cursor: pointer;
}

.check input {
	width: 16px;
	height: 16px;
	accent-color: var(--accent);
}

.switch {
	position: relative;
	display: inline-block;
	width: 36px;
	height: 20px;
	flex: none;
}

.switch input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	opacity: 0;
	cursor: pointer;
}

.switch span {
	position: absolute;
	inset: 0;
	border-radius: 999px;
	background: var(--border-strong);
	transition: background 0.15s;
	pointer-events: none;
}

.switch span::after {
	content: '';
	position: absolute;
	top: 2px;
	left: 2px;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
	transition: transform 0.15s;
}

.switch input:checked + span {
	background: var(--ok);
}

.switch input:checked + span::after {
	transform: translateX(16px);
}

.switch input:focus-visible + span {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

/* ---------- data display ---------- */

.badge {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 1px 8px;
	border-radius: 999px;
	background: var(--surface-2);
	color: var(--muted);
	font-size: 12.5px;
	font-weight: 600;
	line-height: 1.6;
	white-space: nowrap;
}

.badge-ok {
	background: var(--ok-soft);
	color: var(--ok);
}

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

.badge-danger {
	background: var(--danger-soft);
	color: var(--danger);
}

.badge-accent {
	background: var(--accent-soft);
	color: var(--accent);
}

.chips {
	display: flex;
	flex-wrap: wrap;
	gap: 5px;
}

.chip {
	padding: 1px 8px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface-2);
	font-size: 13.5px;
	overflow-wrap: anywhere;
}

.table-wrap {
	overflow-x: auto;
}

table {
	width: 100%;
	border-collapse: collapse;
}

th {
	padding: 10px 14px;
	border-bottom: 1px solid var(--border);
	color: var(--muted);
	font-size: 12.5px;
	font-weight: 600;
	letter-spacing: 0.03em;
	text-align: left;
	text-transform: uppercase;
	white-space: nowrap;
}

td {
	padding: 12px 14px;
	border-bottom: 1px solid var(--border);
	vertical-align: top;
}

tr:last-child td {
	border-bottom: 0;
}

tr.is-off td {
	color: var(--muted);
}

tr.is-off .chip,
tr.is-off .address {
	opacity: 0.6;
}

td.actions {
	text-align: right;
	white-space: nowrap;
}

td.tight,
th.tight {
	width: 1%;
	white-space: nowrap;
}

.address {
	font-family: var(--mono);
	font-size: 14px;
	font-weight: 600;
	overflow-wrap: anywhere;
}

.address .at {
	color: var(--muted);
	font-weight: 400;
}

.wrap-anywhere {
	overflow-wrap: anywhere;
}

.empty {
	padding: 44px 20px;
	text-align: center;
}

.empty h2 {
	font-size: 17px;
}

.empty p {
	margin: 6px auto 16px;
	max-width: 52ch;
	color: var(--muted);
}

.banner {
	padding: 12px 16px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface);
}

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

.banner-danger {
	border-color: var(--danger);
	background: var(--danger-soft);
	color: var(--danger);
}

.banner + * {
	margin-top: 16px;
}

/* ---------- rule tester ---------- */

.tester-form {
	display: grid;
	grid-template-columns: 1.2fr 1fr auto;
	gap: 12px;
	align-items: end;
}

.result {
	margin-top: 16px;
	padding: 14px 16px;
	border-radius: var(--radius-sm);
	background: var(--surface-2);
}

.result dl {
	display: grid;
	grid-template-columns: max-content 1fr;
	gap: 6px 16px;
	margin: 0;
}

.result dt {
	color: var(--muted);
}

.result dd {
	margin: 0;
	min-width: 0;
	overflow-wrap: anywhere;
}

/* ---------- activity ---------- */

.filters {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	padding: 14px;
	border-bottom: 1px solid var(--border);
}

.filters select {
	width: auto;
}

.filters input[type='search'] {
	flex: 1;
	min-width: 180px;
}

.flow {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.flow .from {
	display: flex;
	align-items: baseline;
	gap: 8px;
}

.flow .from .badge {
	flex: none;
}

.flow .to {
	color: var(--muted);
	font-size: 13.5px;
}

th.route {
	width: 38%;
}

.subject {
	font-weight: 550;
}

.detail {
	margin-top: 3px;
	color: var(--muted);
	font-size: 13px;
}

.more {
	padding: 14px;
	text-align: center;
	border-top: 1px solid var(--border);
}

/* ---------- setup ---------- */

.checklist {
	margin: 0;
	padding: 0;
	list-style: none;
}

.checklist li {
	display: flex;
	gap: 12px;
	padding: 14px 20px;
	border-bottom: 1px solid var(--border);
}

.checklist li:last-child {
	border-bottom: 0;
}

.mark {
	flex: none;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: var(--ok-soft);
	color: var(--ok);
	font-size: 13px;
	font-weight: 700;
	line-height: 22px;
	text-align: center;
}

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

.copy {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 8px;
	padding: 8px 10px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface-2);
}

.copy code {
	flex: 1;
	min-width: 0;
	overflow-wrap: anywhere;
}

.kv {
	display: grid;
	grid-template-columns: max-content 1fr;
	gap: 8px 20px;
	margin: 0;
}

.kv dt {
	color: var(--muted);
}

.kv dd {
	margin: 0;
	overflow-wrap: anywhere;
}

.stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: 12px;
}

.stat {
	padding: 14px 16px;
}

.stat-value {
	font-size: 24px;
	font-weight: 650;
	line-height: 1.2;
}

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

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

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

.login-card {
	width: 100%;
	max-width: 400px;
	padding: 32px 28px;
	text-align: center;
}

.login-card img {
	width: 44px;
	height: 44px;
}

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

.login-card p {
	margin: 6px 0 22px;
	color: var(--muted);
}

.login-card .banner {
	margin-bottom: 18px;
	text-align: left;
}

.loading {
	padding: 80px 20px;
	color: var(--muted);
	text-align: center;
}

/* ---------- dialog ---------- */

dialog {
	width: min(560px, calc(100vw - 24px));
	max-height: calc(100vh - 24px);
	padding: 0;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--shadow-lg);
}

dialog::backdrop {
	background: rgb(10 14 20 / 55%);
}

.dialog-head {
	padding: 18px 22px 0;
}

.dialog-head h2 {
	font-size: 18px;
}

.dialog-body {
	padding: 16px 22px 4px;
}

.dialog-foot {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	padding: 18px 22px;
}

/* ---------- toasts ---------- */

.toasts {
	position: fixed;
	right: 16px;
	bottom: 16px;
	z-index: 100;
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-width: min(380px, calc(100vw - 32px));
}

.toast {
	padding: 10px 14px;
	border-radius: var(--radius-sm);
	background: var(--text);
	color: var(--bg);
	box-shadow: var(--shadow-lg);
	font-weight: 500;
}

.toast-error {
	background: var(--danger);
	color: #fff;
}

@media (prefers-color-scheme: dark) {
	.toast-error {
		color: #1b0d0d;
	}
}

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

@media (max-width: 720px) {
	.topbar-inner {
		flex-wrap: wrap;
		gap: 0 12px;
		padding-top: 8px;
	}

	.nav {
		order: 3;
		flex-basis: 100%;
		margin-left: -12px;
	}

	.nav a {
		padding: 10px 12px 9px;
	}

	.account {
		margin-left: auto;
	}

	.account .who {
		display: none;
	}

	.page {
		padding: 20px 14px 48px;
	}

	.page-head {
		flex-direction: column;
	}

	.tester-form {
		grid-template-columns: 1fr;
	}

	/* Tables turn into stacked cards. */
	table.responsive thead {
		display: none;
	}

	table.responsive,
	table.responsive tbody,
	table.responsive tr,
	table.responsive td {
		display: block;
		width: 100%;
	}

	table.responsive tr {
		padding: 12px 14px;
		border-bottom: 1px solid var(--border);
	}

	table.responsive tr:last-child {
		border-bottom: 0;
	}

	table.responsive td {
		padding: 3px 0;
		border: 0;
	}

	table.responsive td.actions {
		padding-top: 8px;
		text-align: left;
	}

	table.responsive td[data-label]::before {
		content: attr(data-label);
		display: block;
		color: var(--muted);
		font-size: 12px;
		font-weight: 600;
		letter-spacing: 0.03em;
		text-transform: uppercase;
	}
}
