:root {
  --bg: #0a0c10;
  --panel: #10131a;
  --panel-2: #151923;
  --raise: #1b2030;
  --line: #222838;
  --line-2: #2c3347;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --faint: #5c6479;
  --accent: #3d8bff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(61, 139, 255, .14);
  --good: #2fbf71;
  --good-soft: rgba(47, 191, 113, .14);
  --warn: #f2b84b;
  --warn-soft: rgba(242, 184, 75, .14);
  --bad: #ff5d5d;
  --bad-soft: rgba(255, 93, 93, .14);
  --bubble-in: #1b2030;
  --bubble-out: #1f4fa3;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
body { overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-soft); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--panel-2); cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: var(--raise); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12.5px; border-radius: 7px; }
.btn.icon { width: 32px; padding: 0; }
.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--bg); outline: none;
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 70px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.label { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: block; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line-2); cursor: pointer; transition: .15s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(16px); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; background: var(--raise); color: var(--muted); white-space: nowrap;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-new { color: #a5adc2; background: rgba(165, 173, 194, .12); }
.st-welcomed { color: #8fb4ff; background: rgba(143, 180, 255, .12); }
.st-engaged { color: #5fd0ff; background: rgba(95, 208, 255, .12); }
.st-qualified { color: #c49bff; background: rgba(196, 155, 255, .13); }
.st-in_app { color: #f2b84b; background: var(--warn-soft); }
.st-onboarding { color: #ff9f5a; background: rgba(255, 159, 90, .14); }
.st-converted { color: var(--good); background: var(--good-soft); }
.st-lost { color: #ff7b7b; background: var(--bad-soft); }
.src-tiktok { color: #ff5c8a; background: rgba(255, 92, 138, .12); }
.src-instagram { color: #e78bff; background: rgba(231, 139, 255, .12); }
.src-cta { color: #5fd0ff; background: rgba(95, 208, 255, .12); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.badge.warn { background: var(--warn); color: #1a1300; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff; letter-spacing: .02em;
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 64px 1fr; height: 100dvh; }
.rail { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 4px; }
.brand { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #3d8bff, #6a5cff);
  display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; margin-bottom: 14px; font-size: 15px; }
.nav { position: relative; width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer; border: 0; background: none; }
.nav:hover { background: var(--panel-2); color: var(--text); }
.nav.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 21px; height: 21px; }
.nav .badge { position: absolute; top: 3px; right: 1px; transform: scale(.85); }
.nav-label { position: absolute; left: 54px; background: var(--raise); padding: 4px 8px; border-radius: 6px; font-size: 12px;
  color: var(--text); white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s; z-index: 30; }
.nav:hover .nav-label { opacity: 1; }
.rail .spacer { flex: 1; }
.health { width: 10px; height: 10px; border-radius: 50%; margin: 6px 0; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

.banner { display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: 13px; border-bottom: 1px solid var(--line); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- inbox ---------- */
.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--list-w, 340px) 1fr 320px; position: relative; }
.inbox.no-panel { grid-template-columns: var(--list-w, 340px) 1fr; }
.list-resize { position: absolute; top: 0; bottom: 0; left: calc(var(--list-w, 340px) - 3px); width: 7px; cursor: col-resize; z-index: 5; }
.list-resize:hover, .resizing .list-resize { background: var(--accent, #3b82f6); opacity: .5; }
body.resizing { cursor: col-resize; user-select: none; }
.list-head .tabs { flex-wrap: wrap; overflow: visible; }
.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tab { height: 28px; padding: 0 10px; border-radius: 7px; border: 0; background: none; color: var(--muted); cursor: pointer; white-space: nowrap;
  font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--text); }
.tab.on { background: var(--raise); color: var(--text); }
.tab .badge { transform: scale(.9); }
.list-body { flex: 1; overflow-y: auto; }
.item { display: flex; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid rgba(34, 40, 56, .55); }
.item:hover { background: var(--panel-2); }
.item.on { background: var(--accent-soft); }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .time { font-size: 11.5px; color: var(--faint); flex: none; }
.item .prev { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .prev.you::before { content: "You: "; color: var(--faint); }
.item .meta { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--faint); }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background:
  radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .025) 1px, transparent 0) 0 0 / 18px 18px, var(--bg); }
.chat-head { height: 58px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head .who { font-weight: 650; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 18px 8px; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 12px 0 8px; font-size: 11.5px; color: var(--muted); background: var(--panel-2); padding: 3px 10px; border-radius: 99px; }
.bubble { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 14px; background: var(--bubble-in); white-space: pre-wrap;
  word-wrap: break-word; overflow-wrap: anywhere; align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-bottom-left-radius: 14px; border-bottom-right-radius: 5px; }
.bubble .t { display: block; text-align: right; font-size: 10.5px; color: rgba(255, 255, 255, .5); margin-top: 1px; }
.bubble img, .bubble video { display: block; max-width: 100%; max-height: 320px; border-radius: 9px; margin: 2px 0 4px; }
.bubble audio { display: block; width: 260px; max-width: 100%; margin: 2px 0; }
.bubble .file { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.load-more { align-self: center; margin-bottom: 8px; }
.composer { flex: none; border-top: 1px solid var(--line); background: var(--panel); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; position: relative; }
.composer textarea { flex: 1; min-height: 38px; max-height: 180px; resize: none; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--bg); outline: none; line-height: 1.4; }
.composer textarea:focus { border-color: var(--accent); }
.tpl-pop { position: absolute; bottom: 58px; left: 12px; width: min(420px, calc(100% - 24px)); max-height: 340px; overflow-y: auto;
  background: var(--raise); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5); z-index: 20; padding: 6px; }
.tpl { padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.tpl:hover { background: var(--panel-2); }
.tpl b { display: block; font-size: 12.5px; }
.tpl span { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--faint); flex-direction: column; gap: 8px; }

.panel { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-height: 0; }
.sect { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sect h4 { margin: 0 0 10px; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); font-weight: 700; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.steps { display: flex; flex-direction: column; gap: 6px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--faint); }
.step i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-2); flex: none; }
.step.done { color: var(--text); }
.step.done i { border-color: var(--good); background: var(--good); box-shadow: inset 0 0 0 2px var(--panel); }
.timeline { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.timeline div { display: flex; gap: 8px; }
.timeline .when { color: var(--faint); flex: none; width: 82px; }
.tags { display: flex; gap: 5px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; background: var(--raise); font-size: 12px; }
.tag button { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0; }

/* ---------- pipeline ---------- */
.page { flex: 1; overflow: auto; padding: 20px 22px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 19px; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; height: calc(100% - 50px); min-height: 400px; }
.lane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.lane.drop { border-color: var(--accent); background: var(--accent-soft); }
.lane-head { padding: 10px 12px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 13px; }
.lane-body { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; cursor: grab; }
.card:hover { border-color: var(--line-2); }
.card .name { font-weight: 600; font-size: 13px; }
.card .prev { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }

/* ---------- dashboard ---------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 4px; font-family: var(--mono); letter-spacing: -.02em; }
.tile .s { font-size: 12px; color: var(--faint); margin-top: 2px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.box h3 { margin: 0 0 14px; font-size: 14px; }
.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.funnel { display: flex; flex-direction: column; gap: 9px; }
.fstep { display: grid; grid-template-columns: 110px 1fr 92px; gap: 10px; align-items: center; font-size: 13px; }
.fbar { height: 22px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.fbar div { height: 100%; background: var(--accent); border-radius: 6px; min-width: 2px; }
.fstep:last-child .fbar div { background: var(--good); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; color: var(--faint); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px; border-bottom: 1px solid rgba(34, 40, 56, .6); vertical-align: top; }
table.t td.n, table.t th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 6px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars div:hover { opacity: 1; }

/* ---------- settings ---------- */
.settings { max-width: 860px; display: flex; flex-direction: column; gap: 14px; }
.setting-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.variant { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: var(--panel-2); }
.variant.off { opacity: .55; }
.variant p { margin: 6px 0 0; white-space: pre-wrap; color: var(--muted); font-size: 13px; }
.code { font-family: var(--mono); font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); padding: 7px 10px; border-radius: 7px; overflow-wrap: anywhere; }
.ok { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.help { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.help ol { margin: 6px 0 0; padding-left: 20px; }

/* ---------- login ---------- */
.login { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card h1 { margin: 14px 0 4px; font-size: 20px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--raise); border: 1px solid var(--line-2); border-radius: 9px; padding: 10px 14px; max-width: 360px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); font-size: 13px; }
.toast.bad { border-color: var(--bad); }
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 520px; max-height: 90dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 20px; }
.modal h3 { margin: 0 0 12px; }

/* ---------- responsive ---------- */
.mobile-back { display: none; }
@media (max-width: 1180px) {
  .inbox { grid-template-columns: var(--list-w, 300px) 1fr; }
  .list-resize { left: calc(var(--list-w, 300px) - 3px); }
  .inbox .panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 92vw); z-index: 40; box-shadow: -10px 0 40px rgba(0, 0, 0, .5); }
  .inbox.no-panel .panel { display: none; }
}
@media (max-width: 760px) {
  .desk-only { display: none; }
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr 58px; }
  .rail { grid-row: 2; flex-direction: row; justify-content: space-around; padding: 0 8px; border-right: 0; border-top: 1px solid var(--line); }
  .brand, .rail .spacer, .nav-label, .health { display: none; }
  .main { grid-row: 1; }
  .inbox, .inbox.no-panel { grid-template-columns: 1fr; }
  .list-resize { display: none; }
  .inbox.has-chat .list { display: none; }
  .inbox:not(.has-chat) .chat { display: none; }
  .mobile-back { display: inline-flex; }
  .page { padding: 16px; }
  .two { grid-template-columns: 1fr; }
  .fstep { grid-template-columns: 84px 1fr 78px; }
  .bubble { max-width: 88%; }
}
