:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --text: #172033; --muted: #5d6779;
  --line: #e2e6ec; --brand: #162a4a; --accent: #c98a1a; --accent-soft: #fbf1df;
  --good: #1f7a4d; --good-soft: #e3f3ea; --hot: #b4332b; --hot-soft: #fbe7e5; --info: #2557a7; --info-soft: #e6eefb;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --surface: #171e29; --surface-2: #1d2532; --text: #e6e9ef; --muted: #98a2b3;
    --line: #2a3342; --brand: #e8b04b; --accent: #e8b04b; --accent-soft: #3a2f1a;
    --good: #5cc48d; --good-soft: #17322a; --hot: #f07a70; --hot-soft: #3a1f1d; --info: #8db4f5; --info-soft: #1b2a44;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 20px; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.mt { margin-top: 20px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
a { color: inherit; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10151d; } }
.btn.ghost { background: transparent; } .btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; white-space: nowrap; }
.mark { width: 28px; height: 28px; border-radius: 7px; background: #162a4a; color: #e8b04b; display: grid; place-items: center; font-weight: 800; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 22px 0 6px; font-size: 22px; }
.login-card form { display: grid; gap: 8px; margin-top: 18px; }
.login-card label { font-size: 13px; color: var(--muted); }
.msg { min-height: 1.4em; margin: 14px 0 0; font-size: 14px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#dealer-select { max-width: 240px; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab { font: inherit; background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.me { margin-left: auto; display: flex; gap: 10px; align-items: center; font-size: 13px; }

main { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { font: inherit; font-size: 13px; border: 0; background: none; padding: 7px 12px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; } #lead-search { width: 240px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow-x: auto; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 13px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--brand); } .chart .axis { fill: var(--muted); font-size: 11px; } .chart .grid { stroke: var(--line); }
.src-row { display: grid; grid-template-columns: 110px 1fr 36px; gap: 10px; align-items: center; margin: 7px 0; font-size: 14px; }
.src-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.src-bar span { display: block; height: 100%; background: var(--accent); }
.att { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.att:last-child { border-bottom: 0; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
  padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr { cursor: pointer; } .table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.empty-row { padding: 24px; text-align: center; color: var(--muted); margin: 0; }
.name { font-weight: 600; } .sub { color: var(--muted); font-size: 13px; }

.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.hot { background: var(--hot-soft); color: var(--hot); font-weight: 600; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.warn { background: var(--accent-soft); color: var(--accent); }

.settings { display: grid; grid-template-columns: 220px 1fr; gap: 10px 18px; margin: 0 0 16px; }
.settings dt { color: var(--muted); } .settings dd { margin: 0; }
@media (max-width: 600px) { .settings { grid-template-columns: 1fr; } .settings dd { margin-bottom: 8px; } }

.empty { text-align: center; padding: 60px 20px; } .empty h2 { margin-bottom: 8px; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(10, 15, 25, .35); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--surface); z-index: 10;
  border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0, 0, 0, .12); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.drawer-head a { text-decoration: none; }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.drawer-body h3 { margin-top: 20px; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.outcomes { display: flex; flex-wrap: wrap; gap: 6px; }
.outcomes button { font: inherit; font-size: 13px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.outcomes button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .outcomes button.on { color: #10151d; } }
.appt { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; font-size: 13px; }
.thread { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 85%; padding: 9px 12px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--info-soft); border-bottom-right-radius: 4px; }
.bubble.pending { opacity: .7; border: 1px dashed var(--line); }
.bubble .t { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.reply { margin-top: 14px; display: grid; gap: 6px; } .reply textarea { width: 100%; resize: vertical; }
.reply-foot { display: flex; justify-content: space-between; align-items: center; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; } main { padding: 16px; }
  .tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .me #me-email { display: none; } #lead-search { width: 100%; } .filters { width: 100%; }
  .table th:nth-child(3), .table td:nth-child(3), .table th:nth-child(5), .table td:nth-child(5) { display: none; }
}
