:root {
  --bg: #f4f7f6; --surface: #fff; --ink: #14272b; --muted: #5d7276; --line: #dbe5e3;
  --brand: #0f766e; --brand-ink: #fff; --brand-soft: #d9f2ee;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe;
  --radius: 12px; --shadow: 0 1px 2px rgba(20, 39, 43, .06), 0 4px 14px rgba(20, 39, 43, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1819; --surface: #152427; --ink: #e8f1f0; --muted: #94aaad; --line: #25393c;
    --brand: #2dd4bf; --brand-ink: #062a27; --brand-soft: #123532;
    --ok: #4ade80; --ok-soft: #123222; --warn: #fbbf24; --warn-soft: #3a2c0b;
    --bad: #f87171; --bad-soft: #3b1717; --info: #7aa7ff; --info-soft: #14233f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; padding: .25rem .5rem 1rem; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; }
.nav a { display: flex; gap: .6rem; align-items: center; padding: .6rem .75rem; border-radius: 9px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--bg); }
.nav a.ativo { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .ico { width: 1.25rem; text-align: center; }
.side .rodape { margin-top: 1.5rem; padding: .75rem; border-top: 1px solid var(--line); }
.main { padding: 1.5rem; max-width: 1180px; width: 100%; }
.btn.menu-btn { display: none; }
.topo { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.acoes { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.aberto { transform: none; }
  .btn.menu-btn { display: inline-flex; margin-bottom: 1rem; }
  .main { padding: 1rem; }
}

/* componentes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.kpi .valor { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.kpi .rotulo { color: var(--muted); font-size: .85rem; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 9px; padding: .5rem .9rem; font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; }
.btn:hover { border-color: var(--brand); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
.btn.primario { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.perigo { color: var(--bad); }
.btn.mini { padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.aviso { background: var(--warn-soft); color: var(--warn); }
.badge.perigo { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.alerta { padding: .7rem .9rem; border-radius: 10px; margin-bottom: .6rem; display: flex; gap: .6rem; align-items: flex-start; justify-content: space-between; border: 1px solid transparent; }
.alerta.info { background: var(--info-soft); color: var(--info); }
.alerta.aviso { background: var(--warn-soft); color: var(--warn); }
.alerta.perigo { background: var(--bad-soft); color: var(--bad); }
.alerta.ok { background: var(--ok-soft); color: var(--ok); }
.alerta a { color: inherit; font-weight: 600; white-space: nowrap; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabela-scroll { overflow-x: auto; }
.receita { color: var(--ok); }
.despesa { color: var(--bad); }
.vazio { padding: 2rem 1rem; text-align: center; color: var(--muted); }

.progresso { height: 12px; border-radius: 999px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.progresso > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.progresso.atencao > i { background: var(--warn); }
.progresso.excedido > i { background: var(--bad); }

/* formulários */
label.campo { display: block; margin-bottom: .8rem; font-size: .88rem; font-weight: 600; }
label.campo > span.dica { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
input, select, textarea { width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 9px; font: inherit; background: var(--surface); color: var(--ink); margin-top: .25rem; }
input[type=checkbox] { width: auto; margin: 0 .5rem 0 0; }
label.check { display: flex; align-items: center; font-weight: 600; font-size: .88rem; margin-bottom: .8rem; }
.linha2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.filtros { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: end; }
.filtros label { font-size: .8rem; color: var(--muted); }
.filtros input, .filtros select { width: auto; min-width: 130px; }
@media (max-width: 520px) { .linha2 { grid-template-columns: 1fr; } }

/* modal e toast */
.overlay { position: fixed; inset: 0; background: rgba(8, 20, 22, .55); display: grid; place-items: center; padding: 1rem; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: min(560px, 100%); max-height: 92vh; overflow-y: auto; padding: 1.25rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.largo { width: min(820px, 100%); }
.modal .rodape-modal { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 60; }
.toast { background: var(--ink); color: var(--bg); padding: .65rem .95rem; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; }
.toast.erro { background: var(--bad); color: #fff; }

/* login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: min(430px, 100%); padding: 1.6rem; }
.auth .brand { justify-content: center; padding-bottom: .5rem; }

/* gráfico */
.grafico { width: 100%; height: auto; display: block; }
.grafico .barra { fill: var(--brand); }
.grafico .barra.servicos { fill: var(--info); }
.grafico .eixo { stroke: var(--line); }
.grafico text { fill: var(--muted); font-size: 11px; }
.grafico .limite { stroke: var(--bad); stroke-dasharray: 4 3; }
.legenda { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; background: var(--brand); }
.legenda i.s { background: var(--info); }

/* calendário */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: .75rem; color: var(--muted); text-align: center; padding: .25rem; }
.cal .dia { min-height: 82px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .3rem; font-size: .8rem; overflow: hidden; }
.cal .dia.fora { background: transparent; border-color: transparent; }
.cal .dia.hoje { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cal .ev { display: block; border-radius: 5px; padding: 1px 5px; margin-top: 2px; font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--bg); }
.cal .ev.das, .cal .ev.dasn, .cal .ev.a_pagar { background: var(--bad-soft); color: var(--bad); }
.cal .ev.a_receber { background: var(--ok-soft); color: var(--ok); }
.cal .ev.lembrete { background: var(--info-soft); color: var(--info); }
.cal .ev.feito { text-decoration: line-through; opacity: .6; }
@media (max-width: 640px) { .cal .dia { min-height: 56px; } .cal .ev { font-size: .65rem; } }

/* relatório imprimível */
.relatorio { background: #fff; color: #111; padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--line); }
.relatorio table td, .relatorio table th { border-color: #ccc; color: #111; }
.relatorio .total td { font-weight: 700; background: #f1f1f1; }
@media print {
  body { background: #fff; }
  .side, .topo, .acoes, .menu-btn, #toasts, .nao-imprimir { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  .relatorio { border: 0; padding: 0; }
}
