:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #eef3f1;
  --ink: #17211d;
  --muted: #68766f;
  --line: #d9e1dd;
  --line-strong: #bac8c1;
  --accent: #17694f;
  --accent-dark: #0f503c;
  --accent-soft: #e3f2ec;
  --warning: #a66a00;
  --shadow: 0 18px 55px rgba(23, 33, 29, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.system-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

.source-status {
  display: grid;
  justify-items: end;
  min-width: 150px;
}

.source-status strong {
  font-size: 28px;
  line-height: 1;
}

.source-status span {
  color: var(--muted);
  font-size: 13px;
}

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

.filters-panel {
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label,
.select-label {
  color: #405049;
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
  font-size: 14px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 105, 79, 0.15);
}

.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 18px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: #405049;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button {
  height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.button.primary {
  background: var(--accent);
  color: white;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}

.data-note {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.data-note strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.workspace {
  min-width: 0;
  height: calc(100vh - 88px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-controls select {
  width: 145px;
}

.segmented {
  display: inline-flex;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #f5f7f8;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(23, 33, 29, 0.1);
}

.content-grid {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(440px, 1.05fr);
  gap: 18px;
  padding: 18px;
}

.results-panel,
.map-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.results-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.selected-card {
  margin: 12px 12px 0;
  border: 1px solid #b7d7cb;
  border-radius: var(--radius);
  background: var(--accent-soft);
  padding: 12px;
}

.results-list {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.result-card {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.result-card + .result-card {
  margin-top: 10px;
}

.result-card:hover,
.result-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 105, 79, 0.09);
}

.result-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.result-title strong {
  font-size: 15px;
  line-height: 1.25;
}

.district-tag {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #edf1f0;
  color: #405049;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
}

.result-meta,
.selected-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.precision {
  color: var(--warning);
  font-size: 12px;
  font-weight: 800;
}

.precision.exact {
  color: var(--accent);
}

.load-more {
  margin: 0 12px 12px;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.map-panel {
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #dfe7e2;
}

.map-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: #edf1f0;
  color: var(--muted);
  text-align: center;
  z-index: 2;
}

.map-fallback[hidden],
.selected-card[hidden],
.load-more[hidden] {
  display: none;
}

.map-legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 500;
  display: flex;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 10px;
  color: #405049;
  font-size: 12px;
  font-weight: 800;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: -1px;
}

.dot.exact {
  background: var(--accent);
}

.dot.approximate {
  background: var(--warning);
}

.leaflet-popup-content {
  margin: 12px;
  min-width: 220px;
  font-family: inherit;
}

.popup-title {
  margin: 0 0 8px;
  font-size: 14px;
}

.popup-list {
  margin: 0;
  padding-left: 18px;
  color: #405049;
  font-size: 12px;
}

.app-shell.view-form .content-grid {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.view-form .map-panel {
  display: none;
}

.app-shell.view-map .content-grid {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.view-map .results-panel {
  display: none;
}

.app-shell.view-map #map {
  min-height: calc(100vh - 180px);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .workspace {
    height: auto;
  }

  .content-grid {
    height: auto;
  }

  .filters-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  #map {
    min-height: 460px;
  }
}

@media (max-width: 720px) {
  .topbar,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .source-status {
    justify-items: start;
  }

  .filters-panel,
  .content-grid,
  .toolbar {
    padding: 14px;
  }

  .field-grid,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .toolbar-controls {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-controls select,
  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1 1 0;
    padding: 0 6px;
  }

  .result-title {
    display: grid;
  }
}
