:root {
  color-scheme: light;
  --surface: oklch(0.985 0.004 190);
  --panel: oklch(0.965 0.007 190);
  --panel-strong: oklch(0.925 0.01 190);
  --text: oklch(0.22 0.018 210);
  --muted: oklch(0.48 0.018 210);
  --border: oklch(0.84 0.012 205);
  --accent: oklch(0.44 0.1 190);
  --accent-strong: oklch(0.36 0.12 190);
  --orange: oklch(0.58 0.14 55);
  --red: oklch(0.54 0.17 28);
  --purple: oklch(0.48 0.13 305);
  --green: oklch(0.5 0.11 145);
  --shadow: 0 18px 50px oklch(0.28 0.03 210 / 0.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* Minimal Leaflet layout fallback. The CDN stylesheet still provides complete
   control styling when available; these rules keep the map usable without it. */
.leaflet-container {
  position: relative;
  overflow: hidden;
  outline-offset: 1px;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-map-pane {
  z-index: 100;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-container img.leaflet-tile,
.leaflet-container .leaflet-marker-icon,
.leaflet-container .leaflet-marker-shadow {
  max-width: none;
  max-height: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  user-select: none;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 900;
  pointer-events: none;
}

.leaflet-top {
  top: 10px;
}

.leaflet-right {
  right: 10px;
}

.leaflet-bottom {
  bottom: 10px;
}

.leaflet-left {
  left: 10px;
}

.leaflet-control-zoom a,
.leaflet-control-layers-toggle {
  display: block;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  line-height: 28px;
  text-align: center;
  text-decoration: none;
}

.leaflet-control-layers {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 8px;
  font-size: 12px;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: var(--shadow);
  text-align: left;
}

.leaflet-popup-tip-container,
.leaflet-tooltip {
  display: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--surface);
}

body {
  overflow: hidden;
}

button,
select {
  font: inherit;
}

.page-body {
  min-height: 100%;
  overflow: auto;
  background: var(--panel);
}

.page-layout {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  min-height: 100vh;
}

.page-shell {
  display: grid;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.page-shell.wide {
  width: min(1480px, calc(100% - 32px));
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.page-header h1 {
  margin: 2px 0 10px;
  font-size: 22px;
  line-height: 1.15;
}

.label {
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
  text-transform: uppercase;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.site-nav a {
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a.active {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.workspace-nav {
  position: relative;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  min-width: 0;
  min-height: 100vh;
  border-right: 1px solid var(--border);
  background: oklch(0.955 0.009 205);
  padding: 12px 9px;
}

.nav-brand,
.nav-links a,
.nav-foot {
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  text-align: center;
  text-decoration: none;
}

.nav-brand {
  display: grid;
  gap: 4px;
  padding: 8px 5px;
}

.nav-brand span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border: 1px solid oklch(0.74 0.045 190);
  border-radius: 7px;
  background: oklch(0.98 0.006 185);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
}

.nav-brand strong,
.nav-foot span {
  display: block;
  overflow-wrap: anywhere;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
}

.nav-brand small,
.nav-foot small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
}

.nav-links {
  display: grid;
  align-content: start;
  gap: 7px;
}

.nav-links a {
  display: grid;
  place-items: center;
  min-height: 54px;
  padding: 7px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.15;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

.nav-links a:hover {
  border-color: oklch(0.78 0.035 200);
  background: oklch(0.982 0.005 190);
  color: var(--text);
}

.nav-links a.active {
  border-color: oklch(0.66 0.075 190);
  background: oklch(0.985 0.006 190);
  color: var(--accent-strong);
  box-shadow: 0 8px 22px oklch(0.3 0.04 200 / 0.1);
}

.nav-foot {
  display: grid;
  gap: 3px;
  padding: 8px 4px;
}

.page-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.page-section {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.page-section h2 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  text-transform: uppercase;
}

.split-section {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stage-card,
.compact-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  padding: 11px;
}

.stage-head,
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-head strong {
  overflow-wrap: anywhere;
}

.stage-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  margin: 10px 0;
}

.stage-card dl div {
  min-width: 0;
}

.stage-card dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.stage-card dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

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

.quality-stack {
  display: grid;
  gap: 8px;
}

.quality-stack div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 22px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 750;
  line-height: 16px;
  text-transform: uppercase;
}

.badge.status-good,
.badge.status-candidate {
  border-color: oklch(0.7 0.08 150);
  color: oklch(0.36 0.09 150);
}

.badge.status-review,
.badge.status-requires_manual_polygon {
  border-color: oklch(0.74 0.11 55);
  color: oklch(0.42 0.1 55);
}

.badge.status-poor,
.badge.status-unknown {
  border-color: oklch(0.7 0.12 25);
  color: oklch(0.44 0.13 25);
}

.table-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.table-toolbar select {
  width: 150px;
  min-height: 32px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.data-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.35;
}

.data-table.dense {
  min-width: 900px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.data-table td strong,
.data-table td small {
  display: block;
  max-width: 260px;
  overflow-wrap: anywhere;
}

.data-table td small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

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

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

.map {
  width: 100%;
  height: 100%;
  background: oklch(0.93 0.009 190);
}

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

.identity,
.status-strip {
  pointer-events: auto;
  border: 1px solid var(--border);
  background: oklch(0.985 0.004 190 / 0.94);
  box-shadow: var(--shadow);
}

.identity {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  max-width: min(520px, 62vw);
}

.identity .label {
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.identity h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
}

.status-strip {
  max-width: 360px;
  padding: 9px 11px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
}

.control-block,
.detail-block {
  display: grid;
  gap: 7px;
}

.control-block label,
.detail-block h2 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

select:focus {
  outline: 2px solid oklch(0.72 0.09 190);
  outline-offset: 1px;
}

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

.metric {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  padding: 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 19px;
  font-weight: 750;
  line-height: 1.05;
}

.detail-block {
  border-top: 1px solid var(--border);
  padding-top: 13px;
}

.detail-content {
  display: grid;
  gap: 9px;
  font-size: 13px;
  line-height: 1.38;
}

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

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

.detail-row strong,
.detail-row span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.note {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  padding: 9px;
  color: var(--text);
}

.note.warning {
  border-color: oklch(0.76 0.1 55);
  background: oklch(0.96 0.025 70);
}

.facility-roles {
  display: grid;
  gap: 7px;
}

.facility-role {
  display: grid;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  padding: 9px;
}

.facility-role > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.facility-role strong,
.facility-role span,
.facility-role small,
.facility-role p {
  min-width: 0;
  overflow-wrap: anywhere;
}

.facility-role strong {
  font-size: 13px;
  line-height: 1.2;
}

.facility-role span,
.facility-role small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.facility-role p {
  margin: 0;
  color: var(--text);
}

.facility-role.status-candidate {
  border-color: oklch(0.72 0.065 155);
}

.facility-role.status-requires_manual_polygon {
  border-color: oklch(0.72 0.1 35);
  background: oklch(0.965 0.018 55);
}

.provider-links {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.provider-links a {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent-strong);
  padding: 6px 9px;
  text-decoration: none;
}

.provider-links a:hover {
  border-color: var(--accent);
}

.legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  color: var(--muted);
  font-size: 12px;
}

.legend label,
.base-control {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
}

.base-control {
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.base-control select {
  width: 180px;
  min-height: 34px;
}

.legend input {
  width: 15px;
  height: 15px;
  margin: 0;
}

.swatch {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: var(--muted);
}

.swatch.road {
  background: oklch(0.55 0.02 210);
}

.swatch.track {
  background: var(--orange);
}

.swatch.snapped {
  background: var(--accent);
}

.swatch.offset {
  background: var(--red);
}

.swatch.object {
  background: var(--purple);
}

.swatch.cluster {
  background: var(--green);
}

.swatch.location {
  background: oklch(0.56 0.07 230);
}

.swatch.facility {
  background: oklch(0.55 0.09 45);
}

.swatch.road-missing {
  background: oklch(0.58 0.15 30);
}

.swatch.osm-missing {
  background: oklch(0.44 0.12 285);
}

.leaflet-control-layers,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  color: var(--text);
  background: var(--surface);
}

.leaflet-popup-content {
  margin: 10px 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.35;
}

.popup-title {
  display: block;
  margin-bottom: 5px;
  font-weight: 750;
}

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

  .page-layout,
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .app-shell {
    grid-template-rows: auto minmax(520px, 58vh) auto;
  }

  .workspace-nav {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto;
    align-items: center;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 8px 10px;
  }

  .nav-brand {
    grid-template-columns: auto;
    width: 56px;
    padding: 0;
  }

  .nav-brand strong,
  .nav-brand small {
    display: none;
  }

  .nav-brand span {
    width: 42px;
    height: 42px;
  }

  .nav-links {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: auto;
  }

  .nav-links a {
    min-width: 104px;
    min-height: 38px;
    padding: 7px 10px;
  }

  .map-stage,
  .inspector {
    height: auto;
  }

  .map-stage {
    min-height: 520px;
  }

  .inspector {
    border-left: 0;
    border-top: 1px solid var(--border);
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .identity,
  .status-strip {
    max-width: none;
  }

  .metric-grid,
  .legend {
    grid-template-columns: 1fr;
  }

  .page-header,
  .split-section {
    grid-template-columns: 1fr;
  }

  .page-header {
    display: grid;
  }

  .page-metrics,
  .stage-grid {
    grid-template-columns: 1fr;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}
