:root {
    --azul: #1d4ed8;
    --azul-escuro: #1e3a8a;
    --verde: #16a34a;
    --vermelho: #dc2626;
    --laranja: #d97706;
    --cinza-100: #f3f4f6;
    --cinza-200: #e5e7eb;
    --cinza-400: #9ca3af;
    --cinza-600: #4b5563;
    --cinza-800: #1f2937;
    --branco: #ffffff;
    --raio: 8px;
    --sombra: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--cinza-100);
    color: var(--cinza-800);
    font-size: 15px;
}

a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    background: var(--azul-escuro);
    color: var(--branco);
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 20px;
    height: 56px;
    flex-wrap: wrap;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.topbar-logo { height: 32px; width: auto; max-width: 32px; object-fit: contain; }
.topbar-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar-nav a {
    color: rgba(255,255,255,.85);
    padding: 8px 12px;
    border-radius: var(--raio);
    font-size: 14px;
}
.topbar-nav a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.topbar-nav a.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }
.btn-link { color: #fff; text-decoration: underline; }

.app-main { padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; }
.app-main--login { max-width: 400px; padding-top: 80px; }

.alerta { padding: 12px 16px; border-radius: var(--raio); margin-bottom: 16px; font-size: 14px; }
.alerta-sucesso { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alerta-erro { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alerta-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

.card {
    background: var(--branco);
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2, .card h3 { margin-top: 0; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { margin: 0; font-size: 22px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--branco);
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    padding: 18px 20px;
}
.stat-card .valor { font-size: 28px; font-weight: 700; color: var(--azul-escuro); }
.stat-card .rotulo { color: var(--cinza-600); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.stat-card.alerta .valor { color: var(--vermelho); }
.stat-card.sucesso .valor { color: var(--verde); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
    text-align: left;
    padding: 10px 12px;
    background: var(--cinza-100);
    border-bottom: 2px solid var(--cinza-200);
    white-space: nowrap;
}
thead th a {
    display: block;
    margin: -10px -12px;
    padding: 10px 12px;
    color: inherit;
    text-decoration: none;
}
thead th a:hover { background: var(--cinza-200); text-decoration: none; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--cinza-200); vertical-align: middle; }
tbody tr:hover { background: #fafbff; }
.table-wrap { overflow-x: auto; }

.th-ordenavel { cursor: pointer; user-select: none; }
.th-ordenavel:hover { background: var(--cinza-200); }
.seta-ordenacao { font-size: 10px; color: var(--azul); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ativo, .badge-pago { background: #dcfce7; color: #166534; }
.badge-inativo, .badge-pendente { background: #f3f4f6; color: #4b5563; }
.badge-suspenso, .badge-atrasado { background: #fee2e2; color: #991b1b; }
.badge-isento { background: #fef3c7; color: #92400e; }

.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: var(--raio);
    background: var(--azul);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    text-align: center;
}
.btn:hover { background: var(--azul-escuro); text-decoration: none; }
.btn-secundario { background: var(--cinza-200); color: var(--cinza-800); }
.btn-secundario:hover { background: var(--cinza-400); }
.btn-perigo { background: var(--vermelho); }
.btn-perigo:hover { background: #b91c1c; }
.btn-pequeno { padding: 4px 10px; font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-grupo { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-grupo label { font-size: 13px; font-weight: 600; color: var(--cinza-600); }
.form-grupo input, .form-grupo select, .form-grupo textarea {
    padding: 9px 12px;
    border: 1px solid var(--cinza-200);
    border-radius: var(--raio);
    font-size: 14px;
    font-family: inherit;
    width: 100%;
}
.form-grupo input:focus, .form-grupo select:focus, .form-grupo textarea:focus {
    outline: none;
    border-color: var(--azul);
    box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.form-acoes { display: flex; gap: 10px; margin-top: 10px; }

.campo-destaque {
    background: #fef3c7;
    border: 1px solid var(--laranja);
    border-radius: var(--raio);
    padding: 10px 12px;
}
.campo-destaque label { color: #92400e; }
.campo-destaque small { color: #92400e; font-weight: 600; }

.filtros { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filtros .form-grupo { margin-bottom: 0; min-width: 140px; }

.login-box { background: #fff; padding: 32px; border-radius: var(--raio); box-shadow: var(--sombra); }
.login-box h1 { text-align: center; font-size: 20px; margin-top: 0; }
.login-box .btn { width: 100%; }
.login-logo { display: block; max-width: 110px; max-height: 110px; margin: 0 auto 16px; }

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

.texto-mudo { color: var(--cinza-600); font-size: 13px; }
.texto-centro { text-align: center; }
.mb-0 { margin-bottom: 0; }

.paginacao { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.paginacao a, .paginacao span {
    padding: 6px 12px; border-radius: var(--raio); border: 1px solid var(--cinza-200); font-size: 13px;
}
.paginacao .atual { background: var(--azul); color: #fff; border-color: var(--azul); }

/* Impressão de cartões e recibos */
@media print {
    .no-print, .topbar, .alerta { display: none !important; }
    body { background: #fff; }
    .app-main { padding: 0; max-width: none; }
    @page { margin: 12mm; }
}

.doc-imprimir {
    background: #fff;
    max-width: 480px;
    margin: 0 auto;
    padding: 28px;
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    border: 1px solid var(--cinza-200);
}
.doc-imprimir h2 { margin-top: 0; text-align: center; }
.doc-imprimir .linha { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--cinza-200); font-size: 14px; }
.doc-imprimir .linha span:first-child { color: var(--cinza-600); }
.doc-imprimir .assinatura { margin-top: 40px; border-top: 1px solid var(--cinza-400); padding-top: 6px; font-size: 12px; color: var(--cinza-600); }

/* Tamanho padrão ISO/IEC 7810 ID-1 (cartão de crédito/cidadão): 85,60 x 53,98 mm — cabe na carteira. */
.cartao-socio {
    width: 85.6mm;
    height: 53.98mm;
    box-sizing: border-box;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    text-align: center;
    border: 2px solid var(--azul-escuro);
    border-radius: 3mm;
    padding: 5mm 6mm;
    background: linear-gradient(135deg, #eef2ff, #ffffff);
    overflow: hidden;
}
.cartao-socio .titulo {
    font-weight: 700;
    color: var(--azul-escuro);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    line-height: 1.25;
}
.cartao-socio .nome-socio {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cartao-socio .numero { font-size: 12px; color: var(--cinza-600); line-height: 1.7; }
.cartao-merito {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 3px 10px;
    border-radius: 999px;
}
.cartao-logo { display: block; max-width: 15mm; max-height: 15mm; margin: 0 auto; }

@media print {
    .cartao-socio { box-shadow: none; }
}

/* ---------- Impressão em lote de cartões de sócio (grelha 2x4, A4 vertical) ---------- */
.folha-cartoes {
    display: grid;
    grid-template-columns: repeat(2, 85.6mm);
    grid-auto-rows: 53.98mm;
    gap: 6mm 8mm;
    justify-content: center;
    background: #fff;
    padding: 8mm;
    margin: 0 auto 10mm;
    box-shadow: var(--sombra);
    border-radius: var(--raio);
    width: fit-content;
}
.folha-cartoes .cartao-socio { margin: 0; }

@media print {
    .folha-cartoes { box-shadow: none; padding: 0; margin: 0 auto; page-break-after: always; }
    .folha-cartoes:last-child { page-break-after: auto; }
}

.doc-logo { display: block; max-width: 80px; max-height: 80px; margin: 0 auto 10px; }
.definicoes-logo-atual { max-width: 120px; max-height: 120px; display: block; margin-bottom: 10px; border: 1px solid var(--cinza-200); border-radius: var(--raio); padding: 6px; }

/* ---------- Mapa anual de quotas (impressão, 4 sócios por folha A4 horizontal, grelha 2x2) ---------- */
.mapa-filtros { margin-bottom: 20px; }
.mapa-folha {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8mm;
    background: #fff;
    width: 297mm;
    max-width: 100%;
    height: 190mm;
    margin: 0 auto 10mm;
    padding: 8mm;
    box-shadow: var(--sombra);
    border-radius: var(--raio);
    box-sizing: border-box;
}
.mapa-cartao {
    border: 1px solid var(--cinza-400);
    border-radius: 6px;
    padding: 6mm 8mm;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.mapa-cabecalho { display: flex; align-items: center; gap: 12px; border-bottom: 2px solid var(--azul-escuro); padding-bottom: 6px; margin-bottom: 8px; }
.mapa-cabecalho img { max-width: 36px; max-height: 36px; }
.mapa-cabecalho .instituicao { font-weight: 700; color: var(--azul-escuro); font-size: 12px; line-height: 1.2; }
.mapa-cabecalho .ano { margin-left: auto; font-size: 15px; font-weight: 700; }
.mapa-socio { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.mapa-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; flex: 1; }
.mapa-mes { border: 1px solid var(--cinza-200); border-radius: 4px; padding: 3px 2px; text-align: center; }
.mapa-mes .nome-mes { font-size: 9px; text-transform: uppercase; color: var(--cinza-600); letter-spacing: .03em; }
.mapa-mes .valor-mes { font-size: 12px; font-weight: 700; margin-top: 2px; }
.mapa-total { margin-top: 4px; padding-top: 4px; border-top: 2px solid var(--azul-escuro); text-align: right; font-size: 12px; }
.mapa-total strong { color: var(--azul-escuro); font-size: 13px; }

/* ---------- Impressão de quotas de um único sócio (mesmo tamanho do cartão do mapa 4-por-folha) ---------- */
.quota-socio-imprimir {
    width: 137mm;
    max-width: 100%;
    margin: 0 auto;
    box-shadow: var(--sombra);
}

@media print {
    .quota-socio-imprimir { box-shadow: none; width: auto; max-width: 137mm; }
    .mapa-folha { page-break-after: always; box-shadow: none; width: auto; padding: 0; margin: 0; }
    .mapa-folha:last-child { page-break-after: auto; }
    /* O @page (tamanho/orientação da folha) NÃO fica aqui: é uma regra global do
       documento, não fica limitada a esta secção — ver <style> inline em cada
       página que precise de uma orientação específica (ex: mapa_anual.php usa
       A4 horizontal), para não afetar a impressão de outras páginas. */
}

/* ---------- Modal (substitui alert()/confirm() nativos do browser) ---------- */
.modal-sobreposicao {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}
.modal-caixa {
    background: #fff;
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    padding: 24px;
    max-width: 400px;
    width: 100%;
}
.modal-caixa p { margin: 0 0 20px; font-size: 15px; color: var(--cinza-800); white-space: pre-line; }
.modal-acoes { display: flex; justify-content: flex-end; gap: 10px; }
