:root {
  --blue: #3A7BF0; --blue-hover: #2C5BBF;
  --text: #111827; --text-2: #4b5563; --text-3: #6b7280;
  --border: #e5e7eb; --bg: #f5f6f8; --card: #ffffff;
  --green: #059669; --green-bg: #ecfdf5; --red: #dc2626; --red-bg: #fef2f2;
  --amber: #b45309; --amber-bg: #fffbeb; --gray-bg: #f3f4f6;
  --radius: 0.5rem;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.lucide { width: 16px; height: 16px; stroke-width: 2; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.5rem 1rem; border-radius: var(--radius); font: 500 14px/1.25 inherit; white-space: nowrap; cursor: pointer; border: 1px solid transparent; transition: background-color .15s, border-color .15s; min-height: 38px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-secondary { background: transparent; border-color: #6b7280; color: #374151; }
.btn-secondary:hover { background: #e5e7eb; }
.btn-icon { padding: 0.5rem; min-width: 38px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn[aria-busy="true"] { opacity: .75; cursor: progress; }
.btn[aria-busy="true"] svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"] svg { animation: none; } }

input[type="text"], input[type="password"], input[type="search"], select { font: inherit; font-size: 14px; color: var(--text); background: #fff; border: 1px solid #d1d5db; border-radius: var(--radius); padding: 0.5rem 0.75rem; min-height: 38px; width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(58, 123, 240, .15); }

.layout { max-width: 1200px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-size: 18px; font-weight: 600; }
.brand svg.lucide { width: 22px; height: 22px; }
.actions { display: flex; gap: 0.5rem; }

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.stat { padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.stat-label { display: flex; align-items: center; gap: 0.4rem; color: var(--text-3); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.15; }
.stat-sub { color: var(--text-3); font-size: 12px; }
.stat-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-size: 14px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue); font: inherit; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem; align-self: flex-start; }
.link-btn:hover { text-decoration: underline; }

.badge { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 12px; font-weight: 600; padding: 0.15rem 0.55rem; border-radius: var(--radius); white-space: nowrap; }
.badge-ok { background: var(--green-bg); color: var(--green); }
.badge-bad { background: var(--red-bg); color: var(--red); }
.badge-warn { background: var(--amber-bg); color: var(--amber); }
.badge-muted { background: var(--gray-bg); color: var(--text-2); }

.section { padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.section-title { font-size: 16px; font-weight: 600; margin: 0; }
.toolbar { display: flex; gap: 0.5rem; align-items: center; }
.search { position: relative; width: 260px; }
.search svg.lucide { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search input { padding-left: 2.1rem; }
.toolbar select { width: 170px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 0.7rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: #fafafa; }
.phone { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; }
.account { font-weight: 600; }
.context { color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 520px; }
.row-actions { display: flex; gap: 0.25rem; }
.icon-link { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: var(--radius); color: var(--text-2); }
.icon-link:hover { background: var(--gray-bg); color: var(--blue); text-decoration: none; }
.muted { color: var(--text-3); }
.empty { text-align: center; color: var(--text-3); padding: 2rem 1rem; }
.lead-cards { display: none; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding-top: 0.75rem; color: var(--text-3); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 1.25rem; }
.grid-2 .section { margin-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.9rem; }
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.35rem 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; font-size: 13px; }
.chip button { display: inline-flex; border: 0; background: none; color: var(--text-3); cursor: pointer; padding: 0.15rem; border-radius: 4px; }
.chip button:hover { color: var(--red); background: var(--red-bg); }
.add-form { display: flex; gap: 0.5rem; }
.hint { color: var(--text-3); font-size: 12px; margin: 0.5rem 0 0; }
.form-error { color: var(--red); font-size: 12px; margin: 0.35rem 0 0; min-height: 1em; }

.runs { list-style: none; margin: 0; padding: 0; }
.run { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.75rem; align-items: center; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.run:last-child { border-bottom: 0; }
.run-meta { font-size: 13px; }
.run-error { color: var(--red); font-size: 12px; word-break: break-word; }

.toast-wrap { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 50; }
.toast { background: #111827; color: #fff; padding: 0.65rem 1rem; border-radius: var(--radius); font-size: 13px; max-width: 360px; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.toast-error { background: var(--red); }

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-page { background: #f2f6fc; }
.login-card .brand { color: #132d57; }
.login-card .btn-primary { background: #2156a5; }
.login-card .btn-primary:hover { background: #132d57; }
.login-card { width: 100%; max-width: 360px; padding: 1.75rem 1.5rem; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 1.25rem 0 0.4rem; }
.login-card .btn { width: 100%; margin-top: 1rem; }

@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .section-head { align-items: stretch; flex-direction: column; }
  .toolbar { flex-wrap: wrap; }
  .search, .toolbar select { width: auto; flex: 1 1 160px; }
}
@media (max-width: 500px) {
  .layout { padding: 0.75rem 0.75rem 5rem; }
  .brand span { font-size: 16px; }
  .actions .btn-label { display: none; }
  .actions .btn { padding: 0.5rem; min-width: 38px; }
  .stat-value { font-size: 22px; }
  .lead-table { display: none; }
  .lead-cards { display: flex; flex-direction: column; gap: 0.6rem; }
  .lead-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; }
  .lead-card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
  .section { padding: 0.9rem; }
  input:not([type="checkbox"]):not([type="radio"]), select { font-size: 16px !important; }
  input::placeholder { font-size: 16px !important; opacity: 1; }
}

.activity-grid { display:grid; grid-template-columns:minmax(0,2fr) minmax(240px,1fr); gap:1rem }
.activity-grid video { width:100%; border-radius:8px; background:#141820 }
.activity-list { padding-left:1.5rem; max-height:24rem; overflow:auto }
.activity-list li { margin:.65rem 0 }
.run-meta a { font-weight:650; color:inherit }
@media(max-width:720px){ .activity-grid { grid-template-columns:1fr } }
