:root {
  --bg: #fafaf8;
  --fg: #1a1a1a;
  --muted: #666;
  --line: #ddd;
  --accent: #c2410c;
  --accent-soft: #fed7aa;
  --covid-band: rgba(150, 150, 160, 0.18);
  --bar-bg: #e2e8f0;
  --notice-bg: #fef3c7;
  --notice-border: #fbbf24;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  font-size: 16px;
}

header {
  padding: 24px 32px 0 32px;
  border-bottom: 1px solid var(--line);
  background: white;
}
header h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.5px; }
.subhead { color: var(--muted); margin: 4px 0 16px 0; font-size: 14px; }

nav { display: flex; gap: 0; margin-top: 8px; }
.tab {
  background: none; border: none; padding: 10px 18px; font-size: 15px;
  cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted);
  font-family: inherit;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 24px 32px 80px 32px; max-width: 1300px; }
.panel { display: none; }
.panel.active { display: block; }
.panel h2 { margin: 36px 0 8px 0; font-size: 20px; font-weight: 600; }
.panel h2:first-child { margin-top: 8px; }

.caption {
  color: var(--muted); font-size: 14px; margin: 0 0 12px 0; max-width: 720px;
}
.caption.notice {
  background: var(--notice-bg);
  border-left: 3px solid var(--notice-border);
  padding: 12px 16px;
  border-radius: 0 4px 4px 0;
  color: #422;
  font-size: 14.5px;
  max-width: none;
}

.filter-bar {
  background: white;
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 8px;
  display: flex;
  gap: 24px;
  align-items: center;
}
.filter-bar label { font-size: 14px; }
.filter-bar select { font-size: 14px; padding: 4px 8px; }

.sort-row { margin: 8px 0; font-size: 14px; }
.sort-row select { font-size: 14px; padding: 4px 8px; }

.chart { width: 100%; height: 420px; margin-bottom: 16px; }
.chart.small { height: 260px; }
.chart.tall { height: 1400px; }

#map { width: 100%; height: 600px; border: 1px solid var(--line); }
.map-controls {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  background: white; padding: 12px 16px; border: 1px solid var(--line);
  border-bottom: none;
}
.map-controls label { font-size: 14px; }
.map-controls .meta { color: var(--muted); margin-left: auto; font-size: 13px; }

table#nycha-table, table#nta-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin: 8px 0 24px 0;
  background: white;
  border: 1px solid var(--line);
}
#nycha-table th, #nycha-table td, #nta-table th, #nta-table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
#nycha-table th, #nta-table th {
  background: #f5f5f3;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}
#nycha-table th.sorted-desc::after, #nta-table th.sorted-desc::after { content: " ↓"; color: var(--accent); }
#nycha-table th.sorted-asc::after,  #nta-table th.sorted-asc::after  { content: " ↑"; color: var(--accent); }
#nycha-table td.num, #nta-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
#nycha-table tr.hot td, #nta-table tr.hot td { background: #fef3c7; }
#nycha-table tr.very-hot td, #nta-table tr.very-hot td { background: var(--accent-soft); }
#nycha-table svg { vertical-align: middle; }

/* Precinct table */
.precinct-table-wrap {
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--line);
  background: white;
  margin-bottom: 24px;
}
#precinct-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  width: max-content;
}
#precinct-table th {
  position: sticky;
  top: 0;
  background: #f5f5f3;
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid #999;
  text-align: left;
  white-space: nowrap;
  z-index: 2;
}
#precinct-table th.sortable { cursor: pointer; user-select: none; }
#precinct-table th.sortable:hover { background: #ebebe7; }
#precinct-table th.sorted-desc::after { content: " ↓"; color: var(--accent); }
#precinct-table th.sorted-asc::after  { content: " ↑"; color: var(--accent); }
#precinct-table th.num, #precinct-table td.num { text-align: right; }
#precinct-table td {
  padding: 4px 8px;
  border-bottom: 1px solid #f0f0ec;
}
#precinct-table tr:hover td { outline: 1px solid #888; }
#precinct-table td.zero { color: #c8c8c8; }
#precinct-table td.boro-divider {
  background: #1a1a1a;
  color: white;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 10px;
  text-transform: capitalize;
  position: sticky;
  left: 0;
}

/* NTA & NYCHA table clickable cell styling */
#nta-table a { color: var(--accent); text-decoration: none; }
#nta-table a:hover { text-decoration: underline; }
#nta-table a.subtle { color: var(--fg); }
#nta-table a.subtle:hover { color: var(--accent); }

/* Map NTA filter banner */
.map-banner {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  border-bottom: none;
  padding: 8px 16px;
  font-size: 14px;
}
.map-banner button {
  margin-left: 12px;
  background: white;
  border: 1px solid #999;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 8px;
}

/* Segmented control (NYT-dashboard pattern) */
.seg {
  display: inline-flex;
  border: 1px solid #ccc;
  border-radius: 3px;
  overflow: hidden;
  font-size: 13px;
  margin-left: 4px;
}
.seg button {
  padding: 4px 12px;
  border: none;
  border-right: 1px solid #ccc;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  background: white;
  color: #555;
}
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent); color: white; }
.seg button:hover:not(.on) { background: #f0ede6; }

#unit-explainer { color: var(--muted); font-size: 13px; }

/* Side-by-side NTA table + map */
.nta-explorer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}
.nta-explorer-table {
  max-height: 600px;
  overflow: auto;
  border: 1px solid var(--line);
  background: white;
}
.nta-explorer-table table { margin: 0; border: none; }
.nta-explorer-table th { position: sticky; top: 0; z-index: 2; }
.nta-explorer-map {
  position: sticky;
  top: 12px;
}
.nta-explorer-map #map { height: 600px; }

@media (max-width: 980px) {
  .nta-explorer { grid-template-columns: 1fr; }
  .nta-explorer-map { position: static; }
  .nta-explorer-map #map { height: 400px; }
}

#sources { font-size: 14px; padding-left: 20px; }
#sources li { margin-bottom: 4px; }

#build-info { font-size: 13.5px; color: var(--muted); }

@media (max-width: 720px) {
  main { padding: 16px; }
  header { padding: 16px 16px 0 16px; }
  .chart { height: 320px; }
  .chart.tall { height: 1100px; }
  .filter-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .map-controls { flex-direction: column; align-items: flex-start; }
}
