/* ============================================================================
   IEADVT · estilos compartilhados (cores da igreja, componentes, gráficos)
   Telas com estilos próprios usam css/telas/<tela>.css (core.usarCss).
   ============================================================================ */
:root {
  --azul-noite: #05132c;
  --azul-profundo: #062552;
  --azul-real: #06306d;
  --dourado: #e5b748;
  --dourado-escuro: #9f7215;
  --marfim: #f5f1e6;
  --fundo: #f7f5ef;
  --card: #ffffff;
  --borda: #e3dfd2;
  --texto: #1b2230;
  --titulo: #05132c;
  --muted: #6b7280;
  --verde: #2e7d5b;
  --laranja: #d9622b;
  --cinza: #9ca3af;
  --vermelho: #b42318;
  --azul-claro: #5b9bd5;
  --raio: 10px;
  --sombra: 0 1px 2px rgba(5, 19, 44, .06);
  --erro-txt: var(--vermelho);           /* texto de erro (.erro); --vermelho continua sendo fundo de botão/aviso */
  --veu: rgba(247, 245, 239, .55);       /* fundo do "processando" (carregandoGlobal) */
  --trilho: color-mix(in srgb, var(--borda) 75%, transparent); /* trilho das barras de adesão */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #0b0f1a; --card: #121a2b; --borda: #243049; --texto: #e8ecf5; --titulo: #ffffff; --muted: #98a2b3;
    --marfim: #1a2338; --dourado-escuro: #e5b748; --azul-real: #7fa8e8; --verde: #4cb784; --laranja: #f08a55;
    --erro-txt: #f97066; --veu: rgba(11, 15, 26, .62);
    /* trilho médio: o texto escuro da barra de adesão fica legível sobre ele e sobre o preenchimento (dourado/verde) */
    --trilho: #8b93a6;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--fundo); color: var(--texto);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.com-modal { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--azul-real); }
h1 { font-size: 24px; margin: 0 0 2px; color: var(--titulo); line-height: 1.2; }
h2 { font-size: 16px; margin: 0 0 10px; color: var(--titulo); }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.peq { font-size: 12.5px; }
.erro { color: var(--erro-txt); font-weight: 600; }
.ok { color: var(--verde); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.centro { text-align: center; }
.cresce { flex: 1; }

/* ---------- estrutura ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--azul-noite); color: #e8ecf5; padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.side .marca { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; }
.side .marca img { width: 44px; height: 44px; border-radius: 50%; }
.side .marca b { font-size: 15px; line-height: 1.2; }
.side .marca small { display: block; color: var(--dourado); font-weight: 500; font-size: 12px; }
.menu { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side a.nav { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: #cdd5e6; text-decoration: none; font-weight: 500; white-space: nowrap; }
.side a.nav .ico { width: 19px; height: 19px; fill: currentColor; flex: none; opacity: .9; }
.side a.nav:hover { background: rgba(255,255,255,.07); }
.side a.nav.on { background: var(--dourado); color: var(--azul-noite); }
.side .rodape { margin-top: auto; font-size: 12px; color: #8b97b3; padding: 8px 6px; display: flex; flex-direction: column; gap: 8px; }
.btn-sair { color: #cdd5e6 !important; border-color: #3a4766 !important; justify-content: center; }
.btn-instalar { color: #e5b748 !important; border-color: rgba(229, 183, 72, .5) !important; justify-content: center; }
.btn-instalar[hidden] { display: none !important; }
.main { padding: 22px 28px 56px; min-width: 0; }
/* cabeçalho e gaveta do menu: só no celular */
.topo-m, .fundo-menu, .fechar-menu { display: none; }
body.sem-rolagem { overflow: hidden; }
img, svg, video { max-width: 100%; }
input, select, textarea { max-width: 100%; }

/* ---------- cabeçalho de página e blocos ---------- */
.pg-topo { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.pg-titulo { flex: 1; min-width: 220px; }
.pg-acoes { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px 18px; box-shadow: var(--sombra); }
.card + .card, .secao + .secao { margin-top: 14px; }
.secao { margin-top: 16px; }
.secao-topo { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.secao-topo h2 { margin: 0; flex: 1; }
.linha { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.filtros { margin-bottom: 14px; }

/* ---------- formulário ---------- */
label.campo { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
label.check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; cursor: pointer; padding: 8px 0; }
input, select, textarea {
  background: var(--card); border: 1px solid var(--borda); border-radius: 8px; padding: 8px 10px; min-width: 0;
  color: var(--texto); font-weight: 400; font-size: 14px;
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--dourado-escuro); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--dourado); outline-offset: 0; border-color: var(--dourado); }
input.invalido { border-color: var(--vermelho); border-width: 2px; }
textarea { min-height: 90px; resize: vertical; }
.btn {
  border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer; white-space: nowrap;
  background: var(--dourado); color: var(--azul-noite); text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { filter: brightness(.95); }
.btn.sec { background: transparent; border: 1px solid var(--borda); color: var(--texto); }
.btn.sec:hover { background: var(--marfim); }
.btn.perigo { background: var(--vermelho); color: #fff; }
.btn.peq { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; filter: none; }

/* ---------- chips, selos, caixas ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip { border: 1px solid var(--borda); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--azul-noite); color: #fff; border-color: var(--azul-noite); }
/* no escuro o azul-noite some no cartão: o selecionado fica dourado */
@media (prefers-color-scheme: dark) { .chip.on { background: var(--dourado); color: var(--azul-noite); border-color: var(--dourado); } }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.b-1 { background: color-mix(in srgb, var(--verde) 16%, transparent); color: var(--verde); }
.b-2 { background: color-mix(in srgb, var(--laranja) 16%, transparent); color: var(--laranja); }
.b-3 { background: color-mix(in srgb, var(--cinza) 24%, transparent); color: var(--muted); }
.b-c { background: color-mix(in srgb, var(--azul-real) 14%, transparent); color: var(--azul-real); }
.b-ouro { background: color-mix(in srgb, var(--dourado) 26%, transparent); color: var(--dourado-escuro); }
.caixa { padding: 10px 14px; border-radius: 8px; border: 1px solid; margin-bottom: 12px; }
.caixa-aviso { background: color-mix(in srgb, var(--dourado) 18%, transparent); border-color: var(--dourado); }
.caixa-erro { background: color-mix(in srgb, var(--vermelho) 10%, transparent); border-color: var(--vermelho); }
.caixa-ok { background: color-mix(in srgb, var(--verde) 12%, transparent); border-color: var(--verde); }
.caixa-info { background: color-mix(in srgb, var(--azul-claro) 12%, transparent); border-color: var(--azul-claro); }
.vazio { padding: 22px; text-align: center; color: var(--muted); }
.giro { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--borda); border-top-color: var(--dourado-escuro); border-radius: 50%; animation: giro .8s linear infinite; vertical-align: -2px; }
@keyframes giro { to { transform: rotate(360deg); } }

/* ---------- indicadores ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 12px 14px; box-shadow: var(--sombra); min-width: 0; }
.kpi-t { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-v { font-size: 23px; font-weight: 700; color: var(--titulo); line-height: 1.25; overflow-wrap: anywhere; }
.kpi-d { font-size: 12px; font-weight: 600; margin-top: 2px; }

/* ---------- tabelas ---------- */
.tabela-wrap { overflow-x: auto; border-radius: var(--raio); }
table.tab { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); overflow: hidden; }
/* cabeçalho das tabelas igual ao DataGrid do WPF (azul profundo, texto branco) */
.tab th { text-align: left; font-size: 13px; font-weight: 600; color: #fff; padding: 9px 12px; background: var(--azul-profundo); white-space: nowrap; }
.tab thead tr { background: var(--azul-profundo); }
.tab th.num { text-align: right; }
/* Botões e links do cabeçalho (ordenar coluna) herdam o branco do th em todas as telas; no hover/foco, só sublinham.
   O !important impede que a regra de uma tela pinte o texto de escuro sobre o fundo azul (sumia no tema claro). */
.tab th :is(button, a) { color: inherit; }
.tab th :is(button, a):is(:hover, :focus-visible) { color: inherit !important; text-decoration: underline; }
.tab td { padding: 8px 12px; border-bottom: 1px solid var(--borda); vertical-align: middle; }
.tab tbody tr:last-child td { border-bottom: 0; }
.tab tfoot td { font-weight: 700; background: var(--marfim); border-top: 1px solid var(--borda); }
.tab tr.destaque td { background: color-mix(in srgb, var(--dourado) 10%, transparent); font-weight: 600; }
tr.clica, .clica { cursor: pointer; }
tr.clica:hover td { background: color-mix(in srgb, var(--dourado) 12%, transparent); }
.avatar { width: 38px; height: 46px; border-radius: 6px; object-fit: cover; background: var(--marfim); display: block; }
.vazio-av { display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.nome { font-weight: 600; }
.pag { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

/* ---------- abas e ficha ---------- */
.abas { display: flex; gap: 4px; border-bottom: 1px solid var(--borda); margin-bottom: 14px; flex-wrap: wrap; }
.aba { padding: 8px 14px; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.aba.on { color: var(--titulo); border-color: var(--dourado); }
.ficha { display: grid; grid-template-columns: 240px 1fr; gap: 18px; align-items: start; }
.foto-card { text-align: center; }
.foto-card img, .foto-card .foto-vazia {
  width: 180px; height: 232px; object-fit: cover; border-radius: 10px; background: var(--marfim); margin: 0 auto 10px; display: grid; place-items: center;
  color: var(--muted); border: 1px solid var(--borda);
}
.grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 14px; }
.grade .largo { grid-column: 1 / -1; }

/* ---------- gráficos ---------- */
svg.grafico { width: 100%; height: auto; max-height: 300px; display: block; overflow: visible; }
.g-val { font-size: 11px; fill: var(--titulo); font-weight: 600; }
.g-rot { font-size: 11px; fill: var(--muted); }
.g-eixo { stroke: var(--azul-profundo); stroke-width: 1; opacity: .6; }
@media (prefers-color-scheme: dark) { .g-eixo { stroke: #7f8db0; opacity: 1; } } /* o azul-profundo some no cartão escuro */
.barrash { display: flex; flex-direction: column; gap: 6px; }
.bh-linha { display: grid; grid-template-columns: var(--rot, 170px) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bh-linha.clica:hover .bh-rot { text-decoration: underline; }
.bh-rot { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bh-trilho { position: relative; height: 16px; background: color-mix(in srgb, var(--borda) 70%, transparent); border-radius: 4px; overflow: visible; }
.bh-barra { height: 100%; border-radius: 4px; }
.bh-meta { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--titulo); opacity: .7; }
.bh-txt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; font-size: 12.5px; }
.pizza-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
svg.pizza { width: 240px; max-width: 100%; height: auto; flex: none; }
svg.pizza path.clica:hover { opacity: .85; }
.legenda { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.leg { display: grid; grid-template-columns: 14px 1fr auto 44px; gap: 8px; align-items: center; padding: 2px 4px; border-radius: 4px; }
.leg.clica:hover { background: var(--marfim); }
.leg-cor { width: 12px; height: 12px; border-radius: 3px; }
.leg-v { font-variant-numeric: tabular-nums; }
.leg-p { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.empilhada { display: flex; width: 100%; border-radius: 4px; overflow: hidden; background: color-mix(in srgb, var(--borda) 70%, transparent); }
.empilhada > div { height: 100%; }
.adesao { position: relative; height: 20px; background: var(--trilho); border-radius: 5px; min-width: 120px; }
.adesao-barra { height: 100%; border-radius: 5px; }
.adesao-meta { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--titulo); opacity: .75; }
/* texto escuro nos dois temas: no escuro, branco sobre o dourado/verde ficava com contraste de ~2:1 */
.adesao span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11.5px; font-weight: 700; color: var(--azul-noite); }
/* Painel (barra própria, .pn-barra): mesmo ajuste no tema escuro. Mover para painel.css quando a tela for revisada. */
@media (prefers-color-scheme: dark) {
  .main .pn { --pn-trilho: var(--trilho); --pn-barra-txt: var(--azul-noite); }
  .main .pn .pn-barra > span { text-shadow: none; }
}

/* ---------- janela (modal), avisos e "processando" ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(5, 19, 44, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
/* janela de login da sessão expirada: acima das outras janelas, do "processando" e dos avisos */
.modal-fundo.sobre-tudo { z-index: 90; }
.reentrar { display: flex; flex-direction: column; gap: 12px; }
.reentrar p { margin: 0; }
.reentrar-txt { font-weight: 600; color: var(--titulo); }
.reentrar-acoes { display: flex; justify-content: flex-end; }
.reentrar-acoes .btn { min-width: 120px; justify-content: center; }
.modal { background: var(--card); color: var(--texto); border-radius: 14px; width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.modal-topo { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--borda); }
.modal-topo h2 { margin: 0; flex: 1; }
.modal-x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-corpo { padding: 16px 18px; overflow: auto; }
.modal-rodape { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--borda); flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 11px 14px; border-radius: 10px; color: #fff; background: var(--azul-profundo); box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: opacity .3s, transform .3s; }
.toast-ok { background: #1f6b4c; } .toast-erro { background: var(--vermelho); }
.toast.sai { opacity: 0; transform: translateY(8px); }
#ocupado { position: fixed; inset: 0; background: var(--veu); display: grid; place-items: center; z-index: 70; }
#ocupado > div { background: var(--card); border: 1px solid var(--borda); padding: 12px 18px; border-radius: 10px; box-shadow: var(--sombra); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--azul-noite), #06306d); padding: 20px; }
.login { width: 100%; max-width: 380px; background: var(--card); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login img { width: 84px; height: 84px; border-radius: 50%; margin: 0 auto; display: block; }
.login h1 { text-align: center; font-size: 20px; }
.login small { text-align: center; color: var(--muted); }
.login .btn { justify-content: center; }

/* ---------- tela que não abriu (sem conexão etc.) ---------- */
.falha-tela { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.falha-tela p { margin: 0; }

/* ---------- impressão ---------- */
@media print {
  .side, .pg-acoes, .filtros, #toasts { display: none !important; }
  .shell { display: block; } .main { padding: 0; }
  .card, .kpi, table.tab { box-shadow: none; }
}

/* ---------- celular e telas médias ---------- */
@media (max-width: 1100px) {
  .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; align-content: start; }

  /* cabeçalho fixo com o botão ☰ */
  .topo-m {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
    height: 56px; padding: 0 12px; background: var(--azul-noite); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18);
  }
  .topo-logo { width: 32px; height: 32px; border-radius: 50%; }
  .topo-titulo { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .btn-menu {
    width: 44px; height: 44px; margin-left: -6px; border: 0; background: none; cursor: pointer; border-radius: 10px;
    display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; flex: none;
  }
  .btn-menu:focus-visible { outline: 2px solid var(--dourado); }
  .btn-menu span { display: block; width: 22px; height: 2.5px; border-radius: 2px; background: #fff; }

  /* gaveta lateral: fechada, fica invisível (fora do Tab, do leitor de tela e sem a faixa de sombra na borda) */
  .side {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; height: 100%; width: min(84vw, 310px);
    padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-105%); box-shadow: 8px 0 30px rgba(0,0,0,.35);
    visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s;
  }
  .menu-aberto .side { transform: none; visibility: visible; transition: transform .22s ease; }
  .fundo-menu {
    display: block; position: fixed; inset: 0; z-index: 40; background: rgba(5, 19, 44, .5);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .menu-aberto .fundo-menu { opacity: 1; pointer-events: auto; }
  .side .marca { padding: 2px 4px 14px; }
  .fechar-menu {
    display: block; margin-left: auto; width: 40px; height: 40px; border: 0; background: rgba(255,255,255,.08);
    color: #fff; font-size: 26px; line-height: 1; border-radius: 10px; cursor: pointer;
  }
  .side a.nav { padding: 13px 14px; font-size: 16px; border-radius: 10px; }
  .side a.nav .ico { width: 22px; height: 22px; }
  .side .rodape { padding: 10px 4px 0; }
  .btn-sair, .btn-instalar { padding: 12px; }

  /* conteúdo */
  .main { padding: 14px 12px 48px; }
  h1 { font-size: 21px; }
  .pg-topo { align-items: stretch; }
  .pg-acoes { width: 100%; }
  .pg-acoes .btn { flex: 1 1 auto; justify-content: center; }
  .linha > .campo, .linha > label.check { flex: 1 1 calc(50% - 12px); min-width: 0; }
  .linha > .campo.cresce { flex-basis: 100%; }
  .linha select, .linha input:not([type=checkbox]) { width: 100% !important; }
  .card { padding: 14px; }
  .ficha, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-v { font-size: 19px; }
  .hide-m { display: none; }
  .bh-linha { grid-template-columns: minmax(90px, 34%) 1fr auto; }
  .tab th, .tab td { padding: 8px 9px; }
  .modal-fundo { padding: 0; align-items: end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
  .modal-rodape .btn { flex: 1 1 auto; justify-content: center; }
  #toasts { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
@media (max-width: 380px) {
  .linha > .campo, .linha > label.check { flex-basis: 100%; }
}

/* ---------- modo demonstração (login separado, banco fictício) ---------- */
.faixa-demo { background: repeating-linear-gradient(135deg, #e5b748 0 18px, #d9a830 18px 36px); color: #05132c; text-align: center; font-size: 13px; line-height: 1.35; padding: 6px 12px; font-weight: 500; letter-spacing: .01em; }
.faixa-demo b { text-transform: uppercase; letter-spacing: .08em; }
.selo-demo { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 6px; background: #e5b748; color: #05132c; font-size: 11px; letter-spacing: .08em; }
