:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f8f9f6;
  --line: #e3e5df;
  --ink: #1b211d;
  --ink-2: #5c665f;
  --ink-3: #8b948d;
  --accent: #0f7b5f;
  --accent-ink: #ffffff;
  --accent-soft: #e2f2ec;
  --side: #14201a;
  --side-ink: #c9d4cd;
  --danger: #c2372e;
  --warn-bg: #fff6e0;
  --warn-ink: #7a5300;
  --bubble-in: #ffffff;
  --bubble-out: #dcf3e8;
  --chat-bg: #eef0eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 32, 26, .06), 0 4px 16px rgba(20, 32, 26, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --surface: #161e1a;
    --surface-2: #1b2520;
    --line: #2a3530;
    --ink: #e6ece8;
    --ink-2: #a3b0a8;
    --ink-3: #75817a;
    --accent: #2fbf8f;
    --accent-ink: #062018;
    --accent-soft: #173a2e;
    --side: #0a0f0c;
    --side-ink: #b4c2ba;
    --warn-bg: #3a2e10;
    --warn-ink: #f2d38a;
    --bubble-in: #1f2a24;
    --bubble-out: #1d4436;
    --chat-bg: #111814;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 12px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-size: 13px; word-break: break-all; }
code.copy { cursor: copy; }
.muted { color: var(--ink-2); }
.center { text-align: center; }
.right { text-align: right; white-space: nowrap; }
.hidden { display: none !important; }
.pad { padding: 16px; }

/* ---------- Layout ---------- */
.shell { display: flex; height: 100vh; }
.side {
  width: 208px; flex-shrink: 0; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 16px 10px; gap: 2px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: #fff; padding: 4px 10px 18px; }
.brand.big { color: var(--ink); justify-content: center; font-size: 20px; padding-bottom: 8px; }
.logo { color: #3ad29f; font-size: 18px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--side-ink); text-decoration: none; font-size: 14px;
}
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: rgba(58, 210, 159, .14); color: #fff; }
.side-foot { margin-top: auto; padding: 10px; font-size: 13px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot a { color: var(--side-ink); }
.me { color: #fff; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
.page { max-width: 980px; width: 100%; margin: 0 auto; padding: 24px 20px 48px; }
.page-head { margin-bottom: 8px; }
.page-head.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head.row h1 { margin: 0; margin-right: auto; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-top: 16px; box-shadow: var(--shadow); }

/* ---------- Formulários e botões ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); }
.check.small { font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%;
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; width: 40px; height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.btn {
  font: inherit; font-size: 14px; font-weight: 600; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 16px; border-radius: 8px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

.flash { margin: 12px 20px 0; padding: 11px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--ink); font-size: 14px; }
.flash.err { background: #fde8e6; color: #8a1f17; }
.flash.warn { background: var(--warn-bg); color: var(--warn-ink); }
.auth-card .flash, .card .flash { margin: 0 0 12px; }
@media (prefers-color-scheme: dark) { .flash.err { background: #3d1714; color: #f6b7b0; } }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 99;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Login ---------- */
body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 640px; }
.auth-card h1 { text-align: center; }
.auth-card.wide h1 { text-align: left; }

/* ---------- Tabelas ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.tag { background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); margin-right: 6px; }
.dot.ok { background: #22a06b; }

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 12px; }
.choice { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.choice h3 { margin: 0; }
.choice p { margin: 0 0 10px; font-size: 14px; flex: 1; }
details.manual { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
details.manual summary { cursor: pointer; font-weight: 600; }
.kv { display: flex; flex-direction: column; gap: 10px; }
.kv > div { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kv span { width: 230px; color: var(--ink-2); font-size: 14px; }
pre.log { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px; overflow: auto; max-height: 220px; white-space: pre-wrap; }

/* ---------- Conversas ---------- */
body.app-inbox .main { overflow: hidden; }
.inbox { flex: 1; display: flex; min-height: 0; }
.convs { width: 340px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.convs-head { display: flex; gap: 8px; padding: 12px 12px 8px; }
.filters { display: flex; gap: 6px; padding: 0 12px 10px; border-bottom: 1px solid var(--line); }
.chip { font: inherit; font-size: 13px; border: 1px solid var(--line); background: transparent; color: var(--ink-2); padding: 4px 11px; border-radius: 99px; cursor: pointer; }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 11px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: var(--ink-2); flex-shrink: 0; }
.conv-body { flex: 1; min-width: 0; }
.conv-top, .conv-bottom { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 12px; color: var(--ink-3); flex-shrink: 0; }
.conv-preview { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; flex-shrink: 0; }
.conv-tags { margin-top: 4px; display: flex; gap: 4px; }
.stage-pill { --c: #64748b; font-size: 11px; padding: 1px 8px; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); font-weight: 600; }
.stage-pill.ad { --c: #c2410c; }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--ink-3); }
.chat-inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-head > div { flex: 1; min-width: 0; }
.chat-name { font-weight: 700; }
.chat-sub { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; font-size: 26px; line-height: 1; background: none; border: 0; color: var(--ink); cursor: pointer; padding: 0 6px 0 0; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: var(--warn-bg); color: var(--warn-ink); }
.msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 6px; }
.day-sep { text-align: center; margin: 10px 0; }
.day-sep span { background: var(--surface); color: var(--ink-2); font-size: 12px; padding: 3px 12px; border-radius: 99px; box-shadow: var(--shadow); }
.msg { max-width: min(72%, 560px); padding: 7px 10px 5px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0,0,0,.06); word-wrap: break-word; }
.msg.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 3px; }
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 3px; }
.msg img, .msg video { max-width: 100%; max-height: 320px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg audio { max-width: 260px; display: block; }
.msg .file { display: inline-block; margin-bottom: 4px; }
.msg-meta { display: flex; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.who { font-style: italic; }
.ticks { letter-spacing: -2px; }
.ticks.read { color: #2b8ae0; }
.ticks.failed { color: var(--danger); letter-spacing: 0; font-weight: 600; cursor: help; }
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px; }
.window-closed { font-size: 13px; color: var(--warn-ink); background: var(--warn-bg); padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row textarea { resize: none; max-height: 160px; }

.panel { width: 300px; flex-shrink: 0; background: var(--surface); border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel h3 { margin: 0; }
.saved { color: var(--accent); font-size: 13px; text-align: center; }
.origin { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 14px; }
.origin p { margin: 0 0 6px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(480px, 92vw); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 15, 12, .45); }
dialog h3 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.tpl-preview { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 14px; }

/* ---------- Funil ---------- */
body.app-board .main { overflow: hidden; }
.board-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 20px 20px 0; }
.board-wrap #bq { width: 240px; }
.board { flex: 1; display: flex; gap: 12px; overflow-x: auto; padding: 12px 0 20px; min-height: 0; }
.col { width: 280px; flex-shrink: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.col.over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.col-head { --c: #64748b; padding: 12px 12px 10px; border-top: 3px solid var(--c); border-radius: var(--radius) var(--radius) 0 0; }
.col-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.count { font-size: 12px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 0 7px; font-weight: 600; }
.col-sum { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.col-body { padding: 0 8px 8px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.col-empty { font-size: 13px; color: var(--ink-3); text-align: center; padding: 20px 8px; border: 1px dashed var(--line); border-radius: 8px; }
.lead-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.lead-card:hover { border-color: var(--accent); }
.lead-card.dragging { opacity: .4; }
.lc-top { display: flex; justify-content: space-between; gap: 6px; }
.lc-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-phone { font-size: 12px; color: var(--ink-2); }
.lc-preview { font-size: 13px; color: var(--ink-2); margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin-top: 8px; gap: 6px; }
.lc-foot span:first-child { color: var(--ink); font-weight: 600; }
.stage-edit { display: flex; gap: 6px; align-items: center; }
.stage-edit .pos { width: 58px; }

/* ---------- Páginas de texto ---------- */
body.doc article { max-width: 760px; margin: 0 auto; padding: 40px 20px 80px; }
body.doc h2 { margin-top: 28px; }

/* ---------- Celular ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column-reverse; height: 100dvh; }
  .side { width: 100%; flex-direction: row; padding: 6px; justify-content: space-around; gap: 0; }
  .brand, .side-foot { display: none; }
  .nav-item { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 8px; }
  .grid2, .choices { grid-template-columns: 1fr; }
  .kv span { width: 100%; }
  .flash { margin: 10px 12px 0; }
  .page { padding: 16px 12px 32px; }
  .convs { width: 100%; border-right: 0; }
  .chat { display: none; }
  .inbox.has-chat .convs { display: none; }
  .inbox.has-chat .chat { display: flex; }
  .back { display: block; }
  .msgs { padding: 12px; }
  .msg { max-width: 85%; }
  .panel { position: fixed; inset: 0 0 56px 0; width: 100%; z-index: 20; }
  .board-wrap { padding: 12px 12px 0; }
  .board-wrap #bq { width: 100%; }
  .col { width: 82vw; }
  .table { display: block; overflow-x: auto; }
}
