:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e4e7ec; --text: #101828; --muted: #667085;
  --brand: #2966e9; --brand-soft: #eaf0fd; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --bubble-in: #fff; --bubble-out: #dcf3e4; --bubble-echo: #e8eefc;
  --r: 10px; --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e12; --panel: #151821; --line: #262b36; --text: #e6e8ee; --muted: #8b93a7;
    --brand-soft: #1a2747; --bubble-in: #1d212b; --bubble-out: #173827; --bubble-echo: #1b2743;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.hidden { display: none !important; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 9px 11px; }
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 20px; font-size: 13px; }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); }
.pill.bot { background: #f3e8ff; color: #7e22ce; }
.pill.closed { background: var(--line); color: var(--muted); }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.logo { font-weight: 700; font-size: 20px; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.logo i { width: 26px; height: 26px; border-radius: 8px; background: var(--brand); display: inline-block; }
.tabs { display: flex; gap: 4px; margin: 18px 0; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 8px 10px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-color: var(--brand); }

/* app shell */
.shell { display: grid; grid-template-columns: 64px 1fr; height: 100vh; }
.rail { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; }
.rail .logo i { width: 32px; height: 32px; margin-bottom: 10px; }
.logo i { box-shadow: inset -7px -7px 0 0 #1b4cc0; }
.rail button { width: 44px; height: 44px; border-radius: 10px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; }
.rail button.on, .rail button:hover { background: var(--brand-soft); color: var(--brand); }
.rail .spacer { flex: 1; }
.view { min-width: 0; height: 100vh; overflow: hidden; }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 280px; height: 100%; }
.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.filters { display: flex; gap: 4px; }
.filters button { flex: 1; border: 1px solid var(--line); background: none; border-radius: 6px; padding: 4px; font-size: 12px; color: var(--muted); }
.filters button.on { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.convs { overflow-y: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover, .conv.on { background: var(--brand-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font-weight: 600; color: var(--muted); }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .meta { text-align: right; font-size: 11px; color: var(--muted); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--ok); color: #fff; font-size: 11px; text-align: center; margin-top: 4px; }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 10px; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who b { display: block; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: min(75%, 560px); padding: 7px 10px; border-radius: 10px; background: var(--bubble-in); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-color: transparent; }
.bubble.echo { align-self: flex-end; background: var(--bubble-echo); border-color: transparent; }
.bubble .foot { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble img, .bubble video { max-width: 100%; max-height: 320px; border-radius: 6px; display: block; }
.bubble audio { width: 260px; }
.bubble.failed { border: 1px solid var(--bad); }
.day { align-self: center; font-size: 11px; color: var(--muted); background: var(--panel); padding: 2px 10px; border-radius: 99px; margin: 6px 0; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 160px; }
.notice { padding: 8px 16px; background: #fff7e6; color: #8a5300; font-size: 13px; border-top: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .notice { background: #2a2010; color: #f5c46b; } }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 24px; }

.side { border-left: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; }
.side h4 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* equipe */
.who-tag { font-size: 11px; color: var(--brand); margin-top: 2px; }
.team-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.team-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; }
@media (max-width: 720px) {
  .team-form { grid-template-columns: 1fr; }
  .chat-head { flex-wrap: wrap; padding: 8px 12px; }
  .chat-head .avatar { display: none; }
  .chat-head .who { flex: 1 1 calc(100% - 60px); }
  .chat-head .who b, .chat-head .who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  .chat-head select { flex: 1 1 40%; }
}

/* funil */
.board-wrap { height: 100%; display: flex; flex-direction: column; }
.page-head { padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 10px; }
.page-head h2 { margin: 0; font-size: 17px; flex: 1; }
.board { flex: 1; display: flex; gap: 12px; padding: 16px; overflow-x: auto; align-items: flex-start; }
.col { flex: 0 0 272px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); display: flex; flex-direction: column; max-height: 100%; }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; font-weight: 600; }
.col-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.col-head .sum { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.cards { padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; overflow-y: auto; }
.cards.drop { background: var(--brand-soft); }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: var(--bg); cursor: grab; }
.card b { display: block; }
.card .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* config */
.settings { padding: 24px; overflow-y: auto; height: 100%; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 720px; margin-bottom: 16px; }
.box h3 { margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; margin-top: 10px; }
.kv code { word-break: break-all; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }

@media (min-width: 1101px) { .inbox:not(.has-chat) { grid-template-columns: 320px 1fr; } .inbox:not(.has-chat) .side { display: none; } }
@media (max-width: 1100px) { .inbox { grid-template-columns: 300px 1fr; } .side { display: none; } }
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr 56px; }
  .rail { order: 2; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); padding: 0; }
  .rail .logo, .rail .spacer { display: none; }
  .view { height: calc(100vh - 56px); }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-chat .list { display: none; }
  .inbox:not(.has-chat) .chat { display: none; }
  .settings { padding: 16px; }
}
