:root {
  --ground: #10211c;
  --panel: #152b24;
  --panel-2: #1b352d;
  --line: #2a4a40;
  --ink: #f3f5ec;
  --muted: #a9b8ae;
  --accent: #c6d62e;
  --accent-ink: #10211c;
  --good: #7bd88f;
  --warn: #f0b34a;
  --bad: #f07a6a;
  --info: #7cc4e6;
  --radius: 10px;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  --display: "Bricolage Grotesque", var(--sans);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground: #f3f5ec; --panel: #ffffff; --panel-2: #eef1e4; --line: #d6dccb; --ink: #10211c; --muted: #56675d;
    --accent: #10211c; --accent-ink: #f3f5ec; --good: #2f8a45; --warn: #a36a0a; --bad: #b8402f; --info: #2a6f93; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --ground: #f3f5ec; --panel: #ffffff; --panel-2: #eef1e4; --line: #d6dccb; --ink: #10211c; --muted: #56675d;
  --accent: #10211c; --accent-ink: #f3f5ec; --good: #2f8a45; --warn: #a36a0a; --bad: #b8402f; --info: #2a6f93; color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); font: 14px/1.45 var(--sans); }
a { color: inherit; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--ground); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font: 700 17px var(--display); text-decoration: none; }
.mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-size: 15px; }
nav { display: flex; gap: 4px; }
nav a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
nav a:hover { color: var(--ink); background: var(--panel); }
nav a.active { color: var(--ink); background: var(--panel-2); }
.me { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }

main { padding: 24px; max-width: 1500px; margin: 0 auto; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; font: 500 13px var(--sans); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px; }
input, select, textarea { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: 13px var(--sans); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { font-family: var(--mono); font-size: 13px; width: 100%; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* cards & tiles */
.grid { display: grid; gap: 14px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.tile .v { font: 700 30px var(--display); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile a, a.tile { text-decoration: none; }
a.tile:hover { border-color: var(--muted); }
.split { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; display: flex; margin-top: 10px; }
.split span { display: block; height: 100%; }
.section { margin-top: 26px; }
.section > .row { margin-bottom: 12px; }
.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel-2); font-weight: 600; font-size: 12px; color: var(--muted); white-space: nowrap; user-select: none; }
th.sort { cursor: pointer; }
th.sort:hover { color: var(--ink); }
tbody tr:hover { background: var(--panel-2); }
tbody tr.clickable { cursor: pointer; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td .name { font-weight: 600; }
td .sub { color: var(--muted); font-size: 12px; }
tr:last-child td { border-bottom: 0; }
.bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); vertical-align: middle; margin-right: 8px; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 500; border: 1px solid var(--line); white-space: nowrap; }
.chip.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-not_contacted { color: var(--muted); }
.st-contacted { color: var(--info); }
.st-replied { color: var(--accent); }
.st-meeting, .st-client { color: var(--good); }
.st-not_interested { color: var(--warn); }
.st-do_not_contact { color: var(--bad); }
.sc-scored { color: var(--good); }
.sc-unscored { color: var(--muted); }
.sc-stale { color: var(--warn); }
.em-verified { color: var(--good); }
.em-accept_all, .em-guessed { color: var(--warn); }
.em-invalid, .em-bounced { color: var(--bad); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }

/* leads page */
.leads-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.filters { position: sticky; top: 74px; display: grid; gap: 14px; max-height: calc(100vh - 96px); overflow: auto; padding-right: 4px; }
.filters fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.filters legend { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.checks { display: grid; gap: 3px; }
.checks label { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 13px; cursor: pointer; }
.checks label .n { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.searchbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.searchbar input[type=search] { flex: 1; min-width: 220px; font-size: 14px; padding: 10px 12px; }
.bulkbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; margin-bottom: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); flex-wrap: wrap; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.filter-toggle { display: none; }
@media (max-width: 900px) {
  .leads-layout { grid-template-columns: 1fr; }
  .filters { position: static; max-height: none; display: none; }
  .filters.open { display: grid; }
  .filter-toggle { display: inline-flex; }
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 16px; }
  .me #me-email { display: none; }
}

/* drawer */
.drawer { position: fixed; inset: 0 0 0 auto; width: min(640px, 100%); background: var(--ground); border-left: 1px solid var(--line); z-index: 40; overflow-y: auto; box-shadow: -20px 0 60px rgba(0,0,0,.35); }
.drawer-inner { padding: 22px; display: grid; gap: 18px; }
.drawer h1 { font-size: 24px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.timeline { display: grid; gap: 8px; }
.timeline .item { border-left: 2px solid var(--line); padding-left: 10px; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
pre { white-space: pre-wrap; word-break: break-word; font: 12px var(--mono); background: var(--panel); padding: 10px; border-radius: 8px; border: 1px solid var(--line); margin: 6px 0 0; }
.inline-form { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); align-items: end; }

/* sql */
.sql-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .sql-layout { grid-template-columns: 1fr; } }
.saved { display: grid; gap: 4px; }
.saved button { text-align: left; background: none; border: 1px solid transparent; color: var(--ink); padding: 7px 9px; border-radius: 8px; cursor: pointer; font: 13px var(--sans); }
.saved button:hover { background: var(--panel); border-color: var(--line); }
#sql-input { min-height: 170px; resize: vertical; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card input { width: 100%; font-size: 15px; padding: 10px 12px; }
.error { color: var(--bad); min-height: 1em; margin: 0; font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: 8px; z-index: 60; font-weight: 500; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.loading { opacity: .55; pointer-events: none; }
