:root {
  --bg: #f5f4fb;
  --card: #ffffff;
  --ink: #1d1b2e;
  --muted: #6b6886;
  --line: #e3e1ef;
  --brand: #5b4bd6;
  --brand-ink: #ffffff;
  --brand-soft: #ece9fd;
  --ok: #157a4a;
  --err-bg: #fdecec;
  --err-ink: #9b1c1c;
  --cbs: #5b4bd6;
  --ibsuf: #0e7c86;
  --ibsmun: #b4610e;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14131c;
    --card: #1d1c29;
    --ink: #ecebf5;
    --muted: #a09db8;
    --line: #2f2d42;
    --brand: #8e81f0;
    --brand-ink: #14131c;
    --brand-soft: #2a2645;
    --ok: #4cc38a;
    --err-bg: #3a1c1f;
    --err-ink: #ffb4b4;
    --cbs: #9d92f3;
    --ibsuf: #4fc3cc;
    --ibsmun: #f0a352;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
.topo {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 20px clamp(16px, 4vw, 40px) 8px;
  max-width: 1180px; margin: 0 auto;
}
.marca { display: flex; gap: 14px; align-items: center; }
.logo {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 22px;
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 14px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.versao { color: var(--muted); font-size: 12px; text-align: right; }

.abas {
  display: flex; gap: 4px; overflow-x: auto;
  max-width: 1180px; margin: 8px auto 0; padding: 0 clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
}
.aba {
  background: none; border: 0; padding: 10px 14px; cursor: pointer; white-space: nowrap;
  color: var(--muted); font: inherit; font-weight: 600; border-bottom: 2px solid transparent;
}
.aba.ativa { color: var(--brand); border-bottom-color: var(--brand); }
main { max-width: 1180px; margin: 0 auto; padding: 18px clamp(16px, 4vw, 40px) 40px; }
.painel { display: none; }
.painel.ativo { display: block; }

.cartao {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.linha-titulo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.linha-titulo h2 { margin: 0; }
.grade3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grade-item { display: grid; grid-template-columns: 90px 1fr 1fr 2fr 1fr 70px 70px; gap: 10px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
input, select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.dica { color: var(--muted); font-size: 12px; font-weight: 400; }

.item { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.item-cab { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

.acoes { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 16px; align-items: center; }
.btn {
  font: inherit; font-weight: 700; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  padding: 9px 18px; border-radius: 9px; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: progress; }
.btn.sec { background: var(--brand-soft); color: var(--brand); }
.btn.link { background: none; border-color: transparent; color: var(--muted); padding: 4px 6px; font-weight: 600; }

.erro { background: var(--err-bg); color: var(--err-ink); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }

.totais { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .rot { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 22px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .det { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.cbs { border-top: 3px solid var(--cbs); }
.kpi.ibsuf { border-top: 3px solid var(--ibsuf); }
.kpi.ibsmun { border-top: 3px solid var(--ibsmun); }
.kpi.total { border-top: 3px solid var(--ink); }

.tabela-rolagem { overflow-x: auto; }
.tabela { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabela th, .tabela td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabela th { font-size: 12px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.tabela .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabela tbody tr:hover { background: var(--brand-soft); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); margin: 1px 2px 1px 0; }

details.memoria { margin-top: 6px; }
details.memoria summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.memoria p { font-size: 13px; margin: 6px 0; color: var(--muted); }
details.json pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  overflow: auto; max-height: 360px; font-size: 12px;
}
.ficha { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin-top: 12px; }
.ficha dt { color: var(--muted); font-size: 13px; }
.ficha dd { margin: 0; font-weight: 600; }
.rodape { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 30px; }
.rodape a { color: var(--brand); }

@media (max-width: 900px) {
  .grade-item { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grade-item .largo { grid-column: 1 / -1; }
  .totais { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .grade3 { grid-template-columns: 1fr; }
  .totais { grid-template-columns: 1fr 1fr; }
  .kpi .val { font-size: 18px; }
}
