:root {
  --bg: #f5f6fa; --panel: #ffffff; --fg: #111827; --muted: #6b7280; --line: #e5e7eb; --accent: #4f46e5; --accent-soft: #eef2ff;
  --ok: #16a34a; --warn: #d97706; --err: #dc2626; --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--fg); font-size: 14px; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; font-weight: 700; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.hidden { display: none !important; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: #111827; color: #d1d5db; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; flex: none; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { color: #fff; font-weight: 700; font-size: 18px; padding: 6px 10px 18px; display: flex; align-items: center; gap: 8px; }
.sidebar .logo span { background: var(--accent); color: #fff; width: 28px; height: 28px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }
.sidebar a { color: #d1d5db; padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; font-weight: 500; }
.sidebar a:hover { background: #1f2937; color: #fff; }
.sidebar a.active { background: var(--accent); color: #fff; }
.sidebar .spacer { flex: 1; }
.main { flex: 1; padding: 26px 30px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Cards / panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Buttons & forms */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--err); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.inp, select.inp, textarea.inp { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none; }
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.inp { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; }
.row > .auto { flex: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 8px; }
.check input { width: 16px; height: 16px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafafa; }
tr:hover td { background: #fafbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow: auto; }

/* Tags */
.tag { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #f3f4f6; color: #374151; white-space: nowrap; }
.tag.ok { background: #dcfce7; color: #166534; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.err { background: #fee2e2; color: #991b1b; }
.tag.info { background: var(--accent-soft); color: #3730a3; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* Funnel */
.funnel .bar { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; margin: 7px 0; font-size: 13px; }
.funnel .bar .track { height: 26px; background: #f3f4f6; border-radius: 6px; overflow: hidden; }
.funnel .bar .fill { height: 100%; border-radius: 6px; min-width: 2px; transition: width .4s; }
.funnel .bar .n { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.funnel .bar .n small { color: var(--muted); font-weight: 400; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-color: var(--accent); }

/* Kanban */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { background: #eceef3; border-radius: var(--radius); width: 270px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 180px); }
.col.over { outline: 2px dashed var(--accent); }
.col .head { padding: 12px 12px 8px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.col .head .cnt { background: #fff; border-radius: 999px; padding: 1px 8px; font-size: 11px; color: var(--muted); }
.col .body { padding: 0 8px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.card { background: #fff; border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); cursor: grab; border-left: 3px solid transparent; }
.card:active { cursor: grabbing; }
.card .nm { font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; gap: 6px; }
.card .meta { color: var(--muted); font-size: 11px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.card.dragging { opacity: .4; }

/* Lead detail */
.lead-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .lead-grid { grid-template-columns: 1fr; } .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); }
.timeline li .t { color: var(--muted); font-size: 11px; }
.answers dt { font-size: 12px; color: var(--muted); margin-top: 8px; }
.answers dd { margin: 2px 0 0; font-weight: 500; }
.msg { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; background: #fafafa; }
.msg.in { background: var(--accent-soft); }
.msg .h { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-bottom: 4px; }

/* Question editor */
.qlist { display: flex; flex-direction: column; gap: 8px; }
.q { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.q.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.q .idx { width: 26px; height: 26px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex: none; }
.q .t { flex: 1; min-width: 0; }
.q .t .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q .t .type { color: var(--muted); font-size: 11px; }
.q .ops { display: flex; gap: 2px; }
.q .ops button { border: 0; background: transparent; cursor: pointer; padding: 2px 5px; color: var(--muted); border-radius: 4px; }
.q .ops button:hover { background: #f3f4f6; color: var(--fg); }

/* Steps */
.step { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: #fff; }
.step .hdr { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.step .hdr .n { font-weight: 600; }

/* Modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(17, 24, 39, .5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 480px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); max-height: 92vh; overflow-y: auto; }
.modal.wide { max-width: 860px; }
.maprow { display: grid; grid-template-columns: 160px 1fr; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; }
#toast div { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); animation: fade .2s; }
#toast div.err { background: var(--err); }
@keyframes fade { from { opacity: 0; transform: translateY(8px);} }

/* Drawer (painel lateral do lead) */
.drawer-bg { position: fixed; inset: 0; background: rgba(17, 24, 39, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 100vw; background: #fff; z-index: 41; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); display: flex; flex-direction: column; animation: slideIn .2s ease; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
.drawer .dh { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.drawer .dh h2 { margin: 0 0 4px; font-size: 17px; }
.drawer .db { padding: 16px 18px; overflow-y: auto; flex: 1; }
.drawer .close { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
.drawer h3 { margin-top: 16px; }
.drawer .df { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.card .nm a { color: inherit; }
.stage-row { display: grid; grid-template-columns: 22px 44px 1fr 120px auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.stage-row .handle { color: var(--muted); font-size: 12px; text-align: center; }
.qimg-preview { max-width: 100%; max-height: 140px; border-radius: 8px; margin-top: 8px; display: block; }

/* Conversas (inbox) */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); height: calc(100vh - 120px); overflow: hidden; }
.inbox .list { border-right: 1px solid var(--line); overflow-y: auto; }
.inbox .conv { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.inbox .conv:hover { background: #fafbff; }
.inbox .conv.active { background: var(--accent-soft); }
.inbox .conv .n { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox .conv .t { color: var(--muted); font-size: 11px; white-space: nowrap; }
.inbox .conv .p { color: var(--muted); font-size: 12px; grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox .conv .u { background: var(--accent); color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 6px; font-weight: 600; }
.inbox .chat { display: flex; flex-direction: column; min-width: 0; }
.inbox .chat .ch { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.inbox .chat .cb { flex: 1; overflow-y: auto; padding: 16px; background: #f0f2f5; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 72%; padding: 8px 12px; border-radius: 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble.in { background: #fff; align-self: flex-start; border-bottom-left-radius: 3px; }
.bubble.out { background: #d9fdd3; align-self: flex-end; border-bottom-right-radius: 3px; }
.bubble.out.erro { background: #fee2e2; }
.bubble .bt { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }
.inbox .chat .cf { padding: 10px 12px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.inbox .chat .cf textarea { flex: 1; min-height: 42px; max-height: 120px; resize: none; }
.daysep { align-self: center; font-size: 11px; color: var(--muted); background: #e5e7eb; border-radius: 999px; padding: 2px 10px; margin: 6px 0; }
.qr { display: block; width: 260px; height: 260px; margin: 12px auto; border: 1px solid var(--line); border-radius: 8px; }
@media (max-width: 800px) { .inbox { grid-template-columns: 1fr; height: auto; } .inbox .list { max-height: 40vh; } }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login .panel { width: 340px; }

/* Bars chart */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.bars div:hover { opacity: 1; }
.bars div span { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); display: none; white-space: nowrap; }
.bars div:hover span { display: block; }
.code { background: #f3f4f6; border-radius: 6px; padding: 8px 10px; font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; }
@media (max-width: 800px) {
  .layout { flex-direction: column; } .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; gap: 2px; }
  .sidebar .logo { width: 100%; padding-bottom: 8px; } .sidebar .spacer { display: none; } .main { padding: 16px; } .lead-grid { grid-template-columns: 1fr; }
}
