:root {
  --bg: #f5f7f8;
  --ink: #182126;
  --muted: #66737b;
  --line: #d8e0e4;
  --crm: #2563eb;
  --gps: #7c3aed;
  --ok: #148f5a;
  --warn: #d97904;
  --bad: #be123c;
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

h1 {
  margin: 0;
  font-size: 22px;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #44525a;
  font-size: 12px;
  font-weight: 650;
}

select,
input {
  min-width: 120px;
  height: 36px;
  border: 1px solid #cbd5da;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
}

button {
  font: inherit;
}

.secondary-button {
  height: 36px;
  border: 1px solid #aab7be;
  border-radius: 6px;
  background: #182126;
  color: white;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.content {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 600px;
  overflow: hidden;
}

.map-column {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
}

.filter-row label {
  flex-direction: row;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}

.filter-row input {
  min-width: 0;
  width: 15px;
  height: 15px;
  padding: 0;
}

.map-home-button {
  height: 30px;
  border: 1px solid #c5d0d6;
  border-radius: 6px;
  background: white;
  color: #2f3b42;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.map-home-button:hover,
.map-home-button:focus {
  border-color: #93a4ae;
  background: #eef4f7;
  outline: none;
}

#map {
  flex: 1;
  min-height: 0;
}

.legend {
  flex: 0 0 auto;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: white;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}

.dot.crm {
  background: var(--crm);
}

.dot.breadcrumb {
  background: #0891b2;
}

.dot.matched {
  background: var(--ok);
}

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

.panel {
  min-width: 0;
  min-height: 0;
  background: white;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.status {
  flex: 0 0 auto;
  padding: 14px 16px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.summary-grid {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.summary-grid div {
  padding: 14px 10px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.summary-grid div:last-child {
  border-right: none;
}

.summary-grid strong {
  display: block;
  font-size: 24px;
}

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

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid #edf1f3;
  vertical-align: top;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafb;
  z-index: 1;
  color: #4b5961;
  font-size: 11px;
  text-transform: uppercase;
}

tbody tr[data-row-key] {
  cursor: pointer;
}

tbody tr[data-row-key]:hover,
tbody tr[data-row-key]:focus {
  background: #f3f7fa;
  outline: none;
}

tbody tr.selected {
  background: #e9f2ff;
  box-shadow: inset 4px 0 0 #2563eb;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 11px;
  white-space: nowrap;
}

.pill.matched {
  background: #dff8eb;
  color: #0f6b43;
}

.pill.no_gps_stop,
.pill.no_nearby_gps,
.pill.outside_gps_coverage,
.pill.gps_only,
.pill.breadcrumb_only {
  background: #fff2dc;
  color: #9a5700;
}

.pill.unresolved_geocode {
  background: #ffe4ea;
  color: #9f1239;
}

.time-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.time-pill.within {
  background: #dff8eb;
  color: #0f6b43;
}

.time-pill.short {
  background: #ffe4ea;
  color: #9f1239;
}

.time-pill.long {
  background: #e0f2fe;
  color: #075985;
}

.time-pill.unknown {
  background: #eef2f5;
  color: #5b6870;
}

.subtle {
  color: var(--muted);
  font-size: 11px;
}

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

  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

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

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

  .panel {
    border-left: none;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  .table-wrap {
    max-height: 70vh;
  }

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