:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --ink: #1b1f1d;
  --muted: #66706b;
  --line: #e2e5e1;
  --brand: #0f7a55;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2ec;
  --in: #ffffff;
  --out: #d9f5e6;
  --warn: #b25e00;
  --bad: #b3261e;
  --good: #0f7a55;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111413; --panel: #1a1e1c; --ink: #e8ece9; --muted: #9aa49f; --line: #2b302d;
    --brand: #3cc48f; --brand-ink: #08130e; --brand-soft: #173328; --in: #222725; --out: #1c3a2d;
    --warn: #f0a24a; --bad: #ff8a80; --good: #3cc48f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #111413; --panel: #1a1e1c; --ink: #e8ece9; --muted: #9aa49f; --line: #2b302d;
    --brand: #3cc48f; --brand-ink: #08130e; --brand-soft: #173328; --in: #222725; --out: #1c3a2d;
    --warn: #f0a24a; --bad: #ff8a80; --good: #3cc48f;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.2em; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 12px 0 6px; }
a { color: var(--brand); }

.brand { font-weight: 800; font-size: 20px; letter-spacing: -.2px; color: var(--ink, inherit); display: flex; align-items: center; gap: 9px; }
.brand b { font-weight: 800; }
.brand span { color: var(--brand); }
.brand img { width: 32px; height: 32px; flex-shrink: 0; }
.brand.big { font-size: 32px; }
.brand.big img { width: 48px; height: 48px; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: wait; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { min-height: 120px; resize: vertical; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; }
.row > .btn, .row > .shrink { flex: 0 0 auto; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi .v { font-size: 28px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 13px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; }

.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.side nav { display: grid; gap: 2px; }
.side nav a { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); display: flex; justify-content: space-between; }
.side nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side nav a .lock { font-size: 11px; color: var(--muted); }
.side-foot { margin-top: auto; display: grid; gap: 6px; }
.tenant-box { font-size: 13px; }
.main { padding: 24px; max-width: 1200px; width: 100%; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--brand-soft); color: var(--brand); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.pill.neutral { background: var(--line); color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }

.convs { display: grid; grid-template-columns: 300px 1fr 320px; gap: 16px; height: calc(100vh - 110px); }
.conv-list { overflow: auto; padding: 0; }
.conv-item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv-item:hover, .conv-item.active { background: var(--brand-soft); }
.conv-item .n { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-body { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.chat-send { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; }
.bubble { max-width: 75%; padding: 8px 10px; border-radius: 10px; background: var(--in); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: var(--out); }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.bubble img { max-width: 100%; border-radius: 6px; display: block; }
.analysis { overflow: auto; }
.analysis ul { padding-left: 18px; margin: 4px 0; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 80px; }
.bars div { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }
.qr { max-width: 280px; background: #fff; padding: 10px; border-radius: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 10; max-width: calc(100% - 32px); }
.locked { text-align: center; padding: 40px 16px; }
code, pre { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow: auto; }

@media (max-width: 1000px) {
  .convs { grid-template-columns: 1fr; height: auto; }
  .conv-list { max-height: 300px; }
  .chat { height: 70vh; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav { grid-template-columns: repeat(2, 1fr); }
  .main { padding: 16px; }
}

/* ===== Conversas no estilo de app de mensagens (visual familiar, arte própria) ===== */
.main.main-wide { max-width: none; padding: 0; }
.main-wide > .card { margin: 12px; }
.wa {
  --wa-bg: #0c1317; --wa-panel: #111b21; --wa-panel-2: #202c33; --wa-hover: #2a3942; --wa-line: #222d34;
  --wa-ink: #e9edef; --wa-sub: #8696a0; --wa-in: #202c33; --wa-out: #005c4b; --wa-accent: #00a884; --wa-read: #53bdeb;
  display: grid; grid-template-columns: minmax(300px, 30%) 1fr; height: 100vh; background: var(--wa-bg); color: var(--wa-ink);
  font-size: 14.5px; position: relative; overflow: hidden;
}
:root[data-theme="light"] .wa {
  --wa-bg: #efeae2; --wa-panel: #ffffff; --wa-panel-2: #f0f2f5; --wa-hover: #f5f6f6; --wa-line: #e9edef;
  --wa-ink: #111b21; --wa-sub: #667781; --wa-in: #ffffff; --wa-out: #d9fdd3; --wa-accent: #00a884; --wa-read: #53bdeb;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .wa { --wa-bg: #efeae2; --wa-panel: #ffffff; --wa-panel-2: #f0f2f5; --wa-hover: #f5f6f6; --wa-line: #e9edef;
        --wa-ink: #111b21; --wa-sub: #667781; --wa-in: #ffffff; --wa-out: #d9fdd3; --wa-accent: #00a884; --wa-read: #53bdeb; }
}
.wa.ai-open { grid-template-columns: minmax(300px, 28%) 1fr 340px; }
.wa-side { background: var(--wa-panel); border-right: 1px solid var(--wa-line); display: flex; flex-direction: column; min-height: 0; }
.wa-side-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 8px; }
.wa-side-head strong { font-size: 20px; }
.wa-sub { color: var(--wa-sub); font-size: 12.5px; }
.wa-side-head .wa-sub { flex: 1; }
.wa-iconbtn { background: none; border: 0; color: var(--wa-sub); cursor: pointer; padding: 6px; border-radius: 50%; display: inline-grid; place-items: center; text-decoration: none; font-size: 18px; }
.wa-iconbtn:hover { background: var(--wa-hover); color: var(--wa-ink); }
.wa-searchbox { margin: 4px 12px 8px; background: var(--wa-panel-2); border-radius: 10px; display: flex; align-items: center; gap: 10px; padding: 0 12px; color: var(--wa-sub); }
.wa-searchbox input, .wa-msgsearch input { background: transparent; border: 0; color: var(--wa-ink); padding: 9px 0; outline: none; }
.wa-chips, .wa-period { display: flex; gap: 6px; padding: 0 12px 8px; flex-wrap: wrap; align-items: center; }
.wa-chip { background: var(--wa-panel-2); color: var(--wa-sub); border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 13.5px; }
.wa-chip.small { padding: 3px 10px; font-size: 12px; }
.wa-chip.on { background: color-mix(in srgb, var(--wa-accent) 25%, transparent); color: var(--wa-accent); font-weight: 600; }
.wa-period input[type=date] { width: auto; background: var(--wa-panel-2); border: 0; color: var(--wa-sub); font-size: 12px; padding: 3px 6px; color-scheme: dark light; }
.wa-list { flex: 1; overflow-y: auto; border-top: 1px solid var(--wa-line); }
.wa-item { display: flex; gap: 12px; padding: 0 0 0 14px; cursor: pointer; align-items: center; }
.wa-item:hover { background: var(--wa-hover); }
.wa-item.active { background: var(--wa-panel-2); }
.wa-item-main { flex: 1; min-width: 0; padding: 12px 14px 12px 0; border-bottom: 1px solid var(--wa-line); }
.wa-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.wa-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-time { font-size: 12px; color: var(--wa-sub); flex: 0 0 auto; }
.wa-time.unread { color: var(--wa-accent); }
.wa-preview { color: var(--wa-sub); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 3px; }
.wa-badge { background: var(--wa-accent); color: #111b21; font-weight: 700; font-size: 11.5px; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; flex: 0 0 auto; }
.wa-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.wa-dot.bad { background: #f15c6d; }
.wa-avatar { border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 600; flex: 0 0 auto; font-size: 15px; }
.wa-empty { color: var(--wa-sub); padding: 20px; text-align: center; }
.wa-msgsearch { border-top: 1px solid var(--wa-line); padding: 4px 14px; }
.wa-note { color: var(--wa-sub); font-size: 12px; padding: 0 14px 8px; margin: 0; }

.wa-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0;
  /* fundo com padrão discreto próprio */
  background-color: var(--wa-bg);
  background-image: radial-gradient(color-mix(in srgb, var(--wa-sub) 12%, transparent) 1px, transparent 1.4px), radial-gradient(color-mix(in srgb, var(--wa-sub) 7%, transparent) 1px, transparent 1.4px);
  background-size: 22px 22px, 22px 22px; background-position: 0 0, 11px 11px; }
.wa-chat-head { background: var(--wa-panel-2); display: flex; align-items: center; gap: 12px; padding: 8px 16px; min-height: 60px; }
.wa-chat-title { flex: 1; min-width: 0; }
.wa-chat-title strong { font-size: 16px; font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-back { display: none; }
.wa-pillbtn { border: 1px solid var(--wa-line); background: transparent; color: var(--wa-ink); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.wa-pillbtn.ok { color: var(--wa-accent); border-color: transparent; cursor: default; }
.wa-body { flex: 1; overflow-y: auto; padding: 16px 7% 8px; display: flex; flex-direction: column; gap: 2px; }
.wa-day { text-align: center; margin: 10px 0 6px; }
.wa-day span { background: var(--wa-panel-2); color: var(--wa-sub); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.wa-msg { display: flex; margin: 1px 0; }
.wa-msg.out { justify-content: flex-end; }
.wa-bubble { position: relative; max-width: min(65%, 560px); padding: 6px 8px 8px 9px; border-radius: 8px; background: var(--wa-in); box-shadow: 0 1px .5px rgba(11,20,26,.13); white-space: pre-wrap; word-wrap: break-word; line-height: 1.35; }
.wa-msg.out .wa-bubble { background: var(--wa-out); }
.wa-msg.in + .wa-msg.out, .wa-msg.out + .wa-msg.in { margin-top: 8px; }
.wa-msg.in:not(.wa-msg.in + .wa-msg.in) .wa-bubble { border-top-left-radius: 0; }
.wa-msg.out:not(.wa-msg.out + .wa-msg.out) .wa-bubble { border-top-right-radius: 0; }
.wa-msg.in:not(.wa-msg.in + .wa-msg.in) .wa-bubble::before { content: ""; position: absolute; top: 0; left: -8px; border: 8px solid transparent; border-top-color: var(--wa-in); border-right-color: var(--wa-in); border-width: 0 8px 10px 0; }
.wa-msg.out:not(.wa-msg.out + .wa-msg.out) .wa-bubble::before { content: ""; position: absolute; top: 0; right: -8px; border-style: solid; border-color: var(--wa-out) transparent transparent var(--wa-out); border-width: 0 0 10px 8px; border-top-color: transparent; }
.wa-msg.out:not(.wa-msg.out + .wa-msg.out) .wa-bubble::before { border-width: 10px 8px 0 0; border-color: var(--wa-out) transparent transparent transparent; }
.wa-msg.in:not(.wa-msg.in + .wa-msg.in) .wa-bubble::before { border-width: 10px 0 0 8px; border-color: var(--wa-in) transparent transparent transparent; }
.wa-meta { float: right; margin: 6px -2px -4px 10px; font-size: 11px; color: var(--wa-sub); display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.wa-msg.out .wa-meta { color: color-mix(in srgb, var(--wa-ink) 60%, transparent); }
.wa-tick { display: inline-flex; color: var(--wa-sub); }
.wa-tick.read { color: var(--wa-read); }
.wa-by { background: color-mix(in srgb, var(--wa-accent) 30%, transparent); color: var(--wa-ink); border-radius: 4px; padding: 0 4px; font-size: 10px; text-transform: uppercase; letter-spacing: .3px; }
.wa-from { color: var(--wa-accent); font-size: 12.5px; font-weight: 600; }
.wa-bubble img { max-width: 330px; width: 100%; border-radius: 6px; display: block; }
.wa-bubble img.wa-sticker { max-width: 150px; }
.wa-bubble audio { width: 260px; max-width: 100%; display: block; }
.wa-bubble video { max-width: 330px; width: 100%; border-radius: 6px; }
.wa-caption { margin-top: 4px; }
.wa-doc { color: var(--wa-ink); text-decoration: none; display: block; background: color-mix(in srgb, var(--wa-bg) 40%, transparent); padding: 10px; border-radius: 6px; }
.wa-muted { color: var(--wa-sub); font-style: italic; }
.wa-compose { background: var(--wa-panel-2); display: flex; align-items: center; gap: 8px; padding: 8px 16px; min-height: 62px; }
.wa-compose input { background: var(--wa-panel); border: 0; border-radius: 10px; color: var(--wa-ink); padding: 11px 14px; font-size: 15px; outline: none; }
.wa-compose.readonly { color: var(--wa-sub); font-size: 13px; justify-content: center; text-align: center; }
.wa-send { background: none; border: 0; color: var(--wa-sub); cursor: pointer; padding: 6px; }
.wa-send:not(:disabled):hover { color: var(--wa-accent); }
.wa-placeholder { margin: auto; text-align: center; color: var(--wa-sub); max-width: 420px; padding: 20px; }
.wa-placeholder h2 { color: var(--wa-ink); font-weight: 300; font-size: 28px; margin: 12px 0 8px; }
.wa-ph-icon { width: 80px; height: 80px; margin: 0 auto; border-radius: 50%; background: var(--wa-panel-2); color: var(--wa-accent); display: grid; place-items: center; }
.wa-ph-icon svg { width: 40px; height: 40px; }

.wa-ai { display: none; background: var(--wa-panel); border-left: 1px solid var(--wa-line); overflow-y: auto; padding: 0 16px 16px; color: var(--wa-ink); }
.wa.ai-open .wa-ai { display: block; }
.wa-ai-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--wa-panel); padding: 14px 0 6px; }
.wa-ai-head h2 { margin: 0; }
.wa-ai .muted { color: var(--wa-sub); }
.wa-ai .bubble.out { background: var(--wa-out); color: var(--wa-ink); border-color: transparent; }

@media (max-width: 900px) {
  .wa, .wa.ai-open { grid-template-columns: 1fr; height: calc(100vh - 0px); }
  .wa .wa-chat { display: none; }
  .wa.has-chat .wa-side { display: none; }
  .wa.has-chat .wa-chat { display: flex; }
  .wa-back { display: inline-grid; }
  .wa.ai-open .wa-ai { position: absolute; inset: 0; z-index: 5; }
  .wa-body { padding: 12px 10px; }
  .wa-bubble { max-width: 85%; }
}
@media (max-width: 760px) { .wa, .wa.ai-open { height: 85vh; } }

.theme-switch { display: flex; gap: 4px; }
.theme-switch button { flex: 1; font-size: 12px; padding: 4px 6px; }
.theme-switch button.on { border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* vendedores */
.table-wrap { overflow-x: auto; }
table.sellers td, table.sellers th { white-space: nowrap; }
table.sellers td.bad-cell { color: var(--bad); font-weight: 600; }
.seller-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.seller-dot.on { background: var(--good); }
.wa-seller { background: var(--wa-panel-2); color: var(--wa-accent); border-radius: 6px; padding: 0 6px; font-size: 11.5px; font-weight: 600; flex-shrink: 0; }
.wa-sellerbar { padding: 0 12px 8px; }
.wa-sellerbar select { width: 100%; background: var(--wa-panel-2); color: var(--wa-ink); border: 0; border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.num-card .qr { max-width: 240px; }
.wa-assign { width: auto; max-width: 180px; background: var(--wa-panel-2); color: var(--wa-ink); border: 0; border-radius: 16px; padding: 5px 10px; font-size: 13px; }
#addUser input, #addUser select { flex: 1 1 160px; width: auto; }

/* funil de vendas */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kb-col { flex: 0 0 240px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; max-height: 75vh; }
.kb-col header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px 12px 0 0; }
.kb-col header strong { flex: 1; }
.kb-col.over { outline: 2px dashed var(--brand); }
.kb-list { overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 8px; }
.kb-card { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: grab; display: flex; flex-direction: column; gap: 3px; }
.kb-card.dragging { opacity: .5; }
.kb-add { border-style: dashed; align-items: center; justify-content: center; min-height: 80px; background: transparent; }
.late-txt { color: var(--bad); font-weight: 600; }
.funnel-bars { display: flex; flex-direction: column; gap: 6px; }
.fb-row { display: grid; grid-template-columns: 150px 1fr 40px; align-items: center; gap: 10px; }
.fb-bar { background: var(--line); border-radius: 6px; height: 12px; overflow: hidden; }
.fb-bar i { display: block; height: 100%; border-radius: 6px; }
.fb-n { text-align: right; }
.crm-box { border-bottom: 1px solid var(--wa-line, var(--line)); padding-bottom: 12px; margin-bottom: 12px; }
.crm-box label { font-size: 13px; }
.crm-sub { margin-top: 10px; font-size: 13px; }
.crm-form { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.crm-form input { flex: 1 1 140px; width: auto; }
.crm-item { display: flex; justify-content: space-between; gap: 6px; align-items: center; padding: 4px 0; }
.crm-item.late span { color: var(--bad); font-weight: 600; }
.crm-note { background: color-mix(in srgb, #f5a623 14%, transparent); border-radius: 8px; padding: 6px 8px; margin-top: 6px; font-size: 13px; }
.stage-pill { white-space: nowrap; }
.ai-title { margin-top: 4px; }
.wa-sellerbar { display: flex; gap: 6px; }
.wa-chat-title .wa-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-chat-head > .wa-pillbtn, .wa-chat-head > .wa-assign { flex-shrink: 0; }
.main.main-funil { max-width: none; }
.main { min-width: 0; }
.main.main-funil { overflow-x: hidden; }
.wa.ai-open .stage-pill { display: none; }
