:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --brand: #16a34a; --brand-soft: #dcfce7; --blue: #2563eb; --amber: #d97706; --red: #dc2626; --purple: #7c3aed;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --panel: #171b23; --text: #e6e8ec; --muted: #9aa1ad; --line: #2a303b; --brand-soft: #0f2e1b; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--blue); }
h1, h2, h3 { margin: 0 0 12px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .error { color: var(--red); min-height: 1em; } .small { font-size: 12px; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-weight: 500; margin-bottom: 10px; } label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(.97); } .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--red); } .btn.sm { padding: 4px 9px; font-size: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; } .grow { flex: 1; }
.grid { display: grid; gap: 12px; } .g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; } .kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; }

/* layout */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; } .login-card .btn { width: 100%; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; } .logo { color: var(--brand); font-size: 22px; }
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.side .brand { padding: 4px 8px 16px; }
.side a { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
.side a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side .spacer { flex: 1; }
.main { padding: 20px 24px; min-width: 0; }
.topbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.topbar select, .topbar input { width: auto; }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .side .brand, .side .spacer { display: none; }
  .main { padding: 16px; }
}

/* tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); }
.b-meta_ads { background: #dbeafe; color: #1d4ed8; } .b-tracking_link { background: #ede9fe; color: #6d28d9; } .b-organic { background: #f3f4f6; color: #4b5563; }
.b-lead { background: #e0f2fe; color: #0369a1; } .b-qualified { background: #fef3c7; color: #b45309; } .b-sale { background: #dcfce7; color: #15803d; } .b-lost { background: #fee2e2; color: #b91c1c; }
.b-sent, .b-connected { background: #dcfce7; color: #15803d; } .b-error { background: #fee2e2; color: #b91c1c; } .b-skipped, .b-pending, .b-disconnected { background: #f3f4f6; color: #4b5563; }
.b-qr, .b-connecting, .b-reconnecting, .b-waiting_webhook { background: #fef3c7; color: #b45309; }

/* gráfico de barras */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; max-width: 48px; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.bars .bar:hover { opacity: 1; }
.bars .bar .sale { position: absolute; bottom: 0; left: 0; right: 0; background: #15803d; border-radius: 3px 3px 0 0; }

/* drawer do lead */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: none; z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--panel); border-left: 1px solid var(--line); z-index: 11; overflow-y: auto; padding: 20px; transform: translateX(100%); transition: transform .2s; }
.drawer.open { transform: none; } .drawer-bg.open { display: block; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; margin: 12px 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.chat { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.msg { max-width: 85%; padding: 7px 10px; border-radius: 10px; background: var(--bg); white-space: pre-wrap; word-break: break-word; }
.msg.out { align-self: flex-end; background: var(--brand-soft); }
.msg .t { font-size: 11px; color: var(--muted); margin-top: 2px; }
.qr { width: 240px; height: 240px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }
code { background: var(--bg); padding: 2px 6px; border-radius: 5px; font-size: 12.5px; word-break: break-all; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 8px; z-index: 20; display: none; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- Pipeline (kanban) ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; min-height: calc(100vh - 170px); }
.kcol { flex: 0 0 272px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.kcol.over { outline: 2px dashed var(--brand); outline-offset: -2px; }
.kcol header { background: var(--panel); padding: 10px 12px; border-top: 4px solid; border-radius: var(--radius) var(--radius) 0 0; border-bottom: 1px solid var(--line); }
.kcount { background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.kbody { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 80px; }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.kcard:hover { border-color: #c4b5fd; } .kcard.dragging { opacity: .5; }
.ktitle { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.av { width: 26px; height: 26px; border-radius: 6px; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: none; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.klast { background: var(--bg); border-radius: 6px; padding: 5px 7px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 4px 0; }
.kfoot { margin-top: 6px; } .kval { color: var(--brand); }
.kphone { display: inline-block; margin-top: 6px; background: #fce7f3; color: #be185d; padding: 1px 6px; border-radius: 5px; font-variant-numeric: tabular-nums; }
.kempty { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 0; border: 1px dashed var(--line); border-radius: 8px; }
.b-manual { background: #fef3c7; color: #92400e; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: none; place-items: center; z-index: 30; padding: 16px; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow-y: auto; }
.strow { margin-bottom: 8px; flex-wrap: nowrap; } .stlist { margin: 12px 0; }

/* ---------- Funil ---------- */
.funnel-card { display: flex; flex-direction: column; align-items: center; }
.funnel-svg { width: 100%; max-width: 520px; height: auto; }
.fslice path { transition: opacity .15s; } .fslice:hover path { opacity: .85; }
.fslice.worst path { stroke: #f59e0b; stroke-width: 4; }
.fname { fill: #fff; font-size: 15px; font-weight: 600; text-anchor: middle; }
.fnum { fill: #fff; font-size: 17px; font-weight: 800; text-anchor: middle; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.worst-row td { background: #fffbeb; }
.alert { margin-top: 14px; background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; padding: 12px; border-radius: 8px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { .worst-row td, .alert { background: #3a2a08; color: #fde68a; } .kphone { background: #3b1027; color: #f9a8d4; } }

/* ---------- Regras: trilha das etapas ---------- */
.flowline { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; }
.flowstep { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 130px; max-width: 200px; background: var(--panel); }
.flowname { font-weight: 600; margin-bottom: 4px; }
.flowarrow { align-self: center; color: var(--muted); }

/* ---------- Visão geral da agência ---------- */
.ovgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.ovcard { cursor: pointer; } .ovcard:hover { border-color: #c4b5fd; }
.ovnums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.ovnums div { display: flex; flex-direction: column; } .ovnums b { font-size: 16px; } .ovnums span { font-size: 11px; color: var(--muted); }
.ovline { margin-top: 6px; }
.alertrow { padding: 6px 0; border-bottom: 1px solid var(--line); cursor: pointer; gap: 8px; }
.alertrow:last-child { border-bottom: 0; }

td code { white-space: nowrap; word-break: normal; }

/* ---------- Google Ads ---------- */
.b-google { background: #e8f0fe; color: #1a73e8; }
.gconv { display: grid; grid-template-columns: 90px 1fr 1.4fr; gap: 6px 8px; align-items: center; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.gcred { background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
