:root {
  color-scheme: light;
  --ink: #15212a;
  --muted: #5e6b76;
  --line: #d8dee4;
  --panel: #ffffff;
  --soft: #f5f7f8;
  --teal: #127078;
  --blue: #2d5f9a;
  --gold: #d58a13;
  --green: #4b7f4a;
  --danger: #a33d31;
  --side-panel-width: 430px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--soft);
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, var(--side-panel-width));
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.map-pane {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background: #e8edf0;
}

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

.google-3d-view {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #111820;
}

.google-3d-view[hidden] {
  display: none;
}

.google-3d-active #map {
  visibility: hidden;
}

.map-title {
  position: absolute;
  z-index: 5;
  top: 16px;
  left: 16px;
  max-width: min(440px, calc(100% - 32px));
  padding: 12px 14px;
  border: 1px solid rgb(255 255 255 / 70%);
  border-radius: 6px;
  background: rgb(255 255 255 / 86%);
  box-shadow: 0 10px 35px rgb(24 35 42 / 12%);
  backdrop-filter: blur(8px);
}

.map-title h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
}

.map-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.map-toolbar {
  position: absolute;
  z-index: 5;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.map-toolbar button,
.map-select-control,
.profile-actions a,
.profile-actions button,
.area-list button {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: rgb(255 255 255 / 92%);
  cursor: pointer;
}

.map-toolbar button {
  min-width: 58px;
  height: 36px;
  padding: 0 10px;
  box-shadow: 0 10px 35px rgb(24 35 42 / 12%);
}

.map-select-control {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 8px;
  box-shadow: 0 10px 35px rgb(24 35 42 / 12%);
}

.map-select-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.map-select-control select {
  width: 154px;
  height: 28px;
  border: 0;
  color: var(--ink);
  background: transparent;
  outline: none;
}

.map-toolbar button[aria-pressed="false"] {
  color: var(--muted);
  background: rgb(245 247 248 / 82%);
}

.map-status {
  position: absolute;
  z-index: 5;
  top: 92px;
  left: 16px;
  max-width: min(380px, calc(100% - 32px));
  padding: 10px 12px;
  border: 1px solid rgb(216 222 228 / 90%);
  border-radius: 6px;
  color: var(--ink);
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 10px 35px rgb(24 35 42 / 14%);
  font-size: 13px;
  line-height: 1.35;
  backdrop-filter: blur(8px);
}

.map-status[hidden] {
  display: none;
}

.hover-card {
  position: absolute;
  z-index: 6;
  max-width: 280px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgb(255 255 255 / 94%);
  box-shadow: 0 10px 35px rgb(24 35 42 / 16%);
  pointer-events: none;
}

.hover-card strong {
  display: block;
  font-size: 13px;
}

.hover-card span {
  color: var(--muted);
  font-size: 12px;
}

.side-panel {
  position: relative;
  z-index: 7;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: -12px 0 30px rgb(24 35 42 / 8%);
  container-type: inline-size;
}

.panel-resizer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: calc(var(--side-panel-width) - 5px);
  z-index: 12;
  width: 10px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: col-resize;
  touch-action: none;
}

.panel-resizer::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 4px;
  width: 2px;
  height: 64px;
  border-radius: 999px;
  background: rgb(21 33 42 / 20%);
  transform: translateY(-50%);
  transition: background 120ms ease, box-shadow 120ms ease;
}

.panel-resizer:hover::before,
.panel-resizer:focus-visible::before,
body.panel-resizing .panel-resizer::before {
  background: var(--teal);
  box-shadow: 0 0 0 3px rgb(18 112 120 / 16%);
}

body.panel-resizing {
  cursor: col-resize;
  user-select: none;
}

body.panel-resizing iframe,
body.panel-resizing #map {
  pointer-events: none;
}

.political-map .political-hidden {
  display: none !important;
}

.search-block {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.search-block label,
.stat-label,
.chart-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

#search,
#geography-type,
#opportunity-overlay,
#election-overlay,
#language-select,
#finder-sort,
#finder-race,
#finder-min-pop,
#finder-limit {
  width: 100%;
  height: 42px;
  margin-top: 7px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline-color: var(--teal);
}

#geography-type,
#opportunity-overlay,
#election-overlay,
#language-select,
#finder-sort,
#finder-race,
#finder-min-pop,
#finder-limit {
  margin-bottom: 12px;
  background: #fff;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.race-finder {
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.race-finder[hidden] {
  display: none;
}

.election-tools {
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.election-tools[hidden] {
  display: none;
}

.election-mode-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.election-mode-row button {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.election-mode-row button.active {
  border-color: var(--teal);
  color: #fff;
  background: var(--teal);
}

.finder-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.finder-heading h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.finder-heading button {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #fff;
  cursor: pointer;
}

.finder-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 10px;
}

.finder-row label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.finder-summary {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.profile {
  flex: 0 0 auto;
  overflow: visible;
  border-bottom: 1px solid var(--line);
}

.legend-block {
  padding: 13px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.legend-block h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.legend-subtitle {
  margin: 5px 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.legend-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.2;
}

.legend-dot {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid rgb(21 33 42 / 22%);
  box-shadow: 0 0 0 2px rgb(255 255 255 / 78%);
}

.legend-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.map-legend {
  position: absolute;
  z-index: 5;
  right: 16px;
  bottom: 16px;
  width: min(310px, calc(100% - 32px));
  border: 1px solid rgb(255 255 255 / 70%);
  border-radius: 6px;
  background: rgb(255 255 255 / 90%);
  box-shadow: 0 10px 35px rgb(24 35 42 / 14%);
  backdrop-filter: blur(8px);
}

.opportunity-legend {
  background: #fff;
}

.opportunity-legend[hidden] {
  display: none;
}

.legend-ramp {
  height: 12px;
  border: 1px solid rgb(21 33 42 / 18%);
  border-radius: 999px;
}

.legend-scale {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.legend-status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.empty-state,
.loading-state,
.error-state {
  padding: 28px 18px;
}

.empty-state h2,
.loading-state h2,
.error-state h2,
.list-block h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.empty-state p,
.loading-state p,
.error-state p {
  margin: 0;
  color: var(--muted);
}

.profile-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafb 100%);
}

.profile-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.profile-subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.headline-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 10px;
  margin-top: 14px;
}

.headline-card,
.stat-card,
.mini-chart {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.headline-card {
  padding: 12px;
}

.headline-value {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  font-weight: 800;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.profile-actions a,
.profile-actions button {
  min-height: 34px;
  padding: 7px 10px;
  color: var(--ink);
  text-decoration: none;
}

.section {
  padding: 16px 18px 4px;
}

.section h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 10px;
}

.stat-card {
  min-height: 88px;
  padding: 11px;
}

.representative-card {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  min-height: 110px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.school-ratings-card {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.school-ratings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.school-summary {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.rating-pill-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.rating-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid #d8e6df;
  border-radius: 6px;
  background: #f8fbf9;
  color: var(--muted);
  font-size: 12px;
}

.rating-pill strong {
  color: var(--green);
  font-size: 14px;
}

.compact-stat-grid {
  margin-top: 12px;
}

.compact-stat-grid .stat-card {
  min-height: 70px;
}

.school-list {
  margin-top: 12px;
}

.school-list ul {
  margin: 7px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.school-list strong {
  color: var(--ink);
  font-weight: 750;
}

.school-list li span {
  color: var(--muted);
}

.school-source-list a {
  display: inline-block;
  color: var(--blue);
  text-decoration: none;
}

.school-source-list li span {
  display: block;
  margin-top: 2px;
}

.school-mini-chart {
  padding: 0;
}

.school-mini-chart .bar-row {
  grid-template-columns: minmax(120px, 160px) minmax(0, 1fr) 44px;
}

.fallback-links {
  margin-top: 10px;
}

.representative-card.no-image {
  grid-template-columns: minmax(0, 1fr);
}

.representative-card img {
  width: 72px;
  height: 88px;
  object-fit: cover;
  border-radius: 4px;
  background: #e8edf0;
}

.representative-card a,
.external-links a {
  display: inline-block;
  margin-right: 10px;
  margin-top: 7px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.external-links a:last-child {
  margin-right: 0;
}

.party-republican {
  background: #fff2f1;
  border-color: #e5b6b2;
}

.party-democrat {
  background: #f0f5ff;
  border-color: #b8c9e8;
}

.party-other {
  background: #f5f7f8;
}

.stat-value {
  display: block;
  margin-top: 7px;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
}

.stat-note {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.mini-chart {
  padding: 11px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(92px, 120px) minmax(0, 1fr) 48px;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
}

.bar-track {
  display: block;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf0;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.bar-row:nth-child(3n) .bar-fill {
  background: var(--blue);
}

.bar-row:nth-child(4n) .bar-fill {
  background: var(--green);
}

.bar-value {
  color: var(--muted);
  text-align: right;
}

.source-note {
  padding: 12px 18px 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.source-note a {
  color: var(--blue);
}

.full-profile-section {
  padding-bottom: 18px;
}

.full-profile-frame {
  display: block;
  width: 100%;
  height: min(5200px, 75vh);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.list-block {
  flex: 0 0 auto;
  min-height: 180px;
  padding: 14px 18px 18px;
  overflow: visible;
}

.area-list {
  display: grid;
  gap: 8px;
}

.search-results {
  max-height: 315px;
  margin-top: 10px;
  padding-top: 10px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.search-results[hidden] {
  display: none;
}

.area-list button {
  width: 100%;
  min-height: 58px;
  padding: 9px 10px;
  text-align: left;
  background: #fff;
}

.area-list button.active {
  border-color: var(--gold);
  background: #fff8ee;
}

.area-list button.finder-result {
  display: grid;
  gap: 7px;
}

.area-name {
  display: block;
  font-weight: 750;
  line-height: 1.2;
}

.finder-result .area-name {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.finder-rank {
  flex: 0 0 auto;
  min-width: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.finder-metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.finder-metric strong {
  color: var(--ink);
  font-size: 16px;
}

.finder-bar {
  display: block;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf0;
}

.finder-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.component-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
}

.component-list li + li {
  margin-top: 3px;
}

.area-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.list-hint {
  margin: 4px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

@container (max-width: 390px) {
  .headline-grid,
  .rating-pill-grid,
  .legend-list,
  .finder-row {
    grid-template-columns: 1fr;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .representative-card {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .representative-card img {
    width: 58px;
    height: 72px;
  }

  .bar-row,
  .school-mini-chart .bar-row {
    grid-template-columns: minmax(74px, 1fr) minmax(0, 1fr) 44px;
  }
}

@container (min-width: 560px) {
  .search-block {
    display: grid;
    grid-template-columns: minmax(132px, 180px) minmax(0, 1fr);
    align-items: center;
    gap: 10px 12px;
  }

  .search-block > label {
    margin: 0;
  }

  #search,
  #geography-type,
  #opportunity-overlay,
  #election-overlay,
  #language-select,
  #finder-sort,
  #finder-race,
  #finder-min-pop,
  #finder-limit {
    margin-top: 0;
  }

  #geography-type,
  #opportunity-overlay,
  #election-overlay,
  #language-select,
  #finder-sort,
  #finder-race,
  #finder-min-pop,
  #finder-limit {
    margin-bottom: 0;
  }

  .search-results,
  .meta-row,
  .election-tools,
  .race-finder {
    grid-column: 1 / -1;
  }

  .election-tools,
  .race-finder {
    margin-top: 4px;
  }

  .race-finder #finder-sort,
  .race-finder #finder-race {
    margin-top: 7px;
    margin-bottom: 12px;
  }

  .race-finder #finder-min-pop,
  .race-finder #finder-limit {
    margin-top: 7px;
  }

  .area-list {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  }

  .area-list button.finder-result {
    align-content: start;
  }

  .headline-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container (min-width: 720px) {
  .search-block {
    grid-template-columns: minmax(150px, 210px) minmax(0, 1fr);
  }

  .school-ratings-head {
    align-items: center;
  }

  .rating-pill-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

.ol-zoom {
  top: auto;
  right: auto;
  bottom: 18px;
  left: 16px;
}

.ol-control button {
  background-color: rgb(255 255 255 / 92%);
  color: var(--ink);
}

html[dir="rtl"] .side-panel {
  border-right: 1px solid var(--line);
  border-left: 0;
  box-shadow: 12px 0 30px rgb(24 35 42 / 8%);
}

html[dir="rtl"] .bar-value {
  text-align: left;
}

@media (max-width: 980px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(360px, 52vh) minmax(0, 1fr);
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .map-pane {
    min-height: 360px;
  }

  .side-panel {
    height: auto;
    max-height: none;
    overflow: visible;
    min-height: 560px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel-resizer {
    display: none;
  }
}

@media (max-width: 620px) {
  .map-title {
    top: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
  }

  .map-toolbar {
    top: auto;
    right: 10px;
    bottom: 12px;
    left: 10px;
    justify-content: flex-end;
  }

  .map-select-control select {
    width: 136px;
  }

  .map-status {
    top: 86px;
    left: 10px;
    max-width: calc(100% - 20px);
  }

  .map-legend {
    right: 10px;
    bottom: 94px;
    width: min(280px, calc(100% - 20px));
    max-height: 136px;
    overflow: auto;
    padding: 10px 12px;
  }

  .map-legend h2 {
    font-size: 13px;
  }

  .map-legend .legend-subtitle,
  .map-legend .legend-note {
    display: none;
  }

  .map-legend .legend-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 10px;
  }

  .map-legend .legend-item {
    font-size: 11px;
  }

  .headline-grid,
  .stat-grid,
  .rating-pill-grid,
  .finder-row,
  .legend-list {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 92px minmax(0, 1fr) 44px;
  }
}
