:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e6eaf2;
  --line-2: #eef2f8;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --brand-ink: #4338ca;
  --good: #059669;
  --bad: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 28px rgba(15, 23, 42, .07);
  --sidebar-w: 236px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- boot ---------- */
.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.boot-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 34px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.boot-card h2 { font-size: 20px; margin-bottom: 8px; }
.boot-card p { color: var(--muted); font-size: 14px; }
.spinner {
  width: 30px; height: 30px; margin: 0 auto 16px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #0f172a;
  color: #cbd5e1;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid; place-items: center;
  color: #fff; font-size: 15px;
  flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { color: #fff; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-text span { font-size: 11.5px; color: #7c8aa1; letter-spacing: .04em; text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 10px;
  font-size: 14px; color: #a9b6c9;
  transition: background .15s, color .15s;
}
.nav a i { width: 16px; text-align: center; font-size: 13px; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(99, 102, 241, .22); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 0 8px; }
.sidebar-foot p { font-size: 12px; color: #64748b; line-height: 1.5; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px;
  background: rgba(245, 247, 251, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { min-width: 0; }
.topbar h1 { font-size: 19px; }
.view-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 12px;
  height: 38px;
  width: 260px;
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: #c7d2fe; box-shadow: 0 0 0 3px rgba(99, 102, 241, .12); }
.search i { color: #94a3b8; font-size: 12px; }
.search input {
  border: 0; outline: 0; background: transparent; width: 100%;
  font-size: 13.5px;
}
.search input::-webkit-search-cancel-button { cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 15px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 13.5px; font-weight: 550;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: #fecaca; background: #fef2f2; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.view { padding: 22px 28px 90px; flex: 1; min-width: 0; }

.mobile-nav { display: none; }

/* ---------- board ---------- */
.board {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 14px;
  scroll-snap-type: x proximity;
}
.board-col {
  flex: 0 0 284px;
  width: 284px;
  background: #eef1f7;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 190px);
  scroll-snap-align: start;
}
.col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 13px 9px;
  border-bottom: 1px solid rgba(15, 23, 42, .06);
}
.col-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.col-title { font-size: 13px; font-weight: 650; color: var(--ink-2); }
.col-count {
  font-size: 11.5px; color: var(--muted);
  background: #fff; border-radius: 20px; padding: 1px 7px; font-weight: 600;
}
.col-value { margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.col-body {
  padding: 10px;
  display: flex; flex-direction: column; gap: 9px;
  overflow-y: auto;
  min-height: 70px;
  flex: 1;
}
.col-empty {
  border: 1.5px dashed #d3dae6;
  border-radius: 11px;
  padding: 16px 10px;
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
}
.col-add {
  margin: 0 10px 10px;
  border: 0; background: transparent;
  color: var(--muted); font-size: 12.5px;
  padding: 7px; border-radius: 9px; text-align: left;
}
.col-add:hover { background: #e2e8f2; color: var(--ink-2); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: box-shadow .15s, border-color .15s;
}
.card:hover { border-color: #d5dced; box-shadow: 0 2px 10px rgba(15, 23, 42, .08); }
.card-ghost { opacity: .4; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.src-pill {
  font-size: 10.5px; font-weight: 650; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 20px;
  color: #fff;
}
.card-val { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.card-name { font-size: 13.5px; font-weight: 600; line-height: 1.3; margin-bottom: 3px; }
.card-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-foot { display: flex; align-items: center; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.fu {
  font-size: 10.5px; font-weight: 650;
  padding: 2px 7px; border-radius: 20px;
  background: #f1f5f9; color: var(--muted);
}
.fu.due { background: #fef3c7; color: #b45309; }
.fu.over { background: #fee2e2; color: #b91c1c; }
.tag {
  font-size: 10.5px; color: var(--muted);
  background: #f1f5f9; border-radius: 6px; padding: 2px 6px;
}
.card-foot .tag:first-of-type { margin-left: auto; }

.board-skeleton { display: flex; gap: 14px; overflow: hidden; }
.skel-col {
  flex: 0 0 284px; height: 260px; border-radius: 14px;
  background: linear-gradient(90deg, #eef1f7 25%, #e5eaf3 37%, #eef1f7 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.empty-state {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 46px 24px;
  text-align: center;
  color: var(--muted);
}
.empty-state i { font-size: 26px; color: #c7d2fe; margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 16px; color: var(--ink-2); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; max-width: 380px; margin: 0 auto; }

/* ---------- table ---------- */
.toolbar {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.select, .input {
  height: 36px; padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-size: 13px;
  color: var(--ink-2);
  outline: none;
}
.select:focus, .input:focus { border-color: #c7d2fe; box-shadow: 0 0 0 3px rgba(99, 102, 241, .12); }
.toolbar .spacer { margin-left: auto; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); font-weight: 650;
  padding: 11px 14px; background: #fbfcfe; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: #fafbff; }
.table tbody tr:last-child td { border-bottom: 0; }
.lead-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.avatar {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; flex: 0 0 auto;
}
.lead-name { font-weight: 600; line-height: 1.25; }
.lead-sub { font-size: 11.5px; color: var(--muted); }
.table .select { height: 30px; font-size: 12px; padding: 0 8px; border-radius: 8px; }
.row-value { font-weight: 650; white-space: nowrap; }
.pager { display: flex; justify-content: center; padding: 16px; }

/* ---------- dashboard ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 13px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 5px; letter-spacing: -.02em; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi.warn .kpi-value { color: var(--warn); }
.kpi.good .kpi-value { color: var(--good); }
.kpi.bad .kpi-value { color: var(--bad); }

.panels { display: grid; grid-template-columns: 1.15fr .85fr; gap: 14px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h3 { font-size: 14.5px; }
.chart-wrap { position: relative; height: 230px; }
.funnel { display: flex; flex-direction: column; gap: 11px; }
.funnel-row { display: grid; grid-template-columns: 108px 1fr 54px; align-items: center; gap: 10px; font-size: 12.5px; }
.funnel-label { color: var(--ink-2); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.funnel-track { background: #f1f5f9; border-radius: 20px; height: 9px; overflow: hidden; }
.funnel-bar { height: 100%; border-radius: 20px; transition: width .4s ease; }
.funnel-count { text-align: right; color: var(--muted); font-weight: 650; }
.feed { display: flex; flex-direction: column; gap: 0; }
.feed-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.feed-item:last-child { border-bottom: 0; }
.feed-icon {
  width: 26px; height: 26px; border-radius: 8px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 11px;
  background: var(--brand-soft); color: var(--brand-ink);
}
.feed-body { min-width: 0; }
.feed-title { font-size: 12.5px; font-weight: 600; }
.feed-text { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-time { font-size: 11px; color: #94a3b8; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.card-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-panel h3 { font-size: 15px; margin-bottom: 4px; }
.card-panel .hint { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  background: #fff;
  outline: none;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: #c7d2fe; box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}
.field textarea { resize: vertical; min-height: 74px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-wide { grid-column: 1 / -1; }

/* ---------- drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .38);
  z-index: 60; animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--bg);
  z-index: 61;
  display: flex; flex-direction: column;
  box-shadow: -20px 0 50px rgba(15, 23, 42, .18);
  animation: slide .22s ease;
}
@keyframes slide { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 20px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 17px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.drawer-close {
  margin-left: auto; border: 0; background: #f1f5f9;
  width: 32px; height: 32px; border-radius: 9px;
  color: var(--muted); flex: 0 0 auto;
}
.drawer-close:hover { background: #e2e8f0; color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 16px; }
.drawer-foot {
  display: flex; gap: 9px; align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.drawer-foot .spacer { margin-left: auto; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: 9px; }
.timeline { display: flex; flex-direction: column; gap: 2px; }
.tl-item { display: flex; gap: 11px; padding: 8px 0; }
.tl-dot {
  width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: 0 0 auto;
  background: #cbd5e1;
}
.tl-dot.message { background: #0a84ff; }
.tl-dot.call { background: #059669; }
.tl-dot.stage { background: #7c3aed; }
.tl-dot.created { background: #94a3b8; }
.tl-dot.meeting { background: #d97706; }
.tl-body { min-width: 0; flex: 1; }
.tl-head { display: flex; gap: 8px; align-items: baseline; }
.tl-head strong { font-size: 12.5px; font-weight: 650; }
.tl-head span { font-size: 11px; color: #94a3b8; }
.tl-text { font-size: 13px; color: var(--ink-2); white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.composer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px;
}
.comp-types { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 9px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 20px;
}
.chip.active { background: var(--brand-soft); border-color: #c7d2fe; color: var(--brand-ink); }
.comp-input {
  width: 100%; border: 0; outline: 0; resize: vertical; min-height: 58px;
  font-size: 13.5px; background: transparent;
}
.comp-actions { display: flex; justify-content: flex-end; margin-top: 6px; }

/* ---------- modal ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(15, 23, 42, .42);
  display: grid; place-items: center;
  padding: 18px;
  animation: fade .16s ease;
}
.modal {
  background: var(--panel);
  border-radius: 16px;
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.97); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--line);
}
.lock-card { max-width: 400px; }
.lock-card .field { margin-bottom: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .panels { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 12px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar h1 { font-size: 17px; }
  .topbar-right { flex: 1 1 100%; }
  .search { width: auto; flex: 1; }
  .btn-primary span { display: none; }
  .btn-primary { width: 38px; padding: 0; justify-content: center; }
  .view { padding: 14px 14px 96px; }
  .mobile-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
  }
  .mobile-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 10.5px; color: var(--muted); padding: 4px 0; border-radius: 10px;
  }
  .mobile-nav a i { font-size: 15px; }
  .mobile-nav a.active { color: var(--brand); }
  .board-col { flex: 0 0 82vw; width: 82vw; max-height: none; }
  .board { scroll-snap-type: x mandatory; }
  .form-grid { grid-template-columns: 1fr; }
  .drawer { width: 100%; }
  .table-wrap { overflow-x: auto; }
  .table { min-width: 720px; }
}

@media (min-width: 901px) {
  .view { max-width: 1680px; }
}

.swal2-popup { font-size: 14px !important; border-radius: 14px !important; }
