/* New Business Leads — internal tool styling.
   Dense and scannable: a rep reads many rows and acts on one. No build step,
   no framework; everything below is hand-written and served as-is. */

:root {
  --bg:        #f7f7f9;
  --surface:   #ffffff;
  --surface-2: #f2f2f5;
  --border:    #e2e2e7;
  --border-2:  #cfcfd6;
  --text:      #1a1a1f;
  --muted:     #6b6b76;
  --faint:     #9a9aa4;
  --accent:    #4f46e5;
  --accent-fg: #ffffff;
  --accent-soft: #eeecfd;
  --danger:    #b42318;
  --ok:        #067647;

  --pill-new-bg:#eaeaef; --pill-new-fg:#4a4a55;
  --pill-claimed-bg:#fdf0d5; --pill-claimed-fg:#8a5a00;
  --pill-contacted-bg:#e3effd; --pill-contacted-fg:#14539a;
  --pill-callback-bg:#f0e8fd; --pill-callback-fg:#6b34c4;
  --pill-won-bg:#e2f6ea; --pill-won-fg:#08663f;
  --pill-dead-bg:#f0eef0; --pill-dead-fg:#84808a;

  --radius: 7px;
  --rail: 264px;
  --topbar: 52px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgba(16,16,24,.05), 0 4px 12px rgba(16,16,24,.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0d0d10;
    --surface:   #16161a;
    --surface-2: #1d1d23;
    --border:    #292930;
    --border-2:  #3a3a44;
    --text:      #ebebef;
    --muted:     #9494a0;
    --faint:     #6d6d78;
    --accent:    #8b93f8;
    --accent-fg: #12121a;
    --accent-soft: #21213a;
    --danger:    #ff8a7a;
    --ok:        #5ddba4;

    --pill-new-bg:#25252c; --pill-new-fg:#b0b0bc;
    --pill-claimed-bg:#3a2e12; --pill-claimed-fg:#f0c063;
    --pill-contacted-bg:#132c47; --pill-contacted-fg:#79b6f5;
    --pill-callback-bg:#2b1f45; --pill-callback-fg:#bd9ff5;
    --pill-won-bg:#0f3327; --pill-won-fg:#5fd6a0;
    --pill-dead-bg:#232026; --pill-dead-fg:#77737e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  /* Dates and IDs must line up column to column. */
  font-variant-numeric: tabular-nums lining-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------- top bar -- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand span { color: var(--faint); font-weight: 400; }
.topbar .spacer { flex: 1; }
.topbar .stat { color: var(--muted); font-size: 12px; white-space: nowrap; }
.topbar .stat b { color: var(--text); font-weight: 600; }

/* --------------------------------------------------------------- layout -- */

.shell { display: flex; align-items: flex-start; }

.rail {
  position: sticky; top: var(--topbar);
  width: var(--rail); flex: none;
  height: calc(100vh - var(--topbar));
  overflow-y: auto;
  padding: 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.main { flex: 1; min-width: 0; padding: 14px 16px 56px; }

.rail-group { margin-bottom: 18px; }
.rail-group h3 {
  margin: 0 0 7px; font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em; color: var(--faint);
}

/* ------------------------------------------------------------- controls -- */

input[type="text"], input[type="search"], input[type="password"],
input[type="date"], input[type="email"], select, textarea {
  width: 100%; padding: 6px 8px;
  font: inherit; font-size: 13px;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border-2); border-radius: 6px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
textarea { resize: vertical; min-height: 62px; }
label.field { display: block; margin-bottom: 8px; }
label.field > span {
  display: block; margin-bottom: 3px; font-size: 11.5px; color: var(--muted);
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; font: inherit; font-size: 13px; font-weight: 500;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-2); border-radius: 6px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Facet lists: value on the left, count right-aligned. The count is the point —
   it tells a rep how much work sits behind each filter before they click. */
.facet { display: flex; flex-direction: column; gap: 1px; }
.facet a {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 4px 7px; border-radius: 5px;
  color: var(--text); font-size: 12.5px;
}
.facet a:hover { background: var(--surface-2); text-decoration: none; }
.facet a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.facet a .n { color: var(--faint); font-variant-numeric: tabular-nums; }
.facet a.on .n { color: var(--accent); }

.check { display: flex; align-items: center; gap: 7px; padding: 3px 0; font-size: 12.5px; }
.check input { width: auto; }

/* ---------------------------------------------------------------- table -- */

.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.toolbar .count { color: var(--muted); font-size: 12.5px; }
.toolbar .count b { color: var(--text); }
.toolbar .spacer { flex: 1; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;            /* wide table scrolls itself, page never does */
}
table.leads { width: 100%; border-collapse: collapse; font-size: 13px; }
table.leads thead th {
  position: sticky; top: var(--topbar); z-index: 10;
  background: var(--surface-2);
  padding: 8px 10px; text-align: left;
  font-size: 11px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.leads tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);  /* hairlines, not zebra striping */
  vertical-align: top;
}
table.leads tbody tr { cursor: pointer; }
table.leads tbody tr:hover { background: var(--surface-2); }
table.leads tbody tr:last-child td { border-bottom: none; }
table.leads tbody tr.sel { background: var(--accent-soft); }

.lead-name { font-weight: 550; color: var(--text); }
.lead-sub { color: var(--faint); font-size: 11.5px; margin-top: 1px; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ----------------------------------------------------------------- pills -- */

.pill {
  display: inline-block; padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.pill-new       { background: var(--pill-new-bg);       color: var(--pill-new-fg); }
.pill-claimed   { background: var(--pill-claimed-bg);   color: var(--pill-claimed-fg); }
.pill-contacted { background: var(--pill-contacted-bg); color: var(--pill-contacted-fg); }
.pill-callback  { background: var(--pill-callback-bg);  color: var(--pill-callback-fg); }
.pill-won       { background: var(--pill-won-bg);       color: var(--pill-won-fg); }
.pill-dead      { background: var(--pill-dead-bg);      color: var(--pill-dead-fg); }

.tag {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
}

/* Confidence dot. A rep should be able to see at a glance that a number came
   from a weak source before they burn a call on it. */
.dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-right: 5px; vertical-align: middle; flex: none;
}
.dot-high { background: var(--ok); }
.dot-medium { background: #d99000; }
.dot-low { background: var(--faint); }
.dot-none { background: transparent; border: 1px solid var(--border-2); }

.no-phone { color: var(--faint); font-style: italic; font-size: 12px; }

/* ------------------------------------------------------------ pagination -- */

.pager { display: flex; align-items: center; gap: 8px; padding: 10px 2px; }
.pager .page-info { color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- drawer -- */

.drawer-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(12,12,18,.34);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  width: min(520px, 100%);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: slide-in .16s ease-out;
}
@keyframes slide-in { from { transform: translateX(18px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }

.drawer header {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.drawer header h2 { margin: 0; font-size: 15.5px; line-height: 1.3; }
.drawer .body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.drawer footer { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.drawer .close { margin-left: auto; }

.sect { margin-bottom: 16px; }
.sect h4 {
  margin: 0 0 6px; font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em; color: var(--faint);
}
dl.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; margin: 0; font-size: 12.5px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }

.officer {
  padding: 7px 9px; margin-bottom: 5px;
  background: var(--surface-2); border-radius: 6px; font-size: 12.5px;
}
.officer .who { font-weight: 600; }

.hist { font-size: 12px; color: var(--muted); }
.hist li { margin-bottom: 4px; }

.notes {
  white-space: pre-wrap; font-size: 12.5px;
  background: var(--surface-2); border-radius: 6px; padding: 8px 10px;
  max-height: 160px; overflow-y: auto;
}

.alert { padding: 8px 11px; border-radius: 6px; font-size: 12.5px; margin-bottom: 10px; }
.alert-warn { background: var(--pill-claimed-bg); color: var(--pill-claimed-fg); }
.alert-ok   { background: var(--pill-won-bg); color: var(--pill-won-fg); }
.alert-err  { background: #fdecea; color: var(--danger); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .alert-err { background: #3a1d1a; }
}

/* --------------------------------------------------------------- htmx UX -- */

.htmx-indicator { opacity: 0; transition: opacity .12s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.htmx-request .table-wrap { opacity: .55; transition: opacity .12s; }

.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border-2); border-top-color: var(--accent);
  animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- login -- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 340px; padding: 26px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 3px; font-size: 18px; }
.login-card p.sub { margin: 0 0 18px; color: var(--muted); font-size: 12.5px; }

/* ----------------------------------------------------------------- admin -- */

table.plain { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.plain th, table.plain td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: left; }
table.plain th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 14px; }

/* ------------------------------------------------------------ responsive -- */

.rail-toggle { display: none; }

@media (max-width: 900px) {
  /* Reps work leads from a phone between calls, so the rail becomes a sheet
     and each row becomes a card. */
  .rail-toggle { display: inline-flex; }
  .rail {
    position: fixed; inset: auto 0 0 0; top: auto; z-index: 50;
    width: 100%; height: 78vh; border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
    transform: translateY(100%); transition: transform .18s ease-out;
  }
  .rail.open { transform: none; }
  .main { padding: 12px; }

  table.leads thead { display: none; }
  table.leads tbody tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  table.leads tbody td { display: inline-block; border: none; padding: 1px 10px 1px 0; vertical-align: middle; }
  table.leads tbody td.cell-name { display: block; width: 100%; margin-bottom: 3px; }

  .drawer { width: 100%; }
  dl.kv { grid-template-columns: 92px 1fr; }
}
