:root {
  /* Paleta Base Inteligente (projects/controle_votos_pb/brand-dna.yaml)
     Regra: nunca texto branco sobre --accent #2DA3FA (2.72:1 reprova) */
  --azul: #1D2733;        /* navy — base da marca: header, CTA primário */
  --azul-claro: #0578CC;  /* azul-texto derivado do accent p/ texto sobre branco (4.60:1 AA) */
  --accent: #2DA3FA;      /* azul oficial — foco, decoração, marcas gráficas */
  --verde: #16a34a;
  --amarelo: #eab308;
  --laranja: #f97316;
  --vermelho: #dc2626;
  --cinza: #64748b;
  --fundo: #f1f5f9;
  --card: #ffffff;
  --borda: #e2e8f0;
  --texto: #0f172a;
  --texto-suave: #64748b;
  --sombra: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  --raio: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--azul-claro); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
/* Upload de foto (perfil do líder / edição admin) */
.foto-upload { text-align: center; margin-bottom: 18px; }
.foto-grande { width: 96px; height: 96px; border-radius: 50%; overflow: hidden; margin: 0 auto 10px; border: 2px solid var(--borda); background: #f1f5f9; }
.foto-grande .av-foto { width: 100%; height: 100%; object-fit: cover; }
.foto-grande .av-inicial { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 38px; }
/* Código: fica inteiro se couber; só quebra (na palavra) se exceder sozinho a linha —
   nunca letra a letra. A quebra normal acontece entre um <code> e outro (vírgula/espaço). */
code { overflow-wrap: break-word; background: #e2e8f0; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
/* Texto comum: quebra palavras muito longas (e-mail, URL) em vez de estourar o card */
h2, h3, p, td, .desc, .alerta, .comp-item, .kpi-label { overflow-wrap: break-word; }

.hidden { display: none !important; }

/* ---------------- Login / cadastro ---------------- */
.tela-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--azul);
  padding: 20px;
}
.card-auth {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
}
.card-auth h1 { font-size: 22px; margin-bottom: 4px; color: var(--azul); }
.card-auth .logo-login { display: block; max-width: 220px; width: 60%; margin: 0 auto 18px; }
.card-auth .sub { color: var(--texto-suave); font-size: 14px; margin-bottom: 24px; }

.campo { margin-bottom: 16px; }
.campo label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #334155; }
.campo.required label::after { content: " *"; color: #dc2626; font-weight: 700; }
.campo input, .campo select, .campo textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--borda);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 163, 250, .18);
}
.linha-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--azul); color: #fff; border: none;
  padding: 11px 18px; border-radius: 8px; font-size: 15px; font-weight: 600;
  transition: filter .15s;
}
.btn:hover { filter: brightness(.94); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-bloco { width: 100%; }
.btn-sec { background: #fff; color: var(--azul-claro); border: 1px solid var(--borda); }
.btn-sec:hover { background: #f8fafc; }
.btn-perigo { background: var(--vermelho); }
.btn-mini { padding: 6px 10px; font-size: 13px; border-radius: 6px; }

/* ---------------- Bloco de convite (ação nº1 do líder) ---------------- */
.bloco-convite {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 4px 0 22px;
}
.btn-convite {
  min-height: 56px;            /* alvo de toque ≥44px com folga */
  padding: 14px 18px;
  font-size: 16px;             /* 16px evita zoom automático no iOS */
  border-radius: 10px;
  gap: 10px;
  box-shadow: var(--sombra);
  transition: transform .12s cubic-bezier(0.4, 0, 0.2, 1), filter .15s;
}
.btn-convite:active { transform: translateY(1px); }
.btn-convite-lider   { background: var(--azul); color: #fff; }
.btn-convite-eleitor { background: #25D366; color: #1D2733; } /* NUNCA texto branco (1.98:1) */

/* ---------------- Busca de cidade (autocomplete) ---------------- */
.busca-cidade { position: relative; }
.busca-cidade > input { font-size: 16px; }   /* herda .campo input; override anti-zoom iOS */
.busca-cidade .lista {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 240px; overflow-y: auto;
  background: #fff;
  border: 1px solid var(--borda);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .14);
  z-index: 120;
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity .15s cubic-bezier(0.16, 1, 0.3, 1), transform .15s cubic-bezier(0.16, 1, 0.3, 1);
}
.busca-cidade .lista.aberta { opacity: 1; transform: translateY(0); pointer-events: auto; }
.busca-cidade .item {
  padding: 12px 14px;
  font-size: 15px;
  color: var(--texto);
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background .1s linear;
}
.busca-cidade .item:last-child { border-bottom: none; }
.busca-cidade .item:hover,
.busca-cidade .item.ativo { background: #e8f4fe; color: #1D2733; } /* navy sobre #e8f4fe = 13.52:1 */
.busca-cidade .vazio { padding: 12px 14px; font-size: 14px; color: var(--texto-suave); font-style: italic; }

.msg { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.msg-erro { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.msg-ok { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ---------------- App shell ---------------- */
.app { display: none; min-height: 100vh; }
.topo {
  background: var(--azul);
  color: #fff;
  padding: 0 20px;
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topo .marca { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.topo .marca-icone { height: 32px; width: 32px; border-radius: 6px; display: block; }
.topo .marca small { font-weight: 400; opacity: .7; font-size: 12px; }
.topo .usuario { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topo .usuario button { background: rgba(255, 255, 255, .15); color: #fff; border: none; padding: 7px 12px; border-radius: 6px; font-size: 13px; }

.layout { display: flex; }
.menu {
  width: 220px; background: var(--card); border-right: 1px solid var(--borda);
  min-height: calc(100vh - 58px); padding: 16px 12px; flex-shrink: 0;
}
.menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; color: #334155; font-size: 14px; font-weight: 500;
  margin-bottom: 2px;
}
.menu a:hover { background: #f1f5f9; }
.menu a.ativo { background: #e8f4fe; color: var(--azul); }
.menu a .ic { width: 18px; text-align: center; }

.conteudo { flex: 1; padding: 24px; max-width: 1200px; }
.conteudo h2 { font-size: 22px; margin-bottom: 4px; }
.conteudo .desc { color: var(--texto-suave); margin-bottom: 20px; font-size: 14px; }

/* ---------------- Cards / KPIs ---------------- */
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px 18px; box-shadow: var(--sombra); }
.kpi .rot { font-size: 13px; color: var(--texto-suave); margin-bottom: 6px; }
.kpi .val { font-size: 28px; font-weight: 700; }
.kpi .val small { font-size: 14px; font-weight: 500; color: var(--texto-suave); }
.kpi.azul .val { color: var(--azul-claro); }
.kpi.verde .val { color: var(--verde); }
.kpi.laranja .val { color: var(--laranja); }

.card { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 20px; box-shadow: var(--sombra); margin-bottom: 20px; }
.card h3 { font-size: 16px; margin-bottom: 14px; }

/* Barra de progresso */
.progresso { background: #e2e8f0; border-radius: 999px; height: 22px; overflow: hidden; position: relative; }
.progresso > span { display: block; height: 100%; background: linear-gradient(90deg, #16a34a, #22c55e); transition: width .5s; }
.progresso.grande { height: 28px; }
.progresso-rotulo { text-align: center; font-size: 13px; margin-top: 6px; color: var(--texto-suave); }

/* ---------------- Tabelas ---------------- */
.tabela-wrap { overflow-x: auto; border-radius: var(--raio); border: 1px solid var(--borda); }
table { width: 100%; border-collapse: collapse; background: var(--card); font-size: 14px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--borda); white-space: nowrap; }
th { background: #f8fafc; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-suave); }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-sim { background: #dcfce7; color: #15803d; }
.badge-nao { background: #fee2e2; color: #b91c1c; }
.badge-indeciso { background: #fef9c3; color: #a16207; }
.badge-ativo { background: #dcfce7; color: #15803d; }
.badge-bloqueado { background: #fee2e2; color: #b91c1c; }
.badge-sev-critica { background: #fee2e2; color: #b91c1c; }
.badge-sev-alerta { background: #fef9c3; color: #a16207; }
.badge-sev-info { background: #e8f4fe; color: #1d2733; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.pill .ponto { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------------- Barra de ações / filtros ---------------- */
.barra { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.barra input, .barra select { padding: 8px 10px; border: 1px solid var(--borda); border-radius: 8px; font-size: 14px; background: #fff; }
.barra .cresce { flex: 1; min-width: 160px; }
.espaco { flex: 1; }

/* ---------------- Alertas ---------------- */
.alerta { padding: 12px 14px; border-radius: 8px; margin-bottom: 10px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.alerta-sucesso { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alerta-info { background: #e8f4fe; color: #1d2733; border: 1px solid #a9d8fc; }
.alerta-aviso { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

/* ---------------- Mapa ---------------- */
.mapa-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }
#mapa-svg { width: 100%; height: auto; background: #f8fafc; border-radius: var(--raio); border: 1px solid var(--borda); }
#mapa-svg path { stroke: #fff; stroke-width: .5; cursor: pointer; transition: opacity .15s; }
#mapa-svg path:hover { opacity: .75; stroke: #0f172a; stroke-width: 1; }
.legenda { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px; height: fit-content; box-shadow: var(--sombra); }
.legenda h4 { font-size: 14px; margin-bottom: 12px; }
.legenda .item { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.legenda .cx { width: 16px; height: 16px; border-radius: 4px; }
.detalhe-mun { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--borda); }
.detalhe-mun.vazio { color: var(--texto-suave); font-size: 13px; }
.detalhe-mun h4 { font-size: 15px; margin-bottom: 8px; }
.detalhe-mun .lin { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }

/* ---------------- Grade de municípios ---------------- */
.grade-mun { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.mun-chip { padding: 10px 12px; border-radius: 8px; color: #fff; font-size: 13px; cursor: pointer; box-shadow: var(--sombra); }
.mun-chip .n { font-weight: 600; display: block; }
.mun-chip .p { font-size: 12px; opacity: .9; }

/* ---------------- Modal ---------------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal h3 { margin-bottom: 16px; font-size: 18px; }
.modal .rodape { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.otp-modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; z-index: 200; padding: 20px; }
.otp-modal { background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.otp-modal h3 { margin-bottom: 6px; font-size: 18px; }

.acoes-linha { display: flex; gap: 6px; }

.vazio-estado { text-align: center; padding: 40px; color: var(--texto-suave); }

.spinner { text-align: center; padding: 30px; color: var(--texto-suave); }

/* Ranking pos */
.pos { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: #e2e8f0; color: #334155; font-weight: 700; font-size: 12px; align-items: center; justify-content: center; }
.pos.ouro { background: #fde68a; color: #92400e; }
.pos.prata { background: #e2e8f0; color: #475569; }
.pos.bronze { background: #fed7aa; color: #9a3412; }

/* ---------------- Responsivo ---------------- */
.menu-toggle { display: none; background: rgba(255,255,255,.15); border: none; color: #fff; font-size: 20px; padding: 4px 10px; border-radius: 6px; }
@media (max-width: 860px) {
  .menu { position: fixed; left: 0; top: 58px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  .menu.aberto { transform: translateX(0); }
  .menu-toggle { display: block; }
  .conteudo { padding: 16px; }
  .mapa-wrap { grid-template-columns: 1fr; }
  .linha-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  /* Dashboard: no celular a meta/KPIs/gráfico vêm ANTES do ranking */
  .dash-main { order: 1; }
  .dash-ranking { order: 2; }
}
@media (max-width: 640px) {
  .bloco-convite { grid-template-columns: 1fr; } /* botões empilham */
  .btn-convite { min-height: 52px; }             /* ainda ≥44px */
  /* Header: esconde o papel (o nome do usuário já basta) — evita aperto no mobile */
  .topo .marca small { display: none; }
  .topo .marca { font-size: 15px; }
  /* Tabelas densas viram cards empilhados (usa data-label injetado via JS) */
  .tabela-wrap { border: none; overflow: visible; }
  .tabela-wrap table, .tabela-wrap tbody, .tabela-wrap tr, .tabela-wrap td { display: block; width: 100%; }
  .tabela-wrap thead { display: none; }
  .tabela-wrap tr { background: var(--card); border: 1px solid var(--borda); border-radius: 8px; margin-bottom: 10px; box-shadow: var(--sombra); overflow: hidden; }
  .tabela-wrap td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; border: none; border-top: 1px solid #f1f5f9; white-space: normal; text-align: right; }
  .tabela-wrap td::before { content: attr(data-label); font-weight: 600; color: var(--texto-suave); font-size: 12px; text-align: left; flex-shrink: 0; }
  .tabela-wrap td:first-child { background: #f8fafc; font-weight: 700; font-size: 15px; border-top: none; }
  .tabela-wrap td:first-child::before { display: none; } /* a 1ª célula (nome) não precisa de rótulo */
  .tabela-wrap td:empty { display: none; }
  /* Rede: nome ocupa a linha toda → as 5 métricas caem para a linha de baixo (não cortam) */
  .no-nome { min-width: 100% !important; }
  .no-stats { width: 100%; justify-content: flex-start !important; gap: 8px 16px !important; margin-top: 6px; }
  /* Alertas: bloco (não flex) no mobile → texto longo com <code> quebra certo, sem estourar */
  .alerta { display: block; }
  .alerta code { display: inline-block; max-width: 100%; }
}
@media (max-width: 400px) {
  .conteudo { padding: 12px; }
  .btn-convite { font-size: 15px; padding: 13px 14px; } /* não abaixo de 15px */
  .topo .usuario span { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .busca-cidade .lista { max-height: 200px; }    /* não cobrir o teclado virtual */
}
