:root {
  --bg: #f6f5fb;
  --panel: #ffffff;
  --ink: #17152b;
  --ink-2: #4a4766;
  --muted: #8a87a3;
  --line: #e9e7f3;
  --line-2: #f1f0f8;
  --brand: #5b4cf0;
  --brand-2: #7b6ff5;
  --brand-soft: #eeecfe;
  --green: #12a46b; --green-soft: #e3f7ee;
  --blue: #2563eb; --blue-soft: #e5eeff;
  --red: #e0384f; --red-soft: #fde8eb;
  --orange: #f07a1a; --orange-soft: #fff0e3;
  --yellow: #c99400; --yellow-soft: #fff6d9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23,21,43,.04), 0 4px 16px rgba(23,21,43,.05);
  --shadow-lg: 0 12px 48px rgba(23,21,43,.18);
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: #15132a; color: #cfcce6; padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 800; font-size: 17px; padding: 4px 8px 14px; }
.logo-mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), #b06cf5); display: grid; place-items: center; }
.ws-switch { margin: 0 4px 12px; }
.ws-switch select { width: 100%; background: #221f3d; border: 1px solid #2f2b52; color: #fff; border-radius: 10px; padding: 9px 10px; }
.ws-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #77739a; padding: 0 8px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: #cfcce6; font-weight: 500; }
.nav a:hover { background: #1f1c38; color: #fff; }
.nav a.on { background: #2a2650; color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.nav .sep { height: 1px; background: #26233f; margin: 10px 6px; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: #8b88a8; border-top: 1px solid #26233f; }
.side-foot b { color: #fff; display: block; font-size: 13px; }
.side-foot button { margin-top: 8px; background: none; border: 1px solid #2f2b52; color: #cfcce6; border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.main { padding: 26px 32px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h1 { font-size: 24px; font-weight: 800; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; gap: 10px; }
.card-h h3 { font-size: 15px; font-weight: 700; }
.card-b { padding: 16px 18px 18px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: 1.6fr 1fr; }
.g2e { grid-template-columns: 1fr 1fr; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3, .g2, .g2e { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; } .main { padding: 18px; } }

.kpi { padding: 16px 18px; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 28px; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- agent flow (mirrors the 'system diagram') ---------- */
.flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: stretch; gap: 10px; }
.agent { border-radius: 14px; padding: 16px; border: 1px solid; position: relative; }
.agent .ah { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.agent .badge-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800; }
.agent h4 { font-size: 14px; }
.agent small { color: var(--ink-2); display: block; font-size: 11.5px; }
.agent .nums { display: flex; gap: 14px; margin-top: 6px; }
.agent .nums div { font-size: 11.5px; color: var(--ink-2); }
.agent .nums b { display: block; font-size: 20px; color: var(--ink); }
.agent.g { background: linear-gradient(180deg, #f2fbf6, #fff); border-color: #c9eedb; } .agent.g .badge-ico { background: var(--green); }
.agent.b { background: linear-gradient(180deg, #f1f5ff, #fff); border-color: #cfdcfb; } .agent.b .badge-ico { background: var(--blue); }
.agent.o { background: linear-gradient(180deg, #fff6ee, #fff); border-color: #fbdcc0; } .agent.o .badge-ico { background: var(--orange); }
.arrow { display: grid; place-items: center; color: var(--muted); font-size: 20px; }
@media (max-width: 1100px) { .flow { grid-template-columns: 1fr; } .arrow { transform: rotate(90deg); } }

/* ---------- buttons & inputs ---------- */
.btn { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: #d5d2e8; background: #fbfaff; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #4d3fe0; }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; outline: none; }
.input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.5; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
label.f > em { display: block; font-style: normal; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip.click { cursor: pointer; border: 1px dashed #cfcbe6; background: #fff; }
.chip.click:hover { border-color: var(--brand); color: var(--brand); }

/* stages */
.st-new { background: #eef0f6; color: #4b5576; }
.st-contacted { background: var(--blue-soft); color: var(--blue); }
.st-replied { background: #efe9ff; color: #6d3fe0; }
.st-interested { background: var(--yellow-soft); color: var(--yellow); }
.st-meeting { background: var(--orange-soft); color: var(--orange); }
.st-won { background: var(--green-soft); color: var(--green); }
.st-lost { background: var(--red-soft); color: var(--red); }
.score { display: inline-grid; place-items: center; min-width: 34px; height: 24px; border-radius: 7px; font-weight: 800; font-size: 12px; }
.score.hi { background: var(--green-soft); color: var(--green); }
.score.mid { background: var(--yellow-soft); color: var(--yellow); }
.score.lo { background: #f0eff5; color: var(--muted); }

/* ---------- table ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fcfbff; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr.click:hover td { background: #faf9ff; cursor: pointer; }
.tbl .name { font-weight: 700; }
.tbl .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.ch-icons { display: flex; gap: 5px; }
.ch { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; background: #f2f1f7; color: #b4b1c8; }
.ch.on.wa { background: #e4f8ec; color: #1aa85a; }
.ch.on.em { background: var(--blue-soft); color: var(--blue); }
.ch.on.web { background: var(--brand-soft); color: var(--brand); }
.bulkbar { position: sticky; top: 10px; z-index: 5; background: #1d1a36; color: #fff; border-radius: 12px; padding: 10px 14px; display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; box-shadow: var(--shadow-lg); }
.bulkbar .btn { background: #2b2750; color: #fff; border-color: #3a3566; }
.bulkbar select { background: #2b2750; color: #fff; border: 1px solid #3a3566; border-radius: 8px; padding: 5px 8px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; color: var(--muted); }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

/* ---------- kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(7, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 10px; }
.col { background: #efeef7; border-radius: 14px; padding: 10px; min-height: 300px; }
.col.drop { outline: 2px dashed var(--brand-2); background: var(--brand-soft); }
.col-h { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-weight: 700; font-size: 13px; }
.kcard { background: #fff; border-radius: 10px; padding: 10px 11px; margin-bottom: 8px; border: 1px solid var(--line); cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.kcard:active { cursor: grabbing; }
.kcard .t { font-weight: 700; font-size: 13px; }
.kcard .m { color: var(--muted); font-size: 11.5px; margin-top: 3px; display: flex; justify-content: space-between; gap: 6px; }

/* ---------- drawer & modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(21,19,42,.35); z-index: 40; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100%); background: var(--bg); z-index: 41; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .2s ease-out; }
.drawer-h { background: #fff; padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.drawer-b { overflow-y: auto; padding: 18px 22px 40px; flex: 1; }
.modal { position: fixed; z-index: 42; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(720px, calc(100% - 24px)); max-height: calc(100vh - 40px); overflow-y: auto; background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; }
.modal.wide { width: min(980px, calc(100% - 24px)); }
.modal-h { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; z-index: 2; }
.modal-b { padding: 20px 22px; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: #fff; }
.x { border: none; background: #f2f1f7; width: 32px; height: 32px; border-radius: 9px; cursor: pointer; font-size: 18px; color: var(--ink-2); }
@keyframes fade { from { opacity: 0 } }
@keyframes slide { from { transform: translateX(40px); opacity: 0 } }
@keyframes pop { from { transform: translate(-50%, -48%) scale(.98); opacity: 0 } }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl { position: relative; margin-bottom: 14px; }
.tl::before { content: ""; position: absolute; left: -19px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: #cfcbe6; border: 2px solid var(--bg); }
.tl.sent::before { background: var(--blue); } .tl.recv::before { background: #6d3fe0; } .tl.fail::before { background: var(--red); }
.tl.stage::before { background: var(--orange); } .tl.note::before { background: var(--yellow); }
.tl .when { font-size: 11.5px; color: var(--muted); }
.tl .what { font-size: 13px; font-weight: 600; }
.bubble { margin-top: 5px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font-size: 13px; white-space: pre-wrap; line-height: 1.45; max-height: 220px; overflow: auto; }
.bubble.in { background: #f5f1ff; border-color: #e3dafd; }
.tabs { display: flex; gap: 4px; background: #eceaf6; padding: 4px; border-radius: 11px; width: fit-content; margin-bottom: 14px; }
.tabs button { border: none; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* steps editor */
.step { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; background: #fcfbff; }
.step-h { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.step-n { width: 26px; height: 26px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 12px; }
.vars { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 10px; }
.preview { background: #f6f5fb; border-radius: 12px; padding: 12px 14px; white-space: pre-wrap; font-size: 13px; line-height: 1.5; border: 1px dashed #d8d4ee; }
.note { background: var(--yellow-soft); border: 1px solid #f3e3a8; color: #6d5600; padding: 10px 12px; border-radius: 10px; font-size: 12.5px; line-height: 1.5; margin-bottom: 14px; }
.note.info { background: var(--blue-soft); border-color: #cddcfb; color: #1e3f8f; }
.ok-pill { color: var(--green); font-weight: 700; font-size: 12px; }
.off-pill { color: var(--muted); font-weight: 600; font-size: 12px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #f1f0f8; padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.funnel-row { display: grid; grid-template-columns: 90px 1fr 44px; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 13px; }
.funnel-bar { height: 22px; border-radius: 7px; background: #f1f0f8; overflow: hidden; }
.funnel-bar i { display: block; height: 100%; border-radius: 7px; min-width: 2px; }
.feed-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.feed-item:last-child { border-bottom: none; }
.feed-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ro .staff { display: none !important; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% 0%, #e7e3ff, transparent), radial-gradient(900px 500px at 100% 100%, #ffe6f1, transparent), var(--bg); padding: 20px; }
.login { width: min(400px, 100%); padding: 34px; }
.login h1 { font-size: 24px; margin: 18px 0 4px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1d1a36; color: #fff; padding: 11px 16px; border-radius: 11px; box-shadow: var(--shadow-lg); font-weight: 500; animation: pop2 .2s; max-width: 90vw; }
.toast.err { background: #b3203a; }
@keyframes pop2 { from { transform: translateY(8px); opacity: 0 } }
.spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: sp .7s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg) } }
