/* Раскладка: тёмная навигация слева, рабочая область справа; в чатах три колонки — список, лента, карточка клиента. */
:root {
  --bg: #eef1f6; --surface: #ffffff; --surface-2: #f6f8fb; --ink: #121a2b; --muted: #5d6a82; --line: #dbe1ec;
  --nav: #121a2b; --nav-ink: #c9d2e3; --nav-active: #232e47;
  --accent: #3d4fe0; --accent-soft: #e6e9fd; --on-accent: #ffffff;
  --ai: #ebe8ff; --ai-ink: #3a2fa8; --warn: #b45309; --warn-soft: #fdf0d9; --ok: #0f7a52; --ok-soft: #dff5ea; --bad: #c2303b; --bad-soft: #fde7e9;
  --wa: #1fa855; --ig: #d2317a; --tt: #0e8f9c;
  --display: 'Unbounded', 'Manrope', system-ui, sans-serif;
  --body: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1220; --surface: #161d2e; --surface-2: #1c2438; --ink: #e8ecf5; --muted: #98a4bd; --line: #2a3450;
    --nav: #0a0e19; --nav-ink: #aab5cc; --nav-active: #1c2438;
    --accent: #7c8aff; --accent-soft: #232b55; --on-accent: #0d1220;
    --ai: #272457; --ai-ink: #c9c3ff; --warn: #f0b354; --warn-soft: #3a2c12; --ok: #4fd39c; --ok-soft: #12352a; --bad: #ff8a93; --bad-soft: #3d1a1f;
    --wa: #3ecf7a; --ig: #f06aa6; --tt: #3fc8d6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1220; --surface: #161d2e; --surface-2: #1c2438; --ink: #e8ecf5; --muted: #98a4bd; --line: #2a3450;
  --nav: #0a0e19; --nav-ink: #aab5cc; --nav-active: #1c2438;
  --accent: #7c8aff; --accent-soft: #232b55; --on-accent: #0d1220;
  --ai: #272457; --ai-ink: #c9c3ff; --warn: #f0b354; --warn-soft: #3a2c12; --ok: #4fd39c; --ok-soft: #12352a; --bad: #ff8a93; --bad-soft: #3d1a1f;
  --wa: #3ecf7a; --ig: #f06aa6; --tt: #3fc8d6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--body); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
h1 { font: 600 17px/1.2 var(--display); letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 700; }
h3 { font-size: 13px; font-weight: 700; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
#app { height: 100%; display: flex; }
.nav { width: 212px; flex: none; background: var(--nav); color: var(--nav-ink); display: flex; flex-direction: column; padding: 16px 10px; gap: 4px; }
.brand { font: 600 15px/1 var(--display); color: #fff; padding: 6px 10px 18px; display: flex; align-items: center; gap: 9px; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; color: var(--on-accent); font: 700 12px var(--body); font-style: normal; }
.nav button { all: unset; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-weight: 600; box-sizing: border-box; width: 100%; }
.nav button:hover { background: var(--nav-active); }
.nav button.active { background: var(--nav-active); color: #fff; }
.nav button:focus-visible { outline: 2px solid var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.nav .foot { margin-top: auto; padding: 10px; font-size: 12px; display: flex; flex-direction: column; gap: 8px; }
.nav .foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .foot a { color: var(--nav-ink); cursor: pointer; text-decoration: underline; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.page { flex: 1; min-height: 0; overflow: auto; padding: 22px 26px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.banner { background: var(--warn-soft); color: var(--warn); padding: 8px 26px; font-weight: 600; font-size: 13px; }

/* ---------- элементы ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 13px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=datetime-local], input[type=time], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; min-height: 70px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 700; font-size: 12px; color: var(--muted); }
label.field > * { font-weight: 500; font-size: 14px; color: var(--ink); }
label.field > span.muted { font-size: 12px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ai { background: var(--ai); color: var(--ai-ink); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 11px; font-size: 12px; font-weight: 700; cursor: pointer; color: var(--muted); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.whatsapp { background: var(--wa); } .dot.instagram { background: var(--ig); } .dot.tiktok { background: var(--tt); }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }
code.copy { display: block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; overflow-x: auto; white-space: nowrap; }

/* ---------- чаты ---------- */
.chats { flex: 1; min-height: 0; display: grid; grid-template-columns: 320px minmax(0, 1fr) 290px; }
.chats > * { min-height: 0; }
.list { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.list-head { padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.list-items { overflow: auto; flex: 1; }
.conv { all: unset; box-sizing: border-box; width: 100%; display: flex; gap: 10px; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); border-left-color: var(--accent); }
.conv.attention { border-left-color: var(--warn); }
.conv:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 800; font-size: 13px; flex: none; position: relative; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border: 2px solid var(--surface); }
.conv .top { display: flex; gap: 6px; align-items: baseline; }
.conv .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.conv .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .meta { display: flex; gap: 5px; margin-top: 4px; align-items: center; flex-wrap: wrap; }
.unread { background: var(--accent); color: var(--on-accent); border-radius: 999px; font-size: 11px; font-weight: 800; padding: 0 6px; margin-left: auto; }

.thread { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.thread-head { background: var(--surface); border-bottom: 1px solid var(--line); padding: 11px 18px; display: flex; align-items: center; gap: 12px; }
.back { display: none; }
.attention-bar { background: var(--warn-soft); color: var(--warn); padding: 8px 18px; font-weight: 700; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: min(560px, 78%); padding: 8px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.msg.ai, .msg.bot { background: var(--ai); border-color: transparent; }
.msg.manager { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.msg.failed { border: 1px solid var(--bad); }
.msg .who { display: block; font-size: 11px; font-weight: 800; margin-bottom: 2px; color: var(--ai-ink); }
.msg.manager .who { color: inherit; opacity: 0.85; }
.msg .when { display: block; font-size: 10px; opacity: 0.65; text-align: right; margin-top: 2px; font-variant-numeric: tabular-nums; }
.msg .err { display: block; color: var(--bad); font-size: 12px; margin-top: 4px; font-weight: 600; }
.note { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line); border-radius: 999px; padding: 3px 12px; text-align: center; max-width: 90%; }
.typing { align-self: flex-end; font-size: 12px; color: var(--ai-ink); font-weight: 700; }
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 12px 18px; display: flex; flex-direction: column; gap: 6px; }
.composer .row { align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 160px; resize: none; }
.side { background: var(--surface); border-left: 1px solid var(--line); padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 8px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- лиды ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile b { display: block; font: 600 22px/1.1 var(--display); font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 12px; font-weight: 600; }
.board { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 160px; }
.col.over { outline: 2px dashed var(--accent); }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.lead { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: grab; display: flex; flex-direction: column; gap: 4px; }
.lead:hover { border-color: var(--accent); }
.lead .last { color: var(--muted); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- списки настроек ---------- */
.grid2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 1fr); gap: 18px; align-items: start; }
.items { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; gap: 14px; align-items: flex-start; }
.item .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.item .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.word { font: 600 14px var(--display); background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 3px 9px; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 18px; counter-reset: step; }
.steps div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 12px 44px; position: relative; font-size: 13px; }
.steps div::before { counter-increment: step; content: counter(step); position: absolute; left: 12px; top: 12px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--surface); display: grid; place-items: center; font-weight: 800; font-size: 12px; }
.kb-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; gap: 8px; align-items: start; }
.kb-row textarea { min-height: 60px; }
.testchat { display: flex; flex-direction: column; gap: 8px; }
.testchat .messages { min-height: 220px; max-height: 380px; background: var(--bg); border-radius: 8px; padding: 12px; }

/* ---------- окна и уведомления ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 24, 0.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: min(560px, 100%); max-height: calc(100% - 20px); overflow: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center; }
.toast { background: var(--ink); color: var(--surface); border-radius: 8px; padding: 9px 14px; font-weight: 600; max-width: min(520px, 90vw); }
.toast.bad { background: var(--bad); color: #fff; }
.sim-btn { position: fixed; right: 18px; bottom: 18px; z-index: 40; box-shadow: 0 6px 20px rgba(8, 12, 24, 0.25); }
.sim { position: fixed; right: 18px; bottom: 66px; width: min(340px, calc(100vw - 36px)); z-index: 40; box-shadow: 0 10px 30px rgba(8, 12, 24, 0.3); }
.login { height: 100%; display: grid; place-items: center; padding: 16px; width: 100%; }
.login .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 26px; }

@media (max-width: 1100px) { .chats { grid-template-columns: 290px minmax(0, 1fr); } .side { display: none; } .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .nav { width: 100%; flex-direction: row; padding: 6px 8px; overflow-x: auto; gap: 2px; }
  .nav .brand, .nav .foot, .nav button span.t { display: none; }
  .nav button { width: auto; padding: 9px 12px; }
  .chats { grid-template-columns: 1fr; }
  .chats.open .list { display: none; }
  .back { display: inline-block; }
  .chats:not(.open) .thread { display: none; }
  .page { padding: 16px; }
  .thread-head .pill { display: none; }
  .sim-btn { bottom: 96px; right: 10px; padding: 5px 10px; font-size: 12px; }
  .sim { bottom: 134px; right: 10px; }
  .main { height: auto; flex: 1; min-height: 0; }
  .kb-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) { .btn, .conv, .chip { transition: background-color 0.12s, border-color 0.12s; } }
