:root {
  --bg: #0f1419;
  --bg-2: #151b22;
  --panel: #1a212b;
  --panel-2: #212a35;
  --border: #2a3644;
  --border-2: #354458;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --text-faint: #6b7987;
  --accent: #4c8dff;
  --accent-2: #3a6fd8;
  --green: #3fb950;
  --amber: #d9a441;
  --red: #f26d6d;
  --purple: #a877ff;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --stage-lead: #6b7987;
  --stage-qualified: #4c8dff;
  --stage-demo: #a877ff;
  --stage-proposal: #d9a441;
  --stage-negotiation: #e08a4b;
  --stage-won: #3fb950;
  --stage-lost: #f26d6d;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--accent); }

#app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff; font-weight: 800; display: grid; place-items: center;
}
.brand-text { font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.brand-text span { color: var(--text-dim); font-weight: 500; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: none; color: var(--text-dim);
  padding: 9px 12px; border-radius: 8px; text-align: left; font-size: 14px;
  transition: background .12s, color .12s;
}
.nav-item .ni { width: 18px; text-align: center; opacity: .8; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.foot-note { color: var(--text-faint); font-size: 11px; padding: 4px 8px; line-height: 1.4; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 58px; flex-shrink: 0; display: flex; align-items: center; gap: 14px;
  padding: 0 22px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.search-wrap { position: relative; flex: 1; max-width: 520px; }
#global-search {
  width: 100%; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: 8px; outline: none;
}
#global-search:focus { border-color: var(--border-2); }
.search-results {
  position: absolute; top: 44px; left: 0; right: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--border-2); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 60vh; overflow: auto; padding: 6px;
}
.search-group-label { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; padding: 8px 10px 4px; }
.search-item { padding: 8px 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.search-item:hover { background: var(--panel-2); }
.search-item .sub { color: var(--text-dim); font-size: 12px; }
.search-item.has-x { gap: 10px; }
.search-item .grow-click { flex: 1; cursor: pointer; }
.search-item .row-x { background: none; border: none; color: var(--text-faint); font-size: 18px; line-height: 1; padding: 0 2px; cursor: pointer; opacity: 0; transition: opacity .12s, color .12s; }
.search-item.has-x:hover .row-x { opacity: 1; }
.search-item .row-x:hover { color: var(--red); }
.search-empty { padding: 14px; color: var(--text-dim); }

.quick-add { position: relative; margin-left: auto; }
.menu {
  position: absolute; right: 0; top: 42px; z-index: 40; background: var(--panel);
  border: 1px solid var(--border-2); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px; min-width: 150px; display: flex; flex-direction: column; gap: 2px;
}
.menu button { background: transparent; border: none; color: var(--text); text-align: left; padding: 8px 10px; border-radius: 7px; }
.menu button:hover { background: var(--panel-2); }

.view { flex: 1; overflow: auto; padding: 22px; }

/* ---------- Buttons ---------- */
.primary { background: var(--accent); color: #fff; border: none; padding: 9px 15px; border-radius: 8px; font-weight: 600; }
.primary:hover { background: var(--accent-2); }
.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--border); padding: 8px 13px; border-radius: 8px; }
.ghost:hover { background: var(--panel-2); border-color: var(--border-2); }
.ghost.sm, .primary.sm { padding: 6px 10px; font-size: 13px; }
.danger { background: transparent; color: var(--red); border: 1px solid var(--border); padding: 8px 13px; border-radius: 8px; }
.danger:hover { background: rgba(242, 109, 109, .12); border-color: var(--red); }
.linkbtn { background: none; border: none; color: var(--accent); padding: 0; font-size: 13px; }
.linkbtn:hover { text-decoration: underline; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; margin: 0; font-weight: 700; }
.page-head .spacer { flex: 1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar select {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 8px 11px; border-radius: 8px; outline: none;
}
.multifilter { position: relative; display: inline-block; }
.mf-btn { display: inline-flex; align-items: center; gap: 8px; }
.mf-btn.mf-active { border-color: var(--accent); color: var(--text); }
.mf-caret { font-size: 10px; opacity: .7; }
.mf-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 50; background: var(--panel); border: 1px solid var(--border-2); border-radius: 9px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; max-height: 300px; overflow-y: auto; }
.mf-row { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.mf-row:hover { background: var(--panel-2); }
.mf-row input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: none; color: var(--text-dim); padding: 7px 13px; }
.seg button.active { background: var(--panel-2); color: var(--text); }

/* ---------- Cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .sub { color: var(--text-faint); font-size: 12px; margin-top: 3px; }

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.card h3 .muted { color: var(--text-faint); font-weight: 400; }

/* pipeline bar chart on dashboard */
.pipe-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.pipe-row .name { width: 120px; color: var(--text-dim); font-size: 13px; flex-shrink: 0; }
.pipe-bar-wrap { flex: 1; background: var(--bg-2); border-radius: 6px; height: 20px; overflow: hidden; }
.pipe-bar { height: 100%; border-radius: 6px; min-width: 2px; }
.pipe-row .amt { width: 110px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; color: var(--text-dim); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .4px; padding: 11px 14px;
  border-bottom: 1px solid var(--border); background: var(--bg-2);
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover, table.data tr.clickable:hover { background: var(--panel-2); }
table.data tr.clickable { cursor: pointer; }
.empty-state { padding: 40px; text-align: center; color: var(--text-dim); }
.empty-state .big { font-size: 15px; color: var(--text); margin-bottom: 6px; }

/* ---------- Kanban ---------- */
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 10px; }
.column {
  width: 250px; flex-shrink: 0; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 170px);
}
.column-head { padding: 11px 13px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.column-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.column-head .ctitle { font-weight: 600; font-size: 13px; }
.column-head .ccount { color: var(--text-faint); font-size: 12px; }
.column-head .cvalue { margin-left: auto; color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.column-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; min-height: 40px; }
.column-body.drag-over { background: rgba(76, 141, 255, .08); outline: 2px dashed var(--border-2); outline-offset: -6px; border-radius: 8px; }
.deal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 11px 12px;
  cursor: grab; transition: border-color .12s, transform .06s;
}
.deal-card:hover { border-color: var(--border-2); }
.deal-card.dragging { opacity: .5; }
.deal-card .dname { font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.deal-card .dmeta { color: var(--text-dim); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.deal-card .dval { color: var(--green); font-weight: 600; }
.deal-card .dcompany { color: var(--text-faint); font-size: 12px; }
.deal-card .dcardfoot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.dcard-tags { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.prio-tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; border: 1px solid; }
.cat-chip { display: inline-block; background: rgba(168, 119, 255, .15); color: var(--purple); border: 1px solid rgba(168, 119, 255, .35); padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.prio-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.stage-badge { color: #fff; }
.chip { display: inline-block; background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim); padding: 2px 8px; border-radius: 999px; font-size: 11px; margin: 0 3px 3px 0; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.pill.overdue { background: rgba(242,109,109,.16); color: var(--red); }
.pill.today { background: rgba(217,164,65,.16); color: var(--amber); }
.pill.upcoming { background: rgba(76,141,255,.14); color: var(--accent); }

/* ---------- Tasks ---------- */
.task-group { margin-bottom: 18px; }
.task-group h3 { font-size: 13px; color: var(--text-dim); margin: 0 0 8px; display: flex; gap: 8px; align-items: center; }
.task-group.overdue h3 { color: var(--red); }
.task-group.overdue h3 .muted { color: var(--red); opacity: .8; }
.task-row {
  display: flex; align-items: flex-start; gap: 11px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 9px; padding: 11px 13px; margin-bottom: 7px;
}
.task-row.done .task-title { text-decoration: line-through; color: var(--text-faint); }
.task-check { width: 18px; height: 18px; margin-top: 1px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 500; }
.task-sub { color: var(--text-dim); font-size: 12px; margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.task-row .row-actions { opacity: 0; transition: opacity .12s; }
.task-row:hover .row-actions { opacity: 1; }

/* ---------- Activity timeline ---------- */
.timeline { position: relative; }
.tl-item { display: flex; gap: 12px; padding: 4px 0 16px; position: relative; }
.tl-dot { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-size: 13px; background: var(--panel-2); border: 1px solid var(--border); }
.tl-body { flex: 1; min-width: 0; }
.tl-body .tl-body-text { white-space: pre-wrap; }
.tl-meta { color: var(--text-faint); font-size: 12px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.tl-line { position: absolute; left: 14px; top: 32px; bottom: 0; width: 1px; background: var(--border); }

/* ---------- Drawer ---------- */
.drawer, .modal { position: fixed; inset: 0; z-index: 60; }
.drawer.hidden, .modal.hidden { display: none; }
.drawer-backdrop, .modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 560px; max-width: 92vw;
  background: var(--bg-2); border-left: 1px solid var(--border-2); box-shadow: var(--shadow);
  overflow-y: auto; animation: slidein .18s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 22px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-2); z-index: 2; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-head .sub { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.drawer-head .x { margin-left: auto; background: transparent; border: none; color: var(--text-dim); font-size: 22px; line-height: 1; }
.drawer-head .x:hover { color: var(--text); }
.drawer-section { padding: 16px 22px; border-bottom: 1px solid var(--border); }
.drawer-section h4 { margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; }
.kv .k { color: var(--text-dim); }
.kv .v { color: var(--text); }

/* ---------- Modal / forms ---------- */
.modal-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 520px; max-width: 94vw; max-height: 90vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 14px; box-shadow: var(--shadow);
}
.modal.nested { z-index: 70; }
.label-action { float: right; font-size: 12px; font-weight: 500; }
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head .x { margin-left: auto; background: transparent; border: none; color: var(--text-dim); font-size: 22px; }
.modal-head .x:hover { color: var(--text); }
form.crm-form { padding: 18px 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; color: var(--text-dim); font-size: 12px; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 8px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--border-2); }
.field textarea { resize: vertical; min-height: 70px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); font-weight: 600; margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--border); }

/* Searchable multi-contact picker */
.contact-picker { }
.cp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.cp-empty { color: var(--text-faint); font-size: 13px; }
.cp-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 999px; padding: 3px 6px 3px 11px; font-size: 13px; }
.cp-x { background: none; border: none; color: var(--text-dim); font-size: 16px; line-height: 1; padding: 0; cursor: pointer; }
.cp-x:hover { color: var(--red); }
.cp-input-wrap { position: relative; }
.cp-input { width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 9px 11px; border-radius: 8px; outline: none; }
.cp-input:focus { border-color: var(--border-2); }
.cp-dropdown { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50; background: var(--panel); border: 1px solid var(--border-2); border-radius: 9px; box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; padding: 5px; }
.cp-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.cp-item:hover { background: var(--panel-2); }
.cp-item .sub { color: var(--text-dim); font-size: 12px; }
.cp-add { color: var(--accent); font-weight: 600; }
.cp-hint-inline { color: var(--text-faint); font-weight: 400; font-size: 12px; margin-left: 4px; }

/* inline add activity/task */
.inline-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.inline-form .row { display: flex; gap: 8px; }
.inline-form textarea, .inline-form input, .inline-form select {
  background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 8px; outline: none;
}
.inline-form textarea { flex: 1; min-height: 42px; resize: vertical; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--panel); border: 1px solid var(--border-2); border-left: 3px solid var(--accent);
  padding: 12px 16px; border-radius: 9px; box-shadow: var(--shadow); min-width: 220px; max-width: 340px;
  animation: toastin .18s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.tabular { font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 8px; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b3745; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
