:root {
  --brand: #ea580c;
  --brand-dark: #c2410c;
  --brand-soft: #fff1e6;
  --side: #1c1917;
  --side-2: #292524;
  --bg: #f5f5f4;
  --panel: #ffffff;
  --line: #e7e5e4;
  --text: #1c1917;
  --muted: #78716c;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --blue: #2563eb;
  --chat-bg: #efeae2;
  --out: #ffe8d6;
  --in: #ffffff;
  --note: #fef9c3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- botões e campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: #fafaf9; border-color: #d6d3d1; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.green { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.icon-btn { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); flex-shrink: 0; }
.icon-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; }
.btn.sm svg { width: 16px; height: 16px; }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(234,88,12,.15); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .03em; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 0; }
.switch input { width: 18px; height: 18px; accent-color: var(--brand); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #fed7aa 0, transparent 40%), radial-gradient(circle at 90% 90%, #fdba74 0, transparent 35%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; }
.login-logo { width: 56px; height: 56px; border-radius: 14px; background: var(--brand); color: #fff; font-weight: 800; font-size: 22px; display: grid; place-items: center; margin-bottom: 16px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; }
.login-card .btn { width: 100%; padding: 11px; }
.form-error { color: var(--red); font-size: 13px; margin: -4px 0 12px; min-height: 0; }

/* ---------- layout ---------- */
.shell { display: flex; height: 100vh; height: 100dvh; }
.side { width: 72px; background: var(--side); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 4px; flex-shrink: 0; }
.side .logo { width: 42px; height: 42px; border-radius: 11px; background: var(--brand); color: #fff; font-weight: 800; display: grid; place-items: center; margin-bottom: 14px; font-size: 16px; }
.nav-btn { width: 56px; padding: 8px 0 6px; border-radius: 10px; border: 0; background: transparent; color: #a8a29e; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; position: relative; text-decoration: none; }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { background: var(--side-2); color: #fff; }
.nav-btn.active { background: var(--side-2); color: #fff; }
.nav-btn.active::before { content: ''; position: absolute; left: -8px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--brand); }
.nav-btn .badge { position: absolute; top: 2px; right: 6px; }
.side .spacer { flex: 1; }
.wa-dot { width: 10px; height: 10px; border-radius: 50%; background: #78716c; display: inline-block; }
.wa-dot.connected { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.25); }
.wa-dot.qr, .wa-dot.connecting { background: #f59e0b; }
.wa-dot.disconnected { background: #ef4444; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; flex-shrink: 0; text-transform: uppercase; }
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.avatar.xs { width: 20px; height: 20px; font-size: 10px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page { flex: 1; overflow: auto; padding: 24px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 19px; height: 19px; padding: 0 6px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; }
.badge.gray { background: #e7e5e4; color: var(--text); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; background: #f5f5f4; border: 1px solid var(--line); white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.banner { padding: 10px 14px; border-radius: 10px; background: #fef3c7; color: #92400e; border: 1px solid #fde68a; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.banner.red { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

/* ---------- conversas ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100%; min-height: 0; }
.inbox.with-details { grid-template-columns: 340px 1fr 320px; }
.list-col { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 14px 14px 8px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0 0 10px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin-top: 10px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: transparent; padding: 7px 11px; border-radius: 20px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tab:hover { background: #f5f5f4; }
.tab.active { background: var(--brand-soft); color: var(--brand-dark); }
.tab .badge { height: 17px; min-width: 17px; font-size: 10px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 11px; padding: 12px 14px; border-bottom: 1px solid #f5f5f4; cursor: pointer; position: relative; }
.conv:hover { background: #fafaf9; }
.conv.active { background: var(--brand-soft); }
.conv .top { display: flex; align-items: baseline; gap: 6px; }
.conv .name { font-weight: 600; flex: 1; min-width: 0; }
.conv .time { font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.conv.unread .time { color: var(--brand); font-weight: 600; }
.conv .preview { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.conv .meta { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; align-items: center; }
.conv .meta .pill { font-size: 11px; padding: 1px 7px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 46px; height: 46px; opacity: .4; margin-bottom: 8px; }

.chat-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); }
.chat-head { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head .who { flex: 1; min-width: 140px; cursor: pointer; }
.chat-head .who b { display: block; font-size: 15px; }
.chat-head .actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chat-head select { width: auto; padding: 6px 8px; font-size: 13px; }
.chat-banner { padding: 8px 14px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 3px;
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
.day-sep { align-self: center; background: #fff; color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 10px 0; box-shadow: 0 1px 1px rgba(0,0,0,.05); }
.msg { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 9px; box-shadow: 0 1px 1px rgba(0,0,0,.07); position: relative; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.38; }
.msg.in { align-self: flex-start; background: var(--in); border-top-left-radius: 2px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 2px; }
.msg.note { align-self: flex-end; background: var(--note); border: 1px dashed #eab308; }
.msg.system { align-self: center; background: #e7e5e4; color: #57534e; font-size: 12px; padding: 4px 12px; border-radius: 8px; box-shadow: none; max-width: 90%; text-align: center; }
.msg .author { font-size: 11.5px; font-weight: 700; color: var(--brand-dark); margin-bottom: 2px; }
.msg.note .author { color: #a16207; }
.msg .foot { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.msg .ticks svg { width: 16px; height: 16px; vertical-align: middle; }
.msg .ticks.read { color: #0ea5e9; }
.msg .ticks.error { color: var(--red); }
.msg img.media, .msg video.media { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; margin-bottom: 4px; cursor: pointer; background: #eee; }
.msg img.sticker { max-width: 140px; background: transparent; }
.msg audio { display: block; width: 260px; max-width: 100%; margin: 2px 0; }
.doc { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: rgba(0,0,0,.04); border-radius: 6px; text-decoration: none; color: inherit; margin-bottom: 4px; }
.doc svg { width: 28px; height: 28px; color: var(--brand); flex-shrink: 0; }
.load-more { align-self: center; margin-bottom: 10px; }

.composer { background: #f5f5f4; border-top: 1px solid var(--line); padding: 8px 12px 10px; position: relative; }
.composer .mode { display: flex; gap: 4px; margin-bottom: 6px; }
.composer .mode button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.composer .mode button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.composer .mode button.active.note { background: var(--note); color: #854d0e; }
.composer .bar { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea { resize: none; max-height: 160px; min-height: 42px; border-radius: 21px; padding: 10px 16px; line-height: 1.4; }
.composer.note-mode textarea { background: #fefce8; border-color: #fde047; }
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--brand); color: #fff; border: 0; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.send-btn:hover { background: var(--brand-dark); }
.send-btn svg { width: 20px; height: 20px; }
.send-btn.rec { background: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(220,38,38,.2); } }
.qr-pop { position: absolute; bottom: 100%; left: 12px; right: 12px; max-height: 260px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); margin-bottom: 6px; z-index: 5; }
.qr-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f5f5f4; }
.qr-item:hover, .qr-item.sel { background: var(--brand-soft); }
.qr-item b { color: var(--brand-dark); }
.qr-item div { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 4px 6px; flex: 1; color: var(--red); font-weight: 600; }

.details-col { background: #fff; border-left: 1px solid var(--line); overflow-y: auto; padding: 18px 16px; }
.details-col h3 { margin: 0; font-size: 17px; }
.details-col .section { margin-top: 18px; }
.details-col .section > .label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 20px; background: #e0f2fe; color: #075985; font-size: 12px; font-weight: 500; }
.tag button { border: 0; background: transparent; cursor: pointer; padding: 0; color: inherit; opacity: .6; font-size: 14px; line-height: 1; }
.timeline { font-size: 12.5px; }
.timeline div { padding: 5px 0; border-bottom: 1px dashed var(--line); }

.no-chat { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.no-chat .big { width: 76px; height: 76px; border-radius: 20px; background: var(--brand); color: #fff; font-weight: 800; font-size: 28px; display: grid; place-items: center; margin: 0 auto 14px; }

/* ---------- funil ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; height: calc(100% - 60px); padding-bottom: 8px; align-items: flex-start; }
.k-col { width: 280px; flex-shrink: 0; background: #ecebea; border-radius: 12px; display: flex; flex-direction: column; max-height: 100%; }
.k-col.drag-over { outline: 2px dashed var(--brand); outline-offset: -2px; background: var(--brand-soft); }
.k-head { padding: 11px 12px 8px; display: flex; align-items: center; gap: 8px; border-top: 4px solid; border-radius: 12px 12px 0 0; }
.k-head b { flex: 1; }
.k-head .sum { font-size: 12px; color: var(--muted); }
.k-body { padding: 4px 8px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.k-card { background: #fff; border-radius: 9px; padding: 10px 11px; box-shadow: 0 1px 2px rgba(0,0,0,.08); cursor: grab; border: 1px solid transparent; }
.k-card:hover { border-color: #fdba74; }
.k-card.dragging { opacity: .4; }
.k-card .nm { font-weight: 600; margin-bottom: 3px; }
.k-card .val { color: var(--green); font-weight: 700; font-size: 13px; }
.k-card .ft { display: flex; align-items: center; gap: 6px; margin-top: 7px; font-size: 12px; color: var(--muted); }
.k-card select { margin-top: 8px; padding: 4px 6px; font-size: 12px; display: none; }

/* ---------- tabelas ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafaf9; white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid #f5f5f4; vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #fafaf9; }

/* ---------- painel ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 800; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.card-pad { padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.fbar { margin-bottom: 10px; }
.fbar .row { font-size: 13px; margin-bottom: 4px; }
.fbar .track { height: 10px; border-radius: 5px; background: #f5f5f4; overflow: hidden; }
.fbar .fill { height: 100%; border-radius: 5px; }
.seg { display: inline-flex; background: #e7e5e4; border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; color: #57534e; }
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- configurações ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; align-items: start; }
.wa-box { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.wa-box img { width: 240px; height: 240px; border-radius: 10px; border: 1px solid var(--line); }
.list-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #f5f5f4; }
.list-item:last-child { border-bottom: 0; }
.steps { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(28,25,23,.45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 20px 0; display: flex; align-items: center; }
.modal-head h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-body { padding: 16px 20px; }
.modal-foot { padding: 0 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }
.lightbox { max-width: 95vw; max-height: 90vh; border-radius: 8px; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; top: 14px; right: 14px; z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: #1c1917; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; pointer-events: auto; animation: fade .2s; cursor: pointer; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

/* ---------- responsivo ---------- */
.mobile-only { display: none; }
@media (max-width: 1180px) {
  .inbox.with-details { grid-template-columns: 320px 1fr; }
  .inbox.with-details .details-col { position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 92vw); z-index: 30; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .mobile-only { display: inline-flex; }
  .shell { flex-direction: column-reverse; }
  .side { width: 100%; height: 60px; flex-direction: row; justify-content: space-around; padding: 0 4px calc(env(safe-area-inset-bottom)); height: calc(60px + env(safe-area-inset-bottom)); }
  .side .logo, .side .spacer, .side .hide-m { display: none; }
  .nav-btn { width: auto; flex: 1; }
  .nav-btn.active::before { left: 25%; right: 25%; top: -1px; bottom: auto; width: auto; height: 3px; }
  .main { min-height: 0; }
  .inbox, .inbox.with-details { grid-template-columns: 1fr; }
  .inbox .chat-col { display: none; }
  .inbox.has-chat .list-col { display: none; }
  .inbox.has-chat .chat-col { display: flex; }
  .messages { padding: 12px 10px; }
  .msg { max-width: 88%; }
  .page { padding: 14px; }
  .settings-grid { grid-template-columns: 1fr; }
  .kanban { height: auto; }
  .k-col { width: 85vw; }
  .k-card select { display: block; }
  .chat-head .actions .lbl { display: none; }
}
@media (max-width: 760px) {
  .chat-head { gap: 6px; padding: 8px 10px; }
  .chat-head .who { min-width: 0; }
  .chat-head select { max-width: 130px; }
}
