/* =========================================================
   Vermont Population Projections
   UVM Brand Colors: Forest #154734 | Green #007A33 | Gold #FFC72C
   ========================================================= */

/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --forest:      #154734;
  --green:       #007A33;
  --gold:        #FFC72C;
  --gold-dark:   #e0a800;
  --green-tint:  #eaf3ee;
  --gray-50:     #fafafa;
  --gray-100:    #f4f5f4;
  --gray-200:    #e4e7e4;
  --gray-400:    #9ba59b;
  --gray-600:    #546054;
  --gray-800:    #1e221e;
  --white:       #ffffff;
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:   0 4px 20px rgba(0,0,0,0.10);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.12);
  --radius:      4px;
  --radius-lg:   8px;
  --nav-h:       62px;
  --max-w:       1240px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--gray-800);
  background: var(--gray-100);
}

/* ── Nav ─────────────────────────────────────────────────── */
#site-nav {
  position: sticky;
  top: 0;
  z-index: 2000;
  background: var(--forest);
  height: var(--nav-h);
  border-bottom: 4px solid var(--gold);
  box-shadow: var(--shadow-lg);
}
.nav-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 2rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--white);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.nav-links { display: flex; gap: 0.15rem; }
.nav-links a {
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover {
  background: rgba(255,255,255,0.12);
  color: var(--white);
}

/* ── Hero / About Header ─────────────────────────────────── */
#about {
  background: var(--white);
  padding: 0 0 3rem;
}
.about-hero {
  background: var(--forest);
  padding: 3rem 2rem;
  margin-bottom: 2.5rem;
}
.about-hero-inner {
  max-width: var(--max-w);
  margin: 0 auto;
}
.about-hero h1 {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 0.35rem;
  letter-spacing: -0.01em;
}
.about-hero .subtitle {
  color: rgba(255,255,255,0.72);
  font-size: 0.95rem;
  margin-bottom: 1.4rem;
}
.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.3rem;
  background: var(--gold);
  color: var(--forest);
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}
.btn-download:hover {
  background: var(--gold-dark);
  box-shadow: 0 3px 10px rgba(0,0,0,0.22);
}

/* ── Sections ────────────────────────────────────────────── */
section { padding: 3rem 0; }
section:nth-child(even) { background: var(--gray-50); }

.section-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 2rem;
}

h2 {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--forest);
  margin-bottom: 0.4rem;
  letter-spacing: -0.01em;
  padding-bottom: 0.6rem;
  border-bottom: 3px solid var(--gold);
  display: inline-block;
}
h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--forest);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.section-desc {
  color: var(--gray-600);
  margin: 0.75rem 0 1.5rem;
  font-size: 0.9rem;
  max-width: 680px;
}

/* ── About Grid ──────────────────────────────────────────── */
.about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.25rem;
}
.about-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--gold);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.15s;
}
.about-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.about-card p { color: var(--gray-800); margin-bottom: 0.6rem; font-size: 0.9rem; }
.about-card p:last-child { margin-bottom: 0; }
.about-card ul { padding-left: 1.2rem; }
.about-card li { font-size: 0.9rem; margin-bottom: 0.3rem; color: var(--gray-800); }

/* ── Controls ────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  align-items: center;
  padding: 0.9rem 1.1rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.control-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.control-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.btn-group { display: flex; }
.toggle-btn {
  background: var(--white);
  border: 1px solid var(--gray-400);
  padding: 0.38rem 1rem;
  cursor: pointer;
  font-size: 0.84rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--gray-800);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  line-height: 1.3;
}
.toggle-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.toggle-btn:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.toggle-btn:only-child  { border-radius: var(--radius); }
.toggle-btn.active {
  background: var(--forest);
  color: var(--white);
  border-color: var(--forest);
  z-index: 1;
}
.toggle-btn:hover:not(.active) { background: var(--green-tint); border-color: var(--green); }
.btn-hint { font-size: 0.74rem; opacity: 0.75; font-weight: 400; }

/* ── County Layout ───────────────────────────────────────── */
#county-layout {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}
#county-map {
  flex: 3;
  height: 700px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  background: #dde8e2;
  min-width: 0;
}
#county-panel {
  flex: 2;
  height: 700px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
#county-panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--gray-200);
  background: var(--forest);
  flex-shrink: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.panel-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--white);
  text-transform: none;
  letter-spacing: 0;
}
#close-panel {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  line-height: 1;
  padding: 0 0.2rem;
  transition: color 0.12s;
}
#close-panel:hover { color: var(--white); }

.panel-view-toggle {
  display: flex;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
  background: var(--gray-50);
}
.view-btn {
  background: var(--white);
  border: 1px solid var(--gray-400);
  padding: 0.3rem 0.85rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--gray-800);
  transition: background 0.12s;
}
.view-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.view-btn:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.view-btn.active { background: var(--forest); color: var(--white); border-color: var(--forest); }
.view-btn:hover:not(.active) { background: var(--green-tint); border-color: var(--green); }

#panel-chart-container {
  flex: 1;
  padding: 0.75rem;
  overflow: hidden;
  position: relative;
}
#panel-chart-container canvas {
  position: absolute;
  inset: 0.75rem;
}

#panel-table-container {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
#county-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
#county-table thead th {
  position: sticky;
  top: 0;
  background: var(--forest);
  color: rgba(255,255,255,0.85);
  border-bottom: 2px solid var(--gold);
  padding: 0.55rem 0.75rem;
  text-align: right;
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#county-table thead th:first-child { text-align: left; }
#county-table tbody td {
  padding: 0.42rem 0.75rem;
  border-bottom: 1px solid var(--gray-200);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
#county-table tbody td:first-child { text-align: left; font-weight: 600; }
#county-table tbody tr:last-child td {
  font-weight: 700;
  background: var(--green-tint);
  border-top: 2px solid var(--gray-200);
}
#county-table tbody tr:hover td { background: var(--green-tint); }
.pct-pos { color: #1a6b3a; font-weight: 600; }
.pct-neg { color: #b91c1c; font-weight: 600; }

.empty-state {
  margin-top: 1rem;
  padding: 1.25rem;
  background: var(--white);
  border: 1px dashed var(--gray-400);
  border-radius: var(--radius-lg);
  color: var(--gray-600);
  font-size: 0.9rem;
  text-align: center;
}
#county-empty-state { display: none; }

/* ── Town Map ─────────────────────────────────────────────── */
#town-map {
  height: 650px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  background: #dde8e2;
}

/* ── Leaflet popup ───────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  border-top: 3px solid var(--gold) !important;
  padding: 0 !important;
}
.leaflet-popup-content {
  margin: 0.75rem 1rem !important;
  font-family: 'Source Sans 3', 'Segoe UI', system-ui, sans-serif !important;
  font-size: 0.88rem !important;
}
.leaflet-popup-content strong {
  font-size: 0.98rem;
  color: var(--forest);
  display: block;
  margin-bottom: 0.1rem;
}
.popup-table {
  border-collapse: collapse;
  font-size: 0.84rem;
  margin-top: 0.4rem;
  width: 100%;
}
.popup-table td {
  padding: 0.22rem 0.4rem;
  border-bottom: 1px solid var(--gray-200);
  font-variant-numeric: tabular-nums;
}
.popup-table td:first-child { color: var(--gray-600); }
.popup-table td:last-child { font-weight: 600; text-align: right; color: var(--gray-800); }
.popup-table .pct-pos { color: #1a6b3a; }
.popup-table .pct-neg { color: #b91c1c; }
.popup-county {
  font-size: 0.78rem;
  color: var(--gray-600);
  margin-bottom: 0.35rem;
  font-style: italic;
}

/* ── Leaflet Legend ──────────────────────────────────────── */
.legend {
  background: var(--white);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border-top: 3px solid var(--gold);
  line-height: 1.45;
  font-size: 0.78rem;
  color: var(--gray-800);
  min-width: 115px;
  font-family: 'Source Sans 3', system-ui, sans-serif;
}
.legend-title {
  font-weight: 700;
  font-size: 0.74rem;
  margin-bottom: 0.45rem;
  color: var(--forest);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.22rem;
}
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}
.legend-no-data {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--gray-200);
}

/* ── Summary Section ─────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.summary-stat {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-top: 4px solid var(--gold);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.summary-stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--forest);
  line-height: 1.1;
  margin-bottom: 0.2rem;
}
.summary-stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.2rem;
}
.summary-stat-sub { font-size: 0.82rem; color: var(--gray-600); }

.summary-tables {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}
.summary-table-block {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.summary-table-block h3 {
  background: var(--forest);
  color: var(--white);
  padding: 0.6rem 0.9rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 3px solid var(--gold);
}
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.summary-table thead th {
  background: var(--gray-100);
  padding: 0.4rem 0.75rem;
  text-align: left;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200);
}
.summary-table thead th:not(:first-child) { text-align: right; }
.summary-table tbody td {
  padding: 0.38rem 0.75rem;
  border-bottom: 1px solid var(--gray-200);
  font-variant-numeric: tabular-nums;
}
.summary-table tbody td:not(:first-child) { text-align: right; }
.summary-table tbody tr:last-child td { border-bottom: none; }
.summary-table tbody tr:hover td { background: var(--green-tint); }

/* ── Footer ──────────────────────────────────────────────── */
#site-footer {
  background: var(--forest);
  border-top: 4px solid var(--gold);
  color: rgba(255,255,255,0.6);
  padding: 1.75rem 0;
  font-size: 0.82rem;
}
#site-footer p { line-height: 1.6; }

/* ── Utilities ───────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 800px) {
  .about-hero h1 { font-size: 1.55rem; }
  h2             { font-size: 1.25rem; }

  #county-layout  { flex-direction: column; }
  #county-map     { flex: none; height: 380px; width: 100%; }
  #county-panel   { flex: none; height: 500px; width: 100%; }

  .nav-title      { font-size: 0.85rem; }
  .btn-hint       { display: none; }
  .about-grid     { grid-template-columns: 1fr; }
  .controls       { gap: 0.85rem; }
}
