:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --borda: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --primaria: #256abf;
  --primaria-hover: #1c5cab;
  --primaria-suave: #e3eefb;
  --texto-primaria: #ffffff;
  --positivo: #006300;
  --negativo: #b42f2f;
  --aviso-bg: #fff4d9;
  --aviso-texto: #6b4a00;
  --erro-bg: #fde8e8;
  --ok-bg: #e5f5e5;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --sombra: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --raio: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --borda: #33332f;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #96958c;
    --primaria: #3987e5;
    --primaria-hover: #5598e7;
    --primaria-suave: #1b2a3d;
    --positivo: #4cc04c;
    --negativo: #f07a7a;
    --aviso-bg: #3a2f12;
    --aviso-texto: #f5d27a;
    --erro-bg: #3d1e1e;
    --ok-bg: #1b331b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --sombra: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --borda: #33332f;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #96958c;
  --primaria: #3987e5;
  --primaria-hover: #5598e7;
  --primaria-suave: #1b2a3d;
  --positivo: #4cc04c;
  --negativo: #f07a7a;
  --aviso-bg: #3a2f12;
  --aviso-texto: #f5d27a;
  --erro-bg: #3d1e1e;
  --ok-bg: #1b331b;
  --series-1: #3987e5;
  --series-2: #d95926;
  --sombra: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text-primary); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--primaria); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--text-muted); }
.sec { color: var(--text-secondary); }
.pequeno { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--positivo); }
.neg { color: var(--negativo); }
.oculto, [hidden] { display: none !important; }

/* ---------- formulários ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 0 0 4px; }
.campo { margin-bottom: 14px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--borda); border-radius: 8px; padding: 9px 11px; min-height: 40px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primaria); outline-offset: 1px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; color: var(--text-secondary); font-size: 14px; }
.check input { margin-top: 3px; }
.linha { display: flex; gap: 10px; flex-wrap: wrap; }
.linha > * { flex: 1 1 140px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; min-height: 40px; cursor: pointer; text-decoration: none;
  background: var(--primaria); color: var(--texto-primaria);
}
.btn:hover { background: var(--primaria-hover); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.sec { background: var(--surface-2); color: var(--text-primary); border-color: var(--borda); }
.btn.sec:hover { background: var(--borda); }
.btn.perigo { background: var(--status-critical); color: #fff; }
.btn.link { background: none; color: var(--primaria); padding: 6px 8px; min-height: 0; }
.btn.bloco { width: 100%; }
.btn.mini { padding: 4px 10px; min-height: 30px; font-size: 13px; }

.alerta { border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
.alerta.erro { background: var(--erro-bg); color: var(--text-primary); }
.alerta.ok { background: var(--ok-bg); color: var(--text-primary); }
.alerta.aviso { background: var(--aviso-bg); color: var(--aviso-texto); }

/* ---------- telas de acesso ---------- */
.acesso { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.acesso .caixa { width: 100%; max-width: 400px; }
.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 22px; color: var(--text-primary); text-decoration: none; }
.marca img { width: 32px; height: 32px; }
.cartao { background: var(--surface-1); border: 1px solid var(--borda); border-radius: var(--raio); padding: 22px; box-shadow: var(--sombra); }
.cartao h1 { margin-bottom: 6px; }
.cartao > p.sec { margin: 0 0 18px; }
.rodape-acesso { text-align: center; margin-top: 16px; font-size: 14px; color: var(--text-secondary); }
.senha-wrap { position: relative; }
.senha-wrap input { padding-right: 70px; }
.senha-wrap button { position: absolute; right: 4px; top: 4px; bottom: 4px; border: 0; background: none; color: var(--primaria); font: inherit; font-size: 13px; cursor: pointer; padding: 0 10px; }

/* ---------- app ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.lateral { background: var(--surface-1); border-right: 1px solid var(--borda); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.lateral .marca { padding: 0 8px; margin-bottom: 20px; font-size: 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text-secondary); text-decoration: none; font-weight: 500; }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a.ativo { background: var(--primaria-suave); color: var(--primaria); }
.lateral .usuario { margin-top: auto; padding: 10px; border-top: 1px solid var(--borda); font-size: 13px; }
.lateral .usuario strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.principal { padding: 22px 28px 40px; min-width: 0; max-width: 1200px; }
.topo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topo h1 { margin-right: auto; }
.seletor-mes { display: inline-flex; align-items: center; gap: 2px; background: var(--surface-1); border: 1px solid var(--borda); border-radius: 8px; }
.seletor-mes button { border: 0; background: none; color: var(--text-secondary); font-size: 18px; width: 36px; height: 38px; cursor: pointer; border-radius: 8px; }
.seletor-mes button:hover { background: var(--surface-2); }
.seletor-mes span { min-width: 128px; text-align: center; font-weight: 600; }

.grade { display: grid; gap: 14px; }
.grade.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
.grade.duas { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.painel { background: var(--surface-1); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px 18px; box-shadow: var(--sombra); min-width: 0; }
.painel > h2 { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.painel > h2 .acao { margin-left: auto; font-size: 13px; font-weight: 500; }
.kpi .rotulo { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.kpi .valor { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .det { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.vazio { text-align: center; padding: 28px 12px; color: var(--text-muted); }
.vazio .btn { margin-top: 10px; }

/* listas */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--borda); }
.lista li:last-child { border-bottom: 0; }
.lista .info { flex: 1; min-width: 0; }
.lista .titulo { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista .sub { font-size: 12px; color: var(--text-muted); }
.ponto { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--text-muted); }

/* tabela de lançamentos */
.filtros { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filtros > * { flex: 1 1 150px; max-width: 240px; }
.filtros input[type="search"] { max-width: none; flex: 2 1 200px; }
.totais { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; margin-bottom: 10px; color: var(--text-secondary); }
.totais strong { color: var(--text-primary); }
table.tab { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tab th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; padding: 8px 8px; border-bottom: 1px solid var(--borda); }
table.tab td { padding: 9px 8px; border-bottom: 1px solid var(--borda); vertical-align: middle; }
table.tab tr:last-child td { border-bottom: 0; }
table.tab tbody tr { cursor: pointer; }
table.tab tbody tr:hover td { background: var(--surface-2); }
table.tab .dir { text-align: right; }
.etiqueta { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.selo { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-secondary); vertical-align: middle; }
.selo.pend { background: var(--aviso-bg); color: var(--aviso-texto); }
.desc-cel { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chk-status { border: 1.5px solid var(--borda); background: none; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: transparent; }
.chk-status.ok { background: var(--status-good); border-color: var(--status-good); color: #fff; }
.chk-status svg { width: 13px; height: 13px; }

/* barras de categoria e orçamento */
.barra-cat { margin-bottom: 12px; }
.barra-cat .cab { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 4px; }
.barra-cat .trilho { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.barra-cat .cheio { height: 100%; border-radius: 4px; background: var(--series-1); }
.barra-cat .cheio.alerta-am { background: var(--status-warning); }
.barra-cat .cheio.estouro { background: var(--status-critical); }
.barra-cat .rodape { font-size: 12px; color: var(--text-muted); margin-top: 3px; display: flex; gap: 6px; align-items: center; }

/* gráfico */
.grafico { position: relative; }
.grafico svg { width: 100%; height: auto; display: block; overflow: visible; }
.grafico .eixo { fill: var(--text-muted); font-size: 11px; }
.grafico .grade-l { stroke: var(--borda); stroke-width: 1; }
.legenda { display: flex; gap: 14px; font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.legenda span { display: inline-flex; align-items: center; gap: 6px; }
.legenda i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dica { position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--borda); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 5; }
.dica b { display: block; margin-bottom: 2px; }

/* modal */
.fundo-modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface-1); border-radius: var(--raio); width: 100%; max-width: 520px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.largo { max-width: 860px; }
.modal h2 { margin-bottom: 16px; }
.modal .acoes { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.modal .acoes .esq { margin-right: auto; }
.abas-natureza { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 16px; }
.abas-natureza button { font: inherit; font-weight: 600; padding: 9px; border-radius: 8px; border: 1px solid var(--borda); background: var(--surface-2); color: var(--text-secondary); cursor: pointer; }
.abas-natureza button.ativo[data-n="despesa"] { background: #b42f2f; border-color: #b42f2f; color: #fff; }
.abas-natureza button.ativo[data-n="receita"] { background: #006300; border-color: #006300; color: #fff; }
.abas-natureza button.ativo[data-n="transferencia"] { background: var(--primaria); border-color: var(--primaria); color: #fff; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text-primary); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 100; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: calc(100% - 32px); }

.fab { display: none; }
.cores { display: flex; gap: 6px; flex-wrap: wrap; }
.cores button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.cores button.ativo { border-color: var(--text-primary); }
.codigos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: Consolas, monospace; font-size: 15px; background: var(--surface-2); padding: 12px; border-radius: 8px; margin: 12px 0; }
.qr-2fa { background: #fff; padding: 8px; border-radius: 8px; display: inline-block; }
.secao-config { margin-bottom: 14px; }
.secao-config p { margin: 0 0 12px; }

@media (max-width: 1000px) {
  .grade.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grade.duas { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .lateral { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--borda); z-index: 40; }
  .lateral .marca, .lateral .usuario { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; }
  .nav a.so-desktop { display: none; }
  .principal { padding: 16px 16px 96px; }
  .kpi .valor { font-size: 20px; }
  .tab .col-conta, .tab .col-cat { display: none; }
  .desc-cel { max-width: 160px; }
  .fab { display: flex; position: fixed; right: 16px; bottom: 76px; width: 54px; height: 54px; border-radius: 50%; padding: 0; font-size: 26px; z-index: 41; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
  .topo .btn-novo { display: none; }
  .filtros > * { max-width: none; }
}
