* {
	box-sizing: border-box;
	-webkit-box-sizing: border-box;
	margin: 0;
	padding: 0;
}

:root {
	--bg: #f2f1ec;
	--paper: #fffefb;
	--ink: #16181d;
	--ink-soft: #6b6d6a;
	--rule: #d8d5cb;
	--red: #e74645;
	--orange: #fb7756;
	--yellow: #facd60;
	--byellow: #fdfa66;
	--teal: #1ac0c6;
	--teal-deep: #0d7f83;
	--red-deep: #a72d2c;
}

html, body {
	height: 100%;
}

body {
	background: var(--bg);
	background-image: repeating-linear-gradient(180deg, rgba(0,0,0,0.015) 0px, rgba(0,0,0,0.015) 1px, transparent 1px, transparent 34px);
	color: var(--ink);
	font-family: 'Space Mono', monospace;
}

h1, h2, h3 {
	font-family: 'Bricolage Grotesque', sans-serif;
}

header {
	padding: 18px 28px;
	border-bottom: 2px solid var(--ink);
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 16px;
	background: var(--paper);
	position: sticky;
	top: 0;
	z-index: 10;
}

header h1 {
	font-size: 21px;
	font-weight: 700;
	letter-spacing: -0.01em;
}

header h1 span {
	color: var(--teal-deep);
}

.header-stats {
	display: none;
	gap: 20px;
	font-size: 12px;
	color: var(--ink-soft);
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

.header-stats.active {
	display: flex;
}

.header-stats b {
	color: var(--ink);
	font-weight: 700;
}

main {
	max-width: 980px;
	margin: 0 auto;
	padding: 28px 24px 60px;
	display: flex;
	flex-direction: column;
	gap: 16px;
}

/* ---- collapsible stage sections ---- */

.stage {
	background: var(--paper);
	border: 1px solid var(--rule);
}

.stage[disabled] summary {
	cursor: not-allowed;
	opacity: 0.5;
	pointer-events: none;
}

.stage summary {
	list-style: none;
	cursor: pointer;
	padding: 16px 20px;
	display: flex;
	align-items: center;
	gap: 14px;
	flex-wrap: wrap;
}

.stage summary::-webkit-details-marker {
	display: none;
}

.stage summary::before {
	content: '▸';
	color: var(--teal-deep);
	font-size: 12px;
	transition: transform 0.15s ease;
}

.stage[open] summary::before {
	transform: rotate(90deg);
}

.stage-tag {
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	font-weight: 700;
	color: var(--teal-deep);
	border: 1px solid var(--teal-deep);
	padding: 2px 7px;
	flex-shrink: 0;
}

.stage-title {
	font-family: 'Bricolage Grotesque', sans-serif;
	font-size: 15px;
	font-weight: 700;
	flex-shrink: 0;
}

.stage-summary {
	font-size: 12px;
	color: var(--ink-soft);
	margin-left: auto;
	text-align: right;
}

.stage-body {
	padding: 0 20px 22px;
	border-top: 1px solid var(--rule);
	padding-top: 18px;
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.ingestion-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 20px;
	min-width: 0;
}

.ingestion-grid > div {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.ingestion-grid h3 {
	font-size: 13px;
	margin-bottom: 10px;
}

.instructions.small {
	border: 1px solid var(--rule);
	background: var(--bg);
	padding: 12px 14px;
	margin-bottom: 12px;
	min-width: 0;
}

.instructions.small p {
	color: var(--ink-soft);
	font-size: 12px;
	margin-bottom: 8px;
}

.instr-steps {
	list-style: none;
	counter-reset: step;
	display: flex;
	flex-direction: column;
	gap: 3px;
}

.instr-steps li {
	counter-increment: step;
	font-size: 12px;
	padding: 2px 0 2px 24px;
	position: relative;
}

.instr-steps li::before {
	content: counter(step);
	position: absolute;
	left: 0;
	top: 1px;
	width: 16px;
	height: 16px;
	border: 1px solid var(--ink);
	font-size: 10px;
	font-weight: 700;
	display: flex;
	align-items: center;
	justify-content: center;
}

.instructions a {
	color: var(--teal-deep);
}

code, kbd {
	background: var(--paper);
	border: 1px solid var(--rule);
	border-radius: 3px;
	padding: 2px 6px;
	font-size: 11px;
	font-family: 'Space Mono', monospace;
}

.query-block {
	border: 1px solid var(--ink);
	min-width: 0;
}

.query-block-head {
	background: var(--ink);
	color: var(--paper);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 6px 10px;
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.1em;
}

.query-block-head button {
	font-family: 'Space Mono', monospace;
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	background: transparent;
	color: var(--byellow);
	border: 1px solid var(--byellow);
	padding: 3px 8px;
	cursor: pointer;
}

.query-block-head button:hover {
	background: var(--byellow);
	color: var(--ink);
}

.query-block pre {
	font-family: 'Space Mono', monospace;
	font-size: 10px;
	line-height: 1.5;
	color: var(--ink);
	background: var(--paper);
	padding: 10px;
	overflow-x: auto;
	white-space: pre;
	min-width: 0;
	max-width: 100%;
}

.dropzone {
	position: relative;
	border: 2px dashed var(--ink);
	padding: 28px 18px;
	text-align: center;
	cursor: pointer;
	background: var(--bg);
	min-width: 0;
	width: 100%;
	transition: border-color 0.15s ease, background 0.15s ease;
	-webkit-transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
	border-color: var(--teal-deep);
	background: #eafbfb;
}

.dropzone .primary {
	font-family: 'Bricolage Grotesque', sans-serif;
	font-size: 15px;
	font-weight: 600;
	margin-bottom: 6px;
}

.dropzone .secondary {
	font-size: 11px;
	color: var(--ink-soft);
}

.dropzone input {
	position: absolute;
	inset: 0;
	opacity: 0;
	cursor: pointer;
}

.load-status {
	text-align: center;
	font-size: 12px;
	color: var(--teal-deep);
	margin-top: 10px;
	min-height: 16px;
}

.load-status.error {
	color: var(--red-deep);
}

.progress-shell {
	background: var(--bg);
	border: 1px solid var(--rule);
	padding: 18px;
}

.progress-shell.hidden {
	display: none;
}

.progress-bar {
	height: 10px;
	background: var(--paper);
	border: 1px solid var(--rule);
	overflow: hidden;
	margin-bottom: 12px;
}

.progress-fill {
	height: 100%;
	width: 0%;
	background: var(--teal-deep);
	transition: width 0.15s ease;
}

.progress-meta {
	display: flex;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 8px;
	font-size: 12px;
	color: var(--ink-soft);
	margin-bottom: 12px;
}

.live-stats {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 10px;
}

.live-stat {
	background: var(--paper);
	border: 1px solid var(--rule);
	padding: 12px;
	text-align: center;
}

.live-stat b {
	display: block;
	font-size: 20px;
	font-family: 'Bricolage Grotesque', sans-serif;
	font-weight: 800;
}

.live-stat span {
	font-size: 10px;
	color: var(--ink-soft);
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.load-status.error {
	text-align: left;
	white-space: pre-wrap;
	font-size: 11px;
	max-height: 100px;
	overflow-y: auto;
	margin-top: 10px;
}

/* ---- sanitize stage ---- */

.sanitize-counts {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 10px;
}

.sanitize-counts .dist-item b {
	color: var(--teal-deep);
}

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

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

.control-check {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	cursor: pointer;
	line-height: 1.4;
}

.control-check input {
	accent-color: var(--teal-deep);
	width: 15px;
	height: 15px;
	cursor: pointer;
	flex-shrink: 0;
}

.controls-note {
	font-size: 11px;
	color: var(--ink-soft);
}

.skip-integrity-check {
	color: var(--red-deep);
	font-weight: 700;
}

.skip-integrity-check input {
	accent-color: var(--red-deep);
}

#stageIntegrity .stage-body.skipped > *:not(.skip-integrity-note):not(.controls-row) {
	opacity: 0.4;
	pointer-events: none;
}

.skip-integrity-note {
	font-size: 11px;
	color: var(--red-deep);
	font-weight: 700;
}

.skip-integrity-note.hidden {
	display: none;
}

#challengeMaxAgeMs {
	width: 100px;
	background: var(--bg);
	border: 1px solid var(--rule);
	color: var(--ink);
	padding: 5px 8px;
	font-size: 12px;
	font-family: 'Space Mono', monospace;
}

.action-btn {
	font-family: 'Space Mono', monospace;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	background: transparent;
	color: var(--red-deep);
	border: 1px solid var(--red-deep);
	padding: 8px 14px;
	cursor: pointer;
	align-self: flex-start;
	-webkit-transition: background 0.15s ease, color 0.15s ease;
	transition: background 0.15s ease, color 0.15s ease;
}

.action-btn:hover:not(:disabled) {
	background: var(--red-deep);
	color: var(--paper);
}

.action-btn.confirm-btn {
	color: var(--teal-deep);
	border-color: var(--teal-deep);
	width: 100%;
	margin-top: 10px;
	align-self: stretch;
}

.action-btn.confirm-btn:hover:not(:disabled) {
	background: var(--teal-deep);
	color: var(--paper);
}

.action-btn.hidden {
	display: none;
}

.staged-files {
	border: 1px solid var(--rule);
	background: var(--bg);
	padding: 10px 14px;
	margin-top: 10px;
	font-size: 12px;
}

.staged-files.hidden {
	display: none;
}

.staged-files ul {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-top: 6px;
}

.staged-files li {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	color: var(--ink-soft);
}

.staged-files li span.fname {
	color: var(--ink);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.staged-files-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--ink-soft);
}

.staged-files-head button {
	font-family: 'Space Mono', monospace;
	font-size: 10px;
	text-transform: uppercase;
	background: transparent;
	color: var(--red-deep);
	border: 1px solid var(--red-deep);
	padding: 2px 7px;
	cursor: pointer;
}

#presetBtn {
	font-family: 'Space Mono', monospace;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	font-weight: 700;
	background: var(--bg);
	color: var(--teal-deep);
	border: 2px solid var(--teal-deep);
	padding: 10px 14px;
	cursor: pointer;
	align-self: flex-start;
	transition: background 0.15s ease, color 0.15s ease;
	-webkit-transition: background 0.15s ease, color 0.15s ease;
}

#presetBtn:hover {
	background: var(--teal-deep);
	color: var(--paper);
}

/* ---- integrity field sections (ported) ---- */

.field-section {
	background: var(--bg);
	border: 1px solid var(--rule);
	padding: 14px;
}

.field-section h3 {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--ink-soft);
	margin-bottom: 10px;
	font-weight: 700;
}

.field-section-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 10px;
}

.field-section-head h3 {
	margin-bottom: 0;
}

.ignore-row {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--ink-soft);
	cursor: pointer;
	white-space: nowrap;
	flex-shrink: 0;
}

.ignore-row input {
	accent-color: var(--red-deep);
}

.field-section.ignored > *:not(.field-section-head) {
	opacity: 0.4;
	pointer-events: none;
}

.field-section.ignored .ignore-row {
	color: var(--red-deep);
	font-weight: 700;
}

.check-row {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 12px;
	padding: 4px 0;
	cursor: pointer;
}

.check-row input {
	accent-color: var(--teal-deep);
}

.field-section input[type="text"],
.field-section input[type="number"] {
	width: 100%;
	background: var(--paper);
	border: 1px solid var(--rule);
	color: var(--ink);
	padding: 6px 8px;
	font-size: 12px;
	font-family: 'Space Mono', monospace;
	margin-top: 6px;
}

.field-section input[type="range"] {
	width: 100%;
	accent-color: var(--teal-deep);
	margin-top: 6px;
}

.slider-label {
	font-size: 11px;
	color: var(--ink-soft);
	display: flex;
	justify-content: space-between;
}

.slider-value {
	color: var(--teal-deep);
	font-weight: 700;
}

.field-desc {
	font-size: 11px;
	color: var(--ink-soft);
	margin-bottom: 8px;
	line-height: 1.4;
}

.field-section select {
	width: 100%;
	background: var(--paper);
	border: 1px solid var(--rule);
	color: var(--ink);
	padding: 6px 8px;
	font-size: 12px;
	font-family: 'Space Mono', monospace;
	margin-bottom: 10px;
}

.hidden-group {
	display: none;
}

.version-details {
	margin-top: 10px;
}

.version-details summary {
	font-size: 11px;
	color: var(--teal-deep);
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	padding: 0;
	list-style: revert;
}

.version-details summary::before {
	content: none;
}

.version-details #grp-versionCode {
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px solid var(--rule);
}

/* ---- results (always visible) ---- */

.results {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.warning-banner {
	border: 1px solid var(--red-deep);
	background: #fbeceb;
	color: var(--red-deep);
	padding: 10px 16px;
	font-size: 12px;
}

.warning-banner.hidden {
	display: none;
}

.verdict-banner {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 32px;
	flex-wrap: wrap;
	padding: 8px 0;
}

.stamp {
	border: 3px double currentColor;
	padding: 10px 20px;
	text-align: center;
}

.stamp.rate {
	border-style: dashed;
	border-width: 2px;
}

.stamp .num {
	font-family: 'Bricolage Grotesque', sans-serif;
	font-size: 30px;
	font-weight: 800;
	line-height: 1;
}

.stamp .label {
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.14em;
	margin-top: 4px;
}

.stamp.pass { color: var(--teal-deep); }
.stamp.fail { color: var(--red-deep); }
.stamp.rate { color: var(--ink); }

.chart-panel {
	background: var(--paper);
	border: 1px solid var(--rule);
	padding: 16px 18px;
}

.chart-panel h3 {
	font-family: 'Bricolage Grotesque', sans-serif;
	font-size: 13px;
	color: var(--ink);
	margin-bottom: 12px;
	font-weight: 700;
}

.dist-scope {
	font-family: 'Space Mono', monospace;
	font-size: 10px;
	text-transform: none;
	color: var(--ink-soft);
	font-weight: 400;
}

.collapsible-panel summary {
	cursor: pointer;
	list-style: none;
}

.collapsible-panel summary::-webkit-details-marker {
	display: none;
}

.collapsible-panel summary::before {
	content: '▸';
	display: inline-block;
	color: var(--teal-deep);
	font-size: 12px;
	margin-right: 8px;
	transition: transform 0.15s ease;
}

.collapsible-panel[open] summary::before {
	transform: rotate(90deg);
}

.collapsible-panel summary h3 {
	display: inline;
	margin-bottom: 0;
}

.collapsible-panel[open] summary {
	margin-bottom: 12px;
	display: block;
}

.chart-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 20px;
	min-width: 0;
}

.chart-row > div {
	min-width: 0;
}

.funnel-wrap {
	position: relative;
	height: 220px;
	min-width: 0;
}

.timeline-wrap {
	position: relative;
	height: 260px;
	min-width: 0;
}

.bar-wrap {
	position: relative;
	height: 260px;
	min-width: 0;
	width: 100%;
	overflow: hidden;
}

.dist-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 10px;
}

.dist-item {
	border: 1px solid var(--rule);
	padding: 10px;
	text-align: center;
}

.dist-item b {
	display: block;
	font-size: 19px;
	font-family: 'Bricolage Grotesque', sans-serif;
	color: var(--teal-deep);
}

.dist-item span {
	font-size: 10px;
	color: var(--ink-soft);
	text-transform: uppercase;
}

.combo-grid {
	grid-template-columns: 1fr;
}

.combo-grid .dist-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	text-align: left;
	padding: 8px 12px;
}

.combo-grid .dist-item b {
	font-size: 15px;
}

.results-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 16px;
}

.dist-item {
	margin-bottom: 0;
}

.dist-item-legend {
	margin-bottom: 16px;
}

.dist-item-legend:last-child {
	margin-bottom: 0;
}

.dist-label {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--ink-soft);
	margin-bottom: 6px;
}

.dist-bar-track {
	display: flex;
	height: 20px;
	border: 1px solid var(--rule);
	overflow: hidden;
	background: var(--bg);
}

.dist-bar-seg {
	height: 100%;
	min-width: 2px;
	cursor: crosshair;
}

.dist-legend {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 6px;
	font-size: 10px;
	color: var(--ink-soft);
}

.dist-legend span.swatch {
	display: inline-block;
	width: 8px;
	height: 8px;
	margin-right: 4px;
}

#customTooltip {
	position: fixed;
	display: none;
	background: var(--ink);
	color: var(--paper);
	font-family: 'Space Mono', monospace;
	font-size: 11px;
	padding: 6px 10px;
	pointer-events: none;
	z-index: 999;
	white-space: nowrap;
	border: 1px solid var(--ink);
}

#customTooltip .tt-val {
	color: var(--yellow);
	font-weight: 700;
}

@media (max-width: 760px) {
	.chart-row, .results-grid, .ingestion-grid { grid-template-columns: 1fr; }
	.live-stats { grid-template-columns: repeat(2, 1fr); }
	.sanitize-counts { grid-template-columns: repeat(2, 1fr); }
	.stage-summary { margin-left: 0; text-align: left; width: 100%; }
}

@media print {
	.stage summary { cursor: default; }
	.stage[open] .stage-body { display: flex !important; }
}
