:root {
  --page-bg: #f5f0e8;
  --panel-bg: #ede8df;
  --text: #2c1810;
  --muted: #7a6e65;
  --text-muted: var(--muted);
  --border: #d4cfc7;
  --accent: #2166ac;
  --header-text: #f5f0e8;
  --header-muted: #d4cfc7;
  --unknown: rgba(158, 152, 144, 0.5);
  --party-dem: #1a6fbf;
  --party-rep: #c0392b;
  --party-wfp: #e07b20;
  --party-other: #666666;
  --bar-height: 6px;
  --bar-radius: 3px;
  --card-gap: 1.25rem;
  --filter-btn-gap: 0.5rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--page-bg);
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.site-header {
  height: 52px;
  min-height: 52px;
  background: var(--text);
  color: var(--header-text);
  border-bottom: 0.5px solid rgba(245, 240, 232, 0.14);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 16px;
}

.site-brand {
  min-width: 0;
}

.site-title {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.03em;
}

.site-description {
  margin-top: 4px;
  font-size: 11px;
  color: var(--header-muted);
  white-space: nowrap;
}

.site-status {
  flex-shrink: 0;
  font-size: 11px;
  color: #9e9890;
  text-align: right;
  letter-spacing: 0.02em;
}

.app-main {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
}

.panel {
  background: var(--panel-bg);
  border: 0.5px solid var(--border);
  box-shadow: none;
}

.control-panel,
.borough-summary {
  position: absolute;
  z-index: 1200;
}

.control-panel {
  left: 16px;
  bottom: 92px;
  width: 320px;
  min-height: 300px;
  max-width: calc(100vw - 32px);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-panel-label {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.03em;
  color: #4a3f36;
  margin: 0;
}

.control-panel-divider {
  border: 0;
  border-top: 0.5px solid var(--border);
  margin: 0;
  width: 100%;
  align-self: stretch;
}

.borough-summary {
  right: 20px;
  top: 16px;
  width: 280px;
  padding: 14px;
}

.section-label,
.borough-summary-title,
.sidebar-section-label {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 10px;
}

.map-type-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
  align-items: stretch;
}

.map-type-btn {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.45);
  border: 0.5px solid var(--border);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
  text-align: center;
  justify-self: stretch;
}

.map-type-btn:hover {
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--muted);
}

.map-type-btn.active {
  color: var(--header-text);
  background: var(--accent);
  border-color: var(--accent);
}

.map-type-btn.active:hover {
  filter: brightness(0.92);
}

.wait-legend-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.wait-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.wait-dot {
  display: inline-block;
  border-radius: 50%;
  flex-shrink: 0;
}

.wait-dot-short {
  width: 8px;
  height: 8px;
  background: #2e7d32;
}

.wait-dot-moderate {
  width: 8px;
  height: 8px;
  background: #e8a820;
}

.wait-dot-long {
  width: 8px;
  height: 8px;
  background: #c0392b;
}

.wait-dot-unknown {
  width: 8px;
  height: 8px;
  background: #aaa;
}

.wait-legend-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.sidebar-stat-left,
.borough-row-top,
.data-row {
  display: flex;
  align-items: center;
}

.borough-summary-rows {
  display: grid;
  gap: 12px;
}

.borough-row {
  display: grid;
  gap: 5px;
}

.borough-row-top {
  justify-content: space-between;
  gap: 12px;
}

.borough-name {
  font-size: 12px;
  color: var(--text);
}

.borough-count {
  font-size: 11px;
  color: var(--muted);
}

.borough-bar {
  display: flex;
  width: 100%;
  height: 6px;
  overflow: hidden;
  background: rgba(44, 24, 16, 0.08);
}

.borough-bar-segment {
  display: block;
  height: 100%;
}

.borough-bar-short {
  background: #2e7d32;
}

.borough-bar-moderate {
  background: #e8a820;
}

.borough-bar-long {
  background: #c0392b;
}

.borough-bar-unknown {
  background: var(--unknown);
}

.borough-empty-state {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 480px;
  min-width: 480px;
  height: 100%;
  background: var(--page-bg);
  border-left: 0.5px solid var(--border);
  z-index: 1300;
  transform: translateX(100%);
  transition: transform 180ms ease-out;
  overflow-y: auto;
}

.sidebar-panel.is-open {
  transform: translateX(0);
}

.sidebar-inner {
  padding: 20px;
}

.sidebar-close {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  margin-left: auto;
}

.sidebar-back {
  display: block;
  width: 100%;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 6px 0 0;
  cursor: pointer;
}

.sidebar-title {
  margin-top: 18px;
  font-family: "Barlow Condensed", sans-serif;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0.03em;
}

.sidebar-subtitle {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.sidebar-divider {
  border-top: 0.5px solid var(--border);
  margin: 12px 0;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-note,
.sidebar-total,
.borough-context {
  font-size: 11px;
  color: var(--muted);
}

.sidebar-stats,
.data-rows {
  display: grid;
  gap: 10px;
}

.sidebar-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

.sidebar-stat-left {
  gap: 8px;
  min-width: 0;
}

.sidebar-stat-right {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat-count {
  color: var(--text);
}

.stat-percent {
  color: var(--muted);
}

.sidebar-total {
  margin-top: 12px;
}

.sidebar-empty-state-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-polling-name {
  font-size: 12px;
  color: var(--text);
}

.sidebar-polling-address {
  margin-top: 4px;
}

.sidebar-ed-wait-label {
  margin-top: 14px;
}

.sidebar-ed-as-of {
  margin-top: 6px;
}

.data-row {
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

.data-row span:first-child {
  color: var(--muted);
}

.sidebar-collapsible {
  border-top: 0.5px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

.sidebar-collapsible summary {
  list-style: none;
  cursor: pointer;
  margin-bottom: 10px;
}

.sidebar-collapsible summary::-webkit-details-marker {
  display: none;
}

.demo-bar-row {
  display: grid;
  gap: 6px;
}

.demo-bar-track {
  width: 100%;
  height: 8px;
  background: rgba(44, 24, 16, 0.09);
}

.demo-bar-track span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.demo-bar-label {
  font-size: 11px;
  color: var(--muted);
}

.race-card {
  border-top: 0.5px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.race-card.is-hidden {
  display: none;
}

.race-card-header {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--text);
  text-transform: uppercase;
  padding-bottom: 8px;
  border-bottom: 0.5px solid var(--border);
}

.race-cards-list {
  display: grid;
  gap: var(--card-gap);
}

.results-filter-bar {
  display: flex;
  gap: var(--filter-btn-gap);
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.results-filter-btn {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.results-filter-btn.active {
  background: var(--accent);
  color: var(--header-text);
  border-color: var(--accent);
}

.race-candidate-block {
  display: grid;
  gap: 4px;
}

.race-candidate-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.race-candidate-name {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
}

.race-candidate-name-text {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.race-candidate-party {
  font-size: 11px;
  letter-spacing: 0.02em;
}

.race-candidate-value {
  display: grid;
  justify-items: end;
  gap: 1px;
  flex: 0 0 auto;
}

.race-candidate-votes {
  font-size: 16px;
  line-height: 1;
  color: var(--text);
}

.race-candidate-pct {
  font-size: 11px;
  color: var(--muted);
}

.candidate-bar {
  height: var(--bar-height);
  border-radius: var(--bar-radius);
  margin-top: 3px;
  margin-bottom: 8px;
  min-width: 4px;
  transition: width 0.3s ease;
}

.race-view-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: #4b4640;
  text-align: right;
  cursor: pointer;
  padding: 0;
  justify-self: end;
}

.full-race-header {
  margin-top: 8px;
}

.full-race-title {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 20px;
  line-height: 1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.full-race-subtitle {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.full-race-primary-context {
  margin-top: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}

.full-race-table {
  display: grid;
  gap: 10px;
}

.full-race-table-head {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  border-bottom: 0.5px solid var(--border);
}

.full-race-candidate {
  display: grid;
  gap: 4px;
}

.full-race-candidate.is-muted {
  opacity: 0.62;
}

.full-race-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.full-race-name {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.full-race-swatch {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  margin-top: 3px;
}

.full-race-values {
  display: grid;
  justify-items: end;
  gap: 1px;
  flex: 0 0 auto;
}

.full-race-votes {
  color: var(--text);
}

.full-race-pct {
  color: var(--muted);
}

.full-race-total {
  margin-top: 8px;
  text-align: right;
  text-transform: uppercase;
}

.low-vote-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.low-vote-toggle.is-open .low-vote-toggle-caret {
  transform: rotate(180deg);
}

.low-vote-toggle-caret {
  transition: transform 160ms ease;
}

.low-vote-list {
  display: grid;
  gap: 10px;
}

.low-vote-list[hidden] {
  display: none;
}

.district-city-block .data-row span:last-child {
  font-weight: 500;
}

.borough-context {
  font-size: 12px;
  color: var(--text);
}

.mobile-panel-toggle {
  display: none;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 240, 232, 0.96);
  z-index: 2000;
}

.loading-card {
  min-width: 280px;
  padding: 24px;
  border: 0.5px solid var(--border);
  background: var(--panel-bg);
  text-align: center;
}

.loading-title {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0.03em;
}

.loading-text {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-line;
}

.loading-text.is-error {
  color: #8b2d2d;
}

.district-hover-tooltip {
  background: rgba(44, 24, 16, 0.9);
  color: var(--header-text);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 4px 6px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.district-hover-tooltip::before {
  display: none;
}

.district-selected-badge-wrapper {
  background: transparent;
  border: 0;
}

.district-selected-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 10px;
  background: rgba(44, 24, 16, 0.85);
  color: var(--header-text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  white-space: nowrap;
}

.leaflet-control-zoom {
  border: 0.5px solid var(--border) !important;
  box-shadow: none !important;
}

.leaflet-control-zoom a {
  background: var(--panel-bg) !important;
  color: var(--text) !important;
  border-radius: 0 !important;
  border-bottom: 0.5px solid var(--border) !important;
}

.leaflet-control-attribution {
  background: rgba(245, 240, 232, 0.92) !important;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
}

@media (max-width: 980px) {
  .site-description {
    white-space: normal;
  }

  .sidebar-panel {
    left: 0;
    width: auto;
    min-width: 0;
  }
}

@media (max-width: 820px) {
  .site-header {
    height: 60px;
    min-height: 60px;
    padding: 8px 12px;
    align-items: flex-start;
  }

  .site-title {
    font-size: 17px;
  }

  .site-description,
  .site-status {
    font-size: 10px;
  }

  .borough-summary,
  .control-panel {
    display: none;
  }

  .borough-summary.is-open,
  .control-panel.is-open {
    display: block;
  }

  .mobile-panel-toggle {
    position: absolute;
    z-index: 1250;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    appearance: none;
    border: 0.5px solid var(--border);
    background: var(--panel-bg);
    color: var(--text);
    padding: 10px 12px;
  }

  .mobile-summary-toggle {
    top: 12px;
    right: 12px;
  }

  .mobile-controls-toggle {
    right: 12px;
    bottom: 12px;
  }

  .borough-summary {
    top: 52px;
    left: 12px;
    right: 12px;
    width: auto;
  }

  .control-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    min-height: 0;
    padding: 16px 18px 22px;
    max-height: 72vh;
    overflow-y: auto;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .sidebar-panel {
    top: 0;
    right: 0;
    left: 0;
    width: auto;
    min-width: 0;
    border-left: 0;
  }
}

/* ============================================================
   SIDEBAR REDESIGN — 2026-03-22
   ============================================================ */

.demo-source-note {
  margin-bottom: 8px;
  font-size: 10px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-style: italic;
}

.demo-bar-row {
  display: grid;
  margin-bottom: 10px;
}

.demo-bar-row:last-child {
  margin-bottom: 0;
}

.demo-bar-label-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text);
}

.demo-bar-label-line-condensed {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.demo-bar-track {
  position: relative;
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 2px;
  overflow: visible;
}

.demo-bar-track-comparative {
  height: 10px;
}

.demo-bar-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
}

.demo-bar-tick {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 12px;
  background: rgba(0, 0, 0, 0.35);
  transform: translateX(-1px);
  pointer-events: none;
}

.demo-bar-subtext {
  margin-top: 2px;
  font-size: 10px;
  color: var(--muted);
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
}

.demo-comparative-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.demo-section-break {
  border-top: 0.5px solid var(--border);
  margin: 8px 0 10px;
}

@media (max-width: 1023px) {
  .sidebar-panel {
    left: 0;
    width: auto;
    min-width: 0;
  }
}
