:root {
  --bg: #0a0a0b;
  --panel: #141416;
  --panel-2: #1b1b1e;
  --border: #2a2a2f;
  --text: #f2f2f3;
  --muted: #9a9aa3;
  --red: #e3161d;
  --red-2: #ff3b41;
  --red-soft: rgba(227, 22, 29, 0.14);
  --green: #22c55e;
  --amber: #f59e0b;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --head: 'Oswald', 'Open Sans', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 'Open Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--red-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--head); font-weight: 600; letter-spacing: 0.02em; margin: 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap; transition: .15s;
}
.btn:hover { border-color: #3a3a40; background: #222226; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--red-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff6b6b; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input, textarea.input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; outline: none;
}
.input:focus { border-color: var(--red); }
textarea.input { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .05em; }
.row { display: flex; gap: 10px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }
.sidebar {
  background: #060607; border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 12px;
}
.brand { padding: 4px 8px 20px; }
.brand img { width: 100%; max-width: 180px; display: block; }
.brand .fallback { font-family: var(--head); font-size: 26px; font-weight: 700; letter-spacing: .06em; }
.brand small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; margin-top: 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--muted);
  text-decoration: none; margin-bottom: 2px; font-weight: 500; position: relative;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--red-soft); color: #fff; }
.nav a.active::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--red); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; }
.sidebar .spacer { flex: 1; }
.wa-pill { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; background: var(--panel); font-size: 13px; cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.dot.wait { background: var(--amber); }
.userbox { display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; margin-top: 10px; border-top: 1px solid var(--border); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: #2a2a2f; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; flex: none; color: #fff;
}
.userbox .info { flex: 1; min-width: 0; font-size: 13px; }
.userbox .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { overflow: auto; min-width: 0; }
.page { padding: 24px 28px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; text-transform: uppercase; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-bar { display: none; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card h3 { font-size: 15px; text-transform: uppercase; margin-bottom: 14px; color: #ddd; }
.card h3 .muted { text-transform: none; font-family: 'Open Sans'; font-weight: 400; font-size: 12px; letter-spacing: 0; }

/* ---------- Dashboard ---------- */
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--red); color: #fff; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-family: var(--head); font-size: 30px; font-weight: 600; margin: 4px 0 2px; }
.kpi .delta { font-size: 12px; }
.delta.up { color: var(--green); }
.delta.down { color: #ff6b6b; }
.kpi .icon { position: absolute; right: 14px; top: 14px; width: 34px; height: 34px; border-radius: 8px; background: var(--red-soft); color: var(--red-2); display: grid; place-items: center; }
.kpi .icon svg { width: 18px; height: 18px; }
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-bottom: 14px; }
.dash-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 220px; }
.funnel-row { display: grid; grid-template-columns: 150px 1fr 130px; gap: 10px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.funnel-bar { height: 22px; border-radius: 5px; background: var(--panel-2); overflow: hidden; }
.funnel-bar div { height: 100%; border-radius: 5px; min-width: 2px; }
.funnel-row .num { text-align: right; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.list li:last-child { border-bottom: 0; }
.list .time { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini-stats div { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.mini-stats b { display: block; font-family: var(--head); font-size: 20px; font-weight: 600; }
.mini-stats span { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.banner {
  display: flex; gap: 14px; align-items: center; background: linear-gradient(90deg, var(--red-soft), transparent);
  border: 1px solid rgba(227, 22, 29, .35); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 18px;
}
.banner .grow { flex: 1; }

/* ---------- Kanban ---------- */
.board-wrap { padding: 0 28px 24px; overflow-x: auto; height: calc(100vh - 92px); }
.board { display: flex; gap: 14px; align-items: flex-start; min-height: 100%; }
.column {
  width: 290px; flex: none; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; max-height: 100%;
}
.column-head { padding: 12px 14px 10px; border-top: 3px solid var(--c, #666); border-radius: var(--radius) var(--radius) 0 0; }
.column-head .t { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.column-head .count { background: var(--panel-2); color: var(--muted); border-radius: 999px; padding: 0 8px; font-size: 12px; }
.column-head .sum { color: var(--muted); font-size: 12px; margin-top: 2px; }
.column-head .menu { margin-left: auto; border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.column-head .menu:hover { background: var(--panel-2); color: var(--text); }
.cards { padding: 4px 10px 10px; overflow-y: auto; flex: 1; min-height: 60px; }
.cards.over { background: rgba(227, 22, 29, .06); outline: 1px dashed rgba(227, 22, 29, .5); outline-offset: -4px; border-radius: 8px; }
.lead-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; margin-bottom: 8px;
  cursor: grab; transition: border-color .15s, transform .15s;
}
.lead-card:hover { border-color: #3d3d44; }
.lead-card.dragging { opacity: .4; }
.lead-card .top { display: flex; align-items: center; gap: 8px; }
.lead-card .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-card .msg { color: var(--muted); font-size: 12.5px; margin: 6px 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lead-card .meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.lead-card .val { font-weight: 700; color: #fff; }
.lead-card .when { margin-left: auto; color: var(--muted); }
.tag { display: inline-block; background: #26262b; color: #d4d4d8; border-radius: 999px; padding: 1px 8px; font-size: 11px; }
.tag.src { background: var(--red-soft); color: #ff8a8e; }
.add-col { width: 240px; flex: none; border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px; color: var(--muted); cursor: pointer; text-align: center; background: transparent; }
.add-col:hover { border-color: var(--red); color: var(--text); }
.board-toolbar { padding: 24px 28px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.board-toolbar h1 { font-size: 26px; text-transform: uppercase; margin-right: 8px; }
.search { position: relative; }
.search input { padding-left: 34px; width: 260px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--muted); }

/* ---------- Drawer / Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 40; animation: fade .15s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(920px, 100vw); background: var(--bg); border-left: 1px solid var(--border);
  z-index: 50; display: grid; grid-template-columns: 1fr 340px; animation: slide .2s ease-out;
}
.drawer .chat-col { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); }
.drawer .info-col { overflow-y: auto; padding: 18px; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; z-index: 60; box-shadow: var(--shadow);
}
.modal h2 { font-size: 20px; margin-bottom: 16px; text-transform: uppercase; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.popmenu { position: fixed; z-index: 70; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 4px; box-shadow: var(--shadow); min-width: 170px; }
.popmenu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.popmenu button:hover { background: #2a2a30; }
.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--red); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 340px; animation: slide .2s; cursor: pointer; }
.toast.ok { border-left-color: var(--green); }

/* ---------- Chat ---------- */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--panel); }
.chat-head .t { flex: 1; min-width: 0; }
.chat-head .t b { display: block; }
.chat-head .t span { color: var(--muted); font-size: 12px; }
.chat-body {
  flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px;
  background: radial-gradient(circle at 20% 0%, rgba(227, 22, 29, .05), transparent 50%), var(--bg);
}
.bubble { max-width: 72%; padding: 8px 12px 6px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); white-space: pre-wrap; word-wrap: break-word; align-self: flex-start; }
.bubble.me { align-self: flex-end; background: #3a0d10; border-color: #5a1418; }
.bubble .ft { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; }
.bubble .ft .read { color: #4fb3ff; }
.bubble .ft .err { color: #ff6b6b; }
.day-sep { align-self: center; font-size: 11px; color: var(--muted); background: var(--panel); border-radius: 999px; padding: 2px 10px; margin: 8px 0; }
.composer { border-top: 1px solid var(--border); padding: 12px; background: var(--panel); position: relative; }
.composer .row { align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 140px; resize: none; }
.qr-pop { position: absolute; bottom: 100%; left: 12px; right: 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; max-height: 240px; overflow-y: auto; box-shadow: var(--shadow); }
.qr-pop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.qr-pop button:hover, .qr-pop button.sel { background: #2a2a30; }
.qr-pop b { color: var(--red-2); }
.qr-pop small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-warn { background: rgba(245, 158, 11, .12); color: #fbbf24; font-size: 12.5px; padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }
.inbox .side { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.inbox .side-head { padding: 20px 16px 12px; }
.inbox .side-head h1 { font-size: 24px; text-transform: uppercase; margin-bottom: 12px; }
.inbox .side-head .search input { width: 100%; }
.filters { display: flex; gap: 6px; margin-top: 10px; }
.filters button { border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.filters button.on { background: var(--red); border-color: var(--red); color: #fff; }
.convs { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #1a1a1d; }
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--red); }
.conv .c { flex: 1; min-width: 0; }
.conv .l1 { display: flex; gap: 6px; align-items: baseline; }
.conv .l1 b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .l1 span { color: var(--muted); font-size: 11.5px; }
.conv .l2 { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12.5px; }
.conv .l2 .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .stage { font-size: 10.5px; padding: 0 6px; border-radius: 4px; color: #fff; opacity: .85; }
.inbox .main-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.inbox .placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; }

/* ---------- WhatsApp ---------- */
.wa-card { max-width: 820px; display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: center; }
.qr-box { background: #fff; border-radius: 12px; padding: 14px; width: 320px; height: 320px; display: grid; place-items: center; color: #333; text-align: center; }
.qr-box img { width: 100%; height: 100%; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.status-big { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; margin-bottom: 14px; }
.status-big .dot { width: 12px; height: 12px; }
.spinner { width: 36px; height: 36px; border: 3px solid #ddd; border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Configurações ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table td, .table th { padding: 9px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #33333a; border-radius: 999px; cursor: pointer; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--red); }
.switch input:checked + span::after { transform: translateX(18px); }
.color-input { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); cursor: pointer; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at top, rgba(227, 22, 29, .18), transparent 60%), var(--bg); }
.login { width: min(380px, 100%); }
.login .brand { text-align: center; padding-bottom: 26px; }
.login .brand img { margin: 0 auto; max-width: 240px; }
.login .error { color: #ff6b6b; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- Responsivo ---------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-grid, .dash-grid-3 { grid-template-columns: 1fr; }
  .drawer { grid-template-columns: 1fr; overflow-y: auto; }
  .drawer .chat-col { height: 70vh; border-right: 0; border-bottom: 1px solid var(--border); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 80; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .mobile-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: #060607; position: sticky; top: 0; z-index: 30; }
  .mobile-bar img { height: 22px; }
  .page, .board-toolbar { padding-left: 16px; padding-right: 16px; }
  .board-wrap { padding: 0 16px 16px; height: calc(100vh - 150px); }
  .search input { width: 100%; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .value { font-size: 24px; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 51px); }
  .inbox.chat-open .side { display: none; }
  .inbox:not(.chat-open) .main-chat { display: none; }
  .wa-card, .settings-grid, .grid-2 { grid-template-columns: 1fr; }
  .qr-box { width: 100%; max-width: 320px; height: auto; aspect-ratio: 1; }
  .funnel-row { grid-template-columns: 100px 1fr 90px; }
  .banner { flex-wrap: wrap; }
  .banner .grow { flex-basis: calc(100% - 50px); }
  .bubble { max-width: 88%; }
}

/* ---------- Rastreamento e tipos de cliente ---------- */
.type-badge {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  color: var(--tc); background: color-mix(in srgb, var(--tc) 16%, transparent); border: 1px solid color-mix(in srgb, var(--tc) 35%, transparent); white-space: nowrap;
}
.how { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.how div { display: flex; gap: 10px; background: var(--panel-2); border-radius: 8px; padding: 12px; font-size: 13px; }
.how b { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-size: 12px; }
.code, code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: #26262b; padding: 1px 6px; border-radius: 4px; color: #ffb4b6; }
.table-wrap { overflow-x: auto; }
.links-table td { vertical-align: middle; }
.links-table tr.off { opacity: .5; }
.link-urls { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.link-urls svg { width: 14px; height: 14px; }
.url-preview { font-size: 11px; margin-top: 4px; word-break: break-all; }
.origin-box { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.origin-box .big { font-family: var(--head); font-size: 18px; font-weight: 600; margin: 2px 0; }
.origin-box .first { font-size: 12px; color: var(--muted); margin-top: 6px; font-style: italic; }
.orders { list-style: none; margin: 0 0 8px; padding: 0; }
.orders li { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.orders li .x { margin-left: auto; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.src-table td, .src-table th { padding: 8px 6px; }
.src-table .bar { height: 6px; border-radius: 3px; background: var(--red); margin-top: 4px; min-width: 2px; }
.attr-pill { display: inline-block; font-size: 11px; color: var(--muted); }
.filter-select { width: auto; padding: 7px 10px; }
@media (max-width: 1200px) { .how { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) { .how { grid-template-columns: 1fr; } }
