:root {
  --bg: #000;
  --surface: #0a0a0a;
  --raised: #111;
  --line: #1a1a1a;
  --line-strong: #333;
  --text: #ededed;
  --muted: #888;
  --dim: #555;
  --accent: #fff;
  --success: #00c853;
  --radius: 6px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Nav ───────────────────────────────────── */
.nav {
  height: 48px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.nav-vertical {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2px 8px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.nav-vertical:hover { border-color: var(--line-strong); color: var(--text); }

.nav-sep {
  color: var(--line-strong);
  font-size: 18px;
  font-weight: 300;
}

.nav-scope {
  color: var(--muted);
  font-size: 14px;
}

.nav-right {
  display: flex;
  gap: 8px;
}

/* ── Buttons ───────────────────────────────── */
.btn {
  height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms, border-color 120ms;
}

.btn:hover { background: var(--raised); border-color: var(--dim); }

.btn-ghost { border-color: transparent; }
.btn-ghost:hover { border-color: var(--line-strong); background: var(--raised); }

.btn-primary {
  background: #fff;
  color: #000;
  border-color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: #e5e5e5; border-color: #e5e5e5; }
.btn-primary:disabled { opacity: 1; cursor: wait; }

.btn-primary {
  position: relative;
  overflow: hidden;
}

.btn-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  transition: width 400ms ease;
  pointer-events: none;
}

.btn-primary:disabled .btn-progress-fill {
  background: rgba(0, 0, 0, 0.25);
}

.btn-progress-text {
  position: relative;
  z-index: 1;
}

/* ── Layout ────────────────────────────────── */
.shell { min-height: 100svh; max-width: 100vw; overflow-x: hidden; }

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  max-width: 100vw;
  overflow-x: hidden;
}

/* ── Panel ─────────────────────────────────── */
.panel {
  border-right: 1px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 48px;
  height: calc(100svh - 48px);
  overflow-y: auto;
  background: var(--bg);
}

.controls { display: flex; flex-direction: column; gap: 12px; }

.control-group { display: flex; flex-direction: column; gap: 4px; }
.control-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select {
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 120ms;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

input:focus, select:focus {
  border-color: var(--accent);
}

/* ── Exclude chips ─────────────────────────── */
.exclude-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 120ms;
}

.chip:hover { border-color: var(--dim); color: var(--text); }

.chip.is-excluded {
  background: #fff;
  color: #000;
  border-color: #fff;
}

/* ── Monitor card ──────────────────────────── */
.monitor-card {
  margin-top: auto;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Status ────────────────────────────────── */
.status-section { display: flex; flex-direction: column; gap: 8px; }

.status-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  font-size: 13px;
  color: var(--dim);
  position: relative;
  padding-left: 20px;
}

.step::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 28px;
  width: 1px;
  height: calc(100% - 14px);
  background: var(--line);
}

.step:last-child::before { display: none; }

.step-dot {
  position: absolute;
  left: 0;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  background: var(--raised);
  transition: all 200ms;
}

.step.active { color: var(--text); }
.step.active .step-dot { border-color: #fff; background: #fff; }

.step.done { color: var(--muted); }
.step.done .step-dot {
  border-color: var(--success);
  background: var(--success);
}

.status-msg {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--dim);
}

/* ── Sources ───────────────────────────────── */
.source-list { display: flex; flex-direction: column; gap: 2px; }

.source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  font-size: 13px;
  color: var(--dim);
}

.source-item.active { color: var(--muted); }

.source-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
  flex-shrink: 0;
}

.source-dot.on { background: var(--success); }

@keyframes source-blink {
  0%, 100% { background: #00c853; box-shadow: 0 0 4px #00c853; }
  50% { background: #00e676; box-shadow: 0 0 8px #00e676, 0 0 16px rgba(0, 230, 118, 0.3); }
}
.source-dot.active-now {
  background: #00c853;
  animation: source-blink 0.8s ease-in-out infinite;
}
.source-item[data-source].source-active-row { color: #ccc; }

/* ── Workspace ─────────────────────────────── */
.workspace {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line);
}

.workspace > * { background: var(--bg); }

/* ── KPI row ───────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  overflow: hidden;
}

.kpi {
  padding: 16px 20px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-value {
  font-family: "Geist Mono", "JetBrains Mono", monospace;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

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

/* ── Map ───────────────────────────────────── */
.map-area { display: flex; flex-direction: column; overflow: hidden; }

.map-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.view-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.toggle-btn {
  height: 28px;
  border: none;
  border-right: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 120ms;
}

.toggle-btn:last-child { border-right: none; }
.toggle-btn:hover { color: var(--text); background: var(--raised); }
.toggle-btn.is-active { background: #fff; color: #000; }

/* Map + detail: equal halves of the workspace row (extends map to ~50% of main content width) */
.map-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  height: 340px !important;
  max-height: 340px !important;
  overflow: hidden;
}

.map-canvas {
  height: 340px !important;
  max-height: 340px !important;
  background: var(--surface);
  overflow: hidden;
}

.detail-pane {
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  font-size: 13px;
  max-height: 340px;
}

.detail-pane h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.detail-pane p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.detail-pane a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--dim);
  text-underline-offset: 2px;
}

.detail-pane a:hover { text-decoration-color: var(--text); }

.empty-state {
  color: var(--dim);
  font-size: 13px;
}

.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0;
  font-family: "Geist Mono", monospace;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.score-badge .grade {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
}

.detail-tag {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
}
.detail-tag.tag-federal {
  border-color: #2a4a2a;
  background: rgba(0, 200, 83, 0.08);
  color: #4caf50;
}
.src-badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(0, 200, 83, 0.12);
  color: #4caf50;
  vertical-align: middle;
  margin-left: 4px;
}
.intent-badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255, 152, 0, 0.15);
  color: #ff9800;
  vertical-align: middle;
  margin-left: 4px;
}
.detail-tag.tag-intent {
  border-color: #4a3a1a;
  background: rgba(255, 152, 0, 0.1);
  color: #ff9800;
}
.detail-tag.tag-generator {
  border-color: #2a2a4a;
  background: rgba(100, 149, 237, 0.1);
  color: #6495ed;
}
.generator-badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(100, 149, 237, 0.15);
  color: #6495ed;
  vertical-align: middle;
  margin-left: 4px;
}

.detail-score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.detail-card {
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 10px;
}

.detail-card-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.contact-card {
  border-color: var(--success);
  background: rgba(0, 200, 83, 0.05);
}

.contact-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
}

.contact-title {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.contact-actions {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 6px;
}

.contact-action {
  font-size: 12px;
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 2px;
}

.contact-action:hover {
  text-decoration-color: var(--text);
}

.contact-notes {
  font-size: 11px;
  color: var(--muted);
  margin: 4px 0 0;
  line-height: 1.4;
  font-style: italic;
}

.contact-src {
  font-size: 10px;
  color: var(--dim);
  margin-top: 4px;
  display: block;
}

.confidence-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 6px;
  vertical-align: middle;
}

.conf-high { background: rgba(0, 200, 83, 0.15); color: #00c853; border: 1px solid rgba(0, 200, 83, 0.3); }
.conf-medium { background: rgba(255, 152, 0, 0.15); color: #FF9800; border: 1px solid rgba(255, 152, 0, 0.3); }
.conf-low { background: rgba(244, 67, 54, 0.15); color: #F44336; border: 1px solid rgba(244, 67, 54, 0.3); }

.email-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-field {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px solid var(--line);
}

.detail-field:last-child { border-bottom: none; }

.detail-field span:first-child {
  color: var(--dim);
  flex-shrink: 0;
}

.detail-field span:last-child,
.detail-field a {
  color: var(--muted);
  text-align: right;
  word-break: break-all;
}

.detail-field a {
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 2px;
}

.detail-rec {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  font-style: italic;
}

.detail-breakdown {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--dim);
}

.detail-breakdown span:nth-child(even) {
  text-align: right;
  font-family: "Geist Mono", monospace;
  color: var(--muted);
}

/* ── Table ─────────────────────────────────── */
.table-area { display: flex; flex-direction: column; overflow: hidden; }

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.table-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.table-count {
  font-size: 12px;
  color: var(--dim);
}

.table-scroll { overflow-x: auto; }

.lead-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

.lead-table th {
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 500;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
}

.lead-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 13px;
}

.lead-table tr { cursor: pointer; transition: background 80ms; }
.lead-table tbody tr:hover { background: var(--raised); }
.lead-table tbody tr.is-selected { background: var(--raised); }
.lead-table tbody tr.row-A { background: rgba(0, 180, 80, 0.10); }
.lead-table tbody tr.row-B { background: rgba(0, 130, 90, 0.09); }
.lead-table tbody tr.row-C { background: rgba(140, 110, 0, 0.08); }
.lead-table tbody tr.row-D { background: rgba(180, 60, 90, 0.09); }
.lead-table tbody tr.row-F { background: rgba(160, 20, 40, 0.10); }
.lead-table tbody tr.row-A:hover { background: rgba(0, 180, 80, 0.16); }
.lead-table tbody tr.row-B:hover { background: rgba(0, 130, 90, 0.14); }
.lead-table tbody tr.row-C:hover { background: rgba(140, 110, 0, 0.13); }
.lead-table tbody tr.row-D:hover { background: rgba(180, 60, 90, 0.14); }
.lead-table tbody tr.row-F:hover { background: rgba(160, 20, 40, 0.16); }

.cell-primary { font-weight: 500; }
.cell-secondary { color: var(--muted); font-size: 12px; margin-top: 1px; }

.cell-link {
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 2px;
  transition: color 120ms;
}
.cell-link:hover { color: var(--text); text-decoration-color: var(--text); }

.score-bar {
  width: 80px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
  margin-bottom: 4px;
}

.score-bar-fill {
  height: 100%;
  background: #fff;
  border-radius: 2px;
  transition: width 300ms;
}

.score-text {
  font-family: "Geist Mono", monospace;
  font-size: 12px;
  color: var(--muted);
}

.status-pill {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  white-space: nowrap;
}

/* ── Popup ─────────────────────────────────── */
.maplibregl-popup-content {
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

.maplibregl-popup-tip { border-top-color: var(--bg); }

/* ── Mobile panel toggle ──────────────────── */
.mobile-panel-toggle {
  display: none;
  width: 100%;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}
.mobile-panel-toggle .toggle-icon {
  font-size: 10px;
  margin-right: 6px;
  display: inline-block;
  transition: transform 200ms;
}
.panel.is-collapsed .mobile-panel-toggle .toggle-icon {
  transform: rotate(-90deg);
}
.panel.is-collapsed .controls,
.panel.is-collapsed .monitor-card {
  display: none !important;
}

/* ── Responsive ────────────────────────────── */

/* Tablet */
@media (max-width: 1060px) {
  .layout { grid-template-columns: 1fr; }
  .panel {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px;
  }
  .controls { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .control-group { min-width: 140px; flex: 1; }
  .monitor-card { margin-top: 0; flex-direction: row; flex-wrap: wrap; gap: 16px; }
  .status-section { min-width: 160px; }
  .map-split { grid-template-columns: 1fr; height: auto !important; max-height: none !important; }
  .detail-pane { border-left: 0; border-top: 1px solid var(--line); max-height: 300px; }
}

/* Mobile */
@media (max-width: 640px) {
  .nav { padding: 0 10px; height: 44px; }
  .logo span { font-size: 12px; }
  .nav-sep, .nav-scope { display: none; }
  .nav-right .btn { font-size: 11px; padding: 0 8px; height: 28px; }

  .mobile-panel-toggle { display: block; }
  .panel {
    padding: 12px;
    gap: 10px;
    flex-direction: column;
  }
  .panel.is-collapsed { padding: 12px; gap: 0; }
  .controls {
    flex-direction: column;
    gap: 8px;
  }
  .control-group { min-width: 0; }
  .control-group label { font-size: 11px; }
  input, select { height: 38px; font-size: 14px; }

  .panel .monitor-card {
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }
  .status-section { min-width: 0; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 22px; }
  .kpi-label { font-size: 11px; }

  .workspace { padding: 8px; gap: 1px; overflow-x: hidden; max-width: 100vw; }

  .map-bar {
    flex-direction: row;
    gap: 6px;
    align-items: center;
    padding: 6px 10px;
    flex-wrap: wrap;
  }
  .toggle-btn { font-size: 11px; padding: 0 8px; height: 26px; }

  .map-split {
    grid-template-columns: 1fr !important;
    height: auto !important;
    max-height: none !important;
    overflow: hidden;
  }
  .map-canvas {
    height: 150px !important;
    max-height: 150px !important;
    width: 100% !important;
    max-width: 100vw !important;
  }
  .detail-pane {
    max-height: 300px;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 12px;
  }
  .detail-pane h3 { font-size: 14px; }
  .score-badge { font-size: 20px; margin: 8px 0; }

  .table-header { padding: 8px 10px; }
  .table-header h2 { font-size: 13px; }
  .lead-table { min-width: 440px; }
  .lead-table th { padding: 6px 10px; font-size: 10px; }
  .lead-table td { padding: 8px 10px; font-size: 12px; }
  .lead-table th:last-child, .lead-table td:last-child { display: none; }
  .cell-secondary { font-size: 11px; }
  .score-bar { width: 50px; }

  .exclude-chips { gap: 4px; }
  .chip { height: 30px; font-size: 12px; padding: 0 12px; }

  .btn-primary { height: 42px; font-size: 15px; border-radius: 8px; }

  .detail-card { padding: 8px 10px; margin-top: 8px; }
  .detail-breakdown { grid-template-columns: 1fr 1fr; gap: 2px 8px; }
  .contact-card { padding: 10px; }

  .src-badge, .intent-badge { font-size: 8px; padding: 1px 4px; }
}

/* Small phones */
@media (max-width: 380px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 18px; }
  .map-canvas { height: 120px !important; max-height: 120px !important; }
  .lead-table { min-width: 380px; }
}

/* ── Animation ─────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.is-loading { animation: pulse 1.5s ease-in-out infinite; }
