/* letterproxy admin console.
 *
 * The palette is SMTP's own semantics: a reply is accepted, held or refused,
 * and those three colours carry information rather than decoration. Monospace
 * is the data face — addresses, reply codes, queue identifiers and header
 * dumps all want a fixed advance — while prose and chrome are set in the
 * system sans. */

:root {
	--paper: #eef1f5;
	--surface: #ffffff;
	--surface-sunk: #f5f7fa;
	--ink: #16202b;
	--ink-soft: #55637a;
	--ink-faint: #8492a6;
	--rule: #ced6e0;
	--rule-soft: #e2e8ef;
	--accent: #1f4e79;
	--accent-soft: #e4edf6;
	--ok: #2f6f4f;
	--held: #9a6414;
	--refused: #a3282b;
	--ok-soft: #e3f0e8;
	--held-soft: #f7edda;
	--refused-soft: #f6e2e2;

	--sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

	--step--1: 0.8125rem;
	--step-0: 0.9375rem;
	--step-1: 1.125rem;
	--step-2: 1.35rem;
	--step-3: 1.625rem;

	--rail: 15rem;
	--radius: 2px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--paper: #131a22;
		--surface: #1a232e;
		--surface-sunk: #141d26;
		--ink: #e6ecf3;
		--ink-soft: #9fb0c4;
		--ink-faint: #6f8199;
		--rule: #2b3947;
		--rule-soft: #223040;
		--accent: #7fb2e5;
		--accent-soft: #1d2c3b;
		--ok: #62b98a;
		--held: #d3a04a;
		--refused: #e0797c;
		--ok-soft: #172a21;
		--held-soft: #2b2317;
		--refused-soft: #2c1a1c;
	}
}

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

body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font-family: var(--sans);
	font-size: var(--step-0);
	line-height: 1.55;
	-webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

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

/* ---- shell ---------------------------------------------------------- */

.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh; }

/* The rail belongs to the window rather than to the page. Left as an ordinary
 * grid item it stretches to the height of whatever is beside it, so on a long
 * message log the sign-out button at its foot ends up a screen or two below
 * the fold. align-self stops the grid stretching it, the sticky position keeps
 * it in view while the content scrolls past, and the overflow is for a window
 * too short for the navigation itself. */
.rail {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	gap: 2rem;
	padding: 1.5rem 1.25rem;
	background: var(--surface);
	border-right: 1px solid var(--rule);

	position: sticky;
	top: 0;
	align-self: start;
	height: 100vh;
	height: 100dvh;
	overflow-y: auto;
}

.brand {
	display: block;
	font-size: var(--step-1);
	font-weight: 620;
	letter-spacing: -0.015em;
	color: var(--ink);
	text-decoration: none;
	margin-bottom: 1.5rem;
}
.brand span { color: var(--ink-faint); font-weight: 400; }

.rail nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.rail nav a {
	display: block;
	padding: 0.4rem 0.6rem;
	border-radius: var(--radius);
	color: var(--ink-soft);
	text-decoration: none;
}
.rail nav a:hover { background: var(--surface-sunk); color: var(--ink); }
.rail nav a[aria-current="page"] {
	background: var(--accent-soft);
	color: var(--accent);
	font-weight: 560;
	box-shadow: inset 2px 0 0 var(--accent);
}

.rail-foot { font-size: var(--step--1); color: var(--ink-faint); display: grid; gap: 0.6rem; }
.rail-foot .who { font-family: var(--mono); word-break: break-all; }

.work { padding: 2rem 2.25rem 4rem; max-width: 78rem; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
h1 { font-size: var(--step-3); font-weight: 640; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: var(--step-1); font-weight: 600; letter-spacing: -0.01em; margin: 2rem 0 0.75rem; }
h2:first-child { margin-top: 0; }
.lede { color: var(--ink-soft); margin: 0.25rem 0 0; max-width: 62ch; }

/* ---- notices -------------------------------------------------------- */

.notice { padding: 0.6rem 0.85rem; border-radius: var(--radius); margin-bottom: 1.25rem; border: 1px solid transparent; }
.notice-ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.notice-bad { background: var(--refused-soft); border-color: var(--refused); color: var(--refused); }

/* ---- tables --------------------------------------------------------- */

.sheet { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
thead th {
	text-align: left;
	font-weight: 560;
	color: var(--ink-soft);
	padding: 0.6rem 0.85rem;
	border-bottom: 1px solid var(--rule);
	white-space: nowrap;
}
tbody td { padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-sunk); }
td.addr, td.mono, .mono { font-family: var(--mono); font-size: 0.95em; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.muted { color: var(--ink-faint); }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-soft); }
.empty p { margin: 0 0 1rem; }

/* ---- status ---------------------------------------------------------- */

.reply { font-family: var(--mono); font-size: var(--step--1); white-space: nowrap; }
.reply-ok { color: var(--ok); }
.reply-held { color: var(--held); }
.reply-refused { color: var(--refused); }

.tag {
	display: inline-block;
	padding: 0.05rem 0.4rem;
	border-radius: var(--radius);
	font-size: 0.8125rem;
	font-family: var(--mono);
	border: 1px solid currentColor;
}
.tag-off { color: var(--ink-faint); }

/* ---- flow strip (dashboard) ------------------------------------------ */

.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); }
.tally > div { padding: 1rem 1.1rem; border-right: 1px solid var(--rule-soft); }
.tally > div:last-child { border-right: 0; }
.tally dt { font-size: var(--step--1); color: var(--ink-soft); margin: 0 0 0.15rem; }
.tally dd { margin: 0; font-family: var(--mono); font-size: var(--step-3); font-variant-numeric: tabular-nums; line-height: 1.1; }
.tally .ok dd { color: var(--ok); }
.tally .held dd { color: var(--held); }
.tally .refused dd { color: var(--refused); }

/* ---- forms ----------------------------------------------------------- */

form.stack { display: grid; gap: 1.1rem; max-width: 42rem; }
/* align-content matters here. A field is a grid stretched to its row's height,
 * and a grid distributes leftover space across auto-sized rows by default — so
 * a field of two rows beside one of three (label, input, hint) would grow the
 * gap under its label and drop its input out of line with the one next to it.
 * Packing the rows to the start keeps every input on the same line whatever is
 * written underneath its neighbour. */
.field { display: grid; gap: 0.3rem; align-content: start; }
.field label { font-weight: 560; }
.hint { font-size: var(--step--1); color: var(--ink-soft); }

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
	font: inherit;
	font-family: var(--mono);
	padding: 0.45rem 0.55rem;
	background: var(--surface);
	color: var(--ink);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	width: 100%;
}
textarea { min-height: 6rem; resize: vertical; }
select { font-family: var(--sans); }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1rem; }
.check { display: flex; align-items: center; gap: 0.5rem; }
.check input { width: auto; }

button, .button {
	font: inherit;
	font-weight: 560;
	padding: 0.45rem 0.9rem;
	border-radius: var(--radius);
	border: 1px solid var(--accent);
	background: var(--accent);
	color: var(--surface);
	cursor: pointer;
	text-decoration: none;
	display: inline-block;
}
@media (prefers-color-scheme: dark) {
	button, .button { color: var(--paper); }
}
button:hover, .button:hover { filter: brightness(1.1); }
button.quiet, .button.quiet { background: transparent; color: var(--accent); }
button.danger { background: transparent; border-color: var(--refused); color: var(--refused); }
.actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { gap: 0.2rem; }
.filters input, .filters select { width: auto; min-width: 10rem; }

/* ---- detail ---------------------------------------------------------- */

.pairs { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.4rem 1.25rem; margin: 0; }
.pairs dt { color: var(--ink-soft); font-size: var(--step--1); }
.pairs dd { margin: 0; font-family: var(--mono); font-size: var(--step--1); word-break: break-word; }

pre.dump {
	font-family: var(--mono);
	font-size: var(--step--1);
	background: var(--surface-sunk);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	padding: 0.9rem 1rem;
	overflow-x: auto;
	white-space: pre-wrap;
	word-break: break-word;
	margin: 0;
}

.pager { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; font-size: var(--step--1); color: var(--ink-soft); }

/* ---- sign in --------------------------------------------------------- */

.gate { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }

/* The one flourish in the console, and it belongs to the pages a person sees
 * before they are anybody — the front page and the sign-in: the red-and-blue
 * border of an airmail envelope. */
.card {
	position: relative;
	width: min(26rem, 100%);
	background: var(--surface);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	padding: 2rem 1.75rem;
}
.card::before {
	content: "";
	position: absolute;
	inset: 0;
	padding: 6px;
	background: repeating-linear-gradient(
		45deg,
		#a3282b 0 10px,
		var(--surface) 10px 20px,
		#1f4e79 20px 30px,
		var(--surface) 30px 40px
	);
	-webkit-mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
	mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
	pointer-events: none;
}
.card h1 { font-size: var(--step-2); margin-bottom: 0.35rem; }
.card p { color: var(--ink-soft); margin: 0 0 1.25rem; }
.card form { display: grid; gap: 1rem; }

/* Six digits, spaced so they read as a code rather than a number. */
input.code {
	font-family: var(--mono);
	font-size: var(--step-3);
	letter-spacing: 0.4em;
	text-align: center;
	padding: 0.5rem;
}

/* ---- narrow ---------------------------------------------------------- */

@media (max-width: 60rem) {
	.shell { grid-template-columns: 1fr; }
	/* Along the top on a narrow screen, where a full-height column would be
	   the whole screen. It scrolls away with the page as it did before. */
	.rail {
		flex-direction: row;
		align-items: center;
		border-right: 0;
		border-bottom: 1px solid var(--rule);
		padding: 0.75rem 1rem;
		position: static;
		height: auto;
		overflow: visible;
	}
	.brand { margin-bottom: 0; }
	.rail nav ul { grid-auto-flow: column; gap: 0.25rem; overflow-x: auto; }
	.rail-foot { display: none; }
	.work { padding: 1.25rem 1rem 3rem; }
}

@media (prefers-reduced-motion: reduce) {
	* { transition: none !important; animation: none !important; }
}

/* ---- option grid ------------------------------------------------------ */

.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; margin-top: 0.5rem; }

.option {
	display: block;
	padding: 1.25rem 1.35rem;
	background: var(--surface);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	color: inherit;
	text-decoration: none;
}
.option:hover { border-color: var(--accent); }
.option h3 { margin: 0 0 0.3rem; font-size: var(--step-1); font-weight: 600; letter-spacing: -0.01em; color: var(--accent); }
.option p { margin: 0; color: var(--ink-soft); font-size: var(--step--1); }
.option .count { margin-top: 0.75rem; font-family: var(--mono); font-size: var(--step--1); color: var(--ink-faint); }

/* ---- modal ------------------------------------------------------------ */

/* Opened by swapping markup into #modal, and closed by swapping it back out,
 * so there is no state here that JavaScript has to keep. Without htmx the same
 * links are ordinary pages, and the console still works. */
.backdrop {
	position: fixed;
	inset: 0;
	display: grid;
	place-items: center;
	padding: 1.5rem;
	background: rgb(9 14 20 / 55%);
	z-index: 10;
}

.modal {
	width: min(32rem, 100%);
	max-height: 85vh;
	overflow-y: auto;
	background: var(--surface);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	padding: 1.5rem 1.6rem;
}
.modal h2 { margin: 0 0 0.35rem; font-size: var(--step-2); }
.modal > p { color: var(--ink-soft); margin: 0 0 1.25rem; }
.modal form.stack { max-width: none; }

/* htmx is asked not to inject its own indicator styles, so the one here is the
 * one that applies: a request in flight dims the form it came from. */
.htmx-request.modal, .htmx-request .modal { opacity: 0.6; }

/* ---- getting started -------------------------------------------------- */

/* Only ever shown on an installation nothing has come through yet, which is
 * why it can afford the room. A step that is done keeps its place — the list
 * is the path a message takes, not a queue of chores. */
.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 1px; }

.steps li {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding: 1.1rem 1.35rem;
	background: var(--surface);
	border: 1px solid var(--rule);
}
.steps li + li { border-top: 0; }
.steps li::before {
	counter-increment: step;
	content: counter(step);
	font-family: var(--mono);
	font-size: var(--step--1);
	color: var(--ink-faint);
	min-width: 1.25rem;
}
.steps li > span:first-of-type { flex: 1; }
.steps li.done { color: var(--ink-soft); }
.steps li.done::before { content: "✓"; color: var(--ok); }

/* ---- breadcrumbs ------------------------------------------------------ */

/* Where a page sits, rather than one step back from it: a trail says what the
 * section is as well as how to leave it, and it reads the same however the
 * page was arrived at. */
.crumbs { margin-bottom: 0.9rem; font-size: var(--step--1); }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; }
.crumbs li + li::before { content: "/"; color: var(--ink-faint); margin: 0 0.45rem; }
.crumbs li[aria-current] { color: var(--ink-soft); }
