@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg-color: #f8fafc;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #1e293b;
    --sidebar-text: #f1f5f9;
    --sidebar-hover: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --transition: all 0.2s ease-in-out;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
}

.app-container { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    position: fixed;
    height: 100vh;
    z-index: 100;
}
.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sidebar-hover);
}


.toggle-btn { background: none; border: none; color: var(--sidebar-text); font-size: 1.5rem; cursor: pointer; }

.sidebar-nav { flex: 1; padding: 20px 0; overflow-y: auto; }
.nav-title { padding: 0 20px; font-size: 1rem; font-weight: 700; color: #94a3b8; margin-bottom: 10px; letter-spacing: 0.5px; }
.sidebar-nav ul { list-style: none; }
.sidebar-nav a { display: block; padding: 10px 20px 10px 35px; font-size: 0.85rem; color: var(--sidebar-text); text-decoration: none; border-left: 3px solid transparent; }
.sidebar-nav a:hover, .sidebar-nav li.active a { background-color: var(--sidebar-hover); border-left-color: var(--primary); }

.main-content { flex: 1; margin-left: 260px; display: flex; flex-direction: column; min-width: 0; transition: var(--transition); }
.main-content.expanded { margin-left: 0; }

.topbar { background-color: var(--surface); padding: 20px 30px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.content { padding: 30px; flex: 1; overflow-y: auto; }

.dados-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; }
.dados-card h1 { margin: 0 0 6px; font-size: 1.35rem; }
.dados-card p { margin: 0 0 22px; color: #64748b; }
.dados-filtros { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 16px; align-items: end; }
.dados-filtros .form-group { margin: 0; }
.dados-filtros small { display: block; color: #475569; margin-top: 5px; min-height: 1em; }
.dados-filtros .btn { height: 40px; white-space: nowrap; }
.dados-mensagem { padding: 12px 14px; border-radius: var(--radius); margin-top: 18px; background: #fef2f2; color: #b91c1c; }
.dados-mensagem.aviso { background: #fffbeb; color: #92400e; }
.dados-mensagem.sucesso { background: #f0fdf4; color: #15803d; }
.dados-metricas { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 24px; }
.dados-metrica { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.dados-metrica span { color: #64748b; font-size: .85rem; }
.dados-metrica strong { color: #15803d; font-size: 1.35rem; }
.dados-resultado-cabecalho { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.dados-resultado-cabecalho h2 { margin: 0 0 3px; }
.dados-resultado-cabecalho span { color: #64748b; font-size: .85rem; }
.dados-acoes { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.dados-url { margin-top: 18px; color: #475569; }
.dados-url code { display: block; margin-top: 8px; padding: 12px; background: #f1f5f9; overflow-wrap: anywhere; }
.dados-paginacao { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.dados-paginacao select { padding: 7px; border: 1px solid var(--border); border-radius: var(--radius); }
.importacao-progresso-cabecalho { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 10px; }
#importacaoTodasBarra { width: 100%; height: 18px; margin-bottom: 20px; }
.importacao-acao { display: flex; flex-direction: column; align-self: end; gap: 8px; }
.importacao-acao .btn { width: 100%; height: 40px; }
.importacao-mensagem { display: block; grid-column: 1 / -1; width: 100%; margin-top: 0; min-height: 34px; font-size: .78rem; padding: 8px 10px; line-height: 1.35; box-sizing: border-box; }
.importacao-filtros > #importacaoTodasMensagem, .importacao-filtros > #importacaoReceitasMensagem { grid-column: 1 / -1; width: 100%; box-sizing: border-box; }
.importacao-filtros { grid-template-columns: repeat(3, minmax(150px, 1fr)) minmax(210px, 1fr); align-items: start; }
@media (max-width: 1150px) { .importacao-filtros { grid-template-columns: repeat(2, minmax(180px, 1fr)); } }
@media (max-width: 650px) { .importacao-filtros { grid-template-columns: 1fr; } }
.importacao-totais-gerais th { background: #ecfdf5; color: #166534; font-weight: 700; border-top: 2px solid #16a34a; }
.importacao-totais-gerais th:first-child { text-align: right; }
.importacao-totais-gerais th:not(:first-child) { text-align: right; white-space: nowrap; }
.importacao-tabela-container { overflow-x: visible; }
.importacao-resultados-table { table-layout: fixed; white-space: normal; font-size: .67rem; }
.importacao-resultados-table th, .importacao-resultados-table td { padding: 6px 4px; overflow-wrap: anywhere; }
.importacao-resultados-table .col-entidade { width: 16%; }
.importacao-resultados-table tbody td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.importacao-resultados-table .col-situacao { width: 10%; }
.importacao-resultados-table .col-contagem { width: 7%; }
.importacao-resultados-table .col-valor { width: 15%; }
.importacao-receitas-table .col-entidade { width: 14%; }
.importacao-receitas-table .col-situacao { width: 9%; }
.importacao-receitas-table .col-contagem { width: 6%; }
.importacao-receitas-table .col-valor { width: 13.25%; }
.receitas-cadastro-table { font-size: .72rem; white-space: nowrap; }
.receitas-cadastro-table th, .receitas-cadastro-table td { padding: 7px 5px; }
.receitas-cadastro-table .totals-row th { background: #f0fdf4; color: #15803d; text-align: right; border-top: 2px solid #16a34a; }
.receita-form-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 15px; }
@media (max-width: 760px) { .receita-form-grid { grid-template-columns: 1fr; } }
.importacao-historico-card { margin-top: 24px; }
.importacao-historico-filtros { display: grid; grid-template-columns: 90px 130px minmax(180px, 1fr) minmax(180px, 1fr) auto; gap: 12px; align-items: end; margin-bottom: 16px; }
.importacao-historico-filtros .form-group { margin: 0; }
.importacao-historico-filtros input, .importacao-historico-filtros select { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-main); }
.importacao-historico-table { table-layout: fixed; white-space: normal; font-size: .72rem; }
.importacao-historico-table th, .importacao-historico-table td { padding: 7px 5px; overflow-wrap: anywhere; }
.importacao-historico-table th:nth-child(1) { width: 5%; }
.importacao-historico-table th:nth-child(2) { width: 9%; }
.importacao-historico-table th:nth-child(3), .importacao-historico-table th:nth-child(4) { width: 9%; }
.importacao-historico-table th:nth-child(5) { width: 18%; }
.importacao-historico-table td:nth-child(5) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.importacao-historico-table th:nth-child(6) { width: 25%; }
.importacao-historico-table th:nth-child(7) { width: 14%; }
.importacao-historico-table th:nth-child(8) { width: 11%; }
.importacao-historico-vazio { text-align: center !important; color: #64748b; padding: 18px !important; }
@media (max-width: 850px) { .importacao-historico-filtros { grid-template-columns: 1fr 1fr; } .importacao-resultados-table { font-size: .6rem; } }
.dados-modal { width: min(920px, 95%); max-height: 90vh; overflow-y: auto; }
.dados-abas { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.dados-abas button { padding: 12px; background: none; border: 0; border-bottom: 3px solid transparent; white-space: nowrap; cursor: pointer; }
.dados-abas button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.dados-detalhes-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
.dados-detalhe { padding: 12px; background: #f8fafc; border-radius: var(--radius); overflow-wrap: anywhere; }
.dados-detalhe span { display: block; color: #64748b; font-size: .78rem; margin-bottom: 4px; }
.dados-detalhe strong { font-size: .92rem; }
.dados-table-clickable tr { cursor: pointer; }
.dados-table-clickable tr:hover { background: #eff6ff; }
@media (max-width: 1050px) { .dados-filtros { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 650px) { .dados-filtros, .dados-metricas, .dados-detalhes-grid { grid-template-columns: 1fr; } .dados-resultado-cabecalho { align-items: flex-start; gap: 12px; flex-direction: column; } }

.btn { padding: 8px 16px; border: none; border-radius: var(--radius); font-size: 0.9rem; font-weight: 500; cursor: pointer; color: white; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-primary { background-color: var(--primary); }
.btn-secondary { background-color: var(--secondary); }
.btn-success { background-color: var(--success); }
.btn-danger { background-color: var(--danger); }

.toolbar { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 15px; background: var(--surface); padding: 15px; border-radius: var(--radius); margin-bottom: 20px; box-shadow: var(--shadow); }
.file-actions, .export-actions { display: flex; gap: 10px; }

.table-responsive { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 20px; }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.data-table th, .data-table td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background-color: #f1f5f9; font-weight: 600; cursor: pointer; }
.filters-row th { background-color: #f8fafc; padding: 8px 15px; }
.filter-input { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; }
.filter-input:focus { outline: none; border-color: var(--primary); }

/* Grade compacta para manter todas as colunas de despesas visíveis. */
.despesas-table-container { overflow-x: hidden; }
.despesas-table { table-layout: fixed; font-size: 0.68rem; }
.despesas-table th, .despesas-table td { padding: 5px 3px; overflow: hidden; text-overflow: ellipsis; }
.despesas-table th { white-space: normal; line-height: 1.15; }
.despesas-table td { white-space: nowrap; }
.despesas-table .filters-row th { padding: 3px 2px; }
.despesas-table .filter-input { min-width: 0; padding: 3px 2px; font-size: 0.65rem; }
.despesas-table .btn-sm { padding: 2px 3px; font-size: 0.6rem; margin: 1px 0; }
.despesas-table th:nth-child(1) { width: 4.5%; }
.despesas-table th:nth-child(2) { width: 4.5%; }
.despesas-table th:nth-child(3) { width: 5%; }
.despesas-table th:nth-child(4) { width: 4.5%; }
.despesas-table th:nth-child(5), .despesas-table th:nth-child(6) { width: 7.5%; }
.despesas-table th:nth-child(7) { width: 12%; }
.despesas-table th:nth-child(8) { width: 10%; }
.despesas-table th:nth-child(n+9):nth-child(-n+12) { width: 7%; }
.despesas-table th:nth-child(13) { width: 16.5%; }
.despesas-table td:nth-child(13) { white-space: normal; }

.pagination { display: flex; justify-content: center; gap: 15px; }

.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal-overlay.active { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 500px; padding: 20px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; }
.form-group input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .toolbar { flex-direction: column; }
    .file-actions, .export-actions { flex-direction: column; }
}





.sortable { cursor: pointer; user-select: none; }
.sortable:hover { background-color: #f1f5f9; }


/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f172a;
        --surface: #1e293b;
        --text-main: #f8fafc;
        --text-muted: #94a3b8;
        --border: #334155;
        --sidebar-bg: #0f172a;
        --sidebar-text: #f1f5f9;
        --sidebar-hover: #1e293b;
        --table-header-bg: #334155;
        --table-row-hover: #334155;
    }
    
    .data-table th { background-color: var(--table-header-bg); }
    .sortable:hover { background-color: #475569; }
    .filters-row th { background-color: var(--surface); }
    .data-table tbody tr:hover { background-color: var(--table-row-hover); }
    
    .filter-input, .form-group input, .form-group select {
        background-color: var(--bg-color);
        color: var(--text-main);
    }
    
    /* Ensure modal text is readable */
    .modal { color: var(--text-main); }
    .close-btn { color: var(--text-main); }
}

.badge-total {
    background-color: #3b82f6;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    margin-left: 10px;
    vertical-align: middle;
}


.logo { 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}
.logo-container {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    margin-bottom: 8px;
    border: 1px solid #bfdbfe;
    overflow: hidden;
}
.logo img { 
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 10px;
}
.logo-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -0.025em;
}

.btn-info { background: #06b6d4; color: white; border: none; }
.btn-info:hover { background: #0891b2; }

.auth-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg-color); padding: 20px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); padding: 32px; border-radius: 12px; box-shadow: 0 12px 30px rgba(15,23,42,.15); }
.auth-card h1 { margin-bottom: 8px; }
.auth-card p { color: var(--text-muted); margin-bottom: 24px; }
.auth-submit { width: 100%; margin-bottom: 18px; }
.auth-error, .auth-success { padding: 12px; border-radius: 6px; margin-bottom: 18px; }
.auth-error { background: #fee2e2; color: #991b1b; }
.auth-success { background: #dcfce7; color: #166534; }
.users-page { padding: 30px; }
.users-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 20px; }

