:root {
	--bg: #f4f5f7;
	--surface: #ffffff;
	--surface-raised: #ffffff;
	--border: #e5e5e5;
	--border-light: #f0f0f0;
	--ink: #1a1a1a;
	--muted: #595959;
	--subtle: #a6a6a6;
	--accent: #4db6ac;
	--accent-light: #b2dfdb;
	--accent-deep: #00796b;
	--danger: #e57373;
	--danger-light: #ffcdd2;
	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
	--shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
	--shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
	--radius-sm: 8px;
	--radius-md: 12px;
	--radius-lg: 16px;
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	padding: 32px 40px;
	font-family: "Space Grotesk", sans-serif;
	background: var(--bg);
	color: var(--ink);
	min-height: 100vh;
	-webkit-font-smoothing: antialiased;
}

/* ── Topbar ─────────────────────────────────────── */

.topbar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 20px;
	margin-bottom: 24px;
	padding-bottom: 20px;
	border-bottom: 1px solid var(--border);
}

.eyebrow {
	margin: 0;
	font-size: 0.72rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.12em;
	color: var(--accent-deep);
}

h1 {
	margin: 2px 0 0;
	font-size: clamp(1.4rem, 3vw, 2rem);
	font-weight: 700;
	letter-spacing: -0.01em;
}

.top-actions a {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	background: var(--ink);
	color: #fff;
	text-decoration: none;
	padding: 8px 16px;
	border-radius: var(--radius-sm);
	font-size: 0.82rem;
	font-weight: 600;
	transition: background 150ms ease;
}

.top-actions a:hover {
	background: #333;
}

/* ── Tabs ───────────────────────────────────────── */

.tabs {
	display: inline-flex;
	gap: 2px;
	margin-bottom: 24px;
	padding: 3px;
	background: var(--border);
	border-radius: var(--radius-sm);
	position: relative;
	z-index: 1;
}

.tab {
	border: 0;
	background: transparent;
	padding: 8px 18px;
	border-radius: 6px;
	font-weight: 600;
	font-size: 0.85rem;
	font-family: inherit;
	cursor: pointer;
	color: var(--muted);
	transition: all 150ms ease;
}

.tab:hover:not(.active) {
	color: var(--ink);
}

.tab.active {
	background: var(--surface);
	color: var(--ink);
	box-shadow: var(--shadow-sm);
}

/* ── Views ──────────────────────────────────────── */

.view {
	display: none;
	animation: rise 200ms ease;
}

.view.active {
	display: block;
}

@keyframes rise {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ── KPI Cards ──────────────────────────────────── */

.kpis {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	gap: 12px;
	margin-bottom: 20px;
}

.kpi {
	padding: 16px 18px;
	border-radius: var(--radius-md);
	background: var(--surface);
	border: 1px solid var(--border);
	box-shadow: var(--shadow-sm);
	transition: box-shadow 150ms ease;
}

.kpi:hover {
	box-shadow: var(--shadow-md);
}

.kpi-value {
	font-size: 1.5rem;
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1.2;
}

.kpi-label {
	margin-top: 4px;
	font-size: 0.72rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--subtle);
}

/* ── Panels ─────────────────────────────────────── */

.panel-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 16px;
	margin-bottom: 16px;
}

.panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	padding: 20px;
	box-shadow: var(--shadow-sm);
	overflow: auto;
	display: flex;
	flex-direction: column;
}

.panel-title {
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--subtle);
	margin-bottom: 14px;
}

.panel-title-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

#matchContextFilter {
	border: 1px solid var(--border);
	background: var(--bg);
	padding: 6px 10px;
	border-radius: 6px;
	font-family: inherit;
	font-size: 0.78rem;
	font-weight: 500;
	text-transform: none;
	letter-spacing: normal;
	color: var(--ink);
	cursor: pointer;
	transition: border-color 150ms ease;
}

#matchContextFilter:hover {
	border-color: var(--accent);
}

/* ── Charts ─────────────────────────────────────── */

.chart-panel {
	display: flex;
	flex-direction: column;
	min-height: 340px;
}

.chart-panel canvas {
	position: absolute;
	inset: 0;
	width: 100% !important;
	height: 100% !important;
}

.chart-canvas-wrap {
	position: relative;
	flex: 1 1 0;
	min-height: 0;
}

.chart-panel-wide {
	min-height: 400px;
}

.match-performance-panel {
	margin-bottom: 20px;
}

/* ── Context Group ──────────────────────────────── */

.context-group {
	margin-bottom: 16px;
	padding: 16px;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background: var(--bg);
}

.context-row {
	margin-bottom: 0;
}

.context-row .chart-panel {
	min-height: 380px;
}

/* ── Summary Cards ──────────────────────────────── */

.summary-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
	gap: 12px;
	margin-bottom: 16px;
}

.parse-phase-summary-grid,
.full-addr-phase-summary-grid {
	margin-bottom: 0;
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.context-summary-grid {
	margin-bottom: 0;
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-card {
	border-radius: var(--radius-md);
	padding: 0;
	background: var(--surface);
	border: 1px solid var(--border);
	box-shadow: var(--shadow-sm);
	overflow: hidden;
}

.stat-card {
	--stat-accent: var(--accent);
}

.stat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--border-light);
	background: var(--bg);
}

.stat-title {
	font-size: 0.72rem;
	font-weight: 700;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	min-width: 0;
}

.stat-badge {
	font-family: "IBM Plex Mono", monospace;
	font-size: 0.68rem;
	font-weight: 600;
	color: var(--stat-accent);
	background: color-mix(in srgb, var(--stat-accent) 10%, transparent);
	padding: 2px 8px;
	border-radius: 99px;
	white-space: nowrap;
	flex-shrink: 0;
}

.stat-hero {
	padding: 16px 16px 12px;
	display: flex;
	align-items: baseline;
	gap: 6px;
}

.stat-hero-value {
	font-family: "IBM Plex Mono", monospace;
	font-size: 1.5rem;
	font-weight: 700;
	letter-spacing: -0.02em;
	color: var(--ink);
	line-height: 1;
}

.stat-hero-label {
	font-size: 0.7rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--subtle);
}

.stat-metrics {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	border-top: 1px solid var(--border-light);
}

.stat-metric {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 10px 16px;
	border-right: 1px solid var(--border-light);
}

.stat-metric:last-child {
	border-right: none;
}

.stat-metric-label {
	font-size: 0.65rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--subtle);
}

.stat-metric-value {
	font-family: "IBM Plex Mono", monospace;
	font-size: 0.82rem;
	font-weight: 500;
	color: var(--muted);
}

/* ── Histograms ─────────────────────────────────── */

.hist-row .chart-panel {
	min-height: 280px;
}

.hist-row {
	grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* ── Database Explorer ──────────────────────────── */

.table-list {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
	gap: 10px;
}

.table-chip {
	border: 1px solid var(--border);
	background: var(--bg);
	border-radius: var(--radius-sm);
	padding: 12px;
	cursor: pointer;
	transition: all 150ms ease;
}

.table-chip:hover {
	border-color: var(--subtle);
	box-shadow: var(--shadow-sm);
}

.table-chip.active {
	border-color: var(--accent);
	background: var(--accent-light);
	box-shadow: 0 0 0 2px rgba(77, 182, 172, 0.2);
}

.table-chip h3 {
	margin: 0;
	font-size: 0.92rem;
	font-weight: 600;
}

.table-chip p {
	margin: 4px 0 0;
	font-family: "IBM Plex Mono", monospace;
	font-size: 0.78rem;
	color: var(--subtle);
}

.db-controls {
	margin-bottom: 14px;
}

.db-controls h2 {
	font-size: 1.1rem;
	font-weight: 700;
}

.db-control-row {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
}

.db-control-row input,
.db-control-row select,
.db-control-row button {
	border: 1px solid var(--border);
	background: var(--bg);
	padding: 9px 12px;
	border-radius: 6px;
	font-family: inherit;
	font-size: 0.85rem;
	transition: border-color 150ms ease;
}

.db-control-row input:focus,
.db-control-row select:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 2px rgba(77, 182, 172, 0.15);
}

.db-control-row input {
	flex: 1;
	min-width: 220px;
}

.db-control-row button {
	background: var(--accent-deep);
	color: #fff;
	border: 0;
	font-weight: 600;
	cursor: pointer;
	transition: background 150ms ease;
}

.db-control-row button:hover {
	background: #00695c;
}

.pager {
	margin-top: 14px;
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 12px;
	font-family: "IBM Plex Mono", monospace;
	font-size: 0.8rem;
	color: var(--muted);
}

.pager button {
	border: 1px solid var(--border);
	background: var(--surface);
	padding: 7px 12px;
	border-radius: 6px;
	font-weight: 500;
	cursor: pointer;
	transition: all 150ms ease;
}

.pager button:hover:not(:disabled) {
	border-color: var(--accent);
	color: var(--accent-deep);
}

.pager button:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* ── Grid.js overrides ──────────────────────────── */

#gridRoot .gridjs-wrapper {
	border-radius: var(--radius-md);
	border: 1px solid var(--border);
}

#gridRoot .gridjs-table {
	font-size: 0.85rem;
	height: auto !important;
}

#gridRoot .gridjs-tr {
	height: auto !important;
}

#gridRoot .gridjs-wrapper {
	min-height: 520px;
}

#gridRoot .gridjs-th {
	font-weight: 600;
	text-transform: uppercase;
	font-size: 0.72rem;
	letter-spacing: 0.04em;
}

/* ── Gauge / Doughnut ───────────────────────────── */

.gauge-panel {
	display: flex;
	flex-direction: column;
}

.gauge-wrap {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.gauge-chart-box {
	position: relative;
	width: 100%;
	max-width: 260px;
	aspect-ratio: 2 / 1;
	margin-bottom: 0;
}

.gauge-chart-box canvas {
	width: 100% !important;
	height: 100% !important;
}

.gauge-center {
	position: absolute;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	text-align: center;
	display: flex;
	flex-direction: column;
	line-height: 1.1;
}

.gauge-value {
	font-size: 1.8rem;
	font-weight: 700;
	color: var(--ink);
}

.gauge-label {
	font-size: 0.72rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--subtle);
}

.gauge-legend {
	width: 100%;
	margin-top: 16px;
}

.gauge-legend-row {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 0;
	border-bottom: 1px solid var(--border-light);
	font-size: 0.84rem;
}

.gauge-legend-row:last-child {
	border-bottom: none;
}

.gauge-dot {
	width: 10px;
	height: 10px;
	border-radius: 3px;
	flex-shrink: 0;
}

.gauge-endpoint {
	flex: 1;
	color: var(--muted);
	font-size: 0.8rem;
}

.gauge-count {
	font-family: "IBM Plex Mono", monospace;
	font-weight: 600;
	font-size: 0.85rem;
	color: var(--ink);
}

.gauge-pct {
	font-family: "IBM Plex Mono", monospace;
	font-size: 0.78rem;
	color: var(--subtle);
	min-width: 48px;
	text-align: right;
}

/* ── Background glows (soft ambient) ────────────── */

.bg-glow {
	position: fixed;
	pointer-events: none;
	filter: blur(100px);
	opacity: 0.12;
	z-index: 0;
}

.bg-glow-a {
	top: -120px;
	left: -80px;
	width: 400px;
	height: 400px;
	background: var(--accent);
}

.bg-glow-b {
	right: -100px;
	bottom: -120px;
	width: 500px;
	height: 500px;
	background: #4fc3f7;
}

.topbar,
main,
.tabs {
	position: relative;
	z-index: 1;
}

/* ── Full Address Explorer ──────────────────────────── */

.fa-search-panel {
	margin-bottom: 16px;
}

.fa-controls {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	margin-bottom: 12px;
}

.fa-controls input {
	border: 1px solid var(--border);
	background: var(--bg);
	padding: 9px 12px;
	border-radius: 6px;
	font-family: inherit;
	font-size: 0.85rem;
	transition: border-color 150ms ease;
	flex: 1;
	min-width: 200px;
}

.fa-controls input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 2px rgba(77, 182, 172, 0.15);
}

.fa-controls button {
	border: 0;
	background: var(--accent-deep);
	color: #fff;
	padding: 9px 22px;
	border-radius: 6px;
	font-family: inherit;
	font-size: 0.85rem;
	font-weight: 600;
	cursor: pointer;
	transition: background 150ms ease;
	white-space: nowrap;
}

.fa-controls button:hover {
	background: #00695c;
}

.fa-enforce-group {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 6px 10px;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--surface);
	min-height: 38px;
	flex-wrap: wrap;
}

.fa-enforce-label {
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--subtle);
}

.fa-enforce-option {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	font-size: 0.82rem;
	color: var(--ink);
	user-select: none;
}

.fa-enforce-option input[type="checkbox"] {
	margin: 0;
	width: 14px;
	height: 14px;
	accent-color: var(--accent-deep);
}

.fa-status {
	font-size: 0.82rem;
	color: var(--muted);
	min-height: 1.2em;
	font-family: "IBM Plex Mono", monospace;
}

.fa-enforce-hint {
	font-size: 0.76rem;
	color: var(--subtle);
	margin-bottom: 8px;
	font-family: "IBM Plex Mono", monospace;
	min-height: 1.2em;
}

.fa-timings {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	margin-bottom: 16px;
}

.fa-timing-chip {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 10px 16px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-sm);
	min-width: 100px;
}

.fa-timing-label {
	font-size: 0.65rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--subtle);
}

.fa-timing-value {
	font-family: "IBM Plex Mono", monospace;
	font-size: 0.92rem;
	font-weight: 600;
	color: var(--ink);
}

#faPoisPanel,
#faAddrsPanel {
	margin-bottom: 16px;
}

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

.fa-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.85rem;
}

.fa-table th {
	text-align: left;
	font-size: 0.7rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--subtle);
	padding: 8px 12px;
	border-bottom: 2px solid var(--border);
	white-space: nowrap;
}

.fa-table td {
	padding: 9px 12px;
	border-bottom: 1px solid var(--border-light);
	color: var(--ink);
	vertical-align: top;
}

.fa-table tbody tr:last-child td {
	border-bottom: none;
}

.fa-table tbody tr:hover td {
	background: var(--bg);
}

.fa-empty {
	color: var(--subtle);
	font-size: 0.85rem;
	text-align: center;
	padding: 24px 0;
}

/* ── Full Address – expandable POI subtable ─────── */

.fa-expand-cell {
	width: 36px;
	text-align: center;
	vertical-align: middle;
	padding: 0 8px;
}

.fa-expand-btn {
	border: 1px solid var(--border);
	background: var(--bg);
	color: var(--muted);
	width: 26px;
	height: 26px;
	border-radius: 6px;
	cursor: pointer;
	font-size: 0.6rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: transform 200ms ease, border-color 150ms ease, background 150ms ease, color 150ms ease;
	transform: rotate(0deg);
	flex-shrink: 0;
}

.fa-expand-btn:hover {
	border-color: var(--accent);
	color: var(--accent-deep);
	background: var(--accent-light);
}

.fa-expand-btn.expanded {
	transform: rotate(90deg);
	border-color: var(--accent);
	color: var(--accent-deep);
	background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.fa-poi-subrow > td {
	background: var(--bg);
	padding: 10px 16px 14px;
}

.fa-subtable-wrap {
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	overflow: hidden;
}

.fa-subtable {
	margin: 0;
}

.fa-subtable th {
	background: color-mix(in srgb, var(--accent) 8%, var(--bg));
	font-size: 0.65rem;
	padding: 6px 12px;
	border-bottom-width: 1px;
}

.fa-subtable td {
	font-size: 0.8rem;
	padding: 7px 12px;
	color: var(--muted);
}

.fa-subtable tbody tr:last-child td {
	border-bottom: none;
}

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 980px) {
	body {
		padding: 20px;
	}

	.panel-row {
		grid-template-columns: 1fr;
	}

	.match-performance-panel {
		margin-bottom: 16px;
	}

	.context-group {
		padding: 12px;
	}

	.context-summary-grid {
		grid-template-columns: 1fr;
	}
}
