:root {
  --color-3ma-navy: #071f40;
  --color-3ma-navy-tint: #0d2d5c;
  --color-3ma-gold: #ebab22;
  --color-3ma-red: #c21f32;
  --color-3ma-white: #ffffff;
  --color-3ma-light-gray: #f4f5f7;
  --color-3ma-dark-gray: #1f2937;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-strong: #f4f5f7;
  --ink: #1f2937;
  --muted: #667085;
  --line: rgba(7, 31, 64, 0.14);
  --shadow: 0 18px 44px rgba(7, 31, 64, 0.14);
  font-family: "Raleway", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Raleway", Arial, sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.map-stage {
  position: relative;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  position: absolute;
  z-index: 700;
  top: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  pointer-events: none;
}

.brand,
.layer-panel,
.detail-panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(7, 31, 64, 0.14);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 720px;
  padding: 12px 18px 13px;
  border-radius: 8px;
  background: var(--color-3ma-navy);
  border-color: rgba(235, 171, 34, 0.42);
  border-bottom: 4px solid var(--color-3ma-gold);
}

.brand-logo {
  display: block;
  flex: 0 0 92px;
  width: 92px;
  height: 50px;
  object-fit: contain;
  object-position: left center;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand h1 {
  color: var(--color-3ma-white);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

#map {
  width: 100%;
  height: 100%;
}

.leaflet-container {
  font-family: inherit;
}

.city-label {
  color: var(--color-3ma-dark-gray);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.95), 1px 0 0 rgba(255, 255, 255, 0.95), -1px 0 0 rgba(255, 255, 255, 0.95), 0 -1px 0 rgba(255, 255, 255, 0.95);
  white-space: nowrap;
}

.city-label span {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.city-rank-1 {
  font-size: 12px;
  color: var(--color-3ma-navy);
}

.city-rank-3 {
  font-size: 10px;
  color: #5d6876;
}

.layer-panel {
  position: absolute;
  z-index: 5000;
  left: 20px;
  top: auto;
  bottom: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px 280px;
  align-items: start;
  gap: 10px 18px;
  width: min(900px, calc(100% - 40px));
  padding: 14px;
  border-radius: 8px;
}

.search-box {
  grid-column: 1 / 3;
  min-width: 0;
}

.search-box label,
legend {
  display: block;
  margin-bottom: 8px;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input[type="search"] {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

input[type="search"]:focus {
  border-color: var(--color-3ma-gold);
  box-shadow: 0 0 0 3px rgba(235, 171, 34, 0.2);
  outline: none;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}

select:focus {
  border-color: var(--color-3ma-gold);
  box-shadow: 0 0 0 3px rgba(235, 171, 34, 0.2);
  outline: none;
}

button {
  border: 0;
  border-radius: 7px;
  padding: 10px 13px;
  background: var(--color-3ma-gold);
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

button:hover {
  background: #d99a17;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.search-results {
  display: grid;
  gap: 4px;
  max-height: 150px;
  margin-top: 8px;
  overflow-y: auto;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.search-result {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  font-family: "Raleway", Arial, sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.25;
  text-align: left;
  text-transform: none;
}

.search-result:hover,
.search-result:focus {
  border-color: var(--color-3ma-gold);
  background: #fffaf0;
  outline: none;
}

.search-result-title,
.search-result-meta {
  display: block;
}

.search-result-title {
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 12px;
  font-weight: 800;
}

.search-result-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.search-message {
  margin: 0;
  padding: 7px 2px;
  color: var(--muted);
  font-size: 12px;
}

fieldset {
  grid-column: 3;
  grid-row: 1 / 3;
  margin: 0;
  padding: 0;
  border: 0;
}

fieldset label {
  display: flex;
  align-items: center;
  min-height: 28px;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-3ma-navy);
}

.party-legend {
  grid-column: 1 / 3;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 0;
  padding-top: 10px;
  border-top: 2px solid var(--color-3ma-gold);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.party-legend strong {
  flex: 0 0 100%;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.party-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(23, 33, 28, 0.18);
}

.legend-swatch.republican {
  background: var(--color-3ma-red);
}

.legend-swatch.democrat {
  background: var(--color-3ma-navy-tint);
}

.legend-swatch.independent {
  background: var(--surface);
  border-color: rgba(7, 31, 64, 0.32);
}

.last-updated {
  grid-column: 1 / -1;
  margin-top: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.last-updated[hidden] {
  display: none;
}

.last-updated strong {
  display: block;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-panel {
  position: relative;
  z-index: 800;
  height: 100vh;
  min-height: 0;
  padding: 26px 24px 30px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  border-width: 0 0 0 1px;
  border-left: 4px solid var(--color-3ma-gold);
  box-shadow: -16px 0 40px rgba(7, 31, 64, 0.12);
}

.detail-panel::-webkit-scrollbar {
  width: 10px;
}

.detail-panel::-webkit-scrollbar-thumb {
  background: rgba(7, 31, 64, 0.22);
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.96);
}

.detail-panel::-webkit-scrollbar-track {
  background: transparent;
}

.panel-header {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyeline {
  color: var(--color-3ma-gold);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.panel-header h2 {
  margin-top: 7px;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 28px;
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0;
}

.panel-header p:last-child {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.42;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.metric-grid[hidden] {
  display: none;
}

.metric-grid div {
  min-height: 88px;
  padding: 13px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--color-3ma-gold);
  border-radius: 8px;
  background: var(--surface-strong);
}

.metric-grid span {
  display: block;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 24px;
  font-weight: 900;
  line-height: 1.05;
}

.metric-grid small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.info-section {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.info-section h3 {
  margin-bottom: 10px;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-list {
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid #edf2ef;
}

.detail-list div:first-child {
  border-top: 0;
}

.detail-list .license-list-wrap {
  display: block;
}

.detail-list .license-list-wrap dt {
  margin-bottom: 8px;
}

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

.license-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.license-card strong,
.license-card span,
.license-card p {
  display: block;
}

.license-card strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
}

.license-card span {
  margin-top: 4px;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 11px;
  font-weight: 800;
}

.license-card p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.32;
}

dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

dd {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

.official-list {
  display: grid;
  gap: 9px;
}

.official-filter {
  display: grid;
  gap: 6px;
}

.official-filter span {
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.official {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.official-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.official-topline > div:not(.grade-badge):not(.official-photo-fallback) {
  min-width: 0;
  flex: 1 1 auto;
}

.official-photo {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  object-position: center top;
  background: var(--surface-strong);
}

.official-photo-fallback {
  display: grid;
  place-items: center;
  background: var(--color-3ma-navy);
  color: #fff;
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 17px;
  font-weight: 900;
}

.official strong {
  display: block;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 14px;
}

.official span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.contact-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.contact-email {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-3ma-navy);
  font-size: 12px;
}

.contact-copy {
  flex: 0 0 auto;
  padding: 6px 10px;
  font-size: 10px;
}

.contact-copy.is-copied {
  background: var(--color-3ma-navy);
  color: #fff;
}

.grade-badge {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  background: var(--color-3ma-navy);
  color: #fff;
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 15px;
  font-weight: 900;
}

.grade-badge.grade-a-plus {
  background: var(--color-3ma-gold);
  color: var(--color-3ma-navy);
}

.grade-badge.grade-a {
  background: #1d7a54;
}

.grade-badge.grade-b {
  background: var(--color-3ma-navy-tint);
}

.grade-badge.grade-c {
  background: #667085;
}

.grade-badge.grade-d,
.grade-badge.grade-f {
  background: var(--color-3ma-red);
}

.vote-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.vote-item {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.vote-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bill-label {
  display: block;
  min-width: 0;
  margin-top: 0;
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 11px;
  font-weight: 900;
  line-height: 1.2;
}

.vote-item p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.32;
}

.vote {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  margin-top: 0;
  min-height: 24px;
  border-radius: 6px;
  padding: 4px 7px;
  background: var(--color-3ma-light-gray);
  color: var(--muted);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 11px;
  font-weight: 800;
}

.vote.support {
  background: rgba(29, 122, 84, 0.12);
  color: #1d7a54;
}

.vote.oppose {
  background: rgba(194, 31, 50, 0.1);
  color: var(--color-3ma-red);
}

.vote.absent {
  background: rgba(102, 112, 133, 0.14);
  color: #667085;
}

.empty-state,
.sources li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.sources ul {
  margin: 0;
  padding-left: 18px;
}

.district-label {
  color: var(--color-3ma-navy);
  font-family: "Montserrat", Arial, sans-serif;
  font-weight: 900;
  text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}

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

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .map-stage {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 68vh;
    overflow: visible;
  }

  #map {
    height: 68vh;
  }

  .layer-panel {
    position: static;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    transform: none;
    display: block;
    width: auto;
    margin: 12px;
    padding: 14px;
  }

  fieldset {
    grid-column: auto;
    grid-row: auto;
    margin: 16px 0 0;
  }

  .party-legend {
    grid-column: auto;
    margin-top: 16px;
    padding-top: 13px;
    border-top: 2px solid var(--color-3ma-gold);
  }

  .last-updated {
    margin-top: 12px;
  }

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

@media (max-width: 720px) {
  .topbar {
    display: block;
    left: 12px;
    right: 12px;
    top: 12px;
  }

  .brand {
    max-width: none;
  }

  .brand h1 {
    font-size: 17px;
  }

  .status-strip {
    display: none;
  }

  .layer-panel {
    margin: 10px;
    padding: 13px;
  }

  .search-results {
    max-height: 180px;
  }

  .detail-panel {
    padding: 22px 16px 26px;
  }
}
