:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --line: #d8dee4;
  --line-strong: #b8c0cc;
  --text: #182230;
  --muted: #667085;
  --nav: #17202a;
  --nav-active: #233143;
  --accent: #0e9384;
  --accent-dark: #0b7569;
  --blue: #175cd3;
  --red: #b42318;
  --orange: #b54708;
  --green: #067647;
  --shadow: 0 12px 32px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  background: var(--nav);
  color: #f7fafc;
  padding: 16px 12px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 4px 8px 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #0e9384;
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-subtitle {
  color: #b9c3cf;
  font-size: 12px;
}

.section-nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d8dee8;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
}

.nav-item.active {
  background: var(--nav-active);
  color: #ffffff;
}

.nav-index {
  color: #97a3b3;
  font-size: 12px;
  text-align: center;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #667085;
}

.nav-status.active {
  background: #32d583;
}

.workspace {
  min-width: 0;
  padding: 18px 20px 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.page-meta {
  min-height: 20px;
  color: var(--muted);
  margin-top: 4px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.button:hover {
  border-color: #8d99a8;
}

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

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

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(128px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

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

.tabs-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px;
}

.tab-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.tab-button {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.tab-button.active {
  background: #e7f8f5;
  border-color: #8edbd0;
  color: #095c53;
  font-weight: 700;
}

.filter-settings-button {
  margin-left: auto;
  white-space: nowrap;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(4, minmax(140px, 0.7fr)) auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: visible;
}

.filter-bar.compact {
  grid-template-columns: minmax(220px, 1.4fr) repeat(3, minmax(140px, 0.8fr)) auto;
}

.input,
.select {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: white;
  color: var(--text);
}

.toggle-field {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 10px;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
}

.multi-select {
  position: relative;
  min-width: 0;
}

.multi-select-button {
  display: flex;
  width: 100%;
  min-height: 36px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: white;
  color: var(--text);
  cursor: pointer;
}

.multi-select-button:hover {
  border-color: #8d99a8;
}

.multi-select-button span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multi-select-caret {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  transition: transform 120ms ease;
}

.multi-select.open .multi-select-caret {
  transform: rotate(180deg);
}

.multi-select-menu {
  position: absolute;
  z-index: 600;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  display: none;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

.multi-select.open .multi-select-menu {
  display: grid;
  gap: 3px;
}

.multi-select-option {
  display: flex;
  min-height: 30px;
  align-items: center;
  gap: 7px;
  padding: 5px 7px;
  border-radius: 6px;
  color: #344054;
  cursor: pointer;
}

.multi-select-option:hover {
  background: var(--panel-soft);
}

.multi-select-option input {
  flex: 0 0 auto;
  margin: 0;
}

.multi-select-option span {
  min-width: 0;
}

.checkbox-group {
  display: flex;
  min-height: 36px;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: white;
}

.checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: #344054;
  font-size: 12px;
  white-space: nowrap;
}

.checkbox-option input {
  margin: 0;
}

.chips-row {
  display: flex;
  min-height: 32px;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 8px 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #344054;
}

.chip span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chip button {
  border: 0;
  background: transparent;
  color: #667085;
  cursor: pointer;
  padding: 0;
}

.content-grid {
  min-height: 520px;
}

.split-view {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 1fr);
  gap: 12px;
}

.split-view.map-split {
  grid-template-columns: minmax(520px, 1.45fr) minmax(380px, 0.8fr);
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.panel-title {
  font-weight: 800;
}

.panel-meta {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  max-height: 620px;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f6;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

td {
  background: white;
}

.name-cell {
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

a {
  color: var(--blue);
  text-decoration: none;
}

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2f6;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.risk {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.critical_risk {
  color: var(--red);
  background: #fee4e2;
}

.high_risk {
  color: var(--orange);
  background: #fef0c7;
}

.possible_risk {
  color: var(--blue);
  background: #d1e9ff;
}

.watch {
  color: #475467;
  background: #eaecf0;
}

.map-panel {
  position: relative;
  height: 620px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(23, 92, 211, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(23, 92, 211, 0.06) 1px, transparent 1px),
    #eef6f3;
  background-size: 48px 48px;
}

.leaflet-map-panel {
  background: #dfe8e2;
}

.leaflet-map-panel .leaflet-popup-content {
  margin: 10px 12px;
  min-width: 220px;
}

.leaflet-map-panel .leaflet-control-attribution {
  font-size: 10px;
}

.business-cluster-icon {
  border: 0;
  background: transparent;
}

.business-cluster-icon span {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: rgba(23, 92, 211, 0.88);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.22);
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 52px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.map-mode-toggle {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.map-mode-button {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: white;
  color: #344054;
  font-size: 12px;
  cursor: pointer;
}

.map-mode-button:last-child {
  border-right: 0;
}

.map-mode-button.active {
  background: #175cd3;
  color: white;
}

.map-layer-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: #344054;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.map-layer-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: #175cd3;
}

.map-radius-field {
  display: grid;
  grid-template-columns: auto 112px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.map-radius-field .input {
  min-height: 34px;
}

.map-stats {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.map-limit-notice {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.14);
}

.map-category-legend {
  display: grid;
  gap: 4px;
  max-width: 260px;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.14);
}

.map-category-legend-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-width: 0;
  color: var(--text);
  font-size: 12px;
}

.map-category-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.map-category-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-category-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.map-dot {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid white;
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.25);
  transform: translate(-50%, -50%);
}

.map-dot.risk-dot {
  width: 7px;
  height: 7px;
  background: var(--red);
}

.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
}

.map-popup {
  display: grid;
  gap: 4px;
  color: var(--text);
  line-height: 1.35;
}

.map-popup details {
  margin-top: 4px;
}

.map-popup summary {
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
}

.raw-json {
  max-width: 340px;
  max-height: 180px;
  overflow: auto;
  margin: 6px 0 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #344054;
  font-size: 11px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.map-result-list {
  display: grid;
  max-height: 620px;
  overflow: auto;
}

.map-result-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: white;
}

.map-result-main {
  min-width: 0;
}

.map-result-main strong,
.map-result-main div {
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-selection-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: white;
}

.map-selection-head {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.map-selection-head strong,
.map-selection-head div {
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-selection-popup .map-popup {
  display: grid;
  gap: 5px;
  line-height: 1.35;
}

.map-detail-list {
  display: grid;
  gap: 6px;
}

.map-detail-row {
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  font-size: 12px;
}

.map-detail-row span {
  color: var(--muted);
}

.vri-class-chip {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid color-mix(in srgb, var(--vri-color) 58%, #ffffff);
  border-radius: 999px;
  background: color-mix(in srgb, var(--vri-color) 16%, #ffffff);
  color: #111827;
  font-size: 11px;
  line-height: 1.25;
}

.vri-manual-control {
  display: grid;
  gap: 4px;
  margin-top: 4px;
}

.vri-manual-control > span {
  color: var(--muted);
  font-size: 11px;
}

.vri-manual-control .select {
  min-height: 32px;
  font-size: 12px;
}

.tag-risk {
  color: var(--red);
  background: #fee4e2;
}

.tag-planning {
  color: #5925dc;
  background: #ebe9fe;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.placeholder-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.placeholder-item {
  min-height: 128px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.placeholder-item strong {
  display: block;
  margin-bottom: 8px;
}

.selection-list {
  display: grid;
  gap: 10px;
}

.selection-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(16, 24, 40, 0.52);
}

.modal-backdrop[hidden] {
  display: none;
}

.filter-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1080px, 100%);
  max-height: min(820px, calc(100vh - 56px));
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgba(16, 24, 40, 0.28);
  overflow: hidden;
}

.filter-modal-header,
.filter-modal-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.filter-modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.filter-modal-title {
  font-size: 18px;
  font-weight: 800;
}

.filter-modal-meta {
  color: var(--muted);
  font-size: 12px;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.filter-modal-body {
  display: grid;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background: var(--panel-soft);
}

.filter-modal-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.filter-modal-section-title {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
  font-weight: 800;
}

.filter-modal-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 10px;
  padding: 12px;
}

.modal-field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.modal-field > span {
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.modal-field small {
  color: var(--muted);
  font-size: 11px;
}

.range-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.modal-check-list {
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.modal-check-option {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
  padding: 5px 4px;
  border-radius: 5px;
  color: #344054;
  font-size: 12px;
  line-height: 1.3;
}

.modal-check-option:hover {
  background: #f8fafc;
}

.modal-check-option input {
  width: 14px;
  height: 14px;
  margin: 1px 0 0;
  accent-color: #175cd3;
}

.filter-apply-button {
  min-width: 170px;
  border-color: var(--blue);
  background: var(--blue);
}

.filter-apply-button:hover {
  border-color: #1849a9;
  background: #1849a9;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .metrics-strip {
    grid-template-columns: repeat(3, minmax(128px, 1fr));
  }

  .filter-bar,
  .filter-bar.compact {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .filter-modal-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .split-view {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding-bottom: 8px;
  }

  .section-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    min-width: 190px;
  }

  .workspace {
    padding: 14px;
  }

  .topbar {
    display: grid;
  }

  .metrics-strip {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .filter-bar,
  .filter-bar.compact {
    grid-template-columns: 1fr;
  }

  .tabs-row {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-settings-button {
    margin-left: 0;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .filter-modal {
    max-height: calc(100vh - 24px);
  }

  .filter-modal-grid {
    grid-template-columns: 1fr;
  }

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