@font-face {
  font-family: "Benton Sans";
  src: url("Benton Sans/Benton Sans Book.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "Benton Sans";
  src: url("Benton Sans/Benton Sans Book Italic.otf") format("opentype");
  font-weight: 400;
  font-style: italic;
}

@font-face {
  font-family: "Benton Sans";
  src: url("Benton Sans/Benton Sans Medium.otf") format("opentype");
  font-weight: 500;
  font-style: normal;
}

@font-face {
  font-family: "Benton Sans";
  src: url("Benton Sans/Benton Sans Bold.otf") format("opentype");
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: "Benton Sans";
  src: url("Benton Sans/Benton Sans Black.otf") format("opentype");
  font-weight: 900;
  font-style: normal;
}
* {
  box-sizing: border-box;
}

:root {
  --red: #FFCF01;
  --blue: #711471;
  --text: #111;
  --muted: #666;
  --border: #fff;
  --light-border: #fff;
  --inactive: #ededed;
}

body {
  margin: 0;
  color: var(--text);
  background: #fff;
  font-family: "Benton Sans", Helvetica, Arial, sans-serif;
}
button,
input,
select {
  font: inherit;
}

.county-map-app {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.map-header h1 {
  max-width: 900px;
  margin: 0 0 20px;
  font-size: 22px;
  line-height: 1.7;
  font-weight: 400;
  color: #111;
}

/*
  The title-break <br> tags force the sentence onto 4 lines so each clause
  reads clearly, but on wide screens there's enough horizontal room to
  flow it as one wrapping block instead — worth doing since vertical
  space above the map is at a premium.
*/
@media (min-width: 800px) {
  .title-break {
    display: none;
  }
}

.map-header h1 .inline-select {
  font-size: inherit;
}

.map-header p {
  max-width: 760px;
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.4;
}

.control-label {
  margin-bottom: 2px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-toggle-row {
  position: relative;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 30px 0 20px;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.toggle-switch button {
  border: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: color 160ms ease;
}

.toggle-switch button.is-active {
  color: #111;
}

.toggle-switch-track {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
  border: 1px solid #777;
  cursor: pointer;
}

.toggle-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #111;
  transition: transform 200ms ease;
}

.toggle-switch:has(button[data-value="percent"].is-active) .toggle-switch-knob {
  transform: translateX(20px);
}

.inline-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.inline-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  border: 0;
  border-radius: 0;
  background: none;
  margin: 0;
  padding: 0 22px 0 0;
  font: inherit;
  font-weight: 700;
  color: #111;
  text-decoration: underline;
  text-decoration-style: solid;
  text-underline-offset: 2px;
  cursor: pointer;
}

.inline-select:hover {
  color: var(--blue);
}

.inline-select:focus-visible {
  outline: 2px solid #111;
  outline-offset: 2px;
}

/*
  #sign-filter, #type-filter, and #group-select all have options whose
  text length varies a lot from the current selection (count suffixes, or
  just longer/shorter labels), and browsers size a <select> box to fit its
  widest option rather than the selected one. That leaves a gap between
  the visible text and the arrow after it. The sibling
  .inline-select-display span (normal flow, sized to its own plain-label
  text) is what's actually visible; the select itself is stretched over it
  fully transparent, so the wrap's width follows the current label instead.
  Text kept in sync in JS via syncInlineSelectDisplay().
*/
.inline-select-wrap > #sign-filter,
.inline-select-wrap > #type-filter,
.inline-select-wrap > #group-select {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}

.inline-select-display {
  padding: 0 22px 0 0;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-style: solid;
  text-underline-offset: 2px;
  color: #111;
  white-space: nowrap;
  pointer-events: none;
}

#sign-filter:hover + .inline-select-display,
#type-filter:hover + .inline-select-display,
#group-select:hover + .inline-select-display {
  color: var(--blue);
}

.inline-select-arrow {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: inherit;
  line-height: 1;
  color: #111;
  pointer-events: none;
}

.button-row button,
.reset-state,
.state-cell {
  border: 1px solid #777;
  border-radius: 0;
  color: #111;
  background: #fff;
  cursor: pointer;
}

.button-row button {
  padding: 7px 10px;
}

.button-row button:hover,
.reset-state:hover,
.state-cell:hover {
  border-color: #fff;
}

.button-row button.is-active {
  color: #fff;
  border-color: #fff;
  background: #111;
}

.loading {
  padding: 24px 0;
  color: var(--muted);
}

.error {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--red);
  color: var(--red);
  line-height: 1.45;
}

.visualization {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
.map-column,
.map-wrap {
  min-width: 0;
}

.map-column {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.map-wrap {
  position: relative;
  z-index: auto;
  min-width: 0;
  overflow: hidden;
}

.tooltip {
  position: absolute;
  z-index: 50;
  max-width: 270px;
  padding: 9px 11px;
  border: 1px solid #000;
  color: #111;
  background: rgba(255, 255, 255, 0.98);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
}

.tooltip-close {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  background: none;
  color: #111;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

#county-map {
  display: block;
  width: 100%;
  aspect-ratio: 975 / 610;
  overflow: hidden;
}

.county {
  stroke: #fff;
  stroke-width: 0.2;
  vector-effect: non-scaling-stroke;
  transition:
    fill 180ms ease,
    opacity 180ms ease;
}

.county.is-filtered {
  fill: var(--inactive) !important;
}

.county.is-dimmed {
  opacity: 0.08;
}

.county-highlight-outline,
.county-hover-outline {
  fill: none;
  stroke: #111;
  stroke-width: 2.5;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.state-outline {
  fill: none;
  stroke: #fff;
  stroke-width: 0.8;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.tooltip strong {
  font-size: 13px;
}


.legend-filter {
  --legend-width: 240px;
}

.legend-scale {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.legend-bar-wrap {
  position: relative;
  width: var(--legend-width);
}

.legend-gradient {
  width: var(--legend-width);
  height: 12px;
  border: 1px solid #aaa;
  background: linear-gradient(90deg, var(--red), #ffffff, var(--blue));
}

.legend-edge-label {
  position: relative;
  top: 1px;
  font-size: 11px;
  white-space: nowrap;
}

.legend-zero-label {
  position: absolute;
  top: 100%;
  margin-top: 3px;
  transform: translateX(-50%);
  font-size: 11px;
  white-space: nowrap;
}

.legend-label,
.status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.status-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  margin-bottom: 10px;
}

.controls-row {
  position: relative;
  z-index: 11;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 14px;
}

/* Search, state and region stay on one row except on narrow phones. */
@media (max-width: 520px) {
  .controls-row {
    grid-template-columns: 1fr;
  }
}

.county-search-label {
  display: grid;
  min-width: 0;
}

.county-search-input-wrap {
  position: relative;
  min-width: 0;
}

.county-search-input {
  width: 100%;
  min-width: 0;
  padding: 5px 24px 5px 6px;
  border: 1px solid #777;
  border-radius: 0;
  color: #111;
  background: #fff;
  font-size: 14px;
}

.county-search-input:disabled {
  color: var(--muted);
  background: var(--inactive);
  cursor: not-allowed;
}

.county-search-clear {
  position: absolute;
  top: 50%;
  right: 3px;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.county-search-clear:hover {
  color: #111;
}

.county-search-suggestions {
  position: absolute;
  z-index: 12;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid #777;
  background: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.county-search-option {
  padding: 5px 6px;
  font-size: 11px;
  cursor: pointer;
}

.county-search-option.is-active,
.county-search-option:hover {
  color: #fff;
  background: #111;
}

.state-select-label {
  display: grid;
  min-width: 0;
}

.state-select-label select {
  width: 100%;
  min-width: 0;
  padding: 5px 34px 5px 6px;
  border: 1px solid #777;
  border-radius: 0;
  color: #111;
  /*
    The native arrow is pinned to the right edge and can't be moved, so it's
    replaced with a drawn chevron inset from the edge.
  */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23111' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  cursor: pointer;
  font-size: 14px;
}

.state-grid {
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  grid-template-rows: repeat(7, 25px);
  gap: 3px;
}

.state-cell {
  min-width: 0;
  padding: 0;
  font-size: 9px;
  line-height: 1;
}

.state-cell.is-selected {
  color: #fff;
  border-color: #111;
  background: #111;
}

.state-cell.is-faded {
  opacity: 0.35;
}

.reset-state {
  width: 100%;
  margin-top: 8px;
  padding: 7px 8px;
}

.method-note {
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}


@media (max-width: 850px) {
  .visualization {
    grid-template-columns: 1fr;
  }

  .state-grid {
    max-width: 460px;
  }
}

@media (max-width: 520px) {
  .county-map-app {
    padding: 14px;
  }

  .map-header h1 {
    font-size: 19px;
  }

  .button-row button {
    padding: 6px 8px;
    font-size: 13px;
  }

  .legend-filter {
    --legend-width: 200px;
  }

  .tooltip-close {
    display: block;
  }

  #tooltip-content {
    padding-right: 20px;
  }
}


.county-table-section {
  min-width: 0;
  margin-top: 10px;
}

.source-note {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.source-note a {
  color: inherit;
}

.county-table-toggle {
  padding: 4px 10px;
  border: 1px solid #777;
  border-radius: 0;
  color: #111;
  background: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.county-table-toggle:hover {
  border-color: #111;
}

.county-table-wrap {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
}

.county-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.county-table th,
.county-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #d7d7d7;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.county-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0;
  border-top: 1px solid #111;
  border-bottom: 1px solid #111;
  background: #fff;
  font-weight: 700;
}

.county-table td.numeric,
.county-table th:nth-child(n + 4) {
  text-align: right;
}

.sort-button {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-align: inherit;
  cursor: pointer;
}

.sort-button:hover,
.sort-button:focus-visible {
  text-decoration: underline;
}

.county-table th:nth-child(n + 4) .sort-button {
  justify-content: flex-end;
}

.sort-arrow {
  min-width: 8px;
  font-size: 9px;
  color: var(--muted);
}

.county-table td:nth-child(1),
.county-table th:nth-child(1) {
  max-width: 140px;
  white-space: normal;
}

.county-table td:nth-child(2),
.county-table th:nth-child(2) {
  max-width: 110px;
  white-space: normal;
}

.county-table td:nth-child(3),
.county-table th:nth-child(3) {
  min-width: 130px;
  max-width: 160px;
  white-space: normal;
}

.county-table th:nth-child(6),
.county-table th:nth-child(7) {
  max-width: 90px;
  white-space: normal;
}

.county-table tbody tr:hover {
  background: #f4f4f4;
}

.county-table-empty {
  padding: 18px 8px !important;
  color: var(--muted);
  text-align: center !important;
}

@media (max-width: 520px) {
  .county-table {
    font-size: 11px;
  }
}
