/* FUSION CRM — identidade visual inspirada na Fusion Proteção Veicular */
:root {
  --navy: #0B1A33;
  --navy-2: #13284D;
  --navy-3: #1C3765;
  --azul: #2F80ED;
  --azul-escuro: #1E5FBF;
  --azul-claro: #E8F1FD;
  --aco: #3D72B8;
  --bg: #F3F6FB;
  --card: #FFFFFF;
  --txt: #0F1B2D;
  --txt-2: #51607A;
  --borda: #E1E7F0;
  --ok: #16A34A;
  --aviso: #D97706;
  --perigo: #DC2626;
  --raio: 14px;
  --sombra: 0 1px 2px rgba(11,26,51,.06), 0 4px 16px rgba(11,26,51,.06);
  --sidebar: 248px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--txt); font-size: 14.5px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--azul); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%); color: #C9D6EA; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px 18px; color: #fff; font-size: 18px; letter-spacing: .04em; }
.brand img { width: 38px; height: 38px; }
.brand small { display: block; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #7FA6DD; }
.sidebar nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #B7C6DE; font-weight: 500; margin-bottom: 2px; position: relative; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.ativo { background: var(--azul); color: #fff; box-shadow: 0 4px 14px rgba(47,128,237,.35); }
.me { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); color: #fff; }
.me div { flex: 1; min-width: 0; }
.me b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me small { color: #7FA6DD; font-size: 11.5px; }
.me .icon-btn { color: #B7C6DE; }
.main { margin-left: var(--sidebar); padding: 24px 28px 150px; min-height: 100vh; max-width: 1600px; }
.badge { margin-left: auto; background: var(--perigo); color: #fff; font-style: normal; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: inline-grid; place-items: center; padding: 0 6px; }
.bottom-nav { display: none; }
/* botão de cadastro rápido — discreto: círculo pequeno, "+" fino; ao passar o mouse mostra "Novo lead" */
.fab { position: fixed; right: 22px; bottom: 22px; height: 44px; min-width: 44px; padding: 0 12px; border-radius: 22px; border: 1px solid var(--borda);
  background: rgba(255,255,255,.92); color: var(--azul); display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  box-shadow: 0 2px 10px rgba(11,26,51,.10); z-index: 30; backdrop-filter: blur(6px); transition: all .18s ease; font-weight: 600; font-size: 13.5px; }
.fab svg { flex: none; }
.fab span { display: none; white-space: nowrap; }
.fab:hover { background: var(--azul); color: #fff; border-color: var(--azul); box-shadow: 0 6px 18px rgba(47,128,237,.35); }
.fab:hover span { display: inline; }

/* ---------- componentes ---------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { font-size: 24px; font-weight: 800; }
.page-head .spacer { flex: 1; }
.muted { color: var(--txt-2); }
.tiny { font-size: 12px; }
.card { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra); padding: 18px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-h h3 { margin: 0; }
.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)); }
.g-dash { grid-template-columns: 2fr 1fr; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--borda); background: #fff; color: var(--txt); padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.btn:hover { border-color: #C5D1E3; background: #F8FAFD; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn-primary:hover { background: var(--azul-escuro); border-color: var(--azul-escuro); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #12843C; }
.btn-perigo { color: var(--perigo); }
.btn-wa { background: #25D366; border-color: #25D366; color: #fff; }
.btn-wa:hover { background: #1EB458; }
.btn-ia { background: linear-gradient(135deg, #6D5BF6, #2F80ED); border: 0; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 12px 18px; font-size: 15px; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; color: var(--txt-2); display: inline-grid; place-items: center; }
.icon-btn:hover { background: rgba(127,140,160,.15); }
.link { border: 0; background: none; color: var(--azul); padding: 0; font-weight: 500; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-end { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.avatar { display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 700; flex: none; position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--azul-claro); color: var(--azul-escuro); white-space: nowrap; }
.chip-cinza { background: #EEF1F6; color: var(--txt-2); }
.chip-ok { background: #DCFCE7; color: #166534; }
.chip-aviso { background: #FEF3C7; color: #92400E; }
.chip-perigo { background: #FEE2E2; color: #991B1B; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.alert { background: #FFF7E6; border: 1px solid #F6D58E; color: #7A5300; padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-size: 13.5px; }
.alert-info { background: var(--azul-claro); border-color: #BFD7F8; color: #17407A; }
.empty { text-align: center; color: var(--txt-2); padding: 40px 16px; }
.loading { display: grid; place-items: center; padding: 60px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--borda); border-top-color: var(--azul); border-radius: 50%; animation: gira .8s linear infinite; }
.splash { height: 100vh; display: grid; place-items: center; background: var(--navy); }
@keyframes gira { to { transform: rotate(360deg); } }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--borda); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--txt-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.ativo { color: var(--azul); border-bottom-color: var(--azul); }

/* ---------- formulários ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--txt-2); }
input, select, textarea { border: 1px solid var(--borda); border-radius: 10px; padding: 9px 11px; background: #fff; font-size: 14.5px; font-weight: 400; color: var(--txt); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,128,237,.35); border-color: var(--azul); }
textarea { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--txt); }
.check input { width: auto; }
fieldset { border: 1px solid var(--borda); border-radius: 12px; padding: 12px; margin: 0; }
legend { font-weight: 700; font-size: 13px; padding: 0 6px; }
.fipe-box { background: var(--azul-claro); border: 1px solid #BFD7F8; border-radius: 12px; padding: 10px 12px; }
.fipe-box select, .fipe-box input { background: #fff; }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filtros > * { width: auto; min-width: 150px; }
.busca { flex: 1; min-width: 200px; }

/* ---------- tabelas ---------- */
.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--txt-2); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--borda); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #EEF2F7; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #F7FAFE; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--borda); border-radius: var(--raio); padding: 14px 16px; box-shadow: var(--sombra); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c, var(--azul)); }
.kpi small { color: var(--txt-2); font-weight: 600; font-size: 12px; display: block; }
.kpi b { font-size: 26px; font-weight: 800; letter-spacing: -.02em; display: block; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--txt-2); }
.kpi.destaque { background: linear-gradient(135deg, var(--navy), var(--navy-3)); color: #fff; border: 0; }
.kpi.destaque small, .kpi.destaque span { color: #9FBCE6; }
.barra { height: 8px; background: #EAF0F8; border-radius: 99px; overflow: hidden; }
.barra > i { display: block; height: 100%; background: var(--azul); border-radius: 99px; transition: width .4s; }
.barra.ok > i { background: var(--ok); }
.chart-box { position: relative; height: 260px; }

/* ---------- ranking ---------- */
.rank-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #EEF2F7; }
.rank-item:last-child { border: 0; }
.rank-pos { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 12px; background: #EEF1F6; color: var(--txt-2); flex: none; }
.rank-pos.p1 { background: #FDE68A; color: #854D0E; } .rank-pos.p2 { background: #E5E7EB; color: #374151; } .rank-pos.p3 { background: #FED7AA; color: #9A3412; }
.rank-item .info { flex: 1; min-width: 0; }
.rank-item .info b { display: block; font-size: 13.5px; }

/* ---------- kanban ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; scroll-snap-type: x proximity; }
.coluna { flex: 0 0 272px; background: #E9EEF6; border-radius: var(--raio); display: flex; flex-direction: column; max-height: calc(100vh - 170px); scroll-snap-align: start; }
.coluna-h { padding: 12px 12px 8px; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; }
.coluna-h .qtd { margin-left: auto; background: #fff; border-radius: 99px; padding: 1px 9px; font-size: 12px; color: var(--txt-2); }
.coluna-h small { display: block; font-weight: 500; color: var(--txt-2); font-size: 11.5px; }
.coluna-b { padding: 4px 8px 10px; overflow-y: auto; min-height: 80px; flex: 1; }
.kcard { background: #fff; border-radius: 11px; padding: 10px 11px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(11,26,51,.08); cursor: grab; border-left: 3px solid var(--c, var(--azul)); }
.kcard:active { cursor: grabbing; }
.kcard b { display: block; font-size: 13.5px; }
.kcard .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; font-size: 11.5px; color: var(--txt-2); align-items: center; }
.kcard.sortable-ghost { opacity: .4; }
.placa { font-family: "SFMono-Regular", Consolas, monospace; background: #F1F5F9; border: 1px solid #CBD5E1; border-radius: 5px; padding: 0 5px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; color: var(--txt); }

/* ---------- lead / detalhes ---------- */
.lead-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.lead-head h1 { font-size: 22px; }
.etapas-bar { display: flex; gap: 3px; margin: 14px 0 4px; overflow-x: auto; }
.etapas-bar button { flex: 1; min-width: 34px; border: 0; height: 30px; border-radius: 6px; background: #E6ECF5; font-size: 11px; font-weight: 600; color: var(--txt-2); padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.etapas-bar button.feita { background: #BFD7F8; color: #17407A; }
.etapas-bar button.atual { background: var(--azul); color: #fff; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; }
.dl dt { color: var(--txt-2); font-weight: 600; }
.dl dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--borda); position: relative; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--azul); }
.timeline small { color: var(--txt-2); display: block; }
.ia-out { white-space: pre-wrap; background: #F6F4FF; border: 1px solid #DDD6FE; border-radius: 12px; padding: 12px; font-size: 13.5px; }

/* ---------- WhatsApp ---------- */
.wa { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 48px); background: #fff; border: 1px solid var(--borda); border-radius: var(--raio); overflow: hidden; box-shadow: var(--sombra); }
.wa-lista { border-right: 1px solid var(--borda); display: flex; flex-direction: column; min-height: 0; }
.wa-lista-h { padding: 12px; border-bottom: 1px solid var(--borda); display: flex; flex-direction: column; gap: 8px; }
.wa-convs { overflow-y: auto; flex: 1; }
.wa-conv { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #F0F3F8; cursor: pointer; align-items: center; }
.wa-conv:hover, .wa-conv.ativo { background: #F2F7FE; }
.wa-conv .info { flex: 1; min-width: 0; }
.wa-conv b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-conv p { margin: 0; font-size: 12.5px; color: var(--txt-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-conv .lado { text-align: right; font-size: 11px; color: var(--txt-2); display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.wa-chat { display: flex; flex-direction: column; min-height: 0; background: #EFEAE2; }
.wa-chat-h { background: #fff; padding: 10px 14px; border-bottom: 1px solid var(--borda); display: flex; align-items: center; gap: 10px; }
.wa-chat-h .info { flex: 1; min-width: 0; }
.wa-msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.bolha { max-width: 75%; padding: 7px 10px 5px; border-radius: 10px; font-size: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; word-wrap: break-word; }
.bolha.in { background: #fff; align-self: flex-start; border-top-left-radius: 2px; }
.bolha.out { background: #D9FDD3; align-self: flex-end; border-top-right-radius: 2px; }
.bolha.falha { background: #FEE2E2; }
.bolha small { display: block; text-align: right; font-size: 10.5px; color: #667781; margin-top: 2px; }
.bolha img { max-width: 240px; border-radius: 8px; display: block; }
.transcricao { margin-top: 6px; padding: 6px 8px; background: rgba(0,0,0,.04); border-radius: 8px; font-size: 13px; font-style: italic; }
.msg-marca { margin-top: 6px; padding: 5px 8px; border-radius: 8px; font-size: 12px; background: #FEF3C7; color: #78350F; white-space: normal; }
.msg-apagada { background: #FEE2E2; color: #991B1B; }
.msg-agendada { background: #E0E7FF; color: #3730A3; }
.dia-sep { align-self: center; background: #fff; font-size: 11.5px; padding: 3px 10px; border-radius: 8px; color: #54656F; margin: 8px 0; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.wa-input { background: #F0F2F5; padding: 10px; display: flex; gap: 8px; align-items: flex-end; flex-wrap: nowrap; }
.wa-input .icon-btn { padding: 6px 4px; font-size: 18px; }
.wa-input textarea { min-height: 42px; max-height: 140px; border-radius: 20px; padding: 10px 14px; }
.wa-gravando { background: #F0F2F5; padding: 10px 14px; display: flex; gap: 10px; align-items: center; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #DC2626; animation: pisca 1s infinite; }
@keyframes pisca { 50% { opacity: .25; } }
.wa-aviso { background: #FFF7E6; padding: 8px 14px; font-size: 12.5px; color: #7A5300; border-top: 1px solid #F6D58E; }
.wa-vazio { flex: 1; display: grid; place-items: center; color: var(--txt-2); text-align: center; padding: 20px; }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(11,26,51,.55); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; }
.modal-h h3 { font-size: 17px; }
.modal-b { padding: 4px 18px 18px; overflow-y: auto; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--navy); color: #fff; padding: 11px 14px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 13.5px; transform: translateX(120%); transition: transform .25s; }
.toast.show { transform: none; }
.toast-erro { background: var(--perigo); }
.toast-aviso { background: #B45309; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, var(--navy-3), var(--navy) 60%); }
.login-card { background: #fff; border-radius: 20px; padding: 28px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login-card label { text-align: left; }
.login-logo { width: 140px; margin: -8px auto 0; }
.login-card h1 { font-size: 22px; letter-spacing: .08em; color: var(--navy); }
.login-card h1 span { color: var(--azul); }
.menu-mais { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.menu-item { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--navy); font-weight: 600; text-align: center; }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-dash, .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  body { font-size: 15px; }
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px 16px 170px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--navy); z-index: 40; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: #8EA6C9; font-size: 10.5px; font-weight: 600; position: relative; padding: 4px 0; }
  .bottom-nav a.ativo { color: #fff; }
  .bottom-nav .badge { position: absolute; top: 0; left: 55%; height: 17px; min-width: 17px; font-size: 10px; }
  .fab { bottom: calc(74px + env(safe-area-inset-bottom)); right: 14px; height: 42px; min-width: 42px; padding: 0; }
  .g2, .g4, .form-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi b { font-size: 22px; }
  .page-title { font-size: 20px; }
  .wa { grid-template-columns: 1fr; height: calc(100dvh - 150px); border-radius: 12px; }
  .wa.com-chat .wa-lista { display: none; }
  .wa:not(.com-chat) .wa-chat { display: none; }
  .bolha { max-width: 88%; }
  .coluna { flex-basis: 84vw; max-height: calc(100vh - 210px); }
  .modal-bg { place-items: end center; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; }
  .dl { grid-template-columns: 110px 1fr; }
  .hide-m { display: none !important; }
  table.resp thead { display: none; }
  table.resp tr { display: block; border-bottom: 1px solid var(--borda); padding: 8px 0; }
  table.resp td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 4px 4px; }
  table.resp td::before { content: attr(data-l); color: var(--txt-2); font-weight: 600; font-size: 12px; }
}
@media print { .sidebar, .bottom-nav, .fab { display: none; } .main { margin: 0; } }
