:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: #e6e8ef;
  --text: #1a1d29;
  --muted: #6b7280;
  --accent: #6366f1;
  --accent-weak: #eef0fe;
  --red: #e5484d;
  --red-weak: #fdecec;
  --amber: #d97706;
  --amber-weak: #fef3e2;
  --green: #16a34a;
  --green-weak: #e7f6ec;
  --shadow: 0 1px 3px rgba(17, 24, 39, .06), 0 8px 24px rgba(17, 24, 39, .05);
  --radius: 14px;
}

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

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 15px;
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px;
}
.stat .n { font-size: 20px; font-weight: 700; }
.stat .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat.alert .n { color: var(--red); }
.stat.warn .n { color: var(--amber); }

.section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; margin: 4px 2px;
  display: flex; justify-content: space-between; align-items: center;
}
.cat-list { display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 9px; border: none; background: none;
  width: 100%; text-align: left; color: var(--text); font-size: 13.5px;
}
.cat-item:hover { background: var(--surface-2); }
.cat-item.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.cat-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cat-item .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.cat-item.active .count { color: var(--accent); }
.cat-edit { margin-left: 6px; opacity: 0; font-size: 12px; color: var(--muted); background:none; border:none; }
.cat-item:hover .cat-edit { opacity: 1; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; text-align: left; cursor: pointer; }
.user-chip:hover { border-color: var(--accent); }
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 650; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.user-cog { color: var(--muted); font-size: 14px; }

.role-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; display: inline-block; }
.role-badge.role-admin { background: #ede9fe; color: #6d28d9; }
.role-badge.role-rep { background: var(--surface-2); color: var(--muted); }

.users-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 10px; }
.users-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.users-table td { padding: 10px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table td.actions { white-space: nowrap; display: flex; gap: 4px; justify-content: flex-end; }
.users-table .dot-ok { color: var(--green); font-size: 14px; }
.users-table .dot-off { color: var(--muted); font-size: 14px; }

.checklist { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.cl { display: flex; align-items: center; gap: 5px; }
.cl.ok { color: var(--green); }

.check-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.check-row input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- main ---------- */
.main { padding: 22px 26px; min-width: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar h1 { font-size: 19px; margin: 0 8px 0 0; }
.search {
  flex: 1; min-width: 180px; max-width: 340px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 9px 12px;
}
.chips { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.chip { border: none; background: none; padding: 8px 13px; font-size: 13px; color: var(--muted); }
.chip + .chip { border-left: 1px solid var(--border); }
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--text); color: #fff; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 9px 14px; font-size: 13.5px; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--red); border-color: var(--red-weak); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.block { width: 100%; justify-content: center; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }

/* ---------- contact cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform .08s ease, box-shadow .12s ease;
  display: flex; flex-direction: column; gap: 10px;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(17,24,39,.10); }
.card-top { display: flex; justify-content: space-between; gap: 8px; }
.card .name { font-weight: 650; font-size: 15px; }
.card .company { color: var(--muted); font-size: 13px; }
.pill {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600;
  white-space: nowrap; display: inline-flex; align-items: center; gap: 5px;
}
.card .lines { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 13px; }
.card .lines a { color: var(--muted); text-decoration: none; }
.card .lines a:hover { color: var(--accent); }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }

.status { font-size: 11px; padding: 3px 9px; border-radius: 6px; font-weight: 600; text-transform: capitalize; }
.status.new { background: var(--accent-weak); color: var(--accent); }
.status.contacted { background: #e0f2fe; color: #0369a1; }
.status.qualified { background: var(--amber-weak); color: var(--amber); }
.status.won { background: var(--green-weak); color: var(--green); }
.status.lost { background: #f1f1f4; color: var(--muted); }

.due { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.due.overdue { color: var(--red); }
.due.today { color: var(--amber); }
.due.future { color: var(--green); }
.due.none { color: var(--muted); font-weight: 500; }
.tasks-badge { font-size: 12px; color: var(--muted); font-weight: 600; }
.tasks-badge.overdue { color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 70px 20px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- modal / drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,.4);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); padding: 22px;
}
.modal.wide { max-width: 720px; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .sub { color: var(--muted); margin: 0 0 16px; font-size: 13px; }

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak);
}
.field textarea { resize: vertical; min-height: 70px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .spacer { margin-right: auto; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.detail-meta { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; color: var(--text); font-size: 13.5px; }
.detail-meta .row { display: flex; gap: 8px; }
.detail-meta .k { color: var(--muted); width: 70px; flex: none; }
.detail-notes { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: 13.5px; color: var(--text); }

.task-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 4px; }
.task {
  display: flex; flex-direction: column; gap: 7px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.task-row { display: flex; align-items: center; gap: 10px; }
.task input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.task .t-title { flex: 1; }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.t-comment { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13px; background: var(--surface); }
.t-comment:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.t-comment-saved { font-size: 12.5px; color: var(--muted); padding: 2px 2px 0; }
.task .t-due { font-size: 12px; color: var(--muted); }
.task .t-due.overdue { color: var(--red); }
.task .t-del { background: none; border: none; color: var(--muted); font-size: 15px; }
.add-task { display: flex; gap: 8px; margin-top: 8px; }
.add-task input { flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; }
.add-task input[type=date] { flex: none; width: 150px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 34px 30px; width: 100%; max-width: 380px; text-align: center;
}
.login-card .logo {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 24px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 22px; font-size: 13.5px; }
.login-card input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 11px; margin-bottom: 12px; }
.login-card .err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; transition: all .2s ease; z-index: 100; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- view toggle ---------- */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.vt { border: none; background: none; padding: 8px 13px; font-size: 13px; color: var(--muted); }
.vt.active { background: var(--text); color: #fff; }

/* status badge — color comes from the status, applied inline */
.status-badge { font-size: 11px; padding: 3px 9px; border-radius: 6px; font-weight: 600; white-space: nowrap; }

/* ---------- kanban board ---------- */
.board { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 10px; }
.column {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  width: 270px; flex: 0 0 270px; display: flex; flex-direction: column; max-height: calc(100vh - 130px);
}
.column.add-col { background: none; border: 1px dashed var(--border); padding: 10px; }
.column-head {
  display: flex; align-items: center; gap: 7px; padding: 11px 12px;
  border-bottom: 1px solid var(--border); border-radius: 12px 12px 0 0;
}
.col-name { font-weight: 650; font-size: 13.5px; }
.col-count { background: var(--border); color: var(--muted); border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; }
.col-actions { margin-left: auto; display: flex; gap: 2px; align-items: center; opacity: 0; transition: opacity .12s; }
.column-head:hover .col-actions { opacity: 1; }
.col-actions button { border: none; background: none; color: var(--muted); font-size: 12px; padding: 2px 5px; border-radius: 5px; }
.col-actions button:hover:not(:disabled) { background: var(--border); color: var(--text); }
.col-actions button:disabled { opacity: .3; cursor: default; }
.column-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; min-height: 60px; }
.column-body.drag-over { background: var(--accent-weak); outline: 2px dashed var(--accent); outline-offset: -6px; }
.col-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 12px 0; }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; box-shadow: var(--shadow); cursor: grab;
  display: flex; flex-direction: column; gap: 6px;
}
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .4; }
.kname { font-weight: 600; font-size: 13.5px; }
.kcard .company { font-size: 12px; }
.kmeta { display: flex; align-items: center; justify-content: flex-start; gap: 7px; flex-wrap: wrap; }

/* ---------- call list ---------- */
.calls { display: flex; flex-direction: column; gap: 10px; max-width: 860px; }
.call-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer;
}
.call-row:hover { border-color: var(--accent); }
.call-info { min-width: 0; }
.call-name { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.call-reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.reason { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 6px; }
.reason.overdue { background: var(--red-weak); color: var(--red); }
.reason.today { background: var(--amber-weak); color: var(--amber); }
.reason.upcoming { background: var(--green-weak); color: var(--green); }
.reason-done { border: none; background: rgba(0, 0, 0, .08); color: inherit; border-radius: 5px; margin-left: 7px; padding: 1px 6px; font-size: 11px; cursor: pointer; font-weight: 700; }
.reason-done:hover { background: rgba(0, 0, 0, .18); }
.call-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.call-actions a.btn { text-decoration: none; white-space: nowrap; }
.bump { display: flex; align-items: center; gap: 4px; }
.bump-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.bump button { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 4px 9px; font-size: 12px; color: var(--text); }
.bump button:hover { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }
.no-phone { font-size: 12px; color: var(--muted); }
@media (max-width: 600px) {
  .call-row { flex-direction: column; align-items: stretch; }
  .call-actions { align-items: stretch; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .grid-2 { grid-template-columns: 1fr; }
}
