:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #222c38;
  --border: #2c3845;
  --text: #e7edf3;
  --muted: #93a1b0;
  --primary: #4f8cff;
  --primary-dark: #3a6fd6;
  --hot: #ff5a4d;
  --grade-d: #ff9f43;
  --grade-c: #ffd24d;
  --grade-b: #7ec8e3;
  --grade-a: #6b7c8f;
  --ok: #34c759;
  --danger: #ff5a4d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Assistant", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.logo {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--primary);
}
.brand-sub { color: var(--muted); font-size: 14px; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
}
.stat .num { font-size: 20px; font-weight: 700; }
.stat .label { font-size: 11px; color: var(--muted); }
.stat.hot .num { color: var(--hot); }

.warning {
  background: #3a2417;
  border: 1px solid #6b3f23;
  color: #ffce9e;
  padding: 12px 24px;
  font-size: 14px;
}
.warning code { background: rgba(255,255,255,0.1); padding: 1px 6px; border-radius: 4px; }
.hidden { display: none !important; }

.container { max-width: 1280px; margin: 20px auto; padding: 0 20px; display: flex; flex-direction: column; gap: 18px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }

.scan-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.small { max-width: 90px; }
.field label { font-size: 12px; color: var(--muted); }
.field input[type="text"],
.field input:not([type]),
.field input[type="number"],
.field select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  min-width: 200px;
}
.field.small input, .field.small select { min-width: auto; }
.field.checkbox { flex-direction: row; align-items: center; }
.field.checkbox label { color: var(--text); font-size: 13px; display: flex; gap: 6px; align-items: center; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: #2c3845; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.mini { padding: 5px 10px; font-size: 12px; }
.btn.mini.demo-btn { background: linear-gradient(135deg, #7c5cff, #4f8cff); color: #fff; border-color: transparent; font-weight: 700; }
.btn.mini.demo-btn:hover { filter: brightness(1.1); background: linear-gradient(135deg, #7c5cff, #4f8cff); }

.scan-status { margin-top: 12px; font-size: 14px; color: var(--muted); min-height: 20px; }
.scan-status.success { color: var(--ok); }
.scan-status.error { color: var(--danger); }

.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
}
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
tbody tr:hover { background: var(--panel-2); }
.empty { text-align: center; color: var(--muted); padding: 30px; }

.grade {
  display: inline-block;
  font-weight: 700;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
  min-width: 34px;
  text-align: center;
}
.grade.HOT { background: var(--hot); color: #fff; }
.grade.D { background: var(--grade-d); color: #1a1209; }
.grade.C { background: var(--grade-c); color: #1a1505; }
.grade.B { background: var(--grade-b); color: #06222b; }
.grade.A { background: var(--grade-a); color: #fff; }

.biz-name { font-weight: 600; }
.biz-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.biz-meta a { color: var(--primary); text-decoration: none; }

.wstatus { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); }
.wstatus.none, .wstatus.broken, .wstatus.timeout, .wstatus.error { color: var(--danger); border-color: #5a2a26; }
.wstatus.ok { color: var(--ok); border-color: #2a5a36; }

.problems { font-size: 12px; color: var(--muted); max-width: 260px; }

.lead-status { font-size: 12px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; margin-bottom: 4px; }
.tag.contacted { background: #1f3a26; color: var(--ok); }
.tag.dnc { background: #3a1f1f; color: var(--danger); }

.row-actions { display: flex; flex-direction: column; gap: 5px; min-width: 130px; }
tr.dnc-row { opacity: 0.5; }

.phone-link { color: var(--text); text-decoration: none; direction: ltr; display: inline-block; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  z-index: 100;
}
.toast.success { border-color: var(--ok); }
.toast.error { border-color: var(--danger); }

.login-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: radial-gradient(1000px 700px at 80% -10%, #1c2950 0%, #0b1220 60%), #0b1220;
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 38px 34px; width: 360px; max-width: 90vw;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-logo { font-size: 26px; font-weight: 800; color: #fff; }
.login-logo span { color: var(--primary); }
.login-sub { color: var(--muted); margin: -6px 0 8px; font-size: 14px; }
.login-card input {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; color: var(--text); font-size: 15px;
}
.login-btn { padding: 12px; font-size: 15px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; text-align: center; }
.logout-btn { align-self: center; }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-left: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Demo-from-URL card --------------------------------------------------- */
.card-sub { color: var(--muted); font-size: 13px; margin: -4px 0 12px; }
.field.grow { flex: 1 1 280px; }
.field.grow input { width: 100%; }
.demo-url-card h2 { background: linear-gradient(135deg, #7c5cff, #4f8cff); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.btn.mini.primary-soft { background: var(--panel-2); border-color: var(--primary); color: var(--primary); font-weight: 700; }
.btn.mini.primary-soft:hover { background: var(--primary); color: #fff; }

/* ---- Lead management modal ------------------------------------------------ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 720px; padding: 24px 26px; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-close {
  position: absolute; inset-inline-start: 16px; top: 14px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.modal-close:hover { color: var(--text); }
.modal-title { margin: 0 0 4px; }
.modal-meta { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.modal-grid label, .modal-full {
  display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted);
}
.modal-full { margin-top: 12px; }
.modal-grid input, .modal-grid select, .modal-full textarea, .modal-section textarea, .add-note-row input {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 11px; color: var(--text); font-size: 14px; font-family: inherit;
}
.modal-actions { margin-top: 14px; }
.modal-section { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 16px; }
.modal-section h3 { margin: 0 0 10px; font-size: 15px; }
.modal-section textarea { width: 100%; resize: vertical; }
.modal-section .btn { margin-top: 8px; }
.warn-inline { color: var(--grade-d); font-size: 13px; margin: 0 0 8px; }
.add-note-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-note-row input { flex: 1; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.timeline-item {
  display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 8px 11px;
}
.tl-type { font-weight: 700; font-size: 12px; }
.tl-note { flex: 1; font-size: 13px; }
.tl-date { color: var(--muted); font-size: 11px; }
.summaries-list { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.summary-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px;
}
.summary-date { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.summary-raw { font-size: 13px; color: var(--muted); border-inline-start: 3px solid var(--border); padding-inline-start: 10px; margin-bottom: 10px; }
.summary-next { color: var(--ok); font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.summary-card ul { margin: 4px 0 10px; padding-inline-start: 20px; font-size: 13px; }
.summary-card strong { font-size: 13px; }
#m-followup-result { margin-top: 10px; }
@media (max-width: 600px) { .modal-grid { grid-template-columns: 1fr; } }
