:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #16213a;
  --ink-2: #4a5672;
  --muted: #8590a8;
  --line: #e4e8f0;
  --nav: #0f1f3d;
  --nav-ink: #b9c3da;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --teal: #0d9488;
  --teal-soft: #e0f5f2;
  --amber: #b45309;
  --amber-soft: #fff4e0;
  --red: #c2410c;
  --red-soft: #fdece4;
  --violet: #6d28d9;
  --violet-soft: #f0eafd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.full { width: 100%; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: var(--nav); color: var(--nav-ink); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 20; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 18px; color: #fff; font-weight: 700; font-size: 17px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: #4fd1c5; color: var(--nav); display: grid; place-items: center; font-weight: 800; }
nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; flex: 1; }
nav a { display: flex; align-items: center; gap: 10px; color: var(--nav-ink); padding: 9px 12px; border-radius: 8px; font-weight: 500; }
nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
nav a.active { background: rgba(79, 209, 197, .14); color: #fff; }
.pill { margin-left: auto; background: #f97316; color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 10px; }
.sidebar-foot .btn { color: #dfe6f5; border-color: rgba(255,255,255,.18); }
.me { display: flex; justify-content: space-between; font-size: 12px; color: #fff; }
.me a { color: var(--nav-ink); }
.main { flex: 1; margin-left: 236px; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; background: rgba(244,246,250,.92); backdrop-filter: blur(6px); display: flex; gap: 12px; align-items: center; padding: 14px 28px; border-bottom: 1px solid var(--line); }
.search { flex: 1; max-width: 560px; }
.search input { width: 100%; }
.icon-btn { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--ink); }
.view { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* controls */
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 90px; resize: vertical; width: 100%; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.btn { font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #c8cfdd; background: #fafbfd; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4fd8; }
.btn.teal { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; color: var(--ink); margin: 0; }
.chk input { width: auto; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.lead-layout { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px; align-items: start; }
.stat { padding: 16px 18px; }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: 12px; font-weight: 500; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 18px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li.click { cursor: pointer; }
.list li.click:hover { background: #f8faff; }
.empty { padding: 26px 18px; text-align: center; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfd; position: sticky; top: 0; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8faff; }
.table-wrap { overflow: auto; max-height: calc(100vh - 230px); }

/* tags */
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eef1f6; color: var(--ink-2); }
.tag.blue { background: var(--accent-soft); color: var(--accent); }
.tag.teal { background: var(--teal-soft); color: var(--teal); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.violet { background: var(--violet-soft); color: var(--violet); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #cbd2e0; }
.dot.on { background: #16a34a; }

/* timeline */
.timeline { position: relative; }
.t-item { display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.t-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; }
.k-email_in { background: var(--accent-soft); color: var(--accent); }
.k-email_out { background: #eef1f6; color: var(--ink-2); }
.k-call { background: var(--teal-soft); color: var(--teal); }
.k-sms { background: var(--violet-soft); color: var(--violet); }
.k-meeting { background: var(--amber-soft); color: var(--amber); }
.k-note { background: #f1f2f4; color: #555; }
.ai-box { background: linear-gradient(0deg, #f7f9ff, #f7f9ff); border: 1px solid #dfe6fb; border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.ai-box .lbl { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.body-toggle { font-size: 12px; cursor: pointer; color: var(--muted); }
.email-body { background: #fafbfd; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 8px; max-height: 320px; overflow: auto; font-size: 13px; }

/* lead fields */
.kv { display: grid; grid-template-columns: 118px 1fr; gap: 8px 10px; font-size: 13px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; word-break: break-word; }
.notes-cell { white-space: pre-wrap; max-height: 180px; overflow: auto; background: #fafbfd; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tabs button { background: none; border: 0; padding: 12px 12px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .wide { grid-column: 1 / -1; }

/* docs */
.doc { display: flex; gap: 12px; align-items: flex-start; }
.doc-ico { width: 40px; height: 48px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 10px; font-weight: 700; flex: none; }

/* modal + toasts */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-card h2 { font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--nav); color: #fff; padding: 11px 15px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; font-size: 13px; }
.toast.err { background: #9a3412; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #1b3a70, var(--nav) 60%); }
.auth-card { background: #fff; border-radius: 16px; padding: 30px; width: min(400px, 100%); box-shadow: 0 30px 60px rgba(0,0,0,.3); }
.auth-card .brand { color: var(--ink); padding: 0 0 18px; }
.auth-card .field { margin-bottom: 12px; }

.steps { counter-reset: s; padding-left: 0; list-style: none; margin: 0; }
.steps li { counter-increment: s; position: relative; padding-left: 30px; margin-bottom: 8px; color: var(--ink-2); font-size: 13px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.banner { padding: 12px 14px; border-radius: 10px; background: var(--amber-soft); color: #7c3d06; font-size: 13px; margin-bottom: 16px; }
.banner.info { background: var(--accent-soft); color: #1e3a8a; }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lead-layout { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .main { margin-left: 0; }
  .icon-btn { display: block; }
  .topbar { padding: 10px 16px; }
  .topbar .btn.primary { padding: 8px 10px; }
  .view { padding: 16px; }
  .g2, .g3, .form-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

/* live search */
.search { position: relative; }
.search-res { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(16,24,40,.16); max-height: 420px; overflow: auto; z-index: 30; }
.sr-item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.sr-item:last-child { border-bottom: 0; }
.sr-item:hover, .sr-item.active { background: #f3f6ff; }
.sr-item mark { background: #fff3b0; color: inherit; border-radius: 3px; padding: 0 1px; }

/* client overview */
.ov { border-top: 3px solid var(--accent); }
.ov-status { font-size: 14.5px; line-height: 1.55; margin: 6px 0 12px; }
.ov-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; margin-top: 14px; }
.ov-grid ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.ov-grid li { margin-bottom: 4px; }
.ov-next { background: var(--teal-soft); color: #0b5e57; border-radius: 10px; padding: 10px 12px; font-weight: 500; }
.counts { display: flex; flex-wrap: wrap; gap: 8px; }
.count { background: #f4f6fa; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 12px; color: var(--ink-2); }
.count b { color: var(--ink); font-size: 14px; margin-right: 3px; }
.att { display: inline-flex; align-items: center; gap: 4px; background: #f4f6fa; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-size: 12px; margin: 6px 6px 0 0; }
@media (max-width: 820px) { .ov-grid { grid-template-columns: 1fr; } }
