:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --surface-3: #262b36;
  --border: #2b313d;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --text-faint: #6b7484;
  --primary: #5b8cff;
  --primary-dim: #3a5bb5;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --purple: #a78bfa;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; font-weight: 500; }
::placeholder { color: var(--text-faint); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; border: 2px solid var(--bg); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 14px; font-size: 13px; font-weight: 600;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: #303644; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #4a7bf0; }
.btn-danger { color: var(--red); border-color: transparent; background: transparent; }
.btn-danger:hover { background: rgba(248,113,113,.12); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: 8px; }

/* ---------------- Login ---------------- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.login-card .logo { font-size: 40px; margin-bottom: 12px; }
.login-card p.sub { color: var(--text-dim); margin-bottom: 24px; }
.login-card .field { margin-bottom: 16px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--text-faint); text-align: center; }
.error-banner { background: rgba(248,113,113,.12); color: var(--red); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }

/* ---------------- App shell ---------------- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 6px 10px 18px; }
.brand .mark { font-size: 22px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 9px; color: var(--text-dim);
  font-weight: 500; font-size: 14px; transition: all .12s; cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); }
.nav-item .ico { width: 18px; text-align: center; }
.nav-spacer { flex: 1; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 9px; background: var(--surface-2); margin-top: 8px;
}
.user-chip .avatar { width: 30px; height: 30px; flex-shrink: 0; }
.user-chip .meta { overflow: hidden; }
.user-chip .meta .n { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .meta .r { font-size: 11px; color: var(--text-faint); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 26px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(15,17,21,.85); backdrop-filter: blur(8px); z-index: 20;
}
.topbar h2 { font-size: 19px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.search-box { position: relative; width: 280px; }
.search-box input { padding-left: 34px; }
.search-box .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden; z-index: 50;
}
.search-results .group-label { font-size: 11px; text-transform: uppercase; color: var(--text-faint); padding: 8px 12px 4px; letter-spacing: .04em; }
.search-results .res-item { padding: 8px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.search-results .res-item:hover { background: var(--surface-3); }
.content { padding: 26px; flex: 1; }

/* ---------------- Notification bell ---------------- */
.notif-bell { position: relative; font-size: 18px; padding: 7px 9px; border-radius: 9px; cursor: pointer; line-height: 1; user-select: none; }
.notif-bell:hover { background: var(--surface-2); }
.notif-badge {
  position: absolute; top: 2px; right: 2px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 20px; padding: 1px 5px;
  min-width: 16px; text-align: center; line-height: 1.4; box-shadow: 0 0 0 2px var(--surface);
}
.notif-dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; width: 340px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 400px; overflow-y: auto; z-index: 50;
}
.notif-dropdown.open { display: block; }
.notif-head { padding: 10px 14px; font-size: 12px; font-weight: 700; color: var(--text-dim); border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .04em; }
.notif-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:last-child { border: none; }
.notif-item:hover { background: var(--surface-3); }
.notif-item .body { flex: 1; min-width: 0; }
.notif-item .body .t { font-size: 13px; font-weight: 500; }
.notif-item .body .sub { font-size: 11px; color: var(--text-faint); }
.notif-empty { padding: 24px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------------- Avatars ---------------- */
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}

/* ---------------- Cards / KPI ---------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; position: relative; overflow: hidden;
}
.kpi .label { font-size: 12px; color: var(--text-dim); font-weight: 500; display: flex; align-items: center; gap: 7px; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 8px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.kpi .ring { position: absolute; right: -18px; top: -18px; font-size: 64px; opacity: .07; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.panel-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.panel-head h3 { font-size: 15px; font-weight: 700; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 8px 0; }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 1000px){ .dash-grid { grid-template-columns: 1fr; } }

/* funnel */
.funnel-row { display: flex; align-items: center; gap: 12px; padding: 9px 18px; }
.funnel-row .stage-name { width: 110px; font-size: 13px; font-weight: 500; }
.funnel-row .bar-track { flex: 1; height: 22px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.funnel-row .bar { height: 100%; border-radius: 6px; min-width: 2px; transition: width .4s; }
.funnel-row .bar-val { width: 130px; text-align: right; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* leaderboard */
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 18px; }
.lb-row .meta { flex: 1; }
.lb-row .name { font-weight: 600; font-size: 13px; }
.lb-row .open { font-size: 11px; color: var(--text-faint); }
.lb-row .won { font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }

/* upcoming list */
.act-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.act-row:last-child { border: none; }
.act-row .check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; cursor: pointer; display: grid; place-items: center; transition: all .15s; }
.act-row .check:hover { border-color: var(--green); }
.act-row .check.done { background: var(--green); border-color: var(--green); }
.act-row .body { flex: 1; min-width: 0; }
.act-row .body .t { font-weight: 500; }
.act-row .body .t.done { text-decoration: line-through; color: var(--text-faint); }
.act-row .body .sub { font-size: 12px; color: var(--text-faint); }
.act-row .type-pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }

/* ---------------- Tables ---------------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
.cell-main { font-weight: 600; }
.cell-with-avatar { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--text-faint); }
.empty { text-align: center; padding: 50px 20px; color: var(--text-faint); }
.empty .big { font-size: 40px; margin-bottom: 10px; }

/* ---------------- Badges ---------------- */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-green { background: rgba(52,211,153,.16); color: var(--green); }
.badge-red { background: rgba(248,113,113,.16); color: var(--red); }
.badge-gray { background: rgba(107,116,132,.18); color: #b6bdca; }
.pill-Call { background: rgba(91,140,255,.16); color: #8fb0ff; }
.pill-Email { background: rgba(167,139,250,.16); color: var(--purple); }
.pill-Meeting { background: rgba(251,191,36,.16); color: var(--amber); }
.pill-Task { background: rgba(107,116,132,.2); color: #b6bdca; }
.role-badge { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-dim); }
.role-badge.admin { background: rgba(167,139,250,.16); color: var(--purple); }

/* ---------------- Kanban ---------------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kan-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 270px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 180px); }
.kan-col.drag-over { border-color: var(--primary); background: var(--surface-2); }
.kan-head { padding: 13px 15px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; }
.kan-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.kan-head .name { font-weight: 700; font-size: 13px; }
.kan-head .count { font-size: 12px; color: var(--text-faint); background: var(--surface-3); padding: 1px 8px; border-radius: 20px; }
.kan-head .sum { margin-left: auto; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.kan-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; flex: 1; }
.deal-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; cursor: grab; transition: border-color .12s, transform .05s;
}
.deal-card:hover { border-color: var(--primary-dim); }
.deal-card:active { cursor: grabbing; }
.deal-card.dragging { opacity: .4; }
.deal-card .title { font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.deal-card .company { font-size: 12px; color: var(--text-dim); margin-bottom: 9px; }
.deal-card .foot { display: flex; align-items: center; justify-content: space-between; }
.deal-card .val { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------------- Modal ---------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
  animation: pop .18s;
}
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h3 { font-size: 17px; font-weight: 700; flex: 1; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: var(--surface); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { margin-bottom: 14px; }

/* detail view */
.detail-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.detail-head .big-avatar { width: 56px; height: 56px; font-size: 22px; border-radius: 14px; }
.detail-head h2 { font-size: 22px; }
.detail-head .sub { color: var(--text-dim); }
.detail-cols { display: grid; grid-template-columns: 1fr 1.3fr; gap: 18px; align-items: start; }
@media (max-width: 900px){ .detail-cols { grid-template-columns: 1fr; } }
.info-list { list-style: none; }
.info-list li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.info-list li:last-child { border: none; }
.info-list .k { width: 90px; color: var(--text-faint); flex-shrink: 0; }
.info-list .v { flex: 1; }
.note-item { padding: 12px 18px; border-bottom: 1px solid var(--border); }
.note-item:last-child { border: none; }
.note-item .body { font-size: 13px; white-space: pre-wrap; }
.note-item .meta { font-size: 11px; color: var(--text-faint); margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.note-compose { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.note-compose textarea { resize: vertical; min-height: 60px; }
.chip-link { background: var(--surface-2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 20px; font-size: 12px; color: var(--text); }
.chip-link:hover { border-color: var(--primary); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin: 22px 0 10px; font-weight: 600; }
.tag-filter { display: flex; gap: 8px; }
.tag-filter .tag { padding: 6px 12px; border-radius: 20px; font-size: 13px; background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); cursor: pointer; }
.tag-filter .tag.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.overdue-text { color: var(--red); }
.due-text { color: var(--amber); }

/* ---------------- Timeline ---------------- */
.timeline { padding: 4px 0; max-height: 480px; overflow-y: auto; }
.timeline-item { display: flex; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border: none; }
.ti-icon { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; flex-shrink: 0; }
.ti-body { flex: 1; min-width: 0; }
.ti-desc { font-size: 13px; }
.ti-meta { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* toast */
#toast-root { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--surface-3); border: 1px solid var(--border); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; animation: slidein .2s; min-width: 200px; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); margin-bottom: 16px; cursor: pointer; font-size: 13px; }
.back-link:hover { color: var(--text); }

/* ---------------- Settings: pipeline stages ---------------- */
.stage-row { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.stage-row:last-child { border: none; }
.stage-row .stage-color { width: 38px; height: 36px; padding: 3px; flex-shrink: 0; cursor: pointer; }
.stage-row .stage-name { flex: 1; min-width: 0; }
.stage-row .stage-flag { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); white-space: nowrap; cursor: pointer; }
.stage-row .stage-flag input { width: auto; cursor: pointer; }
.stage-row .stage-actions { display: flex; gap: 2px; flex-shrink: 0; }
.stage-row .stage-actions .btn[disabled] { opacity: .3; cursor: default; }
.stage-row .stage-actions .btn[disabled]:hover { background: transparent; }
