/* Leads Hub — single stylesheet. Forked from Time Study so the two tools look like siblings.
 * Dark, calm, dense enough for a 91k-row work tool. Rhythm: 4px base. */
:root {
  --bg: #0b1220;
  --bg-2: #0f172a;
  --card: #111a2e;
  --card-2: #16213a;
  --line: #22304d;
  --line-soft: #1a2640;
  --text: #e6ebf5;
  --muted: #94a3b8;
  --accent: #14b8a6;
  --accent-2: #0f766e;
  --accent-ink: #052e2b;
  --danger: #f87171;
  --warn: #fbbf24;
  --blue: #60a5fa;
  --green: #4ade80;
  --radius: 12px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --rail-w: 260px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
body { min-height: 100vh; background: radial-gradient(1200px 600px at 10% -10%, #10203a 0%, var(--bg) 60%); }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h4 { font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--bg-2); }
a { color: var(--accent); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 2px; }
.link:disabled { color: var(--muted); cursor: not-allowed; text-decoration: none; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px; height: 52px;
  padding: 0 24px; background: rgba(11,18,32,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(20,184,166,.18); align-self: center; }
.brand-name { font-weight: 700; }
.brand-sub { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab { background: none; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; font: inherit; }
.tab.is-active { background: var(--card-2); color: var(--text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.clock { font: 13px var(--mono); color: var(--muted); }
.who { font-weight: 500; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px; line-height: 1.2;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text); cursor: pointer; font: inherit; font-weight: 500; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #33466d; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-primary:hover { background: #2dd4bf; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-danger { color: var(--danger); border-color: rgba(248,113,113,.35); background: transparent; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; border-radius: 7px; }
.btn-block { width: 100%; }

/* cards + layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.app { display: flex; flex-direction: column; gap: 14px; padding: 16px 24px 96px; max-width: 1680px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.inline-error { margin: 0; color: var(--danger); font-size: 13px; padding: 8px 16px; border-bottom: 1px solid var(--line-soft); }

/* login */
.login { display: grid; place-items: center; min-height: calc(100vh - 52px); padding: 20px; }
.login-card { width: 100%; max-width: 380px; padding: 26px; display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20,184,166,.18); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; padding: 0; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

/* chip strip */
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 28px; }
.chips:empty { display: none; }
.chip { background: var(--card); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 5px 11px; cursor: pointer; font: inherit; font-size: 12.5px; line-height: 1.2; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { color: var(--text); }
.chip.is-active { background: rgba(20,184,166,.14); color: #5eead4; border-color: rgba(20,184,166,.4); }
.fchip { background: var(--card-2); border: 1px solid #33466d; color: var(--text); border-radius: 999px; padding: 4px 6px 4px 11px; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.fchip b { font-weight: 500; color: var(--muted); }
.fchip .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 4px; line-height: 1; border-radius: 50%; }
.fchip .x:hover { color: var(--danger); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.stat:hover { border-color: #33466d; }
.stat-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font: 600 22px/1.1 var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
.stat.is-danger .stat-value { color: var(--danger); }
.stat.is-warn .stat-value { color: var(--warn); }

/* bar charts (plain CSS) */
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.chart { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.chart h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.brow { display: grid; grid-template-columns: 120px 1fr 56px; align-items: center; gap: 8px; background: none; border: 0; padding: 3px 0; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 6px; }
.brow:hover .bl { color: var(--text); }
.brow[disabled] { cursor: default; }
.bl { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt { height: 10px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.bf { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 999px; min-width: 2px; }
.bn { font: 12px var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.vbars { display: flex; align-items: flex-end; gap: 4px; height: 96px; padding-top: 12px; }
.vb { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; background: none; border: 0; padding: 0; height: 100%; cursor: pointer; color: inherit; font: inherit; }
.vb .bf { width: 100%; min-height: 2px; border-radius: 3px 3px 0 0; }
.vb .bl { font-size: 10px; }
.chart-empty { color: var(--muted); font-size: 12.5px; padding: 12px 0; }

/* leads layout */
.leads { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); gap: 16px; align-items: start; }
.rail { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 66px; max-height: calc(100vh - 82px); overflow-y: auto; padding-right: 4px; }
.rail-block { display: flex; flex-direction: column; gap: 8px; }
.rail-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.search-wrap input { width: 100%; padding: 8px 11px; font-size: 13px; }
.toggles { display: flex; flex-wrap: wrap; gap: 5px; }
.toggles .chip { padding: 4px 9px; font-size: 12px; }
.seg-list { display: flex; flex-direction: column; gap: 2px; }
.seg { display: flex; align-items: center; gap: 6px; }
.seg-btn { flex: 1; background: none; border: 0; color: var(--text); text-align: left; padding: 5px 8px; border-radius: 7px; cursor: pointer; font: inherit; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg-btn:hover, .seg.is-active .seg-btn { background: var(--card-2); }
.seg-del { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; font-size: 13px; }
.seg-del:hover { color: var(--danger); }
.fgroup { border-top: 1px solid var(--line-soft); padding: 4px 0; }
.fgroup summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 6px 2px; font-size: 12.5px; font-weight: 600; color: var(--text); user-select: none; }
.fgroup summary::-webkit-details-marker { display: none; }
.fgroup summary::before { content: "▸"; color: var(--muted); font-size: 11px; width: 10px; transition: transform .15s; }
.fgroup[open] summary::before { transform: rotate(90deg); }
.fsel { margin-left: auto; font: 11px var(--mono); background: rgba(20,184,166,.15); color: #5eead4; border-radius: 999px; padding: 1px 7px; }
.fbody { display: flex; flex-direction: column; gap: 2px; padding: 2px 0 6px; }
.fbody .fsearch { padding: 5px 9px; font-size: 12.5px; margin-bottom: 4px; }
.fopt { display: grid; grid-template-columns: 15px 1fr auto; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.fopt:hover { background: var(--card-2); }
.fopt.is-zero { color: var(--muted); }
.fopt-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fopt-n { font: 11.5px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.fmore { align-self: flex-start; font-size: 12px; padding: 3px 4px; }
.dates .date-row { display: flex; align-items: center; gap: 6px; }
.dates input { width: 100%; padding: 6px 8px; font-size: 12.5px; min-width: 0; }
.dates label { flex: 1; min-width: 0; }
.t65-wrap input { width: 100%; padding: 6px 9px; font-size: 12.5px; }
.rail-loading { color: var(--muted); font-size: 12.5px; padding: 8px 0; }

/* tables */
.table-card { padding: 0; overflow: hidden; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 48px; flex-wrap: wrap; }
.toolbar-title { font-weight: 600; font-size: 13.5px; }
.toolbar-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ctl { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.ctl select { padding: 5px 8px; font-size: 12.5px; }
.pager { display: inline-flex; align-items: center; gap: 4px; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line-soft); }
.tbl th { color: var(--muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; background: rgba(15,23,42,.5); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: rgba(255,255,255,.02); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td.dim { color: var(--muted); }
.tbl .col-chk, .tbl .col-act { width: 1%; white-space: nowrap; }
.leads-tbl tbody tr { cursor: pointer; }
.leads-tbl tbody tr.is-selected td { background: rgba(20,184,166,.07); }
.leads-tbl tbody tr.is-open td { background: rgba(96,165,250,.08); }
.leads-tbl td { white-space: nowrap; }
.leads-tbl.is-loading tbody { opacity: .45; pointer-events: none; }
.lead-name { font-weight: 500; display: flex; align-items: center; gap: 6px; }
.lead-id { display: block; color: var(--muted); font: 11px var(--mono); }
.empty-box { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: 13px; padding: 26px 16px; border: 1px dashed var(--line); border-radius: var(--radius); background: rgba(15,23,42,.35); text-align: center; }
.empty-box.in-card { border: 0; border-radius: 0; background: transparent; padding: 28px 16px; }

/* skeletons */
.sk { display: inline-block; height: 12px; width: 70%; border-radius: 6px; background: linear-gradient(90deg, var(--card-2) 25%, #1d2a47 50%, var(--card-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* pills, tags, badges */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; line-height: 18px; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.pill.stage-lead { background: #1e293b; color: #cbd5e1; }
.pill.stage-contacted { background: rgba(96,165,250,.18); color: var(--blue); }
.pill.stage-sold { background: rgba(20,184,166,.18); color: #5eead4; }
.pill.stage-placed { background: rgba(74,222,128,.18); color: var(--green); }
.pill.stage-lapsed { background: rgba(251,191,36,.18); color: var(--warn); }
.pill.st-ok { background: rgba(74,222,128,.18); color: var(--green); }
.pill.st-bad { background: rgba(248,113,113,.18); color: var(--danger); }
.pill.st-revoked { text-decoration: line-through; opacity: .7; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 0 5px; border-radius: 4px; line-height: 16px; }
.tag-dnc { background: rgba(248,113,113,.2); color: var(--danger); }
.tag-hold { background: rgba(251,191,36,.18); color: var(--warn); }
.tag-match { background: var(--card-2); color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 500; }
.mini { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 5px; background: var(--card-2); color: var(--text); line-height: 17px; margin-right: 3px; }
.src { display: inline-block; font: 600 10px/16px var(--mono); padding: 0 4px; border-radius: 4px; background: rgba(96,165,250,.14); color: #93c5fd; margin-right: 2px; letter-spacing: .02em; }
.plus { color: var(--muted); font-size: 11px; }

/* bulk bar */
.bulkbar { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 8; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  padding: 10px 14px; background: #1e293b; border: 1px solid #33466d; border-radius: 12px; box-shadow: 0 12px 36px rgba(0,0,0,.45); max-width: calc(100vw - 32px); font-size: 13px; }
.bulkbar .bcount { font-weight: 600; white-space: nowrap; }
.bulkbar select, .bulkbar input { padding: 6px 9px; font-size: 12.5px; }
.bulkbar select { max-width: 260px; }
.bulkbar input { width: 200px; }
.bulkbar .bsep { color: var(--line); }

/* drawer */
.drawer-backdrop, .modal-backdrop, .rail-backdrop { position: fixed; inset: 0; background: rgba(2,6,23,.55); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--card); border-left: 1px solid var(--line); z-index: 10; display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(0,0,0,.45); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { overflow-y: auto; padding: 16px 18px 40px; display: flex; flex-direction: column; gap: 16px; }
.lead-head { display: flex; flex-direction: column; gap: 6px; }
.lead-head .row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.lead-head .meta { color: var(--muted); font-size: 13px; }
.dsec h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.dsec h3 .pill { margin-left: auto; }
.scard { border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--bg-2); display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.scard .top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.scard .top strong { font-weight: 600; }
.scard .kv { display: grid; grid-template-columns: 96px 1fr; gap: 2px 10px; font-size: 12.5px; }
.scard .kv dt { color: var(--muted); } .scard .kv dd { margin: 0; word-break: break-word; }
.scard details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.scard .attrs { font: 11.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; color: var(--muted); margin: 6px 0 0; max-height: 240px; overflow: auto; }
.rrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.rrow:last-child { border-bottom: 0; }
.rrow .sub { color: var(--muted); font-size: 12px; grid-column: 1 / -1; }
.rrow .err { color: var(--danger); }

/* modal */
.modal-backdrop { display: grid; place-items: center; padding: 20px; }
.modal { width: 100%; max-width: 560px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid .check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.form-grid textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: #1e293b; color: var(--text); display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 90vw; font-size: 13.5px; z-index: 11; }
.toast.is-error { border-color: rgba(248,113,113,.5); }
.toast .btn { margin-left: 4px; }

/* responsive */
.rail-toggle { display: none; }
@media (max-width: 1400px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 1100px) {
  .app { padding: 14px 16px 96px; }
  .topbar { gap: 10px; padding: 0 14px; }
  .brand-sub, .clock { display: none; }
  .rail-toggle:not([hidden]) { display: inline-flex; }
  .leads { grid-template-columns: 1fr; }
  .rail { position: fixed; top: 52px; left: 0; bottom: 0; width: 300px; max-height: none; background: var(--bg-2); border-right: 1px solid var(--line); padding: 14px; z-index: 10; transform: translateX(-100%); transition: transform .18s ease; }
  .rail.is-open { transform: none; }
  .rail-backdrop { z-index: 9; }
  .brow { grid-template-columns: 96px 1fr 48px; }
}
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, 1fr); } .form-grid { grid-template-columns: 1fr; } .tabs .tab { padding: 6px 8px; } }
