:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #262b36;
  --text: #e6e8ec;
  --muted: #8b93a4;
  --accent: #4cc9f0;
  --accent2: #f72585;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
header {
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 0.9rem 2rem 0;
}
.header-top {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 0.7rem;
}
.header-controls {
  margin-left: auto;
  display: flex; align-items: center; gap: 0.6rem;
}
.hdr-select {
  appearance: none; -webkit-appearance: none;
  background: #222836 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M0 0l5 6 5-6z' fill='%238b93a4'/></svg>") right 0.6rem center no-repeat;
  color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.4rem 1.8rem 0.4rem 0.7rem;
  font-size: 0.9rem; font-family: inherit; cursor: pointer;
}
.hdr-select:focus { outline: none; border-color: var(--accent); }
nav {
  display: flex; flex-wrap: nowrap; overflow-x: auto;
  gap: 0.15rem; padding-bottom: 0.25rem;
}
nav::-webkit-scrollbar { height: 0; }
.search-box { position: relative; }
.search-box input {
  appearance: none; -webkit-appearance: none;
  background: #222836; color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.45rem 0.75rem; font-size: 0.9rem; width: 260px;
  font-family: inherit;
}
.search-box input::placeholder { color: var(--muted); }
.search-box input:focus { outline: none; border-color: var(--accent); }
.search-results {
  position: absolute; top: 100%; right: 0; margin-top: 4px;
  width: 380px; max-height: 440px; overflow-y: auto;
  background: #1b1f28; border: 1px solid var(--border); border-radius: 6px;
  z-index: 1000; display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.search-results.open { display: block; }
.search-results a {
  display: block; padding: 0.6rem 0.75rem; color: var(--text);
  text-decoration: none; border-bottom: 1px solid var(--border);
}
.search-results a:hover { background: #222836; }
.search-results .name { font-weight: 600; }
.search-results .meta { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.search-results .empty { padding: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.1rem; }
.brand-logo { width: 32px; height: 32px; display: block; }
nav a {
  color: var(--muted); text-decoration: none; white-space: nowrap;
  padding: 0.4rem 0.9rem; border-radius: 4px 4px 0 0; font-size: 0.9rem;
  border-bottom: 2px solid transparent;
}
nav a:hover { color: var(--text); background: #222836; }
nav a.active {
  color: var(--text); background: transparent; border-bottom-color: var(--accent);
}
main { padding: 2rem; max-width: 1400px; margin: 0 auto; }
h1 { margin-top: 0; }
h2 { font-size: 1rem; margin: 0 0 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.muted { color: var(--muted); }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 1.25rem; margin-bottom: 1.5rem;
}
.card canvas { max-height: 320px; }
.card.tall { max-width: 1100px; margin-left: auto; margin-right: auto; }
.card.tall canvas { height: 640px !important; max-height: none; }
@media (max-width: 1100px) { .card.tall { max-width: 100%; } }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem;
}
.kpis.kpis-grid-multi { grid-template-columns: repeat(2, 1fr); }
.kpi-group {
  background: var(--panel); border: 1px solid var(--border);
  border-top-width: 3px; border-radius: 8px; padding: 1rem;
}
.kpi-group-city {
  color: var(--muted); font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.1em; margin-bottom: 0.75rem;
}
.kpi-mini { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.kpi-mini > div { display: flex; flex-direction: column; }
.kpi-mini .label { color: var(--muted); font-size: 0.75rem; }
.kpi-mini .value { font-size: 1.3rem; font-weight: 700; }
.kpi {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1rem;
}
.kpi .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; }
.kpi .value { font-size: 1.6rem; font-weight: 700; margin-top: 0.25rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
.toolbar { margin-bottom: 1rem; }
.toolbar label { margin-right: 1rem; color: var(--muted); }

.map-layout {
  display: grid; grid-template-columns: 1fr 380px; gap: 1rem;
}
.zip-panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; max-height: 640px; overflow-y: auto;
}
.zip-panel h3 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.zip-list { list-style: none; padding: 0; margin: 0; }
.zip-list li { border-bottom: 1px solid var(--border); }
.zip-list a {
  display: block; padding: 0.6rem 0.25rem;
  color: var(--text); text-decoration: none;
}
.zip-list a:hover { background: #222836; }
.zip-list .name { font-weight: 600; font-size: 0.9rem; }
.zip-list .meta { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

/* ---- Responsive breakpoints ---- */
@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis.kpis-grid-multi { grid-template-columns: 1fr; }
  .map-layout { grid-template-columns: 1fr; }
  .zip-panel { max-height: 400px; }
  main { padding: 1rem; }
  header { padding: 0.75rem 1rem 0; }
  .search-box input { width: 180px; }
  .search-results { width: 260px; }
}
@media (max-width: 700px) {
  .header-top { flex-wrap: wrap; }
  .header-controls { width: 100%; margin-left: 0; }
  .search-box { flex: 1; }
  .search-box input { width: 100%; }
  .search-results { width: 100%; right: auto; left: 0; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr; }
  .brand span { display: none; }
  nav a { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
  .card { padding: 0.9rem; }
  h1 { font-size: 1.4rem; }
  .card canvas { max-height: 280px; }
  table { font-size: 0.8rem; }
  th, td { padding: 0.35rem; }
}
.status-success { color: #4ade80; }
.status-failed { color: #f87171; }
.status-running { color: var(--accent); }

.empty-msg {
  padding: 2rem; text-align: center; color: var(--muted);
  font-size: 0.9rem;
}
.spinner {
  display: inline-block; width: 18px; height: 18px; vertical-align: middle;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.card.loading { position: relative; min-height: 120px; }
.card.loading::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 24px; height: 24px; margin: -12px 0 0 -12px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: ' ↕'; color: var(--border); font-size: 0.75em; }
th.sortable.asc::after { content: ' ↑'; color: var(--accent); }
th.sortable.desc::after { content: ' ↓'; color: var(--accent); }

.filters {
  display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center;
  margin-bottom: 1rem;
}
.filter-input {
  appearance: none; -webkit-appearance: none;
  background: #222836; color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.4rem 0.7rem; font-size: 0.9rem;
  font-family: inherit;
}
.filter-input:focus { outline: none; border-color: var(--accent); }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.4rem 0.9rem; font-size: 0.9rem; cursor: pointer;
  font-family: inherit;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

.hover-table tbody tr { cursor: pointer; }
.hover-table tbody tr:hover { background: #1b2029; }
.hover-table .num { text-align: right; }
.hover-table th.num { text-align: right; }

.match-fuzzy_zip_block { color: #4ade80; }
.match-mb_only { color: #f9c74f; }
.match-inspection_only { color: #8b93a4; }

.pagination {
  display: flex; gap: 1rem; align-items: center; justify-content: center;
  margin-top: 1rem;
}

.breadcrumbs {
  margin-bottom: 1rem; color: var(--muted); font-size: 0.9rem;
}
.breadcrumbs a { color: var(--accent); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

.clickable { cursor: pointer; }

.controls-row {
  display: flex; gap: 1rem; align-items: center;
  margin-bottom: 1rem; flex-wrap: wrap;
}
.controls-row label { color: var(--muted); font-size: 0.85rem; }
.controls-row input[type="range"] { vertical-align: middle; }
