:root {
  --bg: #0b0d12; --panel: #14171f; --panel2: #1a1e28; --border: #232735;
  --text: #e7e9ee; --muted: #8a90a0; --accent: #6f8cff; --accent2: #8aa2ff;
  --green: #34d399; --amber: #f59e0b; --danger: #ff6f6f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; }
.hidden { display: none !important; }
.screen { height: 100vh; }
.err { color: var(--danger); font-size: .85rem; min-height: 1em; }

/* Login */
#login { display: flex; align-items: center; justify-content: center; }
#login-form { background: var(--panel); padding: 2rem; border-radius: 14px;
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: .75rem; width: 320px; }
#login-form h1 { margin: 0 0 .5rem; font-size: 1.3rem; }
#login-form input { background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: .6rem .7rem; font-size: .95rem; }
#login-form button { background: var(--accent); border: none; color: #fff; font-weight: 600;
  padding: .6rem; border-radius: 8px; cursor: pointer; }

/* App shell */
#app { display: grid; grid-template-columns: 56px 1fr; height: 100vh; }
#rail { background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: .6rem 0; gap: .3rem; }
.rail-btn { width: 40px; height: 40px; border-radius: 10px; border: none; background: transparent;
  color: var(--muted); font-size: 1.15rem; cursor: pointer; }
.rail-btn:hover { background: var(--panel2); color: var(--text); }
.rail-btn.active { background: rgba(111,140,255,.15); color: var(--accent); }
.rail-spacer { flex: 1; }
.view { overflow: hidden; }

/* Inbox 3-pane */
#view-inbox { display: grid; grid-template-columns: 320px 1fr 300px; height: 100vh; }
#lead-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
#lead-pane-top { padding: .6rem; display: flex; gap: .4rem; border-bottom: 1px solid var(--border); }
#search { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: .45rem .6rem; }
#filter { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: .45rem; }
#lead-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.lead-item { padding: .6rem .7rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.lead-item:hover { background: var(--panel); }
.lead-item.active { background: var(--panel2); border-left: 3px solid var(--accent); }
.lead-item .li-top { display: flex; justify-content: space-between; gap: .5rem; }
.lead-item .li-co { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-item .li-when { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.lead-item .li-sub { color: var(--muted); font-size: .78rem; margin-top: .15rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-badge { display: inline-block; font-size: .62rem; padding: 0 .3rem; border-radius: 4px;
  margin-right: .3rem; vertical-align: middle; }
.li-badge.in { background: rgba(52,211,153,.18); color: var(--green); }
#lead-list-more { padding: .5rem; text-align: center; }
#lead-list-more button { background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: .4rem .8rem; cursor: pointer; width: 100%; }

/* Thread pane */
#thread-pane { display: flex; flex-direction: column; min-height: 0; }
.empty { margin: auto; color: var(--muted); }
#thread-wrap { display: flex; flex-direction: column; height: 100%; min-height: 0; }
#thread-head { padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
#thread-head b { font-size: 1.05rem; }
#thread-head .th-sub { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
#thread-msgs { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.msg { max-width: 78%; padding: .55rem .75rem; border-radius: 12px; font-size: .88rem; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; }
.msg .m-when { font-size: .68rem; color: var(--muted); margin-bottom: .25rem; }
.msg.out { align-self: flex-end; background: rgba(111,140,255,.14); border: 1px solid rgba(111,140,255,.3); }
.msg.in { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); }
.msg .m-subj { font-weight: 600; margin-bottom: .2rem; }

/* Reply */
#reply-form { border-top: 1px solid var(--border); padding: .6rem; }
#reply-suggest { background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.3);
  border-radius: 10px; padding: .5rem .65rem; margin-bottom: .5rem; font-size: .82rem; display: none; }
#reply-suggest.show { display: block; }
#reply-suggest .rs-say { color: var(--text); }
#reply-suggest .rs-do { color: var(--amber); margin-top: .3rem; }
#reply-suggest .rs-use { margin-top: .4rem; background: var(--amber); border: none; color: #1a1205;
  border-radius: 6px; padding: .25rem .6rem; cursor: pointer; font-weight: 600; }
#reply-box { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: .55rem; font: inherit; resize: vertical; }
#reply-actions { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
#reply-actions .chk { color: var(--muted); font-size: .8rem; margin-right: auto; }
#reply-actions button { background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .45rem .7rem; cursor: pointer; }
#btn-send { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#reply-actions button:disabled { opacity: .5; cursor: default; }

/* Detail pane */
#detail-pane { border-left: 1px solid var(--border); overflow-y: auto; padding: .9rem; }
.det-empty { color: var(--muted); }
.det-sec { margin-bottom: 1rem; }
.det-sec h4 { margin: 0 0 .4rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.det-row { display: flex; justify-content: space-between; gap: .5rem; padding: .2rem 0; font-size: .84rem; }
.det-row span:first-child { color: var(--muted); }
.stage-pill { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem;
  background: var(--panel2); border: 1px solid var(--border); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 .55rem .9rem; border-left: 2px solid var(--border); font-size: .8rem; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: .25rem; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent); }
.timeline li.in::before { background: var(--green); }
.timeline .tl-when { color: var(--muted); font-size: .7rem; }

/* Lists + senders tables */
#view-lists, #view-senders { padding: 1.2rem; overflow-y: auto; }
h2.view-title { margin: 0 0 1rem; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; color: var(--muted);
  padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); font-size: .85rem; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.dot.ok { background: var(--green); } .dot.bad { background: var(--danger); } .dot.warn { background: var(--amber); }
.list-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem; margin-bottom: .8rem; display: flex; justify-content: space-between; align-items: center; }
.list-card .lc-n { font-weight: 600; } .list-card .lc-c { color: var(--muted); font-size: .82rem; }
.list-card button { background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .45rem .8rem; cursor: pointer; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--border); border-radius: 10px; padding: .6rem 1rem; z-index: 50; }

@media (max-width: 900px) {
  #view-inbox { grid-template-columns: 1fr; }
  #view-inbox[data-mobile="thread"] #lead-pane, #view-inbox[data-mobile="thread"] #detail-pane { display: none; }
  #view-inbox:not([data-mobile="thread"]) #thread-pane, #view-inbox:not([data-mobile="thread"]) #detail-pane { display: none; }
}

/* Scraper view */
#view-scraper { padding: 1.2rem; overflow-y: auto; }
.scr-form { max-width: 640px; margin-bottom: 1.2rem; display: flex; flex-direction: column; gap: .6rem; }
.scr-row { display: flex; gap: .5rem; }
.scr-row input { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: .5rem .65rem; }
.scr-row button { background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .5rem .9rem; cursor: pointer; white-space: nowrap; }
.scr-row button:hover { border-color: var(--accent); color: var(--accent); }
#scr-create, #scr-discover { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.scr-job { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem; margin-bottom: .6rem; }
.scr-job-h { display: flex; align-items: center; gap: .5rem; }
.scr-job-h .scr-when { margin-left: auto; color: var(--muted); font-size: .75rem; }
.scr-out { margin: .5rem 0 0; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .6rem; font-size: .75rem; white-space: pre-wrap; word-break: break-word; max-height: 16em; overflow-y: auto; color: var(--muted); }
.li-badge.out { background: rgba(111,140,255,.18); color: var(--accent); }

/* Re-engage worth score */
.li-score { display: inline-block; min-width: 22px; text-align: center; font-size: .68rem; font-weight: 700;
  padding: .05rem .3rem; border-radius: 5px; margin-right: .4rem; }
.li-score.hot { background: rgba(52,211,153,.2); color: var(--green); }
.li-score.warm { background: rgba(245,158,11,.2); color: var(--amber); }
.li-score.cold { background: rgba(138,144,160,.18); color: var(--muted); }
.score-big { font-size: 1.3rem; font-weight: 800; }
.score-big.hot { color: var(--green); } .score-big.warm { color: var(--amber); } .score-big.cold { color: var(--muted); }

/* Pipeline board (Kanban) */
#view-board { display: flex; flex-direction: column; height: 100vh; padding: 1rem 1rem 0; }
#board-top { display: flex; align-items: baseline; gap: .8rem; margin-bottom: .8rem; }
#board-top h2 { margin: 0; }
#board-hint { color: var(--muted); font-size: .8rem; flex: 1; }
#board-top button { background: transparent; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
#board-cols { display: flex; gap: .7rem; overflow-x: auto; flex: 1; padding-bottom: 1rem; }
.board-col { flex: 0 0 250px; display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; min-height: 0; }
.board-col.drop { border-color: var(--accent); background: rgba(111,140,255,.06); }
.bc-head { padding: .7rem .8rem; font-weight: 600; font-size: .85rem; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; }
.bc-count { color: var(--muted); font-size: .75rem; font-weight: 400; }
.bc-cards { overflow-y: auto; padding: .6rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.board-card { background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: .55rem .65rem;
  cursor: grab; }
.board-card:hover { border-color: var(--accent); }
.board-card.dragging { opacity: .4; }
.bcard-co { font-weight: 600; font-size: .84rem; }
.bcard-sub { color: var(--muted); font-size: .72rem; margin-top: .12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bcard-when { color: var(--muted); font-size: .68rem; margin-top: .2rem; }

/* Activity log + quick actions */
#act-buttons { display: flex; flex-wrap: wrap; gap: .35rem; }
#act-buttons button { background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .35rem .5rem; font-size: .74rem; cursor: pointer; }
#act-buttons button:hover { border-color: var(--accent); color: var(--accent); }
#det-activity { display: flex; flex-direction: column; gap: .45rem; }
.act { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .55rem; }
.act-h { font-size: .76rem; font-weight: 600; display: flex; justify-content: space-between; gap: .5rem; }
.act-when { color: var(--muted); font-weight: 400; font-size: .68rem; }
.act-body { font-size: .8rem; margin-top: .25rem; white-space: pre-wrap; word-break: break-word; }
.act-link { font-size: .72rem; color: var(--accent); }
.act-empty { color: var(--muted); font-size: .78rem; }

.bcard-val { float: right; font-size: .72rem; font-weight: 700; color: var(--green); }
.det-link { display: inline-block; margin-top: .4rem; font-size: .8rem; color: var(--accent); text-decoration: none; }
.det-link:hover { text-decoration: underline; }
