:root {
  --bg: #0b0f17;
  --bg-2: #111725;
  --panel: #151d2c;
  --panel-2: #1a2332;
  --border: #243044;
  --border-2: #2f3d55;
  --text: #e6ebf4;
  --muted: #8a97ad;
  --muted-2: #5f6b80;
  --brand: #4f8cff;
  --brand-2: #6ea3ff;
  --accent: #16c98d;
  --accent-2: #0fae78;
  --warn: #f5b544;
  --danger: #ef5b6b;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }

/* Sidebar */
.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 14px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 20px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), var(--accent)); display: grid; place-items: center; font-weight: 800; color: #04121f; letter-spacing: .5px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11.5px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; background: transparent; border: none; color: var(--muted); padding: 10px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 500; text-align: left; }
.nav-item .ni { width: 16px; text-align: center; opacity: .8; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-2); }
.sidebar-foot { margin-top: auto; }
.src-status { font-size: 11.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; display: flex; flex-direction: column; gap: 7px; }
.src-row { display: flex; align-items: center; justify-content: space-between; }
.pill { font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.pill.on { background: rgba(22,201,141,.15); color: var(--accent); }
.pill.off { background: rgba(138,151,173,.14); color: var(--muted); }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 26px; border-bottom: 1px solid var(--border); background: rgba(11,15,23,.7); backdrop-filter: blur(6px); }
.topbar-title { font-size: 19px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.search input { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 9px 13px; width: 210px; font-size: 13px; outline: none; }
.search input:focus { border-color: var(--border-2); }
.content { padding: 24px 26px 60px; overflow-y: auto; }

/* Buttons */
.btn { border: 1px solid var(--border-2); background: var(--panel); color: var(--text); padding: 9px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 7px; }
.btn:hover { border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #051020; }
.btn.primary:hover { background: var(--brand-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #042014; }
.btn.accent:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: transparent; background: rgba(239,91,107,.1); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn .dot { width: 7px; height: 7px; border-radius: 50%; background: #051020; opacity: .6; }
.btn:disabled { opacity: .5; cursor: default; }

/* KPI cards */
.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 17px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 27px; font-weight: 800; margin-top: 7px; letter-spacing: -.5px; }
.kpi .sub { font-size: 11.5px; color: var(--muted-2); margin-top: 3px; }
.kpi.good .value { color: var(--accent); }

/* Panels / grid */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.panel h3 { margin: 0 0 15px; font-size: 14px; font-weight: 700; }
.panel .sub-h { color: var(--muted); font-size: 12px; font-weight: 500; }

/* Funnel */
.funnel { display: flex; flex-direction: column; gap: 9px; }
.funnel-row { display: flex; align-items: center; gap: 12px; }
.funnel-row .fname { width: 92px; font-size: 12.5px; color: var(--muted); text-transform: capitalize; }
.funnel-bar { flex: 1; height: 22px; background: var(--bg-2); border-radius: 6px; overflow: hidden; }
.funnel-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 6px; min-width: 2px; }
.funnel-row .fcount { width: 28px; text-align: right; font-weight: 700; font-size: 13px; }

/* Source breakdown */
.src-list { display: flex; flex-direction: column; gap: 11px; }
.src-item { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.src-item .bar { flex: 1; margin: 0 12px; height: 7px; background: var(--bg-2); border-radius: 4px; overflow: hidden; }
.src-item .bar > span { display: block; height: 100%; background: var(--accent); }

/* Table */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.filters { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chip { background: var(--bg-2); border: 1px solid var(--border); color: var(--muted); padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #051020; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted-2); padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
.biz { display: flex; flex-direction: column; gap: 2px; }
.biz strong { font-size: 13.5px; }
.biz .biz-sub { font-size: 11.5px; color: var(--muted); }
.contact-cell { display: flex; flex-direction: column; gap: 2px; }
.contact-cell .cname { font-weight: 600; }
.contact-cell .ctitle { font-size: 11.5px; color: var(--muted); }
.muted { color: var(--muted); }

/* Fit score */
.fit { display: inline-flex; align-items: center; gap: 7px; }
.fit .ring { width: 34px; height: 6px; border-radius: 4px; background: var(--bg-2); overflow: hidden; }
.fit .ring > span { display: block; height: 100%; }
.fit b { font-size: 12.5px; width: 22px; }

/* Status badge */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; text-transform: capitalize; }
.st-new { background: rgba(79,140,255,.16); color: var(--brand-2); }
.st-researching { background: rgba(110,163,255,.12); color: #9db9ff; }
.st-contacted { background: rgba(245,181,68,.15); color: var(--warn); }
.st-engaged { background: rgba(245,181,68,.2); color: #ffcf6e; }
.st-qualified { background: rgba(22,201,141,.15); color: var(--accent); }
.st-proposal { background: rgba(22,201,141,.22); color: #4fe0b3; }
.st-won { background: rgba(22,201,141,.3); color: #7fffcf; }
.st-lost { background: rgba(239,91,107,.16); color: var(--danger); }

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

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(3,6,12,.55); opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 40; }
.overlay.show { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 560px; max-width: 94vw; background: var(--bg-2); border-left: 1px solid var(--border); box-shadow: var(--shadow); transform: translateX(100%); transition: transform .22s cubic-bezier(.4,0,.2,1); z-index: 50; overflow-y: auto; }
.drawer.show { transform: translateX(0); }
.drawer-head { padding: 22px 24px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-2); z-index: 2; }
.drawer-head .close { position: absolute; top: 18px; right: 20px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); width: 30px; height: 30px; border-radius: 8px; font-size: 16px; }
.drawer-head h2 { margin: 0; font-size: 20px; }
.drawer-head .dh-sub { color: var(--muted); font-size: 13px; margin-top: 5px; display: flex; gap: 12px; flex-wrap: wrap; }
.drawer-body { padding: 18px 24px 60px; }
.tabs { display: flex; gap: 4px; margin: 14px 0 6px; border-bottom: 1px solid var(--border); }
.tab { background: transparent; border: none; color: var(--muted); padding: 10px 13px; font-size: 13px; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.tab-pane { padding-top: 16px; display: none; }
.tab-pane.active { display: block; }

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.field input, .field select, .field textarea { width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 9px 11px; font-size: 13px; outline: none; }
.field textarea { resize: vertical; min-height: 78px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.strategy-box { white-space: pre-wrap; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 15px; font-size: 12.5px; line-height: 1.65; color: #cdd6e6; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--border); margin-left: 4px; }
.tl-item:last-child { border-left-color: transparent; }
.tl-dot { position: absolute; left: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 2px solid var(--bg-2); }
.tl-item.inbound .tl-dot { background: var(--accent); }
.tl-head { display: flex; align-items: center; gap: 9px; font-size: 12.5px; }
.tl-head .tl-ch { font-weight: 700; text-transform: capitalize; }
.tl-head .tl-date { color: var(--muted-2); font-size: 11.5px; margin-left: auto; }
.tl-body { font-size: 13px; margin-top: 4px; color: #d4dcea; }
.tl-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.tl-next { color: var(--warn); }

/* Draft card */
.draft-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.draft-card .dc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.draft-card .dc-ch { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--brand-2); font-weight: 700; }
.draft-card .dc-actions { margin-left: auto; display: flex; gap: 6px; }
.draft-card pre { white-space: pre-wrap; font-family: inherit; font-size: 12.8px; line-height: 1.55; margin: 0; color: #d4dcea; }
.draft-card .dc-subject { font-weight: 700; margin-bottom: 6px; font-size: 13px; }
.gen-row { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 16px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 13px; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(3,6,12,.6); display: none; align-items: center; justify-content: center; z-index: 60; }
.modal-wrap.show { display: flex; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; width: 520px; max-width: 94vw; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); padding: 24px; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .m-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text); padding: 12px 18px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: all .2s; z-index: 90; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); }

.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title h3 { margin: 0; font-size: 15px; }
.hint { font-size: 12px; color: var(--muted); background: var(--panel); border: 1px dashed var(--border-2); border-radius: 10px; padding: 12px 14px; line-height: 1.55; }

/* Login */
.login-wrap { position: fixed; inset: 0; background: radial-gradient(1200px 600px at 30% -10%, #16233b 0%, var(--bg) 55%); display: none; align-items: center; justify-content: center; z-index: 100; }
.login-wrap.show { display: flex; }
.login-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; padding: 30px 28px; width: 360px; max-width: 92vw; box-shadow: var(--shadow); }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 20px; }
.login-err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin: 4px 0; }

@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(2,1fr); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .app { grid-template-columns: 1fr; } .sidebar { display: none; } .search input { width: 130px; } }
