/* Feedback admin — small, dependency-free stylesheet. Mobile first: the base rules are for a phone
   held in one hand (programming NFC tags on site); wider screens only add columns. Light and dark
   via prefers-color-scheme. */
:root {
	--bg: #f6f7f9;
	--surface: #ffffff;
	--text: #1c2024;
	--muted: #60656c;
	--border: #dfe2e6;
	--primary: #2357d8;
	--primary-text: #ffffff;
	--danger: #c4321f;
	--on-bg: #e3f4e8;
	--on-text: #1d6b37;
	--off-bg: #eef0f2;
	--off-text: #555b62;
	--ok-bg: #e9f6ee;
	--ok-border: #9fd3b0;
	--err-bg: #fdeeec;
	--err-border: #f0b0a6;
	--radius: 10px;
	--shadow: 0 1px 2px rgba(16, 24, 40, .06);
	--tap: 44px; /* minimum touch target */
	--gutter: 16px;
	color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #121417;
		--surface: #1b1e22;
		--text: #e7e9ec;
		--muted: #9aa0a8;
		--border: #2e3238;
		--primary: #5b8cff;
		--primary-text: #0b1020;
		--danger: #ff7a66;
		--on-bg: #183524;
		--on-text: #7ee2a2;
		--off-bg: #262a30;
		--off-text: #b3b8bf;
		--ok-bg: #16301f;
		--ok-border: #2e6b43;
		--err-bg: #3a1a16;
		--err-border: #7a3328;
		--shadow: none;
	}
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	/* 16px: phones zoom into any input smaller than this. */
	font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	overflow-wrap: anywhere;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }

/* ---- Header: brand + sign out on the first row, a swipeable nav on the second ---------------- */
.topbar {
	position: sticky;
	top: 0;
	z-index: 10;
	display: grid;
	grid-template-columns: 1fr auto;
	align-items: center;
	gap: 0 .75rem;
	padding: .5rem var(--gutter) 0;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; color: var(--text); padding: .4rem 0; }
.topbar nav {
	grid-column: 1 / -1;
	display: flex;
	gap: .25rem;
	overflow-x: auto;
	scrollbar-width: none;
	margin: 0 calc(-1 * var(--gutter));
	padding: 0 var(--gutter);
	-webkit-overflow-scrolling: touch;
}
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
	flex: 0 0 auto;
	color: var(--muted);
	padding: .6rem .6rem;
	min-height: var(--tap);
	display: inline-flex;
	align-items: center;
	border-bottom: 2px solid transparent;
	white-space: nowrap;
}
.topbar nav a.active { color: var(--text); border-bottom-color: var(--primary); }
.topbar nav a:hover { text-decoration: none; color: var(--text); }
.signout { display: flex; align-items: center; gap: .75rem; margin: 0; }
.signout .email { display: none; }

/* ---- Layout -------------------------------------------------------------------------------- */
.page { max-width: 1100px; margin: 0 auto; padding: 1rem var(--gutter) 4rem; }
.page-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .9rem; }
.page-head form { width: 100%; }
.page-head > .btn { width: 100%; }

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 1rem;
	box-shadow: var(--shadow);
	margin-bottom: 1rem;
}
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; margin-bottom: 1rem; }
.grid-2 > .card, .stack-lg > .card { margin-bottom: 0; }
.stack, .stack-lg { display: flex; flex-direction: column; gap: .75rem; }
.stack-lg { gap: 1rem; }
/* Input + button pairs stack on a phone, sit side by side on wider screens. */
.row { display: flex; flex-direction: column; gap: .5rem; }
.row input, .row select { width: 100%; }
.spaced { margin-top: .75rem; }

/* ---- Switches --------------------------------------------------------------------------------
   An on/off setting is a switch: a form's submit button with role="switch", so one press changes it
   and it works without a script. aria-checked says which way it is; the words beside it say so too,
   so the state never rests on colour alone. */
.switch-row { display: flex; align-items: center; gap: .75rem; min-height: var(--tap); }
.switch {
	position: relative;
	flex: none;
	width: 52px;
	height: 30px;
	padding: 0;
	border: 1px solid var(--border);
	border-radius: 15px;
	background: var(--off-bg);
	cursor: pointer;
	transition: background-color .15s;
}
.switch::before { content: ""; position: absolute; inset: -8px 0; } /* the press area reaches --tap */
.switch::after {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: var(--off-text);
	transition: left .15s, background-color .15s;
}
.switch[aria-checked="true"] { background: var(--on-text); border-color: var(--on-text); }
.switch[aria-checked="true"]::after { left: 25px; background: var(--surface); }
.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.switch-text { font-weight: 550; }
@media (prefers-reduced-motion: reduce) { .switch, .switch::after { transition: none; } }

/* ---- Login / passkey / error ---------------------------------------------------------------- */
body.centered { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: var(--gutter); }
.card.login { width: 100%; max-width: 400px; text-align: center; }
.card.login h1 { margin-bottom: .5rem; }

/* ---- Forms ---------------------------------------------------------------------------------- */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; font-size: .9rem; }
label .muted { font-weight: 400; }
input, select, textarea {
	font: inherit;
	font-size: 16px;
	color: var(--text);
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: .6rem .75rem;
	min-height: var(--tap);
	width: 100%;
	min-width: 0;
}
textarea { min-height: 6rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
details summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-bottom: .5rem; min-height: var(--tap); display: flex; align-items: center; }

.filters { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .4rem;
	font: inherit;
	font-weight: 550;
	padding: .6rem 1rem;
	min-height: var(--tap);
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
	white-space: nowrap;
	touch-action: manipulation;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
/* Small in type, not in reach: on a phone it keeps the full touch height (shrinks from 860px up). */
.btn-small { padding: .35rem .7rem; font-size: .875rem; min-height: var(--tap); }

/* Authenticator set-up: numbered steps, the QR code on white whatever the theme, a wide code box. */
.steps { text-align: left; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .6rem; }
.qr { background: #ffffff; padding: 8px; border-radius: 8px; width: min(240px, 100%); margin: .6rem auto; }
.qr svg { display: block; width: 100%; height: auto; }
.code-input { font-size: 1.4rem; letter-spacing: .2em; text-align: center; }
.or { color: var(--muted); font-size: .875rem; margin: 1rem 0 .6rem; }

/* A list that stays one line per item on a phone: the thing itself, a quiet second line, and its
   buttons on the right (the quick feedback page's questions). */
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.item-list li:last-child { border-bottom: 0; }
.item-list .item-n { flex: 0 0 1.4rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.item-list .item-main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.item-list .item-main strong { display: block; }
.item-list .item-actions { flex: 0 0 auto; display: flex; gap: .4rem; }
.item-list .item-actions form { display: inline; }
.btn-block { width: 100%; margin-top: 1rem; }
/* The main action of a stacked form spans the width, where a thumb lands. */
.stack > .btn, .stack > form > .btn, .row > .btn { width: 100%; }

/* ---- Tables: cards on a phone, rows on a wide screen ---------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
.card .table-wrap { border: 0; margin: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.empty { text-align: center; padding: 2rem; }
td.actions { text-align: right; }
td.actions form { display: inline; }

/* admin.js marks tables "cards" and copies each column header into data-label; below 760px every
   row becomes a card with "label  value" lines, so nothing scrolls sideways under a thumb. */
@media (max-width: 759px) {
	table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
	table.cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
	table.cards tr { padding: .5rem .9rem; border-bottom: 1px solid var(--border); }
	table.cards tbody tr:last-child { border-bottom: 0; }
	table.cards td {
		display: flex;
		justify-content: space-between;
		align-items: baseline;
		gap: 1rem;
		padding: .3rem 0;
		border: 0;
		text-align: right;
	}
	table.cards td::before {
		content: attr(data-label);
		flex: 0 0 38%;
		text-align: left;
		font-size: .78rem;
		text-transform: uppercase;
		letter-spacing: .03em;
		color: var(--muted);
		font-weight: 600;
	}
	table.cards td:not([data-label])::before, table.cards td[data-label=""]::before { content: none; }
	table.cards td.truncate { max-width: none; white-space: normal; overflow: visible; text-overflow: clip; }
	table.cards td.empty { display: block; text-align: center; }
	table.cards td.actions { justify-content: flex-end; }
	table.cards td.nowrap { white-space: normal; }
}

.pager { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.pager .btn { flex: 1; }

/* ---- Badges, flashes, stats ------------------------------------------------------------------- */
.badge { display: inline-block; white-space: nowrap; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; }
.badge-on { background: var(--on-bg); color: var(--on-text); }
.badge-off { background: var(--off-bg); color: var(--off-text); }

.flash { padding: .75rem .9rem; border-radius: 8px; border: 1px solid; margin: 0 0 1rem; }
.flash-success { background: var(--ok-bg); border-color: var(--ok-border); }
.flash-error { background: var(--err-bg); border-color: var(--err-border); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem 1rem; margin: 0; }
.stats dt { color: var(--muted); font-size: .8rem; }
.stats dd { margin: 0; font-size: 1.35rem; font-weight: 650; }

/* ---- NFC tag URL card ------------------------------------------------------------------------- */
.url-card { display: flex; flex-direction: column; gap: .6rem; align-items: stretch; }
.url-card p { margin: .4rem 0 0; }
.copy-row { display: flex; flex-direction: column; gap: .5rem; width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .6rem; }
.copy-row code { font-size: .9rem; overflow-wrap: anywhere; }
.copy-row .btn { width: 100%; }

/* ---- Businesses, admins ----------------------------------------------------------------------- */
.badge-role { background: var(--off-bg); color: var(--primary); }
.badge-retired { background: var(--err-bg); color: var(--danger); }
h2 .badge, h2 code { margin-left: .4rem; vertical-align: middle; }
.card.stats { padding: 1rem; }
table.matrix td.cell, table.matrix th:not(:first-child) { text-align: center; width: 3rem; }
table.matrix input[type="checkbox"] { width: 1.1rem; height: 1.1rem; }
.check-list { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; max-height: 14rem; overflow-y: auto; margin: 0; }
.check-list legend { font-weight: 550; font-size: .9rem; padding: 0 .25rem; }
label.check { flex-direction: row; align-items: center; gap: .6rem; font-weight: 400; padding: .35rem 0; min-height: var(--tap); }
label.check input { width: 1.25rem; height: 1.25rem; min-height: 0; }
ul.plain { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: .4rem; }

/* ---- Security & recovery ---------------------------------------------------------------------- */
dl.details { display: grid; grid-template-columns: 1fr; gap: .15rem 1.25rem; margin: 0 0 1rem; }
dl.details dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; margin-top: .6rem; }
dl.details dd { margin: 0; overflow-wrap: anywhere; }
.checklist label.check { align-items: flex-start; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.checklist label.check:last-child { border-bottom: 0; }
.checklist label.check input { margin-top: .2rem; }
.checklist { max-height: none; }
[hidden] { display: none !important; }

/* ---- Wider screens: side-by-side rows and forms --------------------------------------------- */
@media (min-width: 600px) {
	h1 { font-size: 1.5rem; }
	.row { flex-direction: row; align-items: center; }
	.row.wrap { flex-wrap: wrap; }
	.row input { flex: 1; width: auto; }
	.row > .btn { width: auto; }
	.filters { flex-direction: row; flex-wrap: wrap; }
	.filters input { flex: 1 1 240px; width: auto; }
	.filters select { width: auto; }
	.page-head form, .page-head > .btn { width: auto; }
	.page-head form { margin-left: auto; }
	.stack > .btn, .stack > form > .btn { width: auto; align-self: flex-start; }
	.btn-block { width: 100%; }
	.copy-row { flex-direction: row; align-items: center; padding: .35rem .35rem .35rem .65rem; }
	.copy-row code { flex: 1; font-size: .85rem; }
	.copy-row .btn { width: auto; }
	.url-card { align-items: flex-start; }
	.stats { display: flex; gap: 2rem; flex-wrap: wrap; }
	dl.details { grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; }
	dl.details dt { font-size: inherit; text-transform: none; letter-spacing: 0; margin-top: 0; }
	.pager { justify-content: center; }
	.pager .btn { flex: 0 0 auto; }
	.card { padding: 1.25rem; }
}

@media (min-width: 860px) {
	.topbar {
		display: flex;
		gap: 1.5rem;
		padding: .5rem 1.25rem;
		position: static;
	}
	.topbar nav { margin: 0; padding: 0; overflow: visible; gap: 1rem; }
	.topbar nav a { padding: .4rem 0; min-height: 0; }
	.signout { margin-left: auto; }
	.signout .email { display: inline; }
	.page { padding: 1.5rem 1rem 3rem; }
	.grid-2 { grid-template-columns: 1fr 1fr; }
	.card.narrow { max-width: 480px; }
	.btn-small { min-height: 36px; }
}
