:root {
	--header-h: 82px;        /* synced to actual header height by JS */
	--footer-h: 0px;         /* synced to actual footer height by JS */
	--csb-w: 15px;           /* scrollbar width */
	--csb-gap: 0px;          /* gap between <main> and scrollbar */
	--csb-min-thumb: 32px;   /* minimum thumb height in px */
	--trend-csb-w: 10px;      /* metrics panel scrollbar width */
}

/* =====================================================================
   RESET + BASE
===================================================================== */
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	font-family: Arial, sans-serif;
	display: flex;
	flex-direction: column;
	align-items: center;
	height: 100vh;
	background-color: #aaa;
	overflow: hidden;
}

/* =====================================================================
	HEADER
===================================================================== */
header {
	display: flex;
	justify-content: left;
	align-items: center;
	background-color: #bbbbbb;
	color: white;
	height: 82px;
	width: 100%;
	border-bottom: 2px solid #777;
}

.logo {
	height: 100%;
	padding: 0px 10px;
	border: none;
}

nav {
	display: flex;
	justify-content: left;
	gap: 15px;
	height: 100%;
	border-left: 2px solid #777;
	border-right: 2px solid #777;
	padding: 0px 20px;
}

.nav-tagline {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 404px;
	border: none;
	color: #222;
	font-size: 20px;
	font-weight: bold;
	text-align: center;
}

/* Header quote (right side of header) */
figure {
	width: 100%;
	padding-right: 16px;
}

blockquote {
	font-size: 1.4rem;
	font-style: italic;
	padding-left: 16px;
	margin: 10px 0px;
	color: #333;
}

figcaption {
	font-size: 1.1rem;
	font-weight: bold;
	color: #666;
	text-align: right;
}

/* =====================================================================
	MAIN LAYOUT
===================================================================== */
.main-wrap {
	display: flex;
	align-items: stretch;
	width: calc(1400px + var(--csb-w) + var(--csb-gap));
	height: calc(100vh - var(--header-h) - var(--footer-h));
}

main {
	padding: 20px;
	width: 1400px;
	flex: 0 0 1400px;
	border-left: 2px solid #777;
	border-right: 2px solid #777;
	background-color: #eee;

	color: #222;

	height: 100%;
	overflow-y: auto;
	scrollbar-width: none; /* Firefox: hide native scrollbar */
}

main h2 {
	font-size: 28px;
	margin-bottom: 10px;
	text-align: left;
}

main p {
	font-size: 18px;
	line-height: 1.55;
	margin-top: 10px;
}

main ul {
	margin-top: 10px;
	margin-left: 22px;
	font-size: 18px;
	line-height: 1.55;
}

main a {
	color: #222;
	text-decoration: underline;
}

/* Chrome/Safari: hide native scrollbar */
main::-webkit-scrollbar {
	width: 0;
	height: 0;
}

/* =====================================================================
	CUSTOM SCROLLBAR
===================================================================== */
.custom-scrollbar {
	position: relative;
	height: 100%;
	margin-left: var(--csb-gap);
	width: var(--csb-w);
	flex: 0 0 var(--csb-w);
	user-select: none;
	touch-action: none;
	z-index: 1;
}

.custom-scrollbar .track {
	position: absolute;
	inset: 0;
	background: #ccc;
	border-right: 2px solid #777;
}

.custom-scrollbar .thumb {
	position: absolute;
	left: 2px;
	right: 2px;
	top: 2px;
	height: 40px;
	background: #999;
	border-radius: 6px;
	cursor: pointer;
}

.custom-scrollbar.is-hidden {
	opacity: 0;
	pointer-events: none;
}

.custom-scrollbar--thumb-only .track {
	background: transparent;
	border: none;
}

/* =====================================================================
	INTRODUCTION
===================================================================== */
.intro {
	border: 2px solid #777;
	background-color: #eee;
	padding: 16px;
	margin-bottom: 20px;
}

.intro .lede {
	font-size: 19px;
}

.intro .disclaimer {
	margin-top: 12px;
	padding-top: 12px;
	border-top: 2px solid #777;
}

.map-section {
	margin-bottom: 22px;
}

.map-help {
	margin-top: 0px;
	margin-bottom: 12px;
}

/* =====================================================================
	POST-MAP SPLIT SECTION
===================================================================== */
.map-followup {
	display: flex;
	flex-direction: row;
	align-items: stretch;
	gap: 0px;
	background-color: #eee;
	margin: 16px 0px 22px 0px;
}

.map-followup-col {
	padding: 6px 14px;
	min-width: 0;
}

.map-followup-col h3 {
	font-size: 25px;
	margin-bottom: 6px;
	text-align: center;
}

.map-followup-col p {
	font-size: 16px;
	line-height: 1.5;
}

.map-followup-col ul {
	margin-top: 8px;
	margin-left: 18px;
	font-size: 16px;
	line-height: 1.5;
	text-align: left;
}

.map-followup-usage {
	width: 380px;
	flex: 0 0 380px;
	border-right: 2px solid #777;
}

.map-followup-closer {
	flex: 1 1 auto;
	text-align: justify;
}

/* =====================================================================
	METRICS OVER TIME
===================================================================== */
.trend-section {
	margin-bottom: 22px;
}

.trend-help {
	margin-top: 0px;
	margin-bottom: 12px;
}

.trend-panel {
	width: 100%;
	height: 344px;
	display: flex;
	flex-direction: row;
	align-items: stretch;
	background-color: #ccc;
	border: 2px solid #777;
}

.trend-metrics {
	width: 168px;
	flex: 0 0 168px;
	border-right: 2px solid #777;
	background-color: #e8e8e8;
	padding: 10px 8px;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.trend-metrics-title {
	font-weight: bold;
	font-size: 17px;
	line-height: 1.2;
}

.trend-metrics-hint {
	margin: 4px 0 8px;
	font: normal 12px Arial, sans-serif;
	color: #444;
	line-height: 1.3;
}

.trend-metrics-scroll {
	display: flex;
	flex: 1 1 auto;
	align-items: stretch;
	min-height: 0;
	gap: var(--csb-gap);
	border: 2px solid #777;
}

.trend-metrics-scroll > .custom-scrollbar {
	width: var(--trend-csb-w);
	flex: 0 0 var(--trend-csb-w);
	height: 100%;
	margin-left: 0px;
	align-self: stretch;
}

.trend-metrics-scroll > .custom-scrollbar .thumb {
	left: 1px;
	right: 1px;
	border-radius: 4px;
}

.trend-metric-checks {
	display: flex;
	flex-direction: column;
	gap: 5px;
	flex: 1 1 auto;
	min-height: 0;
	min-width: 0;
	overflow-y: auto;
	scrollbar-width: none;
}

.trend-metric-checks::-webkit-scrollbar {
	width: 0;
	height: 0;
}

.trend-metric-row {
	position: relative;
}

.trend-metric-row input[type="checkbox"] {
	position: absolute;
	opacity: 0;
	width: 0;
	height: 0;
	pointer-events: none;
}

.trend-metric-chip {
	display: block;
	width: 100%;
	box-sizing: border-box;
	padding: 5px 8px;
	border: 2px solid #888;
	background: #f4f4f4;
	font: bold 13px consolas, monospace;
	color: #222;
	text-align: center;
	cursor: pointer;
	user-select: none;
	line-height: 1.2;
	transition: background-color 0.12s ease, border-color 0.12s ease;
}

.trend-metric-chip:hover {
	background: #fff;
	border-color: #555;
}

.trend-metric-row input[type="checkbox"]:checked + .trend-metric-chip {
	background: #fff;
	border-color: #222;
	box-shadow: inset 0 0 0 1px #222;
}

.trend-metric-row input[type="checkbox"]:focus-visible + .trend-metric-chip {
	outline: 2px solid #333;
	outline-offset: 2px;
}

.trend-config {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: space-between;
	width: 300px;
	flex: 0 0 300px;
	border-right: 2px solid #777;
	padding: 3px 10px;
	gap: 4px;
	font: bold 20px consolas;
}

.trend-config > .cfg-section {
	flex: 1 1 0;
	justify-content: center;
}

.trend-chart {
	flex: 1 1 auto;
	min-width: 0;
	padding: 0px;
	height: 340px;
	position: relative;
}

#trendChart {
	margin-top: 10px;
	position: absolute;
	inset: 0;
}

/* =====================================================================
	FILE EXPLORER
===================================================================== */
.file-explorer-section {
	margin-top: 22px;
}

.file-explorer-help {
	margin-top: 0;
	margin-bottom: 12px;
}

.file-explorer-panel {
	width: 100%;
	min-height: 320px;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	background-color: #ccc;
	border: 2px solid #777;
}

.file-explorer-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 3px;
	padding: 5px 8px 0;
	background-color: #ddd;
	border-bottom: 2px solid #777;
	min-height: 28px;
}

.file-explorer-tab {
	padding: 4px 9px;
	border: 1px solid var(--tab-color, #888);
	border-bottom: none;
	background: #f4f4f4;
	font: bold 12px consolas, monospace;
	color: #222;
	cursor: pointer;
	line-height: 1.15;
}

.file-explorer-tab:hover {
	background: #fff;
	filter: brightness(0.97);
}

.file-explorer-tab.is-active {
	background: color-mix(in srgb, var(--tab-color, #fff) 18%, #fff);
	border-color: var(--tab-color, #222);
	box-shadow: inset 0 -2px 0 var(--tab-color, #222);
	color: #111;
	position: relative;
	top: 1px;
	padding-bottom: 5px;
}

.file-explorer-preview {
	flex: 1 1 auto;
	min-height: 120px;
	overflow: visible;
	background-color: #eee;
	padding: 8px 10px;
	font: 12px consolas, monospace;
}

.file-explorer-preview--csv {
	min-height: 280px;
	max-height: 480px;
	overflow: hidden;
	padding: 0;
	display: flex;
	flex-direction: column;
}

.file-explorer-preview--code {
	min-height: 280px;
	max-height: 640px;
	overflow: hidden;
	padding: 0;
	display: flex;
	flex-direction: column;
}

.file-explorer-code-wrap {
	flex: 1 1 auto;
	min-height: 0;
	overflow: auto;
	padding: 8px 10px;
}

.file-explorer-csv-wrap {
	flex: 1 1 auto;
	min-height: 0;
	overflow: auto;
}

.file-explorer-csv-table {
	border-collapse: collapse;
	width: max-content;
	min-width: 100%;
	font: 11px consolas, monospace;
}

.file-explorer-csv-table th {
	position: sticky;
	top: 0;
	z-index: 1;
	padding: 5px 8px;
	color: #fff;
	font-weight: 700;
	text-align: left;
	border: 1px solid rgba(0, 0, 0, 0.15);
	white-space: nowrap;
}

.file-explorer-csv-table td {
	padding: 3px 8px;
	border: 1px solid #ccc;
	border-left-width: 3px;
	background: #fff;
	white-space: nowrap;
	max-width: 280px;
	overflow: hidden;
	text-overflow: ellipsis;
}

.file-explorer-csv-table tbody tr:nth-child(even) td {
	background: #f8f8f8;
}

.file-explorer-csv-pager {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 6px 10px;
	border-top: 2px solid #777;
	background: #ddd;
	flex: 0 0 auto;
}

.file-explorer-csv-pager-info {
	font: normal 12px Arial, sans-serif;
	color: #333;
}

.file-explorer-csv-pager-btn {
	padding: 4px 10px;
	border: 1px solid #777;
	background: #f4f4f4;
	font: bold 12px consolas, monospace;
	cursor: pointer;
}

.file-explorer-csv-pager-btn:hover:not(:disabled) {
	background: #fff;
}

.file-explorer-csv-pager-btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.file-explorer-empty {
	margin: 0;
	color: #555;
	font: normal 13px Arial, sans-serif;
}

.file-explorer-code {
	margin: 0;
	white-space: pre;
	tab-size: 4;
	font: 12px consolas, monospace;
	line-height: 1.4;
}

.file-explorer-code-line {
	min-height: 1.4em;
}

.file-explorer-comment {
	color: #2f6b2f;
	background: #e8f3e8;
	border-radius: 2px;
	padding: 0 2px;
}

.file-explorer-comment--section {
	color: #1a4f7a;
	background: #dceaf8;
	font-weight: 700;
}

.file-explorer-code-text {
	color: #222;
}

.file-json-tree {
	margin: 0;
}

.file-json-node {
	border: 1px solid #999;
	background-color: #ddd;
	margin-top: 3px;
	border-radius: 2px;
}

.file-json-node--root {
	margin-top: 0;
}

.file-json-node > summary {
	cursor: pointer;
	font-weight: 600;
	font-size: 12px;
	padding: 3px 8px;
	line-height: 1.25;
	list-style: none;
	user-select: none;
}

.file-json-node > summary::-webkit-details-marker {
	display: none;
}

.file-json-node > summary::before {
	content: "▸ ";
	color: #555;
	font-size: 10px;
}

.file-json-node[open] > summary::before {
	content: "▾ ";
}

.file-json-node-body {
	padding: 2px 6px 5px 10px;
	background-color: #eee;
	border-top: 1px solid #bbb;
}

.file-json-node-body .file-json-node {
	margin-left: 4px;
}

.file-json-leaf {
	padding: 1px 0;
	line-height: 1.3;
	font-size: 11px;
	word-break: break-word;
}

.file-json-key {
	font-weight: 600;
	color: #333;
}

.file-json-null {
	color: #888;
	font-style: italic;
}

.details-section {
	border-top: 2px solid #777;
	padding-top: 18px;
	margin-top: 18px;
}

details {
	border: 2px solid #777;
	background-color: #ccc;
	padding: 10px 12px;
	margin-top: 12px;
}

summary {
	cursor: pointer;
	font-weight: bold;
	font-size: 18px;
}

details .detail-body {
	margin-top: 10px;
	background-color: #eee;
	border: 2px solid #777;
	padding: 2px 12px 12px 12px;
}

details .detail-body h4 {
	margin: 16px 0 6px;
	font-size: 16px;
}

details .detail-body h4:first-child {
	margin-top: 8px;
}

details .detail-body code {
	font: 12px consolas, monospace;
	background: #ddd;
	padding: 1px 4px;
	border: 1px solid #aaa;
}

details .detail-body ul li {
	margin-bottom: 8px;
}

.credits-disclosure {
	border: 2px solid #777;
	background-color: #ccc;
	padding: 10px 12px;
	margin-top: 12px;
}

.credits-disclosure h3 {
	margin: 0;
	font-size: 18px;
	font-weight: bold;
}

.credits-disclosure-body {
	margin-top: 10px;
	background-color: #eee;
	border: 2px solid #777;
	padding: 2px 12px 12px 12px;
}

.credits-disclosure-body p {
	margin: 10px 0 0;
	line-height: 1.45;
}

.credits-disclosure-body p:first-child {
	margin-top: 8px;
}

.data-source-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.data-source-item {
	margin-bottom: 16px;
	padding-bottom: 14px;
	border-bottom: 1px solid #bbb;
}

.data-source-item:last-child {
	margin-bottom: 0;
	padding-bottom: 0;
	border-bottom: none;
}

.data-source-name {
	font-weight: bold;
	font-size: 15px;
	margin-bottom: 4px;
}

.data-source-desc {
	margin: 0 0 8px;
	line-height: 1.45;
}

.data-source-meta {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 14px;
	line-height: 1.4;
}

.data-source-label {
	font-weight: bold;
	color: #333;
}

.data-source-download {
	padding: 2px 8px;
	border: 1px solid #777;
	background: #f4f4f4;
	font: bold 12px consolas, monospace;
	color: #222;
	cursor: pointer;
	vertical-align: baseline;
}

.data-source-download:hover:not(:disabled) {
	background: #fff;
	border-color: #555;
}

.data-source-download:disabled {
	opacity: 0.65;
	cursor: wait;
}

.data-source-download-row {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 6px;
}

.data-source-file-size {
	font: normal 12px Arial, sans-serif;
	color: #555;
}

.data-source-site-license-title {
	margin: 20px 0 8px;
	font-size: 16px;
}

/* =====================================================================
	MAP + SETTINGS PANEL
===================================================================== */
.map-settings {
	width: 100%;
	display: flex;
	flex-direction: column;
	background-color: #ccc;
	border: 2px solid #777;
}

.map-top {
	display: flex;
	flex-direction: row;
	align-items: stretch;
	width: 100%;
}

/* Config sidebar */
.msettings {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	width: 300px;
	border-right: 2px solid #777;
	padding: 3px 10px;
	gap: 5px;
	font: bold 20px consolas;
}

/* Generic config block wraps a title + control(s) */
.cfg-section {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-top: 0px;
}

/* Section header row: title on left, optional note on right */
.cfg-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 3px;
	flex-wrap: wrap;
}

.cfg-title {
	font-weight: bold;
	font-size: 18px;
}

.cfg-note {
	font: normal 14px Arial, sans-serif;
	color: #333;
	text-align: right;
}

/* Year dropdown */
.cfg-select {
	width: 100%;
	padding: 0px 10px;
	border: 2px solid #777;
	background: #eee;
	font: bold 16px consolas;
}

/* inputs are visually hidden, labels act as buttons */
.metric-group {
	display: flex;
	gap: 5px;
	flex-wrap: wrap;
}

.metric-group input[type="radio"] {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.metric-group label {
	padding: 0px 4px;
	border: 2px solid #777;
	background: #aaa;
	cursor: pointer;
	user-select: none;
}

.metric-group input[type="radio"]:checked + label {
	background: #888;
	color: #222;
}

.metric-egb {
	display: flex;
	font: bold 16px consolas;
	width: 136px;
	align-items: center;
	justify-content: center;
	text-align: center;
}

/* Description shown below the active metric selection */
.metric-note {
	display: flex;
	align-items: center;
	height: 48px;
	font: normal 14px Arial, sans-serif;
	color: #333;
	padding: 0px 5px;
	margin-top: 5px;
	border-left: 2px solid #777;
}

/* Static index legend (red -> white) */
.cfg-index-section {
	gap: 2px;
}

.cfg-index-bar {
	width: 100%;
	height: 16px;
	border: 2px solid #777;
	background: linear-gradient(to right, #cc3232 0%, #ffffff 100%);
}

.cfg-index-labels {
	display: grid;
	grid-template-columns: 1fr 1fr 1fr;
	font: normal 14px Arial, sans-serif;
	color: #333;
	padding: 0px 2px;
}

.cfg-index-labels span:nth-child(1) { text-align: left; }
.cfg-index-labels span:nth-child(2) { text-align: center; }
.cfg-index-labels span:nth-child(3) { text-align: right; }

/* Options checkboxes */
.opt-row {
	display: grid;
	grid-template-columns: 24px 1fr;
	align-items: start;
	gap: 0px;
}

.opt-row input[type="checkbox"] {
	justify-self: center;
	align-self: start;
	margin-top: 4px;
	margin-right: 12px;
}

.opt-label {
	font: bold 17px consolas;
}

.opt-help {
	font: normal 14px Arial, sans-serif;
	color: #333;
}

.cfg-warnings {
	margin-top: 8px; 
	border-top: 2px solid #777;
	padding-top: 10px;
	text-align: justify;
	width: 100%;
}

.cfg-dl-csv {
    transition: ease 0.2s;
    width: 100%;
    height: 26px;
    margin-top: 1px;
    font: bold 17px consolas;
	padding: 0px 4px;
	border: 2px solid #777;
	background: #aaa;
	cursor: pointer;
	user-select: none;
}

.cfg-dl-csv:hover {
    transition: ease 0.2s;
    background: #888;
}

.cfg-dl-csv:active {
    transition: ease 0.2s;
    transform: translateY(2px);
}

/* Plotly map container fills remaining width after .msettings */
#map {
	height: 550px;
	flex: 1 1 auto;
	min-width: 0;
	background: #cfe8ff;
}

.metric-info-box {
	border-top: 2px solid #777;
	background: #cfe8ff;
	padding: 10px 12px;
	font: normal 14px Arial, sans-serif;
	color: #333;
}

.metric-info-title {
	font-weight: bold;
	font-size: 16px;
	margin-bottom: 4px;
}

.metric-info-body {
	font: normal 14px Arial, sans-serif;
}

.metric-info-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
}

.metric-info-card {
	border: 2px solid #777;
	background: #eee;
	padding: 10px 12px;
}

.metric-info-card-title {
	font-weight: bold;
	font-size: 16px;
	margin-bottom: 4px;
}

.metric-info-card-desc {
	font: normal 14px Arial, sans-serif;
}

.metric-info-card-block {
	margin-top: 8px;
	padding-top: 8px;
	border-top: 1px solid #777;
}

.metric-info-card-subhead {
	font-weight: bold;
	font-size: 13px;
	margin-bottom: 4px;
}

.metric-info-card-formula {
	display: block;
	width: 100%;
	padding: 6px 8px;
	border: 1px solid #777;
	background: #ccc;
	font: normal 13px consolas;
	white-space: pre-wrap;
}

.metric-info-card-list {
	margin: 0px 0px 0px 18px;
	font: normal 14px Arial, sans-serif;
	line-height: 1.45;
}

.tablecon {
	border-top: 2px solid #777;
	overflow-x: auto;
}

/* Scores table (rendered inside #table by JS) */
#table table {
	width: 100%;
	border-collapse: collapse;
	background: #eee;
	font: normal 14px Arial, sans-serif;
}

#table thead th {
	position: sticky;
	top: 0;
	background: #ccc;
	border-bottom: 2px solid #777;
    border-right: 1px solid #777;
	padding: 6px 5px;
	text-align: center;
}

/* Clickable sort headers (label + arrow) */
#table thead th .sort-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0px;
	width: 100%;
	background: transparent;
	border: none;
	padding: 0;
	margin: 0;
	font: inherit;
	color: inherit;
	cursor: pointer;
}

#table thead th .sort-arrow {
	width: 1em;
	text-align: center;
}

#table tbody td {
	padding: 6px 8px;
	border-top: 1px solid #777;
    border-right: 1px solid #777;
	white-space: nowrap;
}

#table thead th:last-child,
#table tbody td:last-child {
	border-right: none;
}

/* Rank */
#table td:nth-child(1) {
	text-align: right;
	width: 52px;
}

/* State */
#table td:nth-child(2) {
	text-align: left;
	font-weight: bold;
}

/* Metrics */
#table td:nth-child(n+3) {
	text-align: right;
    max-width: 120px;
}

/* =====================================================================
	TABLE ROW COLORING
===================================================================== */

/* National table: alternate red / blue rows */
#table table.table-national tbody tr:nth-child(odd)  { background-color: rgba(255, 214, 214, 0.5); }
#table table.table-national tbody tr:nth-child(even) { background-color: rgba(207, 232, 255, 0.5); }

/* State (district) table: color rows by district winner */
#table table.table-districts tbody tr.row-dem { background: #cfe8ff; }
#table table.table-districts tbody tr.row-rep { background: #ffd6d6; }
#table table.table-districts tbody tr.row-tie,
#table table.table-districts tbody tr.row-unknown { background: #eee; }

/* =====================================================================
   FOOTER
===================================================================== */
footer {
	text-align: center;
	padding: 15px;
	background-color: #888;
	color: white;
	width: 100%;
	border-top: 3px solid #333;
	position: fixed;
	bottom: 0;
}

footer a { color: white; }