/* =============================================================================
   SFP v2 — design system
   Tokens → layout → componentes → Tabulator → utilitários
   ============================================================================= */

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;

  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --surface-3: #eceff5;
  --border: #e2e6ee;
  --border-strong: #c9d0dc;
  --text: #17202e;
  --text-2: #4b5563;
  --muted: #7b8494;
  --brand: #1d3557;
  --brand-2: #2f5f9e;
  --brand-soft: #e5ecf7;
  --accent: #457b9d;
  --receita: #0f9d58;
  --receita-soft: #e3f5ea;
  --despesa: #d6455a;
  --despesa-soft: #fbe7ea;
  --warn: #e0a526;
  --warn-soft: #fff4d6;
  --ok: #0f9d58;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px -4px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 40px -8px rgba(16, 24, 40, .25);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 256px;
  --topbar-h: 78px;
  --focus: 0 0 0 3px rgba(69, 123, 157, .35);
}

[data-theme="dark"] {
  --bg: #0f141c;
  --surface: #161c26;
  --surface-2: #1b2230;
  --surface-3: #222b3b;
  --border: #26303f;
  --border-strong: #36425a;
  --text: #e8edf5;
  --text-2: #b7c0cf;
  --muted: #7f8aa0;
  --brand: #9fc2ee;
  --brand-2: #6fa3e3;
  --brand-soft: #1d2a40;
  --accent: #7fb2d6;
  --receita: #38c172;
  --receita-soft: #12301f;
  --despesa: #f0657a;
  --despesa-soft: #3a1b22;
  --warn: #f3c04d;
  --warn-soft: #3a2f12;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px -4px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 40px -8px rgba(0, 0, 0, .6);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--brand-soft); }
[x-cloak] { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; padding: 18px 14px; display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, #1d3557, #457b9d);
}
.brand-name { font-weight: 700; font-size: 1.05rem; }
.brand-sub { font-size: .72rem; color: var(--muted); margin-top: -2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text-2);
  font-weight: 500; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.ativo { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: .85rem; }
.user-pill { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; font-size: .8rem; }
.user-pill .nome { font-weight: 600; line-height: 1.1; }
.user-pill .papel { color: var(--muted); font-size: .72rem; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: flex-end; gap: 14px;
  padding: 0 26px 11px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
/* título com respiro em cima; as ações descem e se alinham com a linha do subtítulo (pedido do Victor, 01/11/2026) */
.topbar .titulo { display: flex; flex-direction: column; }
.topbar .titulo small { color: var(--muted); font-size: .78rem; }
/* etiquetas no subtítulo (ficha do precatório): esfera, devedor, LOA/RPV, tribunal */
.tags { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: .82rem; font-weight: 600;
       line-height: 1.4; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.tag-federal { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.tag-estadual { background: var(--receita-soft); color: var(--receita); }
.tag-municipal { background: var(--warn-soft); color: #9a6b00; }
.tag-rpv { background: var(--brand-soft); color: var(--brand); }
.tag-loa { background: var(--warn-soft); color: #9a6b00; }
.tag-creditorio { background: transparent; color: var(--muted); border: 1px dashed var(--border-strong); }
.topbar .acoes { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.content { padding: 22px 26px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- grid helpers ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.span-2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px 0; }
.card-h h2 { display: flex; align-items: center; gap: 8px; }
.card-h .sub { color: var(--muted); font-size: .8rem; }
.card-b { padding: 14px 18px 18px; }
.card-b.flush { padding: 0; }

.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.kpi .rot { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .val { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: .78rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kpi .delta b { font-weight: 600; }
.kpi.receita .val { color: var(--receita); }
.kpi.despesa .val { color: var(--despesa); }
.kpi::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: var(--border); }
.kpi.receita::after { background: var(--receita); }
.kpi.despesa::after { background: var(--despesa); }
.kpi.brand::after { background: var(--brand-2); }
.pos { color: var(--receita) !important; }
.neg { color: var(--despesa) !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: .88rem; line-height: 1; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
[data-theme="dark"] .btn-primary { color: #0f141c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { color: var(--despesa); border-color: color-mix(in srgb, var(--despesa) 40%, transparent); }
.btn-danger:hover { background: var(--despesa-soft); }
.btn-sm { padding: 6px 10px; font-size: .8rem; border-radius: 8px; }
.btn-icon { padding: 7px; }

/* cabeçalho de caixa recolhível (ex.: atrasados da carteira) */
.dobra-cab { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; width: 100%;
  padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 8px; }
.dobra-cab:focus-visible { outline: 2px solid var(--brand); outline-offset: 4px; }
.dobra-tit { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.dobra-cab svg { width: 16px; height: 16px; flex: none; color: var(--text-2); transition: transform .15s ease; }
.dobra-cab[aria-expanded="false"] svg { transform: rotate(-90deg); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .78rem; font-weight: 600; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s; font-size: .9rem;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--focus); }
.select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237b8494' stroke-width='2.2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.input-sm, .select-sm { padding: 6px 9px; font-size: .84rem; border-radius: 8px; }
/* o padding simétrico do -sm sobrescrevia o espaço reservado à seta: texto longo
   (ex.: "Setembro/2026") passava por baixo do ícone. */
.select-sm { padding-right: 27px; background-position: right 8px center; }
/* campos de moeda (máscara em app.js): valor alinhado à direita, algarismos de largura fixa */
input[data-moeda] { text-align: right; font-variant-numeric: tabular-nums; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.input-icon .input { padding-left: 32px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand-2); }
.hint { font-size: .78rem; color: var(--muted); }
.erro { color: var(--despesa); font-size: .85rem; }

/* ---------- badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-receita { background: var(--receita-soft); color: var(--receita); }
.badge-despesa { background: var(--despesa-soft); color: var(--despesa); }
.badge-warn { background: var(--warn-soft); color: #9a6b00; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font-size: .8rem; cursor: pointer; }
.chip.ativo { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand); font-weight: 600; }

/* ---------- toolbar / seleção em lote ---------- */
.toolbar { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.toolbar .field { min-width: 140px; }
.toolbar .grow { flex: 1 1 220px; }
.bulkbar {
  position: sticky; bottom: 14px; z-index: 15; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 14px; background: var(--brand); color: #fff; box-shadow: var(--shadow-lg);
}
[data-theme="dark"] .bulkbar { color: #0f141c; }
.bulkbar .btn { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: inherit; }
.bulkbar .btn:hover { background: rgba(255,255,255,.24); }
[data-theme="dark"] .bulkbar .btn { background: rgba(0,0,0,.12); border-color: rgba(0,0,0,.2); }
.bulkbar .n { font-weight: 700; font-size: 1rem; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: 9px 12px; text-align: center; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: var(--topbar-h); z-index: 1; }
.table td.num, .table th.num { font-variant-numeric: tabular-nums; }
/* Regra do Victor (11/09/2026): a 1ª coluna é a referência e fica à esquerda; da 2ª em
   diante, título e valores centralizados. Coluna de seleção (.sel) não é a referência:
   nesse caso a referência é a coluna seguinte. */
.table th:first-child, .table td:first-child,
.table th.sel + th, .table td.sel + td { text-align: left; }
.table td > .row { justify-content: center; }
.table td:first-child > .row, .table td.sel + td > .row { justify-content: flex-start; }
.table tr:hover td { background: var(--surface-2); }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
/* Uma rolagem só: a tabela cresce com a página e o cabeçalho gruda logo abaixo da barra de
   título. Só quem tem a classe .rola (altura limitada, ex.: quadros de meia página) rola por
   dentro — duas barras de rolagem na mesma tela confundiam e escondiam as últimas linhas. */
.table-wrap { overflow: visible; border-radius: 0 0 var(--radius) var(--radius); }
.table-wrap.rola { overflow: auto; max-height: 70vh; }   /* sem overscroll-behavior: no fim da lista a roda volta a rolar a página */
.rola .table th { top: 0; }
.pivot th:first-child, .pivot td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; min-width: 190px; }
.pivot th:first-child { z-index: 3; background: var(--surface-2); }
.pivot tr:hover td:first-child { background: var(--surface-2); }
.pivot td.num { padding: 7px 10px; }
.heat { border-radius: 6px; padding: 2px 6px; display: inline-block; min-width: 96px; text-align: right; white-space: nowrap; }
.pivot td.num a { color: inherit; }
.pivot td.num a:hover { text-decoration: underline; }

.bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--brand-2); }
.bar.ok > i { background: var(--ok); }
.bar.atencao > i { background: var(--warn); }
.bar.estourou > i { background: var(--despesa); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 22, .55); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(2px); }
.modal { width: min(640px, 100%); max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-f { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 18px 18px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: .88rem; box-shadow: var(--shadow-lg); display: flex; gap: 10px; align-items: center; animation: up .18s ease-out; }
.toast.ok { background: var(--receita); color: #fff; }
.toast.erro { background: var(--despesa); color: #fff; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* aviso discreto de dados novos (SFP.conferirDados, app.js): pílula fixa no rodapé, só some por clique */
.dados-novos { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 101; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; border-radius: 999px; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg); font-size: .88rem; max-width: calc(100vw - 32px); animation: up .18s ease-out; }
.dados-novos span { min-width: 0; }   /* em tela estreita o texto quebra; os botões, não */
.dados-novos button { border: 0; border-radius: 999px; padding: 6px 13px; font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; white-space: nowrap; }
[data-theme="dark"] .dados-novos button { color: #0f141c; }
.dados-novos button.fechar { background: transparent; color: var(--muted); padding: 2px 8px; font-size: 1.15rem; line-height: 1; font-weight: 400; }
.dados-novos button.fechar:hover { color: var(--text); }

/* ---------- misc ---------- */
.empty { padding: 30px; text-align: center; color: var(--muted); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; min-height: 18px; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.chart { width: 100%; height: 320px; }
.chart.alto { height: 400px; }
.chart.baixo { height: 240px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: 10px; width: fit-content; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--text-2); font-size: .85rem; }
.tabs button.ativo { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
kbd { font-family: var(--mono); font-size: .72rem; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.list { display: flex; flex-direction: column; }
.list > div { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.list > div:last-child { border-bottom: 0; }
.list .desc { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, var(--brand-soft), transparent), var(--bg); }
.login { width: min(420px, 100%); padding: 34px 32px; }
.login .brand { padding: 0 0 22px; }
/* botão do Google: fundo claro nos dois temas, como pedem as diretrizes da marca */
.btn-google { background: #fff; color: #1f1f1f; border-color: #dadce0; justify-content: center; gap: 10px; padding: 10px 14px; text-decoration: none; }
.btn-google:hover { background: #f8f9fa; text-decoration: none; }
.btn-google.btn-sm { padding: 6px 10px; }
.btn-google svg { width: 18px; height: 18px; }
.ou { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .78rem; }
.ou::before, .ou::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.aviso { color: var(--brand); background: var(--brand-soft); padding: 9px 12px; border-radius: 10px; font-size: .85rem; }

/* ---------- precatórios: trilha, histórico e acompanhamento ---------- */
.trilha { display: flex; align-items: flex-start; }
.trilha .passo { flex: 1; text-align: center; position: relative; font-size: .74rem; color: var(--muted); padding: 0 4px; line-height: 1.25; }
.trilha .passo .d { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); margin: 0 auto 6px; position: relative; z-index: 1; }
.trilha .passo:not(:last-child)::after { content: ""; position: absolute; top: 6px; left: 50%; width: 100%; height: 2px; background: var(--border); }
.trilha .passo.ok { color: var(--text-2); }
.trilha .passo.ok .d { background: var(--text-2); border-color: var(--text-2); }
.trilha .passo.ok::after { background: var(--text-2); }
.trilha .passo.atual { color: var(--brand-2); font-weight: 600; }
.trilha .passo.atual .d { background: var(--brand-2); border-color: var(--brand-2); box-shadow: 0 0 0 4px var(--brand-soft); }
.trilha .passo .dt { font-weight: 400; color: var(--muted); font-size: .7rem; min-height: 1.1em; margin-top: 2px; }
.trilha .passo.clicavel { cursor: pointer; }
.trilha .passo.clicavel:hover .d { border-color: var(--brand-2); }
.texto { white-space: pre-wrap; line-height: 1.55; overflow-wrap: anywhere; }
/* histórico: colunas fixas (data · tipo · texto · ✕) — o texto fica sempre ao lado da etiqueta e quebra na própria coluna */
.hist { display: flex; flex-direction: column; }
.hist .hitem { display: grid; grid-template-columns: 82px 64px minmax(0, 1fr) auto; column-gap: 12px; align-items: start;
               padding: 9px 0; border-bottom: 1px solid var(--border); }
.hist .hitem.simples { grid-template-columns: 82px minmax(0, 1fr); }
.hist .hitem:last-child { border-bottom: 0; }
.hist .hdata { color: var(--muted); font-size: .8rem; padding-top: 2px; }
.hist .htipo { padding-top: 1px; }
.hist .hcorpo { min-width: 0; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.hist .hcorpo .texto { flex: 1 1 100%; white-space: pre-line; overflow-wrap: anywhere; }   /* o texto ocupa a linha; etapa, Id. e link vêm sempre na linha de baixo */
.hist .badge-etapa { background: var(--receita-soft); color: var(--receita); }
.hist .t-litigio .badge { background: var(--despesa-soft); color: var(--despesa); }
.hist .t-leitura .badge { background: var(--brand-soft); color: var(--brand); }
.hist .t-etapa .badge { background: var(--receita-soft); color: var(--receita); }
.chk { width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--border-strong); background: var(--surface); cursor: pointer; flex: none; margin-top: 3px; padding: 0; }
.chk:hover { border-color: var(--brand-2); background: var(--brand-soft); }
.chk:disabled { cursor: default; opacity: .5; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; font-size: .84rem; }
.kv > span:nth-child(odd) { color: var(--muted); white-space: nowrap; }
.kv > span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.faixa { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.faixa .et { padding: 10px 8px; text-align: center; color: inherit; text-decoration: none; display: block; }
.faixa .et:hover { text-decoration: none; border-color: var(--brand-2); }
.faixa .et .n { font-size: .74rem; color: var(--text-2); font-weight: 600; min-height: 2.3em; }
.faixa .et .q { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.faixa .et .v { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.faixa .et.vazia { opacity: .55; }
.faixa .et.alerta { border-color: var(--warn); background: var(--warn-soft); }
.faixa .et.apagada { opacity: .4; }

/* ---------- caixa: os três filtros de caixa ---------- */
.filtros-caixa { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.filtros-caixa .filtro { appearance: none; text-align: left; padding: 14px 16px; cursor: pointer; font: inherit; color: inherit;
  display: flex; flex-direction: column; justify-content: center; gap: 4px; position: relative; overflow: hidden; min-height: 108px; }
.filtros-caixa .filtro .n { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.filtros-caixa .filtro .q { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.filtros-caixa .filtro .v { font-size: .78rem; color: var(--text-2); }
.filtros-caixa .filtro::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: var(--border); }
.filtros-caixa .f-proxima::after { background: var(--receita); }
.filtros-caixa .f-regular::after { background: var(--brand-2); }
.filtros-caixa .f-risco::after { background: var(--despesa); }
.filtros-caixa .filtro:hover { border-color: var(--brand-2); }
.filtros-caixa .filtro.ativo { border-color: var(--brand-2); background: var(--brand-soft); }
.filtros-caixa .filtro:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* caixinhas das classes: conteúdo centrado na vertical, sem a altura mínima reservada ao nome */
.faixa.classes .et { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; min-height: 92px; }
.faixa.classes .et .n { min-height: 0; }
.dobra-cab .dobra-tit b { line-height: 1.2; }
.dobra-cab .badge { vertical-align: middle; }
/* blocos recolhíveis do financeiro: sem corpo visível, o cabeçalho precisa de folga igual em cima e embaixo */
.card[id^=cx-] .card-h { padding: 13px 18px; }
.card[id^=cx-] .card-b { border-top: 1px solid var(--border); }
.table tr.grupo td { background: var(--surface-2); text-align: left; font-weight: 600; }
.bloco-form { padding: 12px; border: 1px dashed var(--border-strong); border-radius: 10px; margin-bottom: 12px; }

/* ---------- importar: contas e cartões (com envio de arquivo no canto), histórico, regras ---------- */
.card.solta { position: relative; }
.card.solta.arrastando { border-color: var(--brand-2); }
.solte { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed var(--brand-2); border-radius: var(--radius); font-weight: 600; color: var(--brand);
  background: color-mix(in srgb, var(--brand-soft) 88%, transparent); pointer-events: none; }
.solte svg { width: 22px; height: 22px; }
/* faixa única: os grupos (contas | cartões) dividem a largura na proporção do nº de itens
   (flex-grow vem do template); dentro, uma grade de colunas iguais — chip solitário na 2ª
   linha fica do mesmo tamanho dos outros, nunca esticado */
.faixa-fontes { display: flex; align-items: flex-start; container: faixa / inline-size; }
.faixa-fontes .grupo { flex: 1 1 0%; min-width: 0; }   /* base 0: a divisão é exatamente proporcional ao nº de itens */
.faixa-fontes .grupo.lado { border-left: 1px solid var(--border); margin-left: 14px; padding-left: 14px; }
.faixa-fontes .rot { color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; }
.fonte-card .linha2 { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
.fonte-card .linha2 > b { white-space: nowrap; }
.fonte-card .badge { flex: none; padding: 1px 6px; font-size: .66rem; }
/* faixa estreita (tela menor ou zoom): abaixo de ~1360 px os chips não comportam data e selo
   na mesma linha; o selo desce para a 3ª linha em TODOS os chips ao mesmo tempo (a medida é
   a da faixa, não a de cada chip, para os dois grupos mudarem juntos) */
@container faixa (max-width: 1360px) {
  .fonte-card { align-items: center; text-align: center; }
  .fonte-card .nome { justify-content: center; max-width: 100%; }
  .fonte-card .linha2 { flex-direction: column; align-items: center; gap: 3px; }
}
/* cada conta/cartão com a cor da instituição em tom bem claro (--tint vem do JS) */
.fonte-card { --tint: var(--brand-2); padding: 8px 9px; border-radius: 10px; min-width: 0; max-width: 200px; display: flex; flex-direction: column; gap: 4px;
  border: 1px solid color-mix(in srgb, var(--tint) 32%, var(--border)); background: color-mix(in srgb, var(--tint) 12%, var(--surface)); }
.badge.acao { border: 0; cursor: pointer; font-family: inherit; line-height: 1.5; }
.badge.acao:hover { filter: brightness(.94); }
[data-theme="dark"] .fonte-card { background: color-mix(in srgb, var(--tint) 20%, var(--surface)); }
.fonte-card .nome { display: flex; align-items: center; gap: 6px; min-width: 0; }
.fonte-card .nome i { width: 8px; height: 8px; border-radius: 50%; background: var(--tint); flex: none; }
.fonte-card .nome b { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ver-mais { display: block; width: 100%; padding: 9px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--brand-2); font-weight: 600; font-size: .8rem; cursor: pointer; border-radius: 0 0 var(--radius) var(--radius); }
.ver-mais:hover { background: var(--surface-2); }
/* Tela estreita (meia janela, notebook pequeno, celular): a tabela larga rola de lado DENTRO do quadro,
   em vez de vazar do cartão e arrastar a página inteira. Com o quadro rolando, o cabeçalho passa a
   grudar no topo do próprio quadro: sem o top:0 ele descia a altura da barra de título e cobria a
   primeira linha (medido em 12/11/2026). Acima de 1240 px nada muda: uma rolagem só e cabeçalho
   preso sob a barra de título. */
@media (max-width: 1240px) {
  .table-wrap { overflow-x: auto; }
  .table-wrap .table th { top: 0; }
  /* barra de título com muitos botões (Carteira de precatórios): a fila de ações encolhe e rola por
     dentro, em vez de empurrar a página para o lado */
  .topbar .acoes { min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 4px 2px; margin-bottom: -4px; }
  .topbar .acoes::-webkit-scrollbar { display: none; }
  .topbar .acoes > * { flex: none; }
}
@media (max-width: 860px) {
  .faixa-fontes { flex-direction: column; gap: 14px; }
  .faixa-fontes .grupo.lado { border-left: 0; margin-left: 0; padding-left: 0; border-top: 1px solid var(--border); padding-top: 14px; }
  .chips { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .fonte-card { max-width: none; }
}
@media (max-width: 720px) {
  .trilha { flex-wrap: wrap; }
  .trilha .passo { flex: 1 0 33%; margin-bottom: 10px; }
  .trilha .passo::after { display: none; }
  .hist .hdata { width: 66px; }
}

/* ---------- Tabulator theme ---------- */
.tabulator { border: 0; background: transparent; font-size: .87rem; font-family: var(--font); }
.tabulator .tabulator-header { background: var(--surface-2); border-bottom: 1px solid var(--border); color: var(--muted); }
.tabulator .tabulator-header .tabulator-col { background: transparent; border-right: 1px solid var(--border); }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 8px 10px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover { background: var(--surface-3); }
.tabulator .tabulator-header .tabulator-header-filter input, .tabulator .tabulator-header .tabulator-header-filter select {
  padding: 5px 7px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: .8rem; width: 100%;
}
.tabulator .tabulator-tableholder { background: var(--surface); }
.tabulator .tabulator-row { background: var(--surface); border-bottom: 1px solid var(--border); color: var(--text); min-height: 38px; }
.tabulator .tabulator-row.tabulator-row-even { background: var(--surface); }
.tabulator .tabulator-row:hover { background: var(--surface-2) !important; }
.tabulator .tabulator-row.tabulator-selected { background: var(--brand-soft) !important; }
.tabulator .tabulator-row .tabulator-cell { padding: 8px 10px; border-right: 1px solid var(--border); }
.tabulator .tabulator-row .tabulator-cell.tabulator-editing { border: 1px solid var(--accent); box-shadow: var(--focus); padding: 0 8px; }
.tabulator .tabulator-row .tabulator-cell.tabulator-editing input, .tabulator .tabulator-row .tabulator-cell.tabulator-editing select { background: var(--surface); color: var(--text); border: 0; outline: 0; font-size: .87rem; }
.tabulator .tabulator-footer { background: var(--surface-2); border-top: 1px solid var(--border); color: var(--text-2); padding: 6px 10px; }
.tabulator .tabulator-footer .tabulator-page { background: var(--surface); border-color: var(--border-strong); color: var(--text); border-radius: 7px; }
.tabulator .tabulator-footer .tabulator-page.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabulator .tabulator-footer .tabulator-page-size { background: var(--surface); color: var(--text); border-color: var(--border-strong); border-radius: 7px; }
.tabulator-edit-list { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-lg); color: var(--text); font-family: var(--font); font-size: .86rem; }
.tabulator-edit-list .tabulator-edit-list-item { padding: 6px 10px; }
.tabulator-edit-list .tabulator-edit-list-item.active, .tabulator-edit-list .tabulator-edit-list-item:hover { background: var(--brand-soft); color: var(--brand); }
.tabulator-edit-list .tabulator-edit-list-group { background: var(--surface-2); color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; padding: 6px 10px; }
.tabulator .tabulator-cell .cat { display: inline-flex; align-items: center; gap: 6px; }
.tabulator .tabulator-cell .cat i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.tabulator .tabulator-cell input[type="checkbox"] { accent-color: var(--brand-2); width: 15px; height: 15px; }
.tabulator .tabulator-header input[type="checkbox"] { accent-color: var(--brand-2); width: 15px; height: 15px; }
.tabulator .tabulator-row .tabulator-cell.valor { font-variant-numeric: tabular-nums; font-weight: 600; }
.tabulator-tooltip { background: var(--text); color: var(--bg); border-radius: 8px; padding: 6px 10px; font-size: .8rem; }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  :root { --topbar-h: 54px; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; align-items: center; gap: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border); z-index: 30; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
  }
  .sidebar .brand, .sidebar-footer { display: none; }
  /* são 12 itens: precisam rolar na horizontal em vez de se espremer */
  .nav {
    display: flex; width: 100%; justify-content: flex-start;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;      /* rolagem com inércia no iOS */
    overscroll-behavior-x: contain;         /* não arrasta a página junto */
    scroll-snap-type: x proximity;
    scrollbar-width: none;                  /* Firefox */
    gap: 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    flex: 0 0 auto; min-width: 62px; scroll-snap-align: center;
    flex-direction: column; gap: 3px; padding: 6px 4px; font-size: .64rem; font-weight: 600; border-radius: 10px;
  }
  .nav a.ativo { background: transparent; }
  .nav svg { width: 20px; height: 20px; }
  .topbar { padding: 0 14px; align-items: center; }      /* no celular o subtítulo some: volta a centrar */
  .topbar .titulo { min-width: 0; }
  /* títulos longos (nome do credor na página do precatório) não podem empurrar a barra */
  .topbar .titulo h1 { font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .titulo small { display: none; }
  .content { padding: 14px 14px calc(90px + env(safe-area-inset-bottom)); gap: 14px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .kpi .val { font-size: 1.3rem; }
  .chart { height: 260px; }
  .bulkbar { bottom: calc(78px + env(safe-area-inset-bottom)); }
  .modal-f { flex-wrap: wrap; }
}
@media print {
  .sidebar, .topbar .acoes, .bulkbar, .toasts, .dados-novos { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* página do cartão: fita de faturas (uma por mês de vencimento) e a folha da fatura */
/* fita de meses: sempre proporcional — 12 numa linha quando cabe, senão 6 por linha, 4 em quadro estreito
   e 3 no celular (pedido do Victor, 12/11/2026: 10 em cima e 1 embaixo ficava torto) */
.fita-caixa { container: fita / inline-size; }
.fita-faturas { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
@container fita (min-width: 1320px) { .fita-faturas { grid-template-columns: repeat(12, minmax(0, 1fr)); } }
@container fita (max-width: 700px) { .fita-faturas { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@container fita (max-width: 440px) { .fita-faturas { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.fita-faturas .mes { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 76px; padding: 8px 6px; font: inherit; color: inherit; text-align: center; box-shadow: none; }
.fita-faturas button.mes { cursor: pointer; }
.fita-faturas button.mes:hover { border-color: var(--brand-2); }
.fita-faturas .mes .n { font-size: .76rem; font-weight: 600; color: var(--text-2); }
.fita-faturas .mes .v { font-size: .9rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fita-faturas .mes .s { font-size: .7rem; color: var(--muted); }
.fita-faturas .mes.ativo { border-color: var(--brand-2); background: var(--brand-soft); }
.fita-faturas .mes.vazia { opacity: .55; }
.fatura { width: 100%; }      /* mesma largura dos outros quadros da página */
.fatura-cab { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 22px 24px 16px; border-bottom: 3px solid var(--brand-2); }
.fatura-cab .emissor { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fatura-cab h2 { font-size: 1.45rem; margin: 2px 0 8px; }
.fatura-cab .total { text-align: right; margin-left: auto; }
.fatura-cab .total .val { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.fatura-dados { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.fatura-dados > div { padding: 11px 24px; }
.fatura-dados .rot { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.fatura-dados .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.fatura-sec { padding: 18px 24px 10px; }
.fatura h3 { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); margin: 0 0 8px; }
.fatura-resumo .linha { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.fatura-resumo .linha.total { border-bottom: 0; border-top: 2px solid var(--border-strong); margin-top: 4px; font-weight: 700; font-size: 1.05rem; }
.fatura-cats .cat { margin-bottom: 9px; }
.fatura-cats .cat .bar { margin-top: 4px; height: 6px; }
.fatura .table-wrap { border-radius: 0; }
.fatura-rodape { padding: 14px 24px 20px; }
@media (max-width: 860px) {
  .fatura-cab, .fatura-sec, .fatura-rodape { padding-left: 16px; padding-right: 16px; }
  .fatura-dados > div { padding: 10px 16px; }
  .fatura-cab .total { text-align: left; margin-left: 0; }
}
@media print {
  .so-tela { display: none !important; }
  .fatura { max-width: none; border: 0; }
}

/* compromissos: valor do mês clicável na própria linha */
.valor-mes { background: none; border: 0; border-bottom: 1px dashed var(--border-strong); padding: 0 0 1px; font: inherit; font-variant-numeric: tabular-nums; color: inherit; cursor: pointer; }
.valor-mes:hover { color: var(--brand-2); border-bottom-color: var(--brand-2); }
.valor-mes.vazio { color: var(--muted); }

/* categoria × mês (Receitas e Despesas): rola de lado dentro do cartão; o cabeçalho dos meses é um quadro
   próprio, preso sob a barra do topo, que acompanha a rolagem do corpo (analise.js) */
.pivot.fixa { table-layout: fixed; }
.pivot-cab { position: sticky; top: var(--topbar-h); z-index: 4; overflow: hidden; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.pivot-cab .table th { top: auto; border-bottom: 0; }
.pivot-corpo { overflow-x: auto; }
.heat.credito { background: var(--receita-soft); color: var(--receita); }
