:root {
  --fundo: #f6f5f2;
  --superficie: #ffffff;
  --superficie-2: #fbfaf8;
  --linha: #e4e2dd;
  --linha-forte: #cfccc5;
  --tinta: #121212;
  --tinta-2: #55534e;
  --tinta-3: #8a877f;
  --azul: #2a78d6;
  --azul-escuro: #1d5fae;
  --laranja: #eb6834;
  --agua: #1baf7a;
  --bom: #11782f;
  --bom-fundo: #e8f4ec;
  --ruim: #b42318;
  --ruim-fundo: #fbeceb;
  --aviso: #8a5a00;
  --aviso-fundo: #fdf3dc;
  --raio: 10px;
  --sombra: 0 1px 2px rgba(20, 18, 14, .05), 0 1px 1px rgba(20, 18, 14, .03);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fundo); color: var(--tinta); line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
a { color: var(--azul-escuro); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--tinta-2); font-weight: 600; }
.sub { color: var(--tinta-2); margin: 0 0 1.25rem; }
small, .peq { font-size: .85em; color: var(--tinta-2); }

/* layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.lateral {
  background: #16181d; color: #d7d6d2; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.marca { padding: 4px 10px 16px; border-bottom: 1px solid #2a2d34; margin-bottom: 10px; }
.marca b { display: block; color: #fff; font-size: 1.05rem; letter-spacing: -.01em; }
.marca span { font-size: .8rem; color: #9b9a94; }
.lateral nav a {
  display: flex; align-items: center; gap: 8px; color: #d7d6d2; padding: 7px 10px; border-radius: 7px;
  font-size: .93rem;
}
.lateral nav a:hover { background: #23262d; text-decoration: none; color: #fff; }
.lateral nav a.ativo { background: #2a78d6; color: #fff; }
.lateral .secao { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: #7d7c76; margin: 14px 10px 4px; }
.lateral .rodape { border-top: 1px solid #2a2d34; margin-top: 14px; padding: 12px 10px 0; font-size: .82rem; color: #9b9a94; }
.lateral .rodape a { color: #c9c8c3; }
.conteudo { padding: 26px 32px 60px; max-width: 1500px; width: 100%; }
.topo { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.topo .sub { margin: 0; }

/* cartões */
.cartao { background: var(--superficie); border: 1px solid var(--linha); border-radius: var(--raio); padding: 18px 20px; box-shadow: var(--sombra); }
.grade { 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)); }
.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.mt { margin-top: 16px; }
.kpi .rot { color: var(--tinta-2); font-size: .82rem; }
.kpi .val { font-size: 1.45rem; font-weight: 650; letter-spacing: -.02em; margin: 2px 0; }
.kpi .det { font-size: .8rem; color: var(--tinta-2); }
.neg { color: var(--ruim); }
.pos { color: var(--bom); }

/* tabelas */
.tabela-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--superficie); }
th, td { padding: 7px 10px; border-bottom: 1px solid #efede9; text-align: left; vertical-align: middle; white-space: nowrap; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--tinta-2); font-weight: 600; background: var(--superficie-2); position: sticky; top: 0; }
td.n, th.n { text-align: right; }
td.quebra { white-space: normal; min-width: 220px; }
tr:hover td { background: #fbfaf7; }
tr.grupo td { font-weight: 600; }
tr.subtotal td { font-weight: 700; background: #f1f0ec; border-top: 1px solid var(--linha-forte); }
tr.categoria td:first-child { padding-left: 26px; color: var(--tinta-2); }
tr.total td { font-weight: 700; border-top: 2px solid var(--linha-forte); }

/* formulários */
form.inline { display: inline; }
label { display: block; font-size: .82rem; color: var(--tinta-2); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  font: inherit; border: 1px solid var(--linha-forte); border-radius: 7px; padding: 7px 9px; background: #fff;
  color: var(--tinta); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b9d3f3; border-color: var(--azul); }
input[type=checkbox] { width: auto; }
.campos { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.campo-largo { grid-column: 1 / -1; }
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filtros > div { min-width: 130px; }
.filtros input, .filtros select { padding: 6px 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--linha-forte); background: #fff;
  color: var(--tinta); padding: 7px 13px; border-radius: 7px; font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f4f3f0; text-decoration: none; }
.btn.prim { background: var(--azul); color: #fff; border-color: var(--azul); }
.btn.prim:hover { background: var(--azul-escuro); }
.btn.perigo { color: var(--ruim); border-color: #e9b8b3; }
.btn.peq { padding: 3px 9px; font-size: .85rem; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* mensagens e selos */
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.msg.ok { background: var(--bom-fundo); border-color: #b9dcc4; color: #0c4f20; }
.msg.erro { background: var(--ruim-fundo); border-color: #efc1bc; color: #7a1610; }
.msg.aviso { background: var(--aviso-fundo); border-color: #f0d79b; color: #5c3c00; }
.selo { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; border: 1px solid transparent; }
.selo.pago { background: var(--bom-fundo); color: var(--bom); }
.selo.aberto { background: #eef3fb; color: var(--azul-escuro); }
.selo.vencido { background: var(--ruim-fundo); color: var(--ruim); }
.selo.cinza { background: #efeeeb; color: var(--tinta-2); }

.graf { position: relative; height: 260px; }
.graf.alto { height: 320px; }
.legenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--tinta-2); margin-bottom: 6px; }
.legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.vazio { color: var(--tinta-3); padding: 18px 0; text-align: center; }

/* login */
.tela-login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.tela-login .cartao { width: 100%; max-width: 380px; }

/* chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 420px; }
.chat .historico { flex: 1; overflow-y: auto; padding: 6px 4px 16px; }
.bolha { max-width: 860px; padding: 10px 14px; border-radius: 12px; margin: 8px 0; white-space: pre-wrap; }
.bolha.user { background: #2a78d6; color: #fff; margin-left: auto; max-width: 640px; }
.bolha.assistant { background: #fff; border: 1px solid var(--linha); }
.bolha details { margin-top: 8px; font-size: .8rem; color: var(--tinta-2); }
.bolha code { white-space: pre-wrap; font-size: .78rem; }
.chat form { display: flex; gap: 10px; border-top: 1px solid var(--linha); padding-top: 12px; }
.chat textarea { resize: none; height: 54px; }
.sugestoes { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.sugestoes button { font-size: .85rem; }

/* orçamento */
.orc input { width: 96px; padding: 4px 6px; text-align: right; font-size: .88rem; }
.orc td { padding: 3px 4px; }
.orc td.nome { min-width: 240px; white-space: normal; }

@media (max-width: 1100px) {
  .g4, .g6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .lateral { position: static; height: auto; }
  .g2 { grid-template-columns: 1fr; }
  .conteudo { padding: 18px; }
}
@media print {
  .lateral, .filtros, .acoes, .btn { display: none !important; }
  .app { display: block; }
}

/* campo de dinheiro com prefixo R$ */
.campo-moeda { position: relative; display: block; }
.campo-moeda::before {
  content: "R$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--tinta-2); font-size: .9em; pointer-events: none;
}
.campo-moeda input { padding-left: 34px; text-align: right; }

/* linha vencida */
tr.linha-vencida td { background: var(--ruim-fundo); color: #7a1610; }
tr.linha-vencida td a { color: #7a1610; font-weight: 600; }
tr.linha-vencida:hover td { background: #f7dedb; }

/* respostas do chat em Markdown */
.bolha.assistant { white-space: normal; }
.bolha.assistant .md p { margin: 0 0 8px; }
.bolha.assistant .md h3 { margin: 14px 0 6px; font-size: .95rem; color: var(--tinta); }
.bolha.assistant .md h3:first-child { margin-top: 0; }
.bolha.assistant .md ul, .bolha.assistant .md ol { margin: 4px 0 8px 20px; padding: 0; }
.bolha.assistant .md table { width: auto; min-width: 60%; margin: 6px 0 10px; border: 1px solid var(--linha); border-radius: 8px; overflow: hidden; }
.bolha.assistant .md th { position: static; font-size: .74rem; }
.bolha.assistant .md td, .bolha.assistant .md th { padding: 6px 10px; }
.bolha.assistant .md td.n, .bolha.assistant .md th.n { text-align: right; }
.bolha.assistant .md tr.total td { font-weight: 700; background: #f1f0ec; }
.bolha.assistant .md code { background: #f1f0ec; padding: 1px 5px; border-radius: 4px; }
