/* Dona Jurema — UI mobile-first */
:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e6e8ef;
  --zebra-a: #ffffff;
  --zebra-b: #eaeefb;
  --text: #1a1d29;
  --text-dim: #626777;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-soft: #eef0fe;
  --ok: #0f9d58;
  --ok-soft: #e6f4ec;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --danger: #d64545;
  --danger-soft: #fbe9e9;
  --info: #2563eb;
  /* Paleta dos botões (um papel = uma cor, em todas as telas):
     principal = azul (--primary) · editar = verde · excluir = vermelho · atenção (estornar/cancelar) = âmbar · consultar/abrir = ciano */
  --c-edit: #0b8043;   --c-edit-soft: #e6f4ec;   --c-edit-ink: #0b6b39;
  --c-warn: #b45309;   --c-warn-soft: #fbf0dc;   --c-warn-ink: #92400e;
  --c-info: #0e7490;   --c-info-soft: #e0f2f7;   --c-info-ink: #0b5e74;
  --c-danger-ink: #b42323;
  --shadow: 0 1px 2px rgba(20, 22, 40, .06), 0 8px 24px rgba(20, 22, 40, .06);
  --radius: 14px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1e222d;
    --border: #2a2f3d;
    --zebra-a: #171a23;
    --zebra-b: #242a3c;
    --text: #eceef5;
    --text-dim: #9aa1b2;
    --primary: #7c78f0;
    --primary-soft: #24263a;
    --ok-soft: #17301f;
    --warn-soft: #322709;
    --danger-soft: #331a1a;
    --c-edit: #12805a;   --c-edit-soft: #17301f;   --c-edit-ink: #6fd39a;
    --c-warn: #b45309;   --c-warn-soft: #322709;   --c-warn-ink: #f0b866;
    --c-info: #0e7490;   --c-info-soft: #12303a;   --c-info-ink: #67d0e6;
    --c-danger-ink: #ff8f8f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--primary);
  color: var(--primary-ink); display: grid; place-items: center; font-size: 15px; font-weight: 800;
}
.login-card h1 { font-size: 20px; margin: 18px 0 4px; }
.login-card p.sub { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }

/* ---------- Autocadastro público (sem login) ---------- */
.public-page { min-height: 100dvh; padding: 24px 16px 48px; display: flex; justify-content: center; }
.public-card { width: 100%; max-width: 560px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 13px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent;
}
.field textarea { resize: vertical; min-height: 72px; }
.hint, .field .hint { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.field .hint.err { color: var(--danger); }
.field input.invalid { border-color: var(--danger); }
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 42px; width: 100%; }
.pwd-toggle {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1;
  padding: 8px; color: var(--text-dim);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border: 1px solid transparent; border-radius: 10px;
  background: var(--primary); color: var(--primary-ink); font-weight: 600;
  cursor: pointer; width: 100%; min-height: 46px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--primary); border-color: transparent; }
.btn.danger { background: var(--danger); }
.btn.edit { background: var(--c-edit); }
.btn.warn { background: var(--c-warn); }
.btn.info { background: var(--c-info); }
/* .soft = mesma cor do papel, versão leve (fundo claro) para ações dentro de listas/linhas */
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.soft.edit { background: var(--c-edit-soft); color: var(--c-edit-ink); }
.btn.soft.warn { background: var(--c-warn-soft); color: var(--c-warn-ink); }
.btn.soft.info { background: var(--c-info-soft); color: var(--c-info-ink); }
.btn.soft.danger { background: var(--danger-soft); color: var(--c-danger-ink); }
.btn.sm { width: auto; min-height: 38px; padding: 8px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }
/* Fileira com muitos botões (detalhe do empréstimo): quebra linha em vez de esticar a página no celular. */
.btn-row.wrap { flex-wrap: wrap; }
.btn-row.wrap .btn { flex: 1 1 auto; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--border); flex: 1; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.aviso { background: var(--warn-soft); color: var(--warn); }

/* ---------- App shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 17px; font-weight: 700; flex: 1; }
.topbar .who { font-size: 12px; color: var(--text-dim); text-align: right; line-height: 1.3; }
.topbar .who b { display: block; color: var(--text); font-size: 13px; }

.layout { flex: 1; display: flex; }
.sidebar { display: none; }
.content { flex: 1; padding: 16px; padding-bottom: calc(var(--nav-h) + 24px); max-width: 960px; margin: 0 auto; width: 100%; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottomnav button {
  flex: 1; background: none; border: 0; cursor: pointer; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-dim); font-size: 10.5px; min-height: var(--nav-h);
}
.bottomnav button .ic { font-size: 19px; line-height: 1; }
.bottomnav button.active { color: var(--primary); }

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.section-title { font-size: 13px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin: 4px 2px 10px; }
.page-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--text-dim); }
.stat .value { font-size: 22px; font-weight: 800; margin-top: 4px; }
.stat .value.small { font-size: 16px; }

.list-toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.list-toolbar input[type=search] {
  flex: 1; min-width: 160px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface);
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.chip {
  white-space: nowrap; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); font-size: 12.5px; cursor: pointer;
}
.chip.active { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 600; }

.row-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow);
}
.row-item .main { flex: 1; min-width: 0; }
.row-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item .meta { font-size: 12.5px; color: var(--text-dim); }
.row-item .amount { font-weight: 700; white-space: nowrap; text-align: right; }
.row-item .amount small { display: block; font-size: 11px; font-weight: 500; color: var(--text-dim); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 14px; object-fit: cover;
}

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.ativo, .badge.pago { background: var(--ok-soft); color: var(--ok); }
.badge.pendente { background: var(--surface-2); color: var(--text-dim); }
.badge.atrasado, .badge.inadimplente, .badge.cancelado { background: var(--danger-soft); color: var(--danger); }
.badge.quitado { background: var(--primary-soft); color: var(--primary); }
.badge.renegociado, .badge.cancelada { background: var(--c-info-soft); color: var(--c-info-ink); }
.badge.aviso, .badge.parcial { background: var(--warn-soft); color: var(--warn); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-dim); }
.kv .v { font-weight: 600; text-align: right; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid th { color: var(--text-dim); font-size: 11px; text-transform: uppercase; }
/* Parcelas do empréstimo: tabela no computador; no celular cada parcela vira um cartão (sem rolagem lateral). */
.acoes-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
table.parcelas td.c-acoes:empty { padding: 0; }
@media (max-width: 640px) {
  .table-scroll:has(table.parcelas) { overflow-x: visible; }
  table.parcelas, table.parcelas tbody { display: block; width: 100%; }
  table.parcelas thead { display: none; }
  table.parcelas tr {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; margin-bottom: 10px;
  }
  table.parcelas td { display: block; padding: 0; border: none; white-space: normal; text-align: left; }
  table.parcelas td.c-num { grid-column: 1; grid-row: 1; font-weight: 700; font-size: 15px; }
  table.parcelas td.c-num::before { content: 'Parcela '; font-weight: 700; }
  table.parcelas td.c-num > div { display: inline-block; margin-left: 6px; }
  table.parcelas td.c-status { grid-column: 2; grid-row: 1; justify-self: end; }
  table.parcelas td.c-venc, table.parcelas td.c-valor, table.parcelas td.c-pago {
    grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    padding-top: 6px; border-top: 1px solid var(--border);
  }
  table.parcelas td.c-venc::before, table.parcelas td.c-valor::before, table.parcelas td.c-pago::before {
    content: attr(data-label); color: var(--text-dim); font-size: 12px; flex: none;
  }
  table.parcelas td .cv { text-align: right; }
  table.parcelas td.c-acoes { grid-column: 1 / -1; padding-top: 8px; border-top: 1px solid var(--border); }
  table.parcelas td.c-acoes:empty { display: none; }
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px); z-index: 25;
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: var(--primary-ink); font-size: 26px;
  box-shadow: 0 6px 20px rgba(79, 70, 229, .4);
}

.empty { text-align: center; color: var(--text-dim); padding: 40px 16px; font-size: 14px; }
.loading { text-align: center; color: var(--text-dim); padding: 30px; }

/* ---------- Modal / sheet ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10, 12, 24, .45); display: flex; align-items: flex-end; justify-content: center; }
.photo-overlay { align-items: center; padding: 24px; cursor: zoom-out; }
.photo-overlay img { max-width: 92vw; max-height: 92vh; border-radius: 12px; object-fit: contain; box-shadow: var(--shadow); }
.map-overlay { align-items: center; padding: 24px; }
.map-overlay .map-big-wrap { position: relative; width: 100%; max-width: 560px; }
.map-overlay .map-big { width: 100%; height: 70dvh; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); isolation: isolate; }
.overlay-close {
  position: absolute; top: -14px; right: -14px; width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 17px; line-height: 1; cursor: pointer; box-shadow: var(--shadow);
}
.map-mini { cursor: pointer; }

/* Documento aberto em modal (imagem ou PDF), no lugar de abrir aba nova. */
.overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.overlay-actions .btn { width: auto; min-width: 140px; text-decoration: none; }
.photo-wrap { position: relative; max-width: 92vw; display: flex; flex-direction: column; align-items: center; }
.photo-overlay img { max-height: calc(92vh - 60px); }
.doc-overlay img { max-height: calc(90dvh - 60px); }
.pdf-card { background: var(--surface); border-radius: 14px; padding: 28px 20px 18px; text-align: center; max-width: 380px; }
.pdf-icone { font-size: 44px; line-height: 1; }
.pdf-nome { margin-top: 8px; font-weight: 600; word-break: break-all; }
.doc-overlay { align-items: center; padding: 24px; }
.doc-overlay .doc-big-wrap { position: relative; width: 100%; max-width: 720px; max-height: 90dvh; }
.doc-overlay img { display: block; max-width: 100%; max-height: 90dvh; margin: 0 auto; border-radius: 12px; box-shadow: var(--shadow); object-fit: contain; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0)); max-height: 92dvh; overflow-y: auto;
}
.sheet h3 { font-size: 17px; margin-bottom: 14px; }
.sheet .sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet .sheet-actions .btn { flex: 1; }
.subgroup { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: var(--surface); }
/* Padrão único de blocos: em qualquer grupo de blocos irmãos (cartões, itens de lista, subgrupos,
   indicadores, blocos de formulário) as cores alternam branco / azul-claro. A classe .alt é aplicada
   por alternarBlocos() em app.js (conta só blocos visíveis, ignora títulos entre eles). */
.card.alt, .stat.alt, .row-item.alt, .subgroup.alt, .form-block.alt { background: var(--zebra-b); }
.subgroup-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; font-weight: 700; color: var(--text-dim); }

/* Lista de documentos do cliente: miniatura (imagem real ou ícone de PDF) +
   nome/tamanho/tipo ao lado. */
.doc-row-top { display: flex; gap: 12px; align-items: flex-start; }
.doc-thumb {
  flex: 0 0 auto; width: 56px; height: 56px; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  font-size: 24px; border: 1px solid var(--border);
}
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-thumb-pdf { background: var(--danger-soft); }
.doc-row-info { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; font-size: 14px; overflow-wrap: break-word; }
.doc-tipo-row { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.doc-tipo { padding: 5px 8px; font-size: 12.5px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); width: auto; max-width: 100%; }

/* Comprovante vinculado, listado embaixo do endereço (mesma tela de detalhe). */
.doc-mini-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.doc-mini {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px 5px 5px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 12.5px; cursor: pointer; color: inherit;
}
.doc-thumb-xs { width: 22px; height: 22px; border-radius: 50%; font-size: 12px; }
.doc-thumb-xs img { border-radius: 50%; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Fundo de cor diferente por bloco do formulário de cliente, só pra facilitar
   achar visualmente qual seção é qual (dados pessoais / telefones / endereços). */
.form-block { border-radius: var(--radius); padding: 14px 14px 4px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); }
.form-block .section-title { margin-top: 0; }

.geo-box { margin-top: 8px; }
.geo-box .geo-status { font-size: 11.5px; color: var(--text-dim); margin: 6px 0; }
.nav-links { display: flex; gap: 8px; margin-top: 8px; }
.nav-links .btn { flex: 1; text-decoration: none; }
/* isolation:isolate cria um contexto de empilhamento próprio pro mapa — sem isso,
   os panes internos do Leaflet (z-index até 700) vazam pra cima de qualquer .overlay
   (z-index 50), e um mapa que ficou aberto atrás (ex.: detalhe do cliente) aparece
   flutuando por cima do sheet de edição aberto na frente. */
.map-mini { height: 160px; border-radius: 10px; margin-top: 8px; border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; isolation: isolate; }
.map-mini.mini-sm { height: 120px; }

.foto-picker { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.foto-picker .preview {
  position: relative; width: 96px; height: 96px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary); border: 1px solid var(--border);
  overflow: hidden; display: grid; place-items: center;
  font-weight: 700; font-size: 24px;
}
.foto-picker .preview img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.avatar[data-fotobig] { cursor: zoom-in; }
.foto-picker .preview .cam {
  position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink); display: grid; place-items: center;
  font-size: 13px; border: 2px solid var(--surface);
}
.foto-picker .foto-actions { display: flex; flex-direction: column; gap: 6px; }
.foto-picker .foto-actions .btn { width: auto; }

.comprovante-box {
  display: flex; align-items: center; gap: 12px; padding: 12px 13px;
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px;
  background: var(--surface-2); cursor: default;
}
.comprovante-box.has-file { border-color: var(--primary); background: var(--primary-soft); cursor: pointer; }
.comprovante-icon { font-size: 24px; flex-shrink: 0; }
.comprovante-info { min-width: 0; }
.comprovante-status { font-weight: 600; font-size: 13.5px; }
.comprovante-box.has-file .comprovante-status { color: var(--primary); }
.comprovante-hint { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-size: 13px;
  z-index: 60; max-width: 90vw; text-align: center; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---------- Desktop ---------- */
@media (min-width: 860px) {
  :root { --nav-h: 0px; }
  .bottomnav { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 3px; width: 224px; padding: 16px 12px;
    border-right: 1px solid var(--border); background: var(--surface);
    position: sticky; top: 57px; height: calc(100dvh - 57px);
  }
  .sidebar .navbtn {
    display: flex; align-items: center; gap: 11px; padding: 11px 12px; border: 0; background: none;
    cursor: pointer; border-radius: 10px; color: var(--text-dim); font-size: 14px; text-align: left; width: 100%;
  }
  .sidebar .navbtn .ic { font-size: 17px; width: 20px; text-align: center; }
  .sidebar .navbtn.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
  .sidebar .navbtn:hover { background: var(--surface-2); }
  .content { padding: 24px 28px; padding-bottom: 40px; }
  .fab { display: none; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; max-height: 88dvh; }
}

/* ---------- Relatórios ---------- */
.rel-texto { background: var(--primary-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.kv.destaque { background: var(--primary-soft); border-radius: 8px; padding: 12px 10px; margin: 4px 0; }
.kv.destaque .v { font-size: 20px; font-weight: 800; }
table.rel { table-layout: auto; }
@media (min-width: 641px) { table.rel-estreita { max-width: 60%; } }
table.rel td { white-space: normal; }
table.rel td.num, table.rel td.ctr { white-space: nowrap; }
table.rel th.num, table.rel td.num { text-align: right; }
table.rel th.ctr, table.rel td.ctr { text-align: center; }
table.rel tr:nth-child(even) td { background: var(--zebra-b); }
table.rel tr.tot td { font-weight: 700; background: var(--primary-soft); border-top: 2px solid var(--primary); }
/* Muitas colunas: no celular cada linha vira um cartão (sem rolagem lateral), como as parcelas. */
@media (max-width: 640px) {
  .table-scroll:has(table.rel-cartao) { overflow-x: visible; }
  table.rel-cartao, table.rel-cartao tbody { display: block; width: 100%; max-width: none !important; }
  table.rel-cartao thead { display: none; }
  table.rel-cartao tr, table.rel-cartao tr:nth-child(even) {
    display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px;
  }
  table.rel-cartao td, table.rel-cartao tr:nth-child(even) td {
    display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border: none;
    background: transparent; text-align: right; white-space: normal; font-size: 13px;
  }
  table.rel-cartao td::before { content: attr(data-label); color: var(--text-dim); font-size: 12px; text-align: left; flex: none; }
  table.rel-cartao td.principal { order: -1; justify-content: flex-start; text-align: left; font-weight: 700; font-size: 15px; padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  table.rel-cartao td.principal::before { display: none; }
  table.rel-cartao tr.tot, table.rel-cartao tr.tot:nth-child(even) { background: var(--primary-soft); border-color: var(--primary); }
  table.rel-cartao tr.tot td { background: transparent; border-top: 0; }
  /* Valor ausente some do cartão (especificidade maior que a das linhas pares, senão elas mostram "—"). */
  table.rel-cartao tr td.vazio, table.rel-cartao tr:nth-child(even) td.vazio { display: none; }
  /* No cartão de total, a coluna-título vazia vira o texto "Total". */
  table.rel-cartao tr.tot td.principal.vazio, table.rel-cartao tr.tot:nth-child(even) td.principal.vazio { display: flex; font-size: 0; }
  table.rel-cartao tr.tot td.principal.vazio::after, table.rel-cartao tr.tot:nth-child(even) td.principal.vazio::after { content: 'Total'; font-size: 15px; }
}

.rel-empresa { display: inline-block; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 999px; margin-bottom: 8px; }

/* ---- Gráficos do painel inicial (tokens do dataviz: azul/laranja categóricos, rampa azul ordinal) ---- */
.viz {
  --viz-s1: #2a78d6; --viz-s2: #eb6834;
  --viz-o1: #86b6ef; --viz-o2: #5598e7; --viz-o3: #2a78d6; --viz-o4: #1c5cab;
  --viz-grid: var(--border); --viz-axis: #c3c7d3;
}
@media (prefers-color-scheme: dark) {
  .viz {
    --viz-s1: #3987e5; --viz-s2: #d95926;
    --viz-o1: #184f95; --viz-o2: #256abf; --viz-o3: #3987e5; --viz-o4: #6da7ec;
    --viz-axis: #383d4d;
  }
}
.viz-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.viz-title { font-weight: 700; font-size: 15px; }
.viz-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 8px 0 4px; font-size: 12.5px; color: var(--text-dim); }
.viz-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz svg text { font-family: inherit; fill: var(--text-dim); font-size: 11px; }
.viz svg text.viz-val { fill: var(--text); font-weight: 700; font-size: 11.5px; }
.viz .viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz .viz-base { stroke: var(--viz-axis); stroke-width: 1; }
.viz .viz-hit { fill: transparent; outline: none; cursor: default; }
.viz .viz-hit:hover, .viz .viz-hit:focus-visible { fill: var(--surface-2); }
.viz-bar-1 { fill: var(--viz-s1); } .viz-bar-2 { fill: var(--viz-s2); }
.viz-toggle { font-size: 12px; padding: 4px 10px; }
table.viz-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.viz-table th, .viz-table td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.viz-table th:first-child, .viz-table td:first-child { text-align: left; }
.viz-table th { color: var(--text-dim); font-weight: 600; }
.viz-hbars { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.viz-hrow { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 10px; border-radius: 8px; outline: none; }
.viz-hrow:hover, .viz-hrow:focus-visible { background: var(--surface-2); }
.viz-hlabel { font-size: 12.5px; color: var(--text); line-height: 1.25; }
.viz-hlabel small { display: block; font-size: 11px; color: var(--text-dim); }
.viz-htrack { display: flex; align-items: center; gap: 8px; min-width: 0; }
.viz-hbar { height: 20px; border-radius: 0 4px 4px 0; flex: none; }
.viz-hval { font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.viz-empty { font-size: 13px; color: var(--text-dim); padding: 14px 0 6px; }
.viz-tip { position: fixed; z-index: 90; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); font-size: 12.5px; max-width: 240px; }
.viz-tip .t { color: var(--text-dim); margin-bottom: 4px; }
.viz-tip .r { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.viz-tip .k { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.viz-tip .r b { font-variant-numeric: tabular-nums; }
.viz-tip .r span { color: var(--text-dim); }

.viz .viz-cross { stroke: var(--viz-axis); stroke-width: 1; }
.viz-subtitle { font-size: 13px; font-weight: 600; margin: 10px 0 2px; }
.viz-subtitle span { font-weight: 400; color: var(--text-dim); font-size: 12px; margin-left: 4px; }

.viz-note { font-size: 12px; color: var(--text-dim); margin-top: 8px; line-height: 1.4; }

/* WhatsApp (tela do admin) */
.wa-qr { display: flex; justify-content: center; }
.wa-qr svg { width: min(280px, 100%); height: auto; background: #fff; border-radius: 12px; padding: 6px; }
.wa-regras { margin: 0 0 12px 18px; display: grid; gap: 4px; }
.section-title .badge { margin-left: 6px; vertical-align: middle; }
#wa-root .card .meta { font-size: 13px; color: var(--text-dim); }
#wa-root .stat .value .meta { font-size: 13px; font-weight: 600; }
