:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e3e4e8;
  --text: #16181d;
  --text-2: #52514e;
  --text-3: #8a8985;
  --accent: #2a78d6;
  --accent-2: #eb6834;
  --accent-3: #1baf7a;
  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 8px rgba(0,0,0,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }

.topo { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.marca small { display: block; font-weight: 400; font-size: 11px; color: var(--text-3); line-height: 1; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; }
.abas { display: flex; gap: 4px; flex-wrap: wrap; }
.abas a { padding: 8px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.abas a:hover { background: var(--surface-2); }
.abas a.ativa { background: #e7f0fb; color: var(--accent); }
.topo-info { margin-left: auto; color: var(--text-3); font-size: 12px; text-align: right; }

.conteudo { max-width: 1240px; margin: 0 auto; padding: 24px 24px 60px; }
.carregando { color: var(--text-3); padding: 40px; text-align: center; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 28px 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--text-2); }
.subtitulo { color: var(--text-3); margin: 0 0 18px; }
.cabecalho-pagina { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.cabecalho-pagina .acoes { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.grade-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 16px 0; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .rotulo { color: var(--text-2); font-size: 12px; }
.kpi .valor { font-size: 24px; font-weight: 600; margin-top: 4px; letter-spacing: -.01em; }
.kpi .valor.grande { font-size: 30px; }
.kpi .nota { color: var(--text-3); font-size: 11px; margin-top: 4px; }

.cartao { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.cartao.compacto { padding: 10px 14px; }
.duas-colunas { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 900px) { .duas-colunas { grid-template-columns: 1fr; } }

table.tabela { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tabela td { padding: 8px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tabela tr:last-child td { border-bottom: none; }
.tabela tr.clicavel { cursor: pointer; }
.tabela tr.clicavel:hover td { background: #fafafa; }
.tabela td.num, .tabela th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabela td.dim { color: var(--text-3); }
.tabela tr.detalhe td { background: #fafbfc; padding: 8px 8px 12px 28px; }
.tabela .sub { color: var(--text-3); font-size: 11px; display: block; }
.rolagem { overflow-x: auto; }
.tabela-rodape td { font-weight: 600; background: #fafafa; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.recebido, .badge.conciliado, .badge.ok { background: #e6f6e6; color: #0a6d0a; }
.badge.aguardando, .badge.aguardando_extrato, .badge.previsto { background: #e7f0fb; color: #1c5cab; }
.badge.atrasado, .badge.nao_localizado, .badge.critico { background: #fbe3e3; color: #a42a2a; }
.badge.sem_fatura, .badge.atencao { background: #fff2d6; color: #8a5a00; }
.badge.inadimplente { background: #a42a2a; color: #fff; }
.badge.vencido { background: #fff2d6; color: #8a5a00; }
.badge.negativo, .badge.compensado, .badge.info { background: #ececec; color: #555; }
.badge.direto { background: #efe9fb; color: #5b3fb0; }
.badge.manual { background: #f0efec; color: #555; }

.alertas { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alertas li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.alertas li.critico { border-left: 4px solid var(--critical); }
.alertas li.atencao { border-left: 4px solid var(--warn); }
.alertas li.info { border-left: 4px solid #bbb; }
.alertas .icone { font-size: 16px; line-height: 1.2; }
.vazio { color: var(--text-3); padding: 14px; text-align: center; }

.botao { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.botao:hover { background: var(--surface-2); }
.botao.primario { background: var(--accent); border-color: var(--accent); color: #fff; }
.botao.primario:hover { background: #1c5cab; }
.botao.perigo { color: var(--critical); }
.botao.pequeno { padding: 3px 8px; font-size: 12px; }
.botao:disabled { opacity: .5; cursor: default; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: inherit; }

input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b7d3f6; border-color: var(--accent); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input.curto { width: 90px; }
input.medio { width: 120px; }
input.erro { border-color: var(--critical); background: #fff5f5; }
.campo { display: flex; flex-direction: column; gap: 4px; }
.campo label { font-size: 12px; color: var(--text-2); }
.form-grade { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.filtros { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 12px; }
.chip.ativo { background: var(--accent); color: #fff; border-color: var(--accent); }

.modal-fundo { position: fixed; inset: 0; background: rgba(20,22,28,.45); display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border-radius: 14px; width: min(1180px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.estreito { width: min(640px, 100%); }
.modal-cab { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-cab h2 { margin: 0; font-size: 17px; }
.modal-cab .fechar { margin-left: auto; }
.modal-corpo { padding: 18px 20px; }
.modal-rodape { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }
.revisao { display: grid; grid-template-columns: minmax(280px, 42%) 1fr; gap: 18px; }
@media (max-width: 1000px) { .revisao { grid-template-columns: 1fr; } }
.preview { background: var(--surface-2); border-radius: 8px; padding: 8px; position: sticky; top: 0; }
.preview img { width: 100%; height: auto; border-radius: 6px; }
.checks { list-style: none; margin: 10px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checks li { display: flex; gap: 8px; align-items: center; font-size: 12px; padding: 6px 10px; border-radius: 6px; background: #f6f7f9; }
.checks li.ok { color: #0a6d0a; background: #eef8ee; }
.checks li.falha { color: #a42a2a; background: #fdf0f0; }
.avisos { background: #fff7e6; border: 1px solid #f5dfae; color: #7a5200; padding: 8px 12px; border-radius: 8px; font-size: 12px; margin-bottom: 10px; }
.avisos ul { margin: 4px 0 0 16px; padding: 0; }
.tabela-editar td { padding: 4px 4px; }
.tabela-editar input, .tabela-editar select { width: 100%; padding: 4px 6px; font-size: 12px; }
.tabela-editar td:first-child { min-width: 190px; }
.tabela-editar select { max-width: 190px; }
.tabela-editar input.num { width: 96px; }
.tabela-editar input.data { width: 100px; }
.tabela-editar input.nf { width: 84px; }
.sugestao { font-size: 11px; color: var(--accent); cursor: pointer; }
.arrastar { display: block; border: 2px dashed #c9cbd1; border-radius: 10px; padding: 26px; text-align: center; color: var(--text-2); cursor: pointer; background: #fafbfc; }
.arrastar.ativo { border-color: var(--accent); background: #eef4fc; }
.arrastar input { display: none; }
.opcoes-envio { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }

.grafico { width: 100%; height: auto; display: block; }
.grafico text { font-family: inherit; font-size: 11px; fill: var(--text-2); }
.grafico .grade line { stroke: var(--border); stroke-width: 1; }
.legenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 6px; }
.legenda span { display: inline-flex; align-items: center; gap: 6px; }
.legenda i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.tooltip { position: fixed; background: #16181d; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; pointer-events: none; z-index: 60; white-space: nowrap; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #16181d; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 90vw; }
.toast.erro { background: var(--critical); }
.toast.ok { background: #0a6d0a; }

/* login */
.sem-sessao .abas, .sem-sessao .topo-info { display: none; }
.login { max-width: 360px; margin: 48px auto; display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.login .subtitulo { margin: 0; }
.login input { padding: 9px 10px; }
.login .botao { padding: 9px 12px; }
.login-erro { margin: 0; color: var(--critical); font-size: 13px; }

/* assistente */
.chat-botao { position: fixed; right: 20px; bottom: 20px; z-index: 40; border: 0; border-radius: 999px; padding: 11px 18px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; box-shadow: 0 6px 18px rgba(42,120,214,.35); }
.chat-botao:hover { background: #1c5cab; }
.chat { position: fixed; right: 20px; bottom: 20px; z-index: 40; width: min(440px, calc(100vw - 32px)); height: min(640px, calc(100vh - 40px)); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.chat[hidden] { display: none; }
.chat-cab { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-sub { color: var(--text-3); font-size: 12px; margin-right: auto; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { padding: 8px 12px; border-radius: 12px; max-width: 92%; overflow-wrap: anywhere; }
.chat-msg p { margin: 0 0 6px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg ul { margin: 4px 0 6px; padding-left: 18px; }
.chat-msg .tabela-rolagem { overflow-x: auto; margin: 4px 0 6px; }
.chat-msg .tabela { font-size: 12px; background: var(--surface); }
.chat-msg .tabela th, .chat-msg .tabela td { padding: 4px 6px; }
.chat-msg.eu { align-self: flex-end; background: #e7f0fb; white-space: pre-wrap; }
.chat-msg.ia { align-self: flex-start; background: var(--surface-2); }
.chat-msg.ia.erro { background: #fff5f5; color: var(--critical); }
.chat-msg.pensando { color: var(--text-3); font-style: italic; }
.chat-fonte { margin-top: 6px; font-size: 11px; color: var(--text-3); }
.chat-dica { color: var(--text-2); margin: 0; }
.chat-sugestoes { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-form textarea { flex: 1; resize: none; }
@media (max-width: 600px) { .chat { right: 8px; bottom: 8px; width: calc(100vw - 16px); height: calc(100vh - 16px); } }
.sem-sessao .chat, .sem-sessao .chat-botao { display: none; }

.valor-pos { color: #0a6d0a; }
.valor-neg { color: var(--critical); }
.mono { font-variant-numeric: tabular-nums; }
.pequeno { font-size: 12px; color: var(--text-3); }
.resumo-mes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.resumo-mes .kpi .valor { font-size: 18px; }
.barra-progresso { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.barra-progresso i { display: block; height: 100%; background: var(--accent-3); }
details summary { cursor: pointer; color: var(--text-2); font-size: 12px; }
