/* =========================================================================
   Tokens
   ========================================================================= */
:root {
	color-scheme: light;
	--bg: #f4f6f9;
	--surface: #ffffff;
	--surface-2: #f2f5f9;
	--surface-3: #e7ecf2;
	--border: #dfe4eb;
	--border-strong: #c7cfda;
	--text: #121a26;
	--text-2: #465264;
	--muted: #6b7686;
	--primary: #1f5fb8;
	--primary-hover: #184f95;
	--primary-soft: #e8f0fb;
	--primary-ink: #1a55a6;
	--on-primary: #ffffff;
	--focus: #2a78d6;

	/* Charts: one series + recessive chrome. */
	--series-1: #2a78d6;
	--series-track: #dbe7f8;
	--grid: #e8ebf0;
	--axis: #c3c9d2;

	/* Status: always paired with an icon and a label. */
	--good: #0ca30c;
	--good-ink: #0b6b1f;
	--good-soft: #e7f5e9;
	--critical: #d03b3b;
	--critical-ink: #b42323;
	--critical-soft: #fcecec;
	--warning: #fab219;
	--warning-ink: #8a5a00;
	--warning-soft: #fdf4de;

	--radius: 12px;
	--radius-sm: 8px;
	--shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
	--shadow-lg: 0 10px 30px rgba(16, 24, 40, .14);
	--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--container: 1120px;
	--gutter: 20px;
}

@media (prefers-color-scheme: dark) {
	:root {
		color-scheme: dark;
		--bg: #0f1318;
		--surface: #171c23;
		--surface-2: #1d232c;
		--surface-3: #262e39;
		--border: #2a323d;
		--border-strong: #3a4452;
		--text: #e9eef4;
		--text-2: #b6c0cc;
		--muted: #8b96a3;
		--primary: #2f6fc7;
		--primary-hover: #3a7cd6;
		--primary-soft: #1b2a40;
		--primary-ink: #86b6ef;
		--on-primary: #ffffff;
		--focus: #5598e7;
		--series-1: #3987e5;
		--series-track: #1f3350;
		--grid: #262d37;
		--axis: #3a4350;
		--good-ink: #4cc75a;
		--good-soft: #15291a;
		--critical-ink: #f07a7a;
		--critical-soft: #331b1d;
		--warning-ink: #f3c15a;
		--warning-soft: #33290f;
		--shadow: 0 1px 2px rgba(0, 0, 0, .3);
		--shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
	}
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: var(--font);
	font-size: 16px;
	line-height: 1.55;
	display: flex;
	flex-direction: column;
	min-height: 100vh;
}

img, svg, video { max-width: 100%; height: auto; }

a { color: var(--primary-ink); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }

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

.screen-reader-text {
	position: absolute !important;
	width: 1px; height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

.skip-link {
	position: absolute;
	left: 12px; top: -48px;
	z-index: 100;
	padding: 8px 14px;
	background: var(--primary);
	color: var(--on-primary);
	border-radius: var(--radius-sm);
}
.skip-link:focus { top: 12px; }

.container {
	width: 100%;
	max-width: var(--container);
	margin: 0 auto;
	padding: 0 var(--gutter);
}

@media (max-width: 600px) {
	:root { --gutter: 16px; }
	h1 { font-size: 1.45rem; }
}

/* =========================================================================
   Header & footer
   ========================================================================= */
.site-header {
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	position: sticky;
	top: 0;
	z-index: 50;
}
.admin-bar .site-header { top: 32px; }
@media (max-width: 782px) { .admin-bar .site-header { top: 0; } }

.header-inner {
	display: flex;
	align-items: center;
	gap: 24px;
	min-height: 64px;
}

.brand {
	display: flex;
	align-items: center;
	gap: 10px;
	color: var(--text);
	text-decoration: none;
	font-weight: 700;
	font-size: 1.05rem;
	flex-shrink: 0;
}
.brand:hover { color: var(--text); }
.brand-mark {
	display: grid;
	place-items: center;
	width: 34px; height: 34px;
	border-radius: 9px;
	background: var(--primary);
	color: var(--on-primary);
}
.brand img { max-height: 40px; width: auto; }

.site-nav {
	display: flex;
	align-items: center;
	gap: 16px;
	flex: 1;
}

.nav-list {
	display: flex;
	gap: 4px;
	list-style: none;
	margin: 0;
	padding: 0;
	flex: 1;
}
.nav-list a {
	display: block;
	padding: 8px 12px;
	border-radius: var(--radius-sm);
	color: var(--text-2);
	text-decoration: none;
	font-weight: 550;
	font-size: .95rem;
}
.nav-list a:hover { background: var(--surface-2); color: var(--text); }
.nav-list a[aria-current="page"],
.nav-list .current-menu-item > a {
	background: var(--primary-soft);
	color: var(--primary-ink);
}

.nav-user { display: flex; align-items: center; gap: 8px; }
.user-chip {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 4px 10px 4px 4px;
	border-radius: 999px;
	color: var(--text);
	text-decoration: none;
	font-size: .92rem;
	font-weight: 550;
}
.user-chip:hover { background: var(--surface-2); color: var(--text); }
.avatar {
	display: grid;
	place-items: center;
	width: 30px; height: 30px;
	border-radius: 50%;
	background: var(--primary-soft);
	color: var(--primary-ink);
	font-size: .8rem;
	font-weight: 700;
}

.nav-toggle {
	display: none;
	margin-left: auto;
	background: none;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text);
	width: 40px; height: 40px;
	cursor: pointer;
}

@media (max-width: 860px) {
	.nav-toggle { display: grid; place-items: center; }
	.site-nav {
		display: none;
		position: absolute;
		left: 0; right: 0; top: 100%;
		flex-direction: column;
		align-items: stretch;
		gap: 8px;
		padding: 12px var(--gutter) 16px;
		background: var(--surface);
		border-bottom: 1px solid var(--border);
		box-shadow: var(--shadow-lg);
	}
	.site-nav.is-open { display: flex; }
	.nav-list { flex-direction: column; }
	.nav-user { border-top: 1px solid var(--border); padding-top: 12px; justify-content: space-between; }
}

.site-main { flex: 1; padding: 32px 0 56px; }

.site-footer {
	border-top: 1px solid var(--border);
	background: var(--surface);
	color: var(--muted);
	font-size: .88rem;
}
.footer-inner {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 12px;
	padding-top: 20px;
	padding-bottom: 20px;
}
.footer-menu { display: flex; flex-wrap: wrap; gap: 16px; list-style: none; margin: 0; padding: 0; }
.footer-menu a { color: var(--muted); }

/* =========================================================================
   Content (library: pages & posts)
   ========================================================================= */
.page-head { margin-bottom: 24px; }
.page-head p { color: var(--text-2); margin: 0; }

.entry {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 32px clamp(20px, 5vw, 48px);
	box-shadow: var(--shadow);
}
.entry-meta { color: var(--muted); font-size: .9rem; margin-bottom: 16px; }
.entry-content { max-width: 74ch; font-size: 1.03rem; }
.entry-content > * + * { margin-top: 1em; }
.entry-content h2, .entry-content h3 { margin-top: 1.6em; }
.entry-content blockquote {
	margin: 1.4em 0;
	padding: 12px 20px;
	border-left: 4px solid var(--primary);
	background: var(--surface-2);
	border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.entry-content table { width: 100%; border-collapse: collapse; }
.entry-content th, .entry-content td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.entry-content img { border-radius: var(--radius-sm); }

.post-list { display: grid; gap: 16px; }
.post-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 20px 24px;
}
.post-card h2 { font-size: 1.15rem; margin-bottom: 6px; }
.post-card h2 a { color: var(--text); text-decoration: none; }
.post-card h2 a:hover { color: var(--primary-ink); }
.post-card p { color: var(--text-2); margin: 0; }

.pagination, .post-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 24px; }
.pagination .page-numbers {
	padding: 6px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	text-decoration: none;
}
.pagination .current { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.search-form { display: flex; gap: 8px; max-width: 480px; }

/* =========================================================================
   Library
   ========================================================================= */
.breadcrumbs ol {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	list-style: none;
	margin: 0 0 16px;
	padding: 0;
	font-size: .9rem;
	color: var(--muted);
}
.breadcrumbs li + li::before { content: "›"; margin-right: 4px; color: var(--border-strong); }
.breadcrumbs a { color: var(--text-2); text-decoration: none; }
.breadcrumbs a:hover { color: var(--primary-ink); text-decoration: underline; }
.breadcrumbs [aria-current] { color: var(--text); }

.lib-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.lib-head .search-form { width: min(420px, 100%); }
.lib-section { margin-top: 32px; }
.lib-section h2 { font-size: 1.15rem; margin-bottom: 14px; }

.lib-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.lib-cat {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 18px 20px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}
.lib-cat h3 { margin: 0; font-size: 1.02rem; }
.lib-cat h3 a { color: var(--text); text-decoration: none; }
.lib-cat h3 a:hover { color: var(--primary-ink); }
.lib-cat p { margin: 0; color: var(--text-2); font-size: .92rem; }
.lib-subcats { display: flex; flex-wrap: wrap; gap: 4px 12px; list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.lib-count { margin-top: auto; color: var(--muted); font-size: .85rem; }

.lib-list { list-style: none; margin: 0; padding: 4px 20px; }
.lib-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.lib-item:last-child { border-bottom: 0; }
.lib-item-title { font-weight: 600; color: var(--text); text-decoration: none; }
.lib-item-title:hover { color: var(--primary-ink); text-decoration: underline; }
.lib-item p { margin: 4px 0 0; color: var(--text-2); font-size: .93rem; }
.lib-item-meta { display: inline-flex; align-items: center; gap: 5px; margin-top: 6px; color: var(--muted); font-size: .84rem; }

.chip-links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip-links .chip { text-decoration: none; }
.chip-links .chip:hover { border-color: var(--primary); color: var(--primary-ink); }
.entry-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.entry-meta .chip-links { margin: 0; }
.entry-thumb { margin: 0 0 20px; }
.entry-thumb img { border-radius: var(--radius-sm); }

/* =========================================================================
   UI kit
   ========================================================================= */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 40px;
	padding: 8px 16px;
	border: 1px solid transparent;
	border-radius: var(--radius-sm);
	font: inherit;
	font-weight: 600;
	font-size: .95rem;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
	transition: background-color .15s, border-color .15s, color .15s;
	white-space: nowrap;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--critical); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--critical-ink); color: #fff; }
.btn-sm { min-height: 32px; padding: 5px 12px; font-size: .88rem; }
.btn-lg { min-height: 48px; padding: 12px 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn-link {
	background: none; border: 0; padding: 0;
	color: var(--primary-ink);
	font: inherit;
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 2px;
}
.btn-link:disabled { color: var(--muted); cursor: default; text-decoration: none; }

.input, .select, .search-field {
	width: 100%;
	min-height: 42px;
	padding: 9px 12px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font: inherit;
}
.input:focus, .select:focus, .search-field:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.select { width: auto; padding-right: 32px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label, .field-label { font-weight: 600; font-size: .92rem; }
.field-hint { color: var(--muted); font-size: .86rem; }
.field-error { color: var(--critical-ink); font-size: .9rem; }

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 24px;
}
.card + .card, .card + .section, .section + .section { margin-top: 20px; }
.card-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 16px;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-sub { color: var(--muted); font-size: .9rem; margin: 2px 0 0; }

.stack > * + * { margin-top: 20px; }
.grid-2 > *, .tiles > *, .test-grid > * { margin-top: 0 !important; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.row-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }

.view-head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 24px;
}
.view-head h1 { margin: 0; }
.view-head p { margin: 4px 0 0; color: var(--text-2); }

.back-link {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	margin-bottom: 12px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--text-2);
	font: inherit;
	font-size: .92rem;
	text-decoration: none;
	cursor: pointer;
}
.back-link:hover { color: var(--text); }

/* Badges: status meaning always = icon + label. */
.badge {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 2px 9px;
	border-radius: 999px;
	font-size: .8rem;
	font-weight: 650;
	line-height: 1.6;
	background: var(--surface-3);
	color: var(--text-2);
	white-space: nowrap;
}
.badge svg { width: 14px; height: 14px; flex-shrink: 0; }
.badge-good { background: var(--good-soft); color: var(--good-ink); }
.badge-critical { background: var(--critical-soft); color: var(--critical-ink); }
.badge-warning { background: var(--warning-soft); color: var(--warning-ink); }
.badge-info { background: var(--primary-soft); color: var(--primary-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 12px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--surface);
	color: var(--text-2);
	font: inherit;
	font-size: .88rem;
	cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: transparent; color: var(--primary-ink); font-weight: 600; }
.chip .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.meta-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--text-2);
	font-size: .9rem;
}
.meta-chip svg { width: 16px; height: 16px; color: var(--muted); }

.alert {
	display: flex;
	gap: 12px;
	align-items: flex-start;
	padding: 14px 16px;
	border-radius: var(--radius-sm);
	background: var(--primary-soft);
	color: var(--text);
	border: 1px solid transparent;
}
.alert svg { flex-shrink: 0; width: 20px; height: 20px; margin-top: 1px; color: var(--primary-ink); }
.alert-error { background: var(--critical-soft); }
.alert-error svg { color: var(--critical-ink); }
.alert-warning { background: var(--warning-soft); }
.alert-warning svg { color: var(--warning-ink); }
.alert-good { background: var(--good-soft); }
.alert-good svg { color: var(--good-ink); }
.alert p { margin: 0; }
.alert .grow { flex: 1; }

.empty {
	text-align: center;
	padding: 48px 20px;
	color: var(--text-2);
}
.empty svg { width: 40px; height: 40px; color: var(--muted); margin-bottom: 8px; }

.loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 64px 0;
	color: var(--muted);
}
.spinner {
	width: 20px; height: 20px;
	border: 2px solid var(--border-strong);
	border-top-color: var(--primary);
	border-radius: 50%;
	animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
.is-refreshing { opacity: .55; transition: opacity .15s; pointer-events: none; }

/* Tables */
/* position: relative keeps absolutely positioned children (screen-reader labels) inside the scroll box. */
.table-wrap { position: relative; overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th {
	text-align: left;
	font-weight: 600;
	font-size: .82rem;
	color: var(--muted);
	padding: 8px 12px;
	border-bottom: 1px solid var(--border);
	white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.table tbody tr.is-link { cursor: pointer; }
.table tbody tr.is-link:hover td { background: var(--surface-2); }
.th-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.th-sort[aria-sort] { color: var(--text); }

/* Meter: fill carries the value, track = lighter step of the same ramp. */
.meter {
	position: relative;
	height: 8px;
	border-radius: 4px;
	background: var(--series-track);
	min-width: 60px;
	overflow: hidden;
}
.meter > span {
	position: absolute;
	inset: 0 auto 0 0;
	border-radius: 0 4px 4px 0;
	background: var(--series-1);
}
.meter-mark {
	position: absolute;
	top: -3px; bottom: -3px;
	width: 2px;
	background: var(--text-2);
}

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.tile {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 16px 18px;
	box-shadow: var(--shadow);
}
.tile-label { color: var(--muted); font-size: .86rem; }
.tile-value { font-size: 1.7rem; font-weight: 650; margin-top: 2px; line-height: 1.2; }
.tile-sub { color: var(--text-2); font-size: .85rem; margin-top: 2px; }

/* Tabs */
.tabs {
	display: flex;
	gap: 4px;
	border-bottom: 1px solid var(--border);
	margin-bottom: 20px;
	overflow-x: auto;
}
.tabs a {
	padding: 10px 14px;
	color: var(--text-2);
	text-decoration: none;
	font-weight: 600;
	border-bottom: 2px solid transparent;
	margin-bottom: -1px;
	white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--primary-ink); border-bottom-color: var(--primary); }

/* Filter bar: one row above everything it scopes. */
.filters {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 12px;
	margin-bottom: 20px;
}
.filters .field { margin: 0; }
.filters .field label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.filters .input { width: auto; min-width: 150px; }
.filters .select { max-width: min(340px, 100%); }

/* Dialog & toast */
.dialog {
	border: 0;
	padding: 0;
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--text);
	box-shadow: var(--shadow-lg);
	width: min(460px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(10, 15, 25, .45); }
.dialog-body { padding: 24px; }
.dialog-body h2 { font-size: 1.2rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 24px 20px; flex-wrap: wrap; }

.toasts {
	position: fixed;
	right: 16px; bottom: 16px;
	z-index: 200;
	display: grid;
	gap: 8px;
	max-width: min(380px, calc(100vw - 32px));
}
.toast {
	padding: 12px 16px;
	border-radius: var(--radius-sm);
	background: var(--text);
	color: var(--surface);
	box-shadow: var(--shadow-lg);
	font-size: .93rem;
}
.toast-error { background: var(--critical-ink); color: #fff; }

/* =========================================================================
   Login
   ========================================================================= */
.auth {
	max-width: 440px;
	margin: 24px auto 0;
}
.auth .card { padding: 32px; }
.auth-icon {
	display: grid;
	place-items: center;
	width: 48px; height: 48px;
	border-radius: 12px;
	background: var(--primary-soft);
	color: var(--primary-ink);
	margin-bottom: 16px;
}
.auth h1 { font-size: 1.45rem; }
.auth .lead { color: var(--text-2); margin-bottom: 24px; }
.code-input {
	font-size: 1.6rem;
	letter-spacing: .45em;
	text-align: center;
	font-variant-numeric: tabular-nums;
	padding-left: calc(12px + .45em);
}
.auth-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; font-size: .92rem; }

/* =========================================================================
   Tests list
   ========================================================================= */
.test-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
@media (max-width: 400px) { .test-grid { grid-template-columns: 1fr; } }
.test-card { display: flex; flex-direction: column; gap: 14px; }
.test-card h2 { font-size: 1.15rem; margin: 0; }
.test-desc { color: var(--text-2); font-size: .94rem; }
.test-desc p:last-child { margin-bottom: 0; }
.test-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.test-result {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 6px 12px;
	align-items: center;
	padding: 12px 14px;
	background: var(--surface-2);
	border-radius: var(--radius-sm);
	font-size: .9rem;
}
.test-result .meter { grid-column: 1 / -1; }
.test-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

/* =========================================================================
   Player
   ========================================================================= */
.player-bar {
	position: sticky;
	top: 64px;
	z-index: 20;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px 20px;
	padding: 12px 16px;
	margin-bottom: 20px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}
.admin-bar .player-bar { top: 96px; }
.player-title { font-weight: 650; flex: 1; min-width: 180px; }
.player-title small { display: block; font-weight: 500; color: var(--muted); font-size: .84rem; }
.save-state { color: var(--muted); font-size: .86rem; display: inline-flex; align-items: center; gap: 6px; }
.player-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 600px) {
	.player-actions { width: 100%; }
	.player-actions .btn { flex: 1; }
}
.save-state.is-error { color: var(--critical-ink); }
.timer {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 12px;
	border-radius: var(--radius-sm);
	background: var(--surface-2);
	font-weight: 650;
	font-variant-numeric: tabular-nums;
}
.timer svg { width: 18px; height: 18px; color: var(--muted); }
.timer.is-low { background: var(--critical-soft); color: var(--critical-ink); }
.timer.is-low svg { color: var(--critical-ink); }

.player { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
@media (max-width: 1000px) {
	.player { grid-template-columns: 1fr; }
	.player-bar { top: 64px; }
}

.case-panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-left: 4px solid var(--primary);
	border-radius: var(--radius);
	margin-bottom: 16px;
}
.case-panel summary {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 14px 18px;
	cursor: pointer;
	font-weight: 650;
	list-style: none;
}
.case-panel summary::-webkit-details-marker { display: none; }
.case-panel summary .chev { margin-left: auto; transition: transform .15s; color: var(--muted); }
.case-panel[open] summary .chev { transform: rotate(180deg); }
.case-text { padding: 0 18px 16px; color: var(--text-2); font-size: .97rem; max-height: 50vh; overflow: auto; }
.case-text p:last-child { margin-bottom: 0; }
/* Content of imported tasks: speaker quotes, sub-headings ("Текст А"), tables in texts and comments */
.q-text blockquote, .case-text blockquote { margin: 0 0 14px; padding: 10px 16px; border-left: 3px solid var(--border-strong); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-weight: 400; }
.q-text blockquote p:last-child, .case-text blockquote p:last-child { margin-bottom: 0; }
.case-text h3 { font-size: 1rem; margin: 18px 0 8px; color: var(--text); }
.case-text h3:first-child { margin-top: 4px; }
.q-text table, .case-text table, .explain table { border-collapse: collapse; margin: 10px 0; font-size: .92rem; font-weight: 400; max-width: 100%; display: block; overflow-x: auto; }
.q-text th, .q-text td, .case-text th, .case-text td, .explain th, .explain td { border: 1px solid var(--border-strong); padding: 4px 10px; text-align: left; vertical-align: top; }
.q-text th, .case-text th, .explain th { background: var(--surface-2); font-weight: 650; }

.question-card { padding: 24px clamp(18px, 3vw, 32px); }
.q-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 14px; }
.q-num { font-weight: 700; font-size: 1.02rem; }
.q-section { color: var(--muted); font-size: .88rem; }
.q-text { font-size: 1.08rem; font-weight: 550; margin-bottom: 18px; }
.q-text p:last-child { margin-bottom: 0; }
.q-hint { color: var(--text-2); font-size: .9rem; margin: -6px 0 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.options { display: grid; gap: 10px; }
.option {
	display: grid;
	grid-template-columns: auto auto 1fr;
	gap: 12px;
	align-items: start;
	padding: 12px 14px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	cursor: pointer;
	transition: border-color .12s, background-color .12s;
}
.option:hover { border-color: var(--primary); }
.option input { margin: 3px 0 0; width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.option.is-selected { border-color: var(--primary); background: var(--primary-soft); }
.option.is-disabled { opacity: .55; cursor: not-allowed; }
.option.is-disabled input { cursor: not-allowed; }
.opt-label {
	display: grid;
	place-items: center;
	min-width: 26px; height: 26px;
	padding: 0 6px;
	border-radius: 6px;
	background: var(--surface-3);
	color: var(--text-2);
	font-weight: 700;
	font-size: .88rem;
}
.option.is-selected .opt-label { background: var(--primary); color: var(--on-primary); }
.opt-text p { margin: 0; }

/* Ordering */
.sortable { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sort-item {
	display: grid;
	grid-template-columns: auto auto 1fr auto;
	gap: 10px;
	align-items: center;
	padding: 10px 10px 10px 8px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	touch-action: none;
}
.sort-item.is-dragging { border-color: var(--primary); box-shadow: var(--shadow-lg); background: var(--primary-soft); position: relative; z-index: 2; }
.sort-handle {
	display: grid;
	place-items: center;
	width: 32px; height: 40px;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: var(--muted);
	cursor: grab;
	touch-action: none;
}
.sort-handle:active { cursor: grabbing; }
.sort-handle:hover, .sort-handle:focus-visible { background: var(--surface-2); color: var(--text); }
.sort-pos {
	display: grid;
	place-items: center;
	width: 28px; height: 28px;
	border-radius: 50%;
	background: var(--surface-3);
	font-weight: 700;
	font-size: .88rem;
	font-variant-numeric: tabular-nums;
}
.sortable.is-answered .sort-pos { background: var(--primary); color: var(--on-primary); }
.sort-btns { display: flex; gap: 2px; }
.sort-btns .btn { width: 32px; min-height: 32px; padding: 0; }

/* Gaps in a text (cloze): numbered dropdowns inline */
.cloze-text { font-weight: 400; line-height: 2.15; }
.cloze-text p { margin: 0 0 .6em; }
.gap { display: inline-flex; align-items: center; gap: 4px; margin: 0 2px; vertical-align: baseline; white-space: nowrap; max-width: 100%; }
.gap-num {
	display: inline-grid;
	place-items: center;
	min-width: 24px; height: 22px;
	padding: 0 5px;
	border-radius: 6px;
	background: var(--surface-3);
	color: var(--text-2);
	font-size: .8rem;
	font-weight: 700;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}
.gap.is-filled .gap-num { background: var(--primary); color: var(--on-primary); }
.gap-select {
	max-width: min(100%, 22rem);
	min-height: 34px;
	padding: 3px 8px;
	border: 1px solid var(--border-strong);
	border-radius: 6px;
	background: var(--surface);
	color: var(--text);
	font: inherit;
	font-size: .95rem;
	line-height: 1.3;
	text-overflow: ellipsis;
}
.gap-select:hover { border-color: var(--primary); }
.gap.is-filled .gap-select { border-color: var(--primary); background: var(--primary-soft); }
@media (max-width: 600px) { .gap { white-space: normal; } .gap-select { max-width: calc(100vw - 110px); } }

/* Gaps in the results review */
.rev-gap { display: inline-flex; align-items: center; gap: 4px; margin: 0 2px; padding: 0 6px 0 2px; border: 1px solid var(--border); border-radius: 6px; line-height: 1.6; font-weight: 600; }
.rev-gap.is-correct { border-color: var(--good); background: var(--good-soft); }
.rev-gap.is-wrong { border-color: var(--critical); background: var(--critical-soft); }
.rev-gap del { color: var(--critical-ink); font-weight: 500; }
.rev-gap ins { color: var(--good-ink); text-decoration: none; }
.rev-gap .gap-num { height: 18px; min-width: 20px; }
/* Matching */
.match-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
@media (max-width: 700px) { .match-cols { grid-template-columns: 1fr; } }
.match-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.match-list li {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 10px;
	align-items: start;
	padding: 10px 12px;
	border-radius: var(--radius-sm);
	background: var(--surface-2);
	font-size: .95rem;
}
.match-col-title { font-size: .82rem; font-weight: 650; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .03em; }
.match-grid { border-collapse: separate; border-spacing: 0; }
.match-grid th { font-size: .9rem; padding: 6px 4px; text-align: center; min-width: 44px; }
.match-grid th[scope="row"] { text-align: left; padding-right: 12px; }
.match-grid td { text-align: center; padding: 4px; }
.match-cell {
	display: grid;
	place-items: center;
	width: 40px; height: 40px;
	border: 1px solid var(--border-strong);
	border-radius: 8px;
	cursor: pointer;
	background: var(--surface);
}
.match-cell:hover { border-color: var(--primary); }
.match-cell input { position: absolute; opacity: 0; pointer-events: none; }
.match-cell:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.match-cell:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.match-cell svg { width: 18px; height: 18px; opacity: 0; }
.match-cell:has(input:checked) svg { opacity: 1; }

.q-foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin-top: 24px;
	padding-top: 16px;
	border-top: 1px solid var(--border);
}
.q-foot .spacer { flex: 1; }
@media (max-width: 600px) {
	/* Tools on top, navigation below: [clear][flag] / [prev][next]. */
	.q-foot { display: grid; grid-template-columns: 1fr 1fr; }
	.q-foot .spacer { display: none; }
	.q-foot > :nth-child(3), .q-foot > :nth-child(4) { order: -1; }
	.q-foot > :nth-child(1), .q-foot > :nth-child(5) { width: 100%; }
}
.btn-flag[aria-pressed="true"] { color: var(--warning-ink); background: var(--warning-soft); }

/* Test parts (ТЗНК, Іноземна мова…): tabs above the task, groups in the palette. */
.part-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.part-tab {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 8px 14px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}
.part-tab:hover { border-color: var(--primary); }
.part-tab[aria-current="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-ink); }
.part-count { color: var(--muted); font-weight: 500; font-size: .86rem; font-variant-numeric: tabular-nums; }
.part-tab[aria-current="true"] .part-count { color: var(--primary-ink); }
.pal-group + .pal-group { margin-top: 14px; }
.pal-group-title { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 8px; font-size: .86rem; font-weight: 650; color: var(--text-2); }

.test-parts { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .92rem; }
.test-parts li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-radius: 6px; background: var(--surface-2); }
.part-choice { border: 0; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.part-choice legend { font-weight: 600; margin-bottom: 8px; padding: 0; font-size: .95rem; }
.part-choice .option { grid-template-columns: auto 1fr; }
/* Parts with their own time */
.part-state { display: inline-flex; align-items: center; gap: 3px; font-size: .78rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.part-state.is-open { background: var(--warning-soft); color: var(--warning-ink); }
.part-state.is-done { background: var(--good-soft); color: var(--good-ink); }
.part-state svg { width: 12px; height: 12px; }
.pal-btn.is-locked { background: var(--surface-2); color: var(--muted); border-style: dashed; }
.part-intro { text-align: left; }
.part-intro h2 { margin: 0 0 14px; }
.part-intro-facts { display: flex; gap: 32px; margin: 0 0 14px; }
.part-intro-facts .fact-value { font-size: 1.4rem; font-weight: 700; }
.part-intro .alert { margin-top: 8px; }
.q-readonly { border: 0; margin: 0; padding: 0; min-width: 0; }
.q-readonly .q-hint { color: var(--good-ink); }
.part-times { margin: 4px 0 10px; padding-left: 20px; }
.part-alts { display: block; font-size: .82rem; }
.part-block + .part-block { margin-top: 18px; }
.part-block h3 { font-size: 1rem; margin: 0 0 6px; }

/* Palette */
.palette-card { padding: 18px; position: sticky; top: 150px; }
.palette-card h2 { font-size: .95rem; margin: 0 0 12px; }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; }
.pal-btn {
	position: relative;
	height: 36px;
	border: 1px solid var(--border-strong);
	border-radius: 7px;
	background: var(--surface);
	color: var(--text-2);
	font: inherit;
	font-size: .85rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
}
.pal-btn:hover { border-color: var(--primary); }
/* Two states: white = not saved, blue = saved on the server. */
.pal-btn.is-saved { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.pal-btn.is-current { outline: 2px solid var(--primary); outline-offset: 1px; }
.pal-btn.is-flagged::after {
	content: "";
	position: absolute;
	top: 3px; right: 3px;
	width: 7px; height: 7px;
	border-radius: 50%;
	background: var(--warning);
	box-shadow: 0 0 0 2px var(--surface);
}
.pal-legend { display: grid; gap: 6px; margin-top: 14px; font-size: .82rem; color: var(--muted); }
.pal-legend span { display: inline-flex; align-items: center; gap: 8px; }
.pal-legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border-strong); }
.pal-legend i.saved { background: var(--primary); border-color: var(--primary); }
.pal-legend i.unsaved { background: var(--surface); }
.pal-legend i.flagged { border-radius: 50%; width: 9px; height: 9px; margin: 0 2px; background: var(--warning); border: 0; }
@media (max-width: 1000px) { .palette-card { position: static; } }

.overlay {
	position: fixed;
	inset: 0;
	z-index: 300;
	display: grid;
	place-items: center;
	background: rgba(10, 15, 25, .55);
	color: #fff;
	text-align: center;
	padding: 20px;
}
.overlay .card { color: var(--text); max-width: 400px; }

/* =========================================================================
   Results
   ========================================================================= */
.result-hero { display: grid; grid-template-columns: auto 1fr; gap: 24px 36px; align-items: center; }
@media (max-width: 700px) { .result-hero { grid-template-columns: 1fr; } }
.hero-figure { font-size: 3.4rem; font-weight: 700; line-height: 1; }
.hero-label { color: var(--muted); font-size: .9rem; margin-bottom: 6px; }
.hero-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 24px; }
.fact-label { color: var(--muted); font-size: .84rem; }
.fact-value { font-weight: 650; }

.bar-table td.bar-cell { width: 42%; min-width: 120px; }
.bar-table .meter { height: 10px; border-radius: 5px; }
.bar-table .meter > span { border-radius: 0 5px 5px 0; }
.bar-table .sec-name { font-weight: 550; }
@media (max-width: 640px) {
	.bar-table thead { display: none; }
	.bar-table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
	.bar-table td { border: 0; padding: 0; }
	.bar-table td.bar-cell { grid-column: 1 / -1; width: auto; }
	.bar-table td.extra { display: none; }
}

.review-item { padding: 20px clamp(16px, 3vw, 28px); }
.review-item + .review-item { margin-top: 16px; }
.review-item .q-text { font-size: 1rem; }
.rev-options { display: grid; gap: 8px; }
.rev-option {
	display: grid;
	grid-template-columns: auto 1fr auto;
	gap: 10px;
	align-items: start;
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	font-size: .95rem;
}
.rev-option.is-correct { border-color: var(--good); background: var(--good-soft); }
.rev-option.is-wrong { border-color: var(--critical); background: var(--critical-soft); }
.rev-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.rev-tags:empty { display: none; }
@media (max-width: 600px) {
	.rev-option { grid-template-columns: auto 1fr; }
	.rev-tags { grid-column: 2; justify-content: flex-start; }
	.match-review thead { display: none; }
	.match-review tr { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
	.match-review tr:last-child { border-bottom: 0; }
	.match-review td { border: 0; padding: 0; }
	.match-review td[data-label]::before {
		content: attr(data-label);
		display: block;
		font-size: .78rem;
		font-weight: 650;
		color: var(--muted);
		margin-bottom: 2px;
	}
}
.rev-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .rev-cols { grid-template-columns: 1fr; } }
.rev-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rev-list li {
	display: grid;
	grid-template-columns: auto 1fr auto;
	gap: 10px;
	align-items: start;
	padding: 8px 10px;
	border-radius: var(--radius-sm);
	background: var(--surface-2);
	font-size: .93rem;
}
.rev-list svg { width: 16px; height: 16px; margin-top: 3px; }
.rev-list .ok { color: var(--good-ink); }
.rev-list .bad { color: var(--critical-ink); }

.explain {
	margin-top: 18px;
	padding: 14px 16px;
	border-radius: var(--radius-sm);
	background: var(--surface-2);
	border-left: 3px solid var(--primary);
}
.explain-title { font-weight: 650; font-size: .9rem; margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.explain-title svg { width: 16px; height: 16px; color: var(--primary-ink); }
.explain p:last-child { margin-bottom: 0; }
.library-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.library-links a {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 12px;
	border-radius: 999px;
	background: var(--surface);
	border: 1px solid var(--border);
	font-size: .88rem;
	text-decoration: none;
}
.library-links svg { width: 15px; height: 15px; }

/* =========================================================================
   Charts
   ========================================================================= */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .series-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { fill: var(--series-1); opacity: .1; }
.chart .series-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .series-bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:focus { outline: none; }
.chart .is-hover .series-bar, .chart .series-bar.is-hover { fill: var(--primary-hover); }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .end-label { fill: var(--text); font-weight: 650; }
.chart-tip {
	position: absolute;
	pointer-events: none;
	z-index: 5;
	padding: 8px 10px;
	border-radius: var(--radius-sm);
	background: var(--surface);
	border: 1px solid var(--border);
	box-shadow: var(--shadow-lg);
	font-size: .85rem;
	line-height: 1.35;
	min-width: 120px;
	transform: translate(-50%, calc(-100% - 12px));
	white-space: nowrap;
}
.chart-tip strong { display: block; font-size: 1rem; color: var(--text); }
.chart-tip span { color: var(--text-2); }
.chart-tip[hidden] { display: none; }
.chart-empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* =========================================================================
   Portal container
   ========================================================================= */
.tp-app { min-height: 50vh; }

@media print {
	.site-header, .site-footer, .player-bar, .q-foot, .palette-card, .filters, .test-actions { display: none !important; }
	body { background: #fff; }
	.card, .tile { box-shadow: none; }
}
