:root {
  --brand: #1f6fe5;
  --brand-dark: #1558bd;
  --brand-soft: #e6f0fd;
  --nav: #0b2545;
  --nav-2: #13315c;
  --nav-accent: #5fa8ff;
  --ink: #1d2b3a;
  --muted: #64748b;
  --line: #dfe5ee;
  --bg: #f3f6fa;
  --card: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--brand-dark); }
h1 { font-size: 24px; margin: 0; font-weight: 700; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
code, pre { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: #0f1e33; color: #e5edf7; padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* Barra superior (estilo RD Station) */
.topnav { position: sticky; top: 0; z-index: 60; background: var(--nav); color: #fff; height: 60px; display: flex; align-items: stretch; padding: 0 20px; gap: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.topnav .logo { display: flex; align-items: center; margin-right: 18px; text-decoration: none; }
.topnav .logo img { max-height: 36px; max-width: 190px; }
.menu { display: flex; align-items: stretch; gap: 2px; flex: 1; }
.menu > .item { position: relative; display: flex; align-items: center; }
.menu > .item > a, .menu > .item > button { color: #dbe7f7; background: none; border: 0; font: inherit; font-weight: 700; font-size: 14px; padding: 0 14px; height: 100%; display: flex; align-items: center; gap: 4px; cursor: pointer; text-decoration: none; border-bottom: 3px solid transparent; }
.menu > .item:hover > a, .menu > .item:hover > button, .menu > .item.active > a, .menu > .item.active > button { color: #fff; background: var(--nav-2); }
.menu > .item.active > a, .menu > .item.active > button { border-bottom-color: var(--nav-accent); }
.dropdown { display: none; position: absolute; top: 100%; left: 0; min-width: 230px; background: #fff; border-radius: 0 0 8px 8px; box-shadow: 0 12px 28px rgba(11,37,69,.22); padding: 6px 0; }
.menu > .item:hover .dropdown, .menu > .item.open .dropdown { display: block; }
.dropdown a { display: block; padding: 9px 18px; color: var(--ink); text-decoration: none; font-weight: 600; }
.dropdown a small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.dropdown a:hover, .dropdown a.active { background: var(--brand-soft); color: var(--brand-dark); }
.navright { display: flex; align-items: center; gap: 6px; }
.navright a, .navright button { color: #dbe7f7; background: none; border: 0; font: inherit; cursor: pointer; padding: 8px 10px; border-radius: 6px; text-decoration: none; font-weight: 600; }
.navright a:hover, .navright button:hover { background: var(--nav-2); color: #fff; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; }
#menu-btn { display: none; }
.mobile-only { display: none !important; }
.main { padding: 26px 32px 60px; max-width: 1360px; margin: 0 auto; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 980px) {
  #menu-btn { display: inline-flex; }
  .menu { display: none; position: absolute; top: 60px; left: 0; right: 0; flex-direction: column; background: var(--nav); padding: 8px 0 14px; box-shadow: 0 10px 24px rgba(0,0,0,.25); }
  .menu.open { display: flex; }
  .menu > .item { flex-direction: column; align-items: stretch; }
  .menu > .item > button, .menu > .item > a { padding: 12px 20px; height: auto; border-bottom: 0; }
  .navright .hide-m { display: none; }
  .menu .mobile-only { display: flex !important; border-top: 1px solid var(--nav-2); margin-top: 6px; padding-top: 6px; }
  .topnav { padding: 0 12px; }
  .dropdown { display: block; position: static; box-shadow: none; background: transparent; padding: 0 0 6px 12px; }
  .dropdown a { color: #dbe7f7; padding: 7px 20px; }
  .dropdown a small { display: none; }
  .navright .uname { display: none; }
  .main { padding: 16px; }
}

/* Componentes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 7px; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f3f4f6; }
.btn { border-radius: 6px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand-dark); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

label.f { display: block; font-weight: 600; font-size: 12.5px; margin: 0 0 4px; color: #374151; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=datetime-local], input[type=search], input[type=color], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 7px; font: inherit; background: #fff; color: inherit;
}
input[type=color] { padding: 2px; height: 36px; }
textarea { min-height: 80px; resize: vertical; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; min-height: 380px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-weight: 500; }

table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:hover td { background: #fafafa; }
.t tr.click { cursor: pointer; }
.table-wrap { overflow-x: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #eef2ff; color: #3730a3; white-space: nowrap; }
.badge.lead { background: #e0f2fe; color: #075985; }
.badge.lead_qualificado { background: #fef3c7; color: #92400e; }
.badge.oportunidade { background: #ede9fe; color: #5b21b6; }
.badge.cliente { background: #dcfce7; color: #166534; }
.badge.on { background: #dcfce7; color: #166534; }
.badge.off { background: #f3f4f6; color: #6b7280; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.err { background: #fee2e2; color: #991b1b; }
.tag { display: inline-flex; gap: 4px; align-items: center; background: var(--brand-soft); color: var(--brand-dark); padding: 2px 8px; border-radius: 6px; font-size: 12px; margin: 0 4px 4px 0; }
.tag button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0; font-size: 14px; line-height: 1; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 36px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand-dark); border-color: var(--brand); }

/* Funil */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel .step { display: grid; grid-template-columns: 140px 1fr 80px; align-items: center; gap: 10px; }
.grade { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-variant-numeric: tabular-nums; }
.grade b { display: inline-flex; width: 22px; height: 22px; border-radius: 5px; align-items: center; justify-content: center; color: #fff; font-size: 12px; }
.grade.A b { background: #0b8a4a; } .grade.B b { background: #1f6fe5; } .grade.C b { background: #d97706; } .grade.D b { background: #94a3b8; }
.bar { height: 26px; background: #f3f4f6; border-radius: 6px; overflow: hidden; }
.bar > div { height: 100%; background: var(--brand); border-radius: 6px; min-width: 2px; }
.hbars .r { display: grid; grid-template-columns: minmax(0, 1fr) 2fr 50px; gap: 10px; align-items: center; margin-bottom: 6px; }
.hbars .r span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .bar { height: 14px; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 22px; border-left: 2px solid var(--line); position: relative; margin-left: 6px; }
.timeline li:before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline .when { color: var(--muted); font-size: 11.5px; }

/* Editor de automação */
.flow { display: flex; flex-direction: column; align-items: stretch; gap: 0; max-width: 760px; }
.flow .node { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 8px; padding: 12px 14px; }
.flow .node.trigger { border-left-color: #0b2545; }
.flow .node.wait { border-left-color: #d97706; }
.flow .node.condition { border-left-color: #7c3aed; }
.flow .arrow { text-align: center; color: #9ca3af; font-size: 18px; line-height: 1.6; }
.node-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.node-head b { font-size: 13px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(17, 24, 39, .5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 22px; }
.modal.wide { max-width: 900px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

#toast { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: var(--nav); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; }
#toast div.err { background: var(--err); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(135deg, #0b2545 0%, #13315c 55%, #1f6fe5 100%); }
.login .brandbox { text-align: center; margin-bottom: 18px; }
.login .brandbox img { max-height: 54px; max-width: 260px; }
.login .card { width: 100%; max-width: 400px; padding: 28px; }
.preview-frame { width: 100%; height: 640px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.split-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) { .split-editor { grid-template-columns: 1fr; } }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 12px; }
.spark { width: 100%; height: 160px; }
.copy-box { display: flex; gap: 8px; }
.copy-box input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

/* ===== Editor visual (arrastar e soltar) ===== */
.be { position: fixed; inset: 0; z-index: 90; background: #e9eef5; display: flex; flex-direction: column; }
.be-top { height: 58px; background: var(--nav); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; flex: none; }
.be-top .be-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.be-top .be-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.be-top .be-title .muted { color: #9fb3cf; font-size: 12px; }
.be-top select { background: var(--nav-2); color: #fff; border-color: #2c4a76; }
.be-top .btn { border-color: #2c4a76; }
.be-top .btn:not(.primary) { background: var(--nav-2); color: #fff; }
.be-seg { display: inline-flex; border: 1px solid #2c4a76; border-radius: 6px; overflow: hidden; }
.be-seg button { background: var(--nav-2); color: #cfe0f7; border: 0; padding: 6px 10px; font: inherit; font-weight: 600; cursor: pointer; }
.be-seg button.on { background: var(--brand); color: #fff; }
.be-body { flex: 1; display: grid; grid-template-columns: 210px minmax(0, 1fr) 300px; min-height: 0; }
.be-palette, .be-props { background: #fff; overflow-y: auto; border-right: 1px solid var(--line); }
.be-props { border-right: 0; border-left: 1px solid var(--line); }
.be-ph { font-weight: 800; padding: 14px 14px 8px; font-size: 14px; position: sticky; top: 0; background: #fff; z-index: 2; }
.be-pbody { padding: 0 14px 30px; }
.be-item { display: flex; align-items: center; gap: 10px; margin: 0 10px 6px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; cursor: grab; font-weight: 600; background: #fbfcfe; user-select: none; }
.be-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.be-item .ic { width: 22px; text-align: center; }
.be-stage { overflow: auto; padding: 22px; position: relative; }
.be-canvas { min-height: calc(100% - 4px); border-radius: 6px; box-shadow: 0 2px 12px rgba(11,37,69,.08); }
.be-preview { display: none; border: 0; background: #fff; margin: 0 auto; height: calc(100% - 4px); border-radius: 6px; box-shadow: 0 2px 12px rgba(11,37,69,.12); }
.be.previewing .be-canvas, .be.previewing .be-palette > * { display: none; }
.be.previewing .be-preview { display: block; }
.be-rt { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.be-rt button { border: 1px solid var(--line); background: #fff; border-radius: 5px; min-width: 32px; height: 30px; cursor: pointer; font-size: 13px; }
.be-rt button:hover { background: var(--brand-soft); border-color: var(--brand); }
.be-img { border: 1px dashed var(--line); border-radius: 6px; padding: 8px; text-align: center; margin-bottom: 6px; background: #f8fafc; }
.be-img img { max-width: 100%; max-height: 120px; }
.be-col { border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; margin-bottom: 10px; }
.be-col summary { font-weight: 700; cursor: pointer; padding: 4px 0; }
.im-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; max-height: 340px; overflow: auto; }
.im-thumb { border: 2px solid var(--line); border-radius: 6px; background: #f6f8fb; padding: 4px; height: 100px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.im-thumb:hover { border-color: var(--brand); }
.im-thumb img { max-width: 100%; max-height: 100%; }
.be-starters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.be-starter { border: 2px solid var(--line); border-radius: 8px; background: #fff; padding: 8px; cursor: pointer; font: inherit; font-weight: 700; display: flex; flex-direction: column; gap: 8px; }
.be-starter:hover { border-color: var(--brand); }
.be-st-prev { height: 170px; overflow: hidden; border-radius: 4px; background: #eef3fa; position: relative; }
.be-st-prev iframe { width: 640px; height: 900px; border: 0; transform: scale(.23); transform-origin: 0 0; pointer-events: none; }
.be-st-code { display: flex; align-items: center; justify-content: center; font-size: 34px; color: var(--muted); }
@media (max-width: 1000px) { .be-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; } .be-palette { display: flex; overflow-x: auto; border: 0; } .be-palette .be-ph, .be-palette .hint { display: none; } .be-item { flex: none; margin: 8px 4px; } .be-props { max-height: 40vh; } .be-top .be-title { display: none; } }
