﻿:root {
  --ink: #18201d;
  --muted: #66706b;
  --faint: #8a938f;
  --surface: #ffffff;
  --surface-soft: #f4f6f5;
  --line: #d9dfdc;
  --line-strong: #c5cdc9;
  --primary: #137a68;
  --primary-dark: #0d5c50;
  --primary-soft: #e6f2ef;
  --blue: #2f6f9f;
  --amber: #d18b17;
  --amber-soft: #fff4df;
  --danger: #c84f4a;
  --danger-soft: #fff0ef;
  --shadow: 0 10px 26px rgba(24, 32, 29, 0.14);
  --topbar-height: 60px;
  --sidebar-width: 326px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--surface-soft);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

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

body {
  font-size: 14px;
  line-height: 1.4;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="checkbox"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(19, 122, 104, 0.24);
  outline-offset: 2px;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  height: var(--topbar-height);
  padding: 0 14px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 244px;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: #fff;
  background: var(--ink);
  border-radius: 7px;
}

.brand-mark svg {
  width: 20px;
  height: 20px;
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.15;
}

.brand-copy strong {
  overflow: hidden;
  font-size: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.brand-copy span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.top-summary {
  display: flex;
  align-items: center;
  height: 100%;
  margin-left: 22px;
  gap: 24px;
  color: var(--muted);
  font-size: 12px;
}

.top-summary span {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.top-summary strong {
  color: var(--ink);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.top-actions {
  display: flex;
  align-items: center;
  margin-left: auto;
  gap: 10px;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  padding: 6px 8px;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}

.connection-status > span {
  width: 7px;
  height: 7px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.connection-status.error > span {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
}

.icon-button:hover {
  background: var(--surface-soft);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button.small {
  width: 30px;
  height: 30px;
}

.icon-button.small svg {
  width: 15px;
  height: 15px;
}

.icon-button.bordered {
  border: 1px solid var(--line-strong);
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: calc(100vh - var(--topbar-height));
}

.sidebar {
  position: relative;
  z-index: 10;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}

.sidebar-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar h1,
.sidebar h2,
.detail-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.sidebar h1 {
  font-size: 20px;
  line-height: 1.2;
}

.sidebar h2 {
  font-size: 13px;
}

#filterForm {
  display: flex;
  flex-direction: column;
  padding: 18px 20px 20px;
  border-bottom: 1px solid var(--line);
}

.field-label {
  margin: 13px 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.field-label:first-child {
  margin-top: 0;
}

input[type="search"],
select {
  width: 100%;
  height: 40px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

select {
  padding: 0 34px 0 11px;
}

input[type="search"] {
  min-width: 0;
  padding: 0 36px;
  cursor: text;
}

input[type="search"]::placeholder {
  color: var(--faint);
}

input[type="search"]:focus,
select:focus {
  border-color: var(--primary);
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field > svg {
  position: absolute;
  left: 11px;
  z-index: 1;
  width: 16px;
  height: 16px;
  color: var(--faint);
  pointer-events: none;
}

.clear-search {
  position: absolute;
  right: 5px;
  display: none;
  width: 30px;
  height: 30px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
}

.clear-search.visible {
  display: grid;
}

.clear-search:hover {
  background: var(--surface-soft);
}

.clear-search svg {
  width: 14px;
  height: 14px;
}

.toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  margin-top: 16px;
  gap: 12px;
}

.toggle-row > span:first-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.toggle-row strong {
  font-size: 12px;
}

.toggle-row small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.toggle-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.toggle-control {
  position: relative;
  width: 38px;
  height: 22px;
  flex: 0 0 auto;
  background: #aeb7b3;
  border-radius: 11px;
  transition: background 160ms ease;
}

.toggle-control::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(24, 32, 29, 0.28);
  transition: transform 160ms ease;
}

.toggle-row input:checked + .toggle-control {
  background: var(--primary);
}

.toggle-row input:checked + .toggle-control::after {
  transform: translateX(16px);
}

.toggle-row input:focus-visible + .toggle-control {
  outline: 3px solid rgba(19, 122, 104, 0.24);
  outline-offset: 2px;
}

.filter-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 18px;
  gap: 8px;
}

.primary-button,
.text-button {
  display: inline-flex;
  min-width: 0;
  height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  border-radius: 6px;
}

.primary-button {
  color: #fff;
  background: var(--primary);
  border: 1px solid var(--primary);
}

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

.text-button {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.text-button:hover {
  background: var(--surface-soft);
}

.primary-button svg,
.text-button svg {
  width: 15px;
  height: 15px;
}

.result-summary,
.review-section {
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
}

.section-title-row > span {
  color: var(--muted);
  font-size: 10px;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.metric-grid > div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 12px;
}

.metric-grid > div + div {
  border-left: 1px solid var(--line);
}

.metric-grid strong {
  overflow: hidden;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  text-overflow: ellipsis;
}

.metric-grid span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.review-line {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto 16px;
  width: 100%;
  min-height: 38px;
  align-items: center;
  padding: 0;
  gap: 8px;
  color: var(--ink);
  background: transparent;
  border: 0;
  text-align: left;
}

.review-line:hover span:nth-child(2) {
  color: var(--danger);
}

.review-line strong {
  font-variant-numeric: tabular-nums;
}

.review-line svg {
  width: 14px;
  height: 14px;
  color: var(--faint);
}

.legend-list {
  display: flex;
  margin-top: 8px;
  gap: 18px;
  color: var(--muted);
  font-size: 10px;
}

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

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.legend-dot.principal {
  background: var(--primary);
}

.legend-dot.secondary {
  background: var(--amber);
}

.legend-dot.outlier {
  background: var(--danger);
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #dfe6e2;
}

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

.maplibregl-map,
.maplibregl-canvas {
  outline: none;
}

.maplibregl-ctrl-top-right {
  top: 8px;
  right: 8px;
}

.maplibregl-ctrl-group {
  overflow: hidden;
  border: 1px solid rgba(50, 64, 58, 0.25);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(24, 32, 29, 0.12);
}

.maplibregl-ctrl-group button {
  width: 34px;
  height: 34px;
}

.maplibregl-popup-content {
  padding: 9px 11px;
  color: var(--ink);
  font-family: inherit;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.boundary-popup strong,
.boundary-popup span {
  display: block;
}

.boundary-popup strong {
  font-size: 12px;
}

.boundary-popup span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.map-loading,
.map-message {
  position: absolute;
  z-index: 5;
  top: 14px;
  left: 50%;
  display: flex;
  min-height: 38px;
  align-items: center;
  padding: 8px 12px;
  gap: 9px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(50, 64, 58, 0.18);
  border-radius: 6px;
  box-shadow: 0 5px 16px rgba(24, 32, 29, 0.12);
  font-size: 11px;
  transform: translateX(-50%);
}

.map-loading.hidden,
.map-message.hidden {
  display: none;
}

.map-message.error {
  color: #8f302d;
  background: var(--danger-soft);
  border-color: #edb9b6;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid #bdd1cb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.detail-panel {
  position: absolute;
  z-index: 8;
  top: 12px;
  right: 54px;
  width: min(340px, calc(100% - 72px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid rgba(50, 64, 58, 0.2);
  border-radius: 7px;
  box-shadow: var(--shadow);
  transform: translateX(calc(100% + 70px));
  visibility: hidden;
  transition: transform 180ms ease, visibility 180ms;
}

.detail-panel.open {
  transform: translateX(0);
  visibility: visible;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.status-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 8px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-badge.secondary {
  color: #8a5708;
  background: var(--amber-soft);
}

.status-badge.outlier {
  color: #923734;
  background: var(--danger-soft);
}

.detail-panel h2 {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

.client-id {
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 11px;
}

.detail-list {
  margin: 0;
  border-top: 1px solid var(--line);
}

.detail-list > div {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  padding: 10px 0;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.detail-list dt {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
}

.detail-list dt svg {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
}

.detail-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 11px;
  font-weight: 600;
}

.detail-actions {
  display: flex;
  margin-top: 16px;
  gap: 8px;
}

.detail-actions .primary-button {
  flex: 1;
}

.mobile-only,
.sidebar-backdrop,
.mobile-filter-button {
  display: none;
}

@media (max-width: 920px) {
  :root {
    --sidebar-width: 296px;
  }

  .top-summary {
    gap: 12px;
  }

  .connection-status {
    display: none;
  }
}

@media (max-width: 720px) {
  :root {
    --topbar-height: 56px;
  }

  .mobile-only {
    display: inline-grid;
  }

  .topbar {
    padding: 0 8px;
    gap: 6px;
  }

  .brand {
    min-width: 0;
    flex: 1;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand-copy strong {
    font-size: 14px;
  }

  .brand-copy span,
  .top-summary {
    display: none;
  }

  .top-actions {
    margin-left: 0;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: absolute;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(326px, calc(100vw - 44px));
    border-right: 0;
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

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

  .sidebar-backdrop {
    position: absolute;
    z-index: 29;
    inset: 0;
    background: rgba(18, 26, 22, 0.36);
  }

  .sidebar-backdrop.visible {
    display: block;
  }

  .map-stage {
    width: 100%;
    height: 100%;
  }

  .mobile-filter-button {
    position: absolute;
    z-index: 7;
    bottom: 22px;
    left: 50%;
    display: inline-flex;
    height: 40px;
    align-items: center;
    padding: 0 15px;
    gap: 7px;
    color: #fff;
    background: var(--ink);
    border: 0;
    border-radius: 6px;
    box-shadow: var(--shadow);
    font-size: 12px;
    font-weight: 700;
    transform: translateX(-50%);
  }

  .mobile-filter-button svg {
    width: 15px;
    height: 15px;
  }

  .detail-panel {
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-height: 58%;
    transform: translateY(calc(100% + 24px));
  }

  .detail-panel.open {
    transform: translateY(0);
  }

  .map-loading,
  .map-message {
    top: 10px;
    max-width: calc(100% - 92px);
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
