/* NH Election Results - Newspaper Style */

/* Accessibility */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: #1e3a5f;
  color: white;
  padding: 0.5rem 1rem;
  z-index: 10000;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  top: 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  /* Muted Party Colors */
  --republican: #8b0000;
  --republican-light: #a52a2a;
  --republican-bg: #fef7f7;
  --democrat: #1e3a5f;
  --democrat-light: #2c5282;
  --democrat-bg: #f7fafc;

  /* Text */
  --text: #111;
  --text-muted: #555;
  --text-light: #777;

  /* Backgrounds & Borders */
  --bg: #fff;
  --bg-alt: #f9f9f9;
  --border: #ddd;
  --border-dark: #999;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

/* Typography */
h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: normal;
  line-height: 1.2;
}

h1 {
  font-size: 2rem;
  margin-bottom: 0.25rem;
}

h2 {
  font-size: 1.4rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--text);
}

h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

a {
  color: var(--democrat);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  margin-bottom: 2rem;
}

header .container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title {
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-weight: normal;
  color: var(--text);
  text-decoration: none;
}

.site-title:hover {
  text-decoration: none;
}

/* Header Search */
.header-search {
  position: relative;
  width: 250px;
}

.header-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
}

.header-search input:focus {
  outline: none;
  border-color: var(--democrat);
}

.search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  z-index: 1000;
}

.search-dropdown a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.search-dropdown a:last-child {
  border-bottom: none;
}

.search-dropdown a:hover {
  background: var(--bg-alt);
  text-decoration: none;
}

/* Navigation */
header nav {
  display: flex;
  align-items: center;
  gap: 0;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

header nav > a,
.nav-dropdown > a {
  display: block;
  padding: 0.4rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-radius: 4px;
  text-decoration: none;
}

header nav > a:hover,
.nav-dropdown:hover > a {
  background: var(--bg-alt);
  color: var(--text);
  text-decoration: none;
}

/* Dropdown Navigation */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  min-width: 160px;
  z-index: 1000;
}

.nav-dropdown:hover .nav-dropdown-content {
  display: block;
}

.nav-dropdown-content a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.nav-dropdown-content a:last-child {
  border-bottom: none;
}

.nav-dropdown-content a:hover {
  background: var(--bg-alt);
  text-decoration: none;
}

/* Two Column Layout */
.two-col {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 3rem;
}

.main-content {
  min-width: 0;
}

.sidebar {
  font-size: 0.9rem;
}

@media (max-width: 800px) {
  .two-col {
    grid-template-columns: 1fr;
  }
  .sidebar {
    order: -1;
  }
}

/* Sidebar Sections */
.sidebar-section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-section:last-child {
  border-bottom: none;
}

.sidebar-section h3 {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* Forms */
select {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  margin-bottom: 0.75rem;
}

select:focus {
  outline: none;
  border-color: var(--border-dark);
}

/* Party Control (sidebar) */
.party-control {
  font-size: 0.95rem;
}

.party-control-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.party-control-row:last-child {
  border-bottom: none;
}

.party-control-label {
  color: var(--text-muted);
}

.party-control-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.party-control-change {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.5rem;
}

/* Race List */
.race-list {
  list-style: none;
}

.race-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.race-item:last-child {
  border-bottom: none;
}

.race-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.race-name {
  font-weight: 600;
}

.race-margin {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.race-margin.r { color: var(--republican); }
.race-margin.d { color: var(--democrat); }

.race-office {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:hover {
  background: var(--bg-alt);
}

/* Party Colors */
.r { color: var(--republican); }
.d { color: var(--democrat); }
.r-bg { background: var(--republican-bg); }
.d-bg { background: var(--democrat-bg); }

/* Page Header */
.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.page-header .lean {
  font-size: 1rem;
  font-family: -apple-system, sans-serif;
  font-weight: 600;
}

.page-header .subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

/* Metrics Row */
.metrics {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.metric {
  text-align: center;
}

.metric-value {
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-weight: normal;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Section */
.section {
  margin-bottom: 2.5rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--text);
}

.section-header h2 {
  margin: 0;
  padding: 0;
  border: none;
}

.section-link {
  font-size: 0.85rem;
}

/* Candidates */
.candidates {
  list-style: none;
}

.candidate {
  display: flex;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.candidate:last-child {
  border-bottom: none;
}

.candidate-name {
  flex: 1;
}

.candidate.winner .candidate-name {
  font-weight: 600;
}

.winner-check {
  color: #22c55e;
  font-weight: bold;
  margin-left: 0.25rem;
}

.candidate-party {
  width: 100px;
  font-size: 0.85rem;
}

.candidate-votes {
  width: 80px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Town List */
.town-list {
  list-style: none;
  columns: 2;
  column-gap: 1rem;
}

.town-list li {
  padding: 0.3rem 0;
}

.town-list a {
  color: var(--text);
}

.town-list a:hover {
  color: var(--democrat);
}

/* Footer */
footer {
  margin-top: 3rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Utility */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.font-serif { font-family: Georgia, serif; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 1rem; }

/* Year nav */
.year-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.year-nav a, .year-nav span {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.year-nav a:hover {
  background: var(--bg-alt);
  text-decoration: none;
}

.year-nav .active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Key races table */
.key-races th {
  text-align: center;
}

.key-races td {
  text-align: center;
}

.key-races td:first-child {
  text-align: left;
}

.key-races .margin {
  font-weight: 600;
}

/* District history */
.election-year {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.election-year:last-child {
  border-bottom: none;
}

.election-year-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
}

.election-year-header h3 {
  font-family: -apple-system, sans-serif;
  font-weight: 600;
  margin: 0;
}

/* Chart container */
.chart-container {
  height: 200px;
  margin: 1rem 0;
}

/* Mobile Responsive Improvements */
@media (max-width: 600px) {
  body {
    font-size: 14px;
  }

  .container {
    padding: 0 12px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.2rem;
  }

  /* Header */
  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .header-search {
    width: 100%;
  }

  header nav {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  header nav > a,
  .nav-dropdown > a {
    padding: 0.5rem 0.6rem;
    font-size: 0.85rem;
  }

  /* Tables */
  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: 0.4rem 0.5rem;
  }

  /* Tables - horizontal scroll on small screens */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Page header */
  .page-header h1 {
    flex-direction: column;
    gap: 0.25rem;
  }

  /* Metrics */
  .metrics {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .metric {
    flex: 1 1 40%;
  }

  .metric-value {
    font-size: 1.2rem;
  }

  /* Map controls */
  .map-controls {
    flex-direction: column;
    gap: 0.75rem;
  }

  .map-controls > div {
    width: 100%;
  }

  .map-controls select {
    width: 100%;
  }

  #map {
    height: 450px;
  }

  /* Town list single column on mobile */
  .town-list {
    columns: 1;
  }

  /* Year nav - smaller */
  .year-nav {
    flex-wrap: wrap;
  }

  .year-nav a, .year-nav span {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
  }

  /* Candidates list */
  .candidate {
    flex-wrap: wrap;
  }

  .candidate-party {
    width: auto;
  }

  /* Info box on map - adjust for mobile */
  .info-box {
    max-width: 180px;
    font-size: 0.85rem;
  }

  .info-box h4 {
    font-size: 0.95rem;
  }

  /* Legend - smaller */
  .legend {
    font-size: 0.75rem;
    padding: 6px;
  }

  /* Race list */
  .race-header {
    flex-direction: column;
    gap: 0.25rem;
  }
}

/* Tablet adjustments */
@media (max-width: 800px) and (min-width: 601px) {
  .map-controls {
    flex-wrap: wrap;
  }

  #map {
    height: 550px;
  }
}

/* Social Share Buttons */
.share-buttons {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.share-btn:hover {
  background: var(--bg-alt);
  color: var(--text);
  text-decoration: none;
}
.share-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

