:root {
  --bg-base: #eaf3f8;
  --canvas-bg: #e8f2f8;
  --text-primary: #0c1e2e;
  --text-secondary: rgba(12, 30, 46, 0.62);
  --accent: #2563eb;
  --accent-2: #0d9488;
  --accent-text: #1d4ed8;
  --accent-gradient: linear-gradient(115deg, #2563eb 0%, #0ea5e9 45%, #0d9488 100%);
  --danger: #e5484d;
  --success: #30a46c;
  --bg-elevated: rgba(255, 255, 255, 0.72);
  --border: rgba(37, 99, 235, 0.14);
  --shadow-sm: 0 1px 2px rgba(40, 20, 80, 0.08), 0 8px 24px rgba(40, 20, 80, 0.08);
  --shadow-md: 0 4px 16px rgba(40, 20, 80, 0.1), 0 24px 48px rgba(40, 20, 80, 0.08);
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-btn: 10px / 50%;
  --font: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html[data-theme="dark"] {
  --bg-base: #061018;
  --canvas-bg: #061018;
  --text-primary: #e8f4ff;
  --text-secondary: rgba(232, 244, 255, 0.62);
  --accent: #3b82f6;
  --accent-2: #14b8a6;
  --accent-text: #93c5fd;
  --bg-elevated: rgba(12, 24, 36, 0.72);
  --border: rgba(100, 160, 255, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--canvas-bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-text); }

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--canvas-bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 14px; background: var(--accent-gradient); font-size: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.brand-title { font-weight: 800; font-size: 1.05rem; line-height: 1.2; }
.brand-sub { font-size: 0.72rem; color: var(--text-secondary); font-weight: 600; }

.tabs { display: flex; gap: 8px; }
.tab {
  min-height: 44px; padding: 0 14px; border: 1px solid var(--border);
  border-radius: var(--radius-btn); background: var(--bg-elevated);
  font-weight: 700; cursor: pointer;
}
.tab.active {
  background: var(--accent); color: #fff; border-color: transparent;
}
.badge {
  display: inline-grid; place-items: center; min-width: 1.4em; height: 1.4em;
  padding: 0 6px; border-radius: 999px; background: rgba(255,255,255,.25);
  font-size: 0.75rem; margin-left: 4px;
}
.tab:not(.active) .badge { background: rgba(37,99,235,.12); color: var(--accent-text); }

main { flex: 1; padding: 16px; max-width: 1280px; width: 100%; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.glass {
  background: var(--bg-elevated);
  backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.search-card { padding: 16px; margin-bottom: 16px; }
.grid-3 {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
@media (max-width: 800px) {
  .grid-3 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; font-weight: 700; color: var(--text-secondary); }
input, select {
  min-height: 44px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(255,255,255,.7); font-size: 16px;
}
html[data-theme="dark"] input, html[data-theme="dark"] select { background: rgba(0,0,0,.25); }
.tip { margin: 12px 0 0; color: var(--text-secondary); font-size: 0.9rem; font-weight: 600; }
.hint { margin: 10px 0 0; font-size: 0.75rem; color: var(--text-secondary); }
.row.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.check { flex-direction: row; align-items: center; gap: 8px; font-size: 0.85rem; }
.check input { width: 18px; height: 18px; min-height: 0; }

.btn {
  min-height: 44px; padding: 0 16px; border-radius: var(--radius-btn);
  border: 1px solid var(--border); background: var(--bg-elevated);
  font-weight: 700; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary:hover, .btn.primary:hover { filter: brightness(1.05); }
.btn.icon { min-width: 44px; justify-content: center; padding: 0; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 0.875rem; }
.btn.danger { color: var(--danger); background: rgba(229,72,77,.12); border-color: transparent; }

.status {
  margin-bottom: 12px; padding: 12px 14px; border-radius: 12px;
  background: rgba(37,99,235,.08); border: 1px solid var(--border); font-weight: 600;
}
.status.error { background: rgba(229,72,77,.12); color: #8b1e22; }
.status.ok { background: rgba(48,164,108,.12); }

.results-layout {
  display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; min-height: 520px;
}
@media (max-width: 960px) {
  .results-layout { grid-template-columns: 1fr; }
  .map { min-height: 280px !important; }
}
.map { min-height: 520px; overflow: hidden; }
.results-col { display: flex; flex-direction: column; min-height: 0; }
.results-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px;
}
.results-head h2 { margin: 0; font-size: 1.05rem; }
.results-list {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 620px; overflow: auto; padding-right: 4px;
}

.card {
  padding: 14px; border-radius: var(--radius-md);
  background: var(--bg-elevated); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card h3 { margin: 0; font-size: 1rem; line-height: 1.3; }
.score {
  flex-shrink: 0; min-width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; font-weight: 800; color: #fff;
  background: var(--accent-gradient);
}
.meta { margin: 6px 0; font-size: 0.82rem; color: var(--text-secondary); font-weight: 600; }
.note { margin: 8px 0; font-size: 0.88rem; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  font-size: 0.65rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px; background: rgba(37,99,235,.12); color: var(--accent-text);
}
.chip.teal { background: rgba(13,148,136,.15); color: #0f766e; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.leads-toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end; padding: 14px; margin-bottom: 12px;
}

.footer {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  text-align: center; font-size: 0.72rem; color: var(--text-secondary); font-weight: 600;
}

dialog {
  border: none; border-radius: var(--radius-lg); padding: 0;
  width: min(640px, calc(100vw - 24px));
  background: var(--canvas-bg); color: var(--text-primary);
  box-shadow: var(--shadow-md);
}
dialog::backdrop { background: rgba(6, 16, 24, 0.45); }
.detail-card { padding: 16px; }
.detail-card header { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.detail-card h3 { margin: 0; }
.detail-body { margin: 12px 0; font-size: 0.92rem; line-height: 1.45; }
.detail-actions {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  border-top: 1px solid var(--border); padding-top: 12px;
}
.detail-actions .grow { flex: 1; min-width: 180px; }

.leaflet-container { font: inherit; border-radius: var(--radius-lg); }
