:root {
  --color-bg: #ffffff;
  --color-bg-alt: #f8f9fa;
  --color-bg-highlight: #fff9e6;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-accent: #1a5276;
  --color-border: #dee2e6;
  --color-link: #0d6efd;
  --color-link-hover: #0a58ca;
  --color-heatmap-0: #f0f0f0;
  --color-heatmap-low: #c6dbef;
  --color-heatmap-mid: #6baed6;
  --color-heatmap-high: #08519c;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Header / Nav */
.site-header {
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.main-nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.nav-brand {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--color-accent);
  text-decoration: none;
  margin-right: auto;
}

.nav-brand:hover {
  color: var(--color-link-hover);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-link {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--color-text);
  transition: background 0.15s;
}

.nav-link:hover {
  background: var(--color-bg-alt);
  text-decoration: none;
}

.nav-muted {
  color: var(--color-text-muted);
}

.nav-sep {
  width: 1px;
  height: 1rem;
  background: var(--color-border);
  margin: 0 0.25rem;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 2rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Page Header */
.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--color-border);
}

.page-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--color-accent);
}

.page-header .subtitle {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 1rem;
}

/* Info Sections */
.info-section {
  margin-bottom: 2.5rem;
}

.info-section h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.5rem;
}

.info-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
}

.info-section p {
  margin: 0 0 0.75rem;
}

.info-section ul, .info-section ol {
  margin: 0 0 0.75rem;
  padding-left: 1.5rem;
}

.info-section li {
  margin-bottom: 0.35rem;
}

/* Hero Section */
.hero {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2.5rem;
  text-align: center;
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  color: var(--color-accent);
}

.hero .tagline {
  margin: 0 0 0.5rem;
  color: var(--color-text-muted);
  font-size: 1.1rem;
}

.hero .stats {
  margin: 1rem 0;
  display: flex;
  justify-content: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.hero .stat {
  text-align: center;
}

.hero .stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-accent);
}

.hero .stat-label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.hero .version {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Download Buttons */
.download-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  background: var(--color-accent);
  color: #fff;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.15s;
}

.download-btn:hover {
  background: var(--color-link-hover);
  color: #fff;
  text-decoration: none;
}

.download-btn .icon {
  font-size: 1.1rem;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--color-bg-alt);
  border-bottom: 2px solid var(--color-border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

tbody td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--color-bg-alt);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Sticky first column for balance sheet tables */
.bs-table th:first-child,
.bs-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--color-bg);
  border-right: 2px solid var(--color-border);
  font-weight: 600;
}

.bs-table thead th:first-child {
  z-index: 3;
  background: var(--color-bg-alt);
}

/* Highlighted rows for is_filled_in */
.bs-table tr.filled-in {
  background: var(--color-bg-highlight);
}

.bs-table tr.filled-in td:first-child {
  background: var(--color-bg-highlight);
}

.bs-table tr.filled-in:hover {
  background: #fff3cd;
}

.bs-table tr.filled-in:hover td:first-child {
  background: #fff3cd;
}

/* Numeric values right-aligned */
.bs-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* State Grid */
.state-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.state-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.state-card:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  text-decoration: none;
}

.state-card .state-name {
  font-weight: 600;
  color: var(--color-accent);
}

.state-card .state-count {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Navigation Row */
.nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.nav-row a {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-row .nav-placeholder {
  visibility: hidden;
}

/* Bank Info */
.bank-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem 2rem;
  margin: 1rem 0 1.5rem;
  font-size: 0.9rem;
}

.bank-meta dt {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bank-meta dd {
  margin: 0 0 0.5rem;
  font-weight: 500;
}

/* Footnotes */
.footnote {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* Citation Block */
.citation-block {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 1rem;
  margin: 0.75rem 0;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s;
}

.citation-block:hover {
  border-color: var(--color-accent);
}

.citation-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.bibtex-block .citation-text {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
}

.copy-hint {
  display: block;
  text-align: right;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
}

.copy-hint.copied {
  color: #198754;
  font-weight: 600;
}

/* Version Table */
.version-table {
  font-size: 0.85rem;
}

.version-table th {
  white-space: nowrap;
}

.version-table td:first-child {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: nowrap;
}

.version-table td:nth-child(2) {
  white-space: nowrap;
}

/* Variable Definition Table (narrow first column) */
.vardef-table {
  font-size: 0.85rem;
}

.vardef-table td:first-child {
  width: 1%;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* NIC-only rows (bs_merge=1, no balance sheet data) */
.bs-table tr.nic-only {
  background: #f0f0f0;
}

.bs-table tr.nic-only td:first-child {
  background: #f0f0f0;
}

.bs-table tr.nic-only:hover {
  background: #e8e8e8;
}

.bs-table tr.nic-only:hover td:first-child {
  background: #e8e8e8;
}

/* Variable Heatmap */
.heatmap-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}

.heatmap-controls button {
  padding: 0.4rem 1rem;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.heatmap-controls button:hover {
  background: var(--color-link-hover);
}

.heatmap-controls input[type="range"] {
  flex: 1;
  min-width: 200px;
}

.heatmap-year-label {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-accent);
  min-width: 3rem;
}

.heatmap-container {
  overflow-x: auto;
  margin: 1rem 0;
}

.heatmap-grid {
  display: grid;
  gap: 1px;
  background: var(--color-border);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.65rem;
}

.heatmap-cell {
  padding: 3px 4px;
  text-align: center;
  min-width: 28px;
  cursor: default;
  transition: opacity 0.2s;
}

.heatmap-header {
  background: var(--color-bg-alt);
  font-weight: 600;
  font-size: 0.7rem;
  white-space: nowrap;
  padding: 4px 6px;
}

.heatmap-row-label {
  background: var(--color-bg);
  text-align: left;
  font-weight: 500;
  white-space: nowrap;
  padding: 3px 8px;
  position: sticky;
  left: 0;
  z-index: 1;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.heatmap-legend-gradient {
  width: 120px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid var(--color-border);
}

/* Tooltip */
.tooltip {
  position: fixed;
  background: var(--color-text);
  color: #fff;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .main-nav {
    padding: 0.75rem 1rem;
  }

  .hero {
    padding: 1.5rem 1rem;
  }

  .hero .stats {
    gap: 1rem;
  }

  .bank-meta {
    grid-template-columns: 1fr;
  }

  .state-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

@media (max-width: 480px) {
  .nav-links {
    gap: 0.25rem;
  }

  .nav-sep {
    display: none;
  }

  .download-links {
    flex-direction: column;
    align-items: stretch;
  }

  .download-btn {
    justify-content: center;
  }
}

/* Print */
@media print {
  .site-header,
  .site-footer,
  .nav-row,
  .heatmap-controls {
    display: none;
  }

  .container {
    max-width: none;
    padding: 0;
  }

  .table-wrapper {
    overflow: visible;
  }

  .bs-table th:first-child,
  .bs-table td:first-child {
    position: static;
  }
}
