nav.navbar {
    position: static !important;
    min-height: auto;
    padding: 0.75rem 0 !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Navbar Brand com layout responsivo */
.navbar-brand {
    flex-wrap: wrap;
    white-space: normal;
    line-height: 1.2;
}

/* Mobile: ajustes de brand */
@media (max-width: 991.98px) {
    .navbar-brand {
        font-size: 0.95rem;
    }
    
    .navbar-brand small {
        font-size: 0.65rem !important;
    }
    
    .navbar-brand .rounded-circle {
        width: 35px !important;
        height: 35px !important;
    }
    
    .navbar-brand i {
        font-size: 1.2rem !important;
    }
}

/* Mobile: menu itens */
@media (max-width: 991.98px) {
    .navbar-nav {
        padding-top: 1rem;
        border-top: 1px solid rgba(255,255,255,0.2);
    }
    
    .nav-link {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
}

/* Navbar toggler customizado */
.navbar-toggler {
    padding: 0.25rem 0.5rem !important;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 0.25rem rgba(255,255,255,0.25);
}

/* Links de navegação */
.navbar-nav .nav-link {
    transition: all 0.3s ease;
    position: relative;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

.navbar-nav .nav-link:hover {
    opacity: 0.85;
    transform: translateY(-2px);
}

.navbar-nav .nav-link.active {
    font-weight: 600;
    opacity: 1;
}

/* Tabs de busca com contraste */
.nav-tabs-busca {
    border-bottom: 2px solid rgba(255, 255, 255, 0.35);
}

.nav-tabs-busca .nav-link {
    color: #0b2f5a;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(11, 47, 90, 0.15);
    border-bottom: none;
    margin: 0 0.25rem;
    font-weight: 600;
}

.nav-tabs-busca .nav-link:hover {
    color: #0b2f5a;
    background: #ffffff;
}

.nav-tabs-busca .nav-link.active {
    color: #0b2f5a;
    background: #ffffff;
    border-color: #ffffff;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
}

main.app-container {
    padding-top: 2rem !important;
}
/* ===================== AJUSTES FILTROS AVANÇADOS ===================== */
.filters-container, .filter-summary, .filters-body, .filter-card, .summary-item {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    word-break: break-word !important;
    white-space: normal !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}
.summary-number, .summary-label, .summary-icon, .filter-card-title, .filter-card-subtitle, .filter-card-body, .summary-content {
    word-break: break-word !important;
    white-space: normal !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}
.filters-title, .filters-subtitle, .summary-label, .summary-number, .summary-icon, .filter-card-title, .filter-card-subtitle {
    overflow-wrap: break-word !important;
    hyphens: auto !important;
}
.filters-body, .filter-summary {
    overflow-x: hidden !important;
    overflow-y: auto !important;
}
.filter-card {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
}

nav.navbar {
     margin-bottom: 1.5rem !important;
     z-index: 1040;
}

/* Layout: conteúdo cresce e footer acompanha */
.main-content-wrapper {
    padding-top: 24px;
    padding-bottom: 24px;
    flex: 1 0 auto;
}

footer {
    margin-top: auto;
}

/* Loading local da tabela de resultados */
.resultados-wrapper {
    min-height: 220px;
}

.results-loading {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 8px;
}
/* ===================== MELHORIAS MOBILE ===================== */
@media (max-width: 575.98px) {
    html, body {
        font-size: 15px;
    }
    .main-wrapper, .app-container .main-wrapper {
        padding: 0.25rem !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        overflow-x: auto !important;
    }
    .container-fluid, .filters-container, .results-container, .filter-card, .stat-card, .chart-card {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        box-sizing: border-box;
        max-width: 100vw !important;
        min-width: 0 !important;
        overflow-x: auto !important;
    }
    .filters-header, .results-header, .filters-body, .chart-card-body, .stat-card-content, .filter-card-body {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        font-size: 0.98em;
    }
    .summary-item, .filter-card, .stat-card, .chart-card {
        flex-direction: column !important;
        align-items: flex-start !important;
        min-width: 0 !important;
        word-break: break-word !important;
    }
    .summary-number, .stat-number {
        font-size: 1.2rem !important;
        word-break: break-word !important;
    }
    .filters-title, .chart-title, .results-title {
        font-size: 1.1rem !important;
        word-break: break-word !important;
    }
    .filters-subtitle, .chart-subtitle, .results-subtitle {
        font-size: 0.95rem !important;
        word-break: break-word !important;
    }
    input, select, textarea {
        font-size: 1em !important;
        min-width: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    table, th, td {
        font-size: 0.95em !important;
        word-break: break-word !important;
        min-width: 0 !important;
    }
    .table-responsive, .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        max-width: 100vw !important;
    }
    .btn, button {
        font-size: 1em !important;
        padding: 0.5rem 0.75rem !important;
        min-width: 0 !important;
        word-break: break-word !important;
    }
}
/* ===================== MELHORIAS GERAIS ===================== */

/* Foco visível para acessibilidade */
button:focus, .btn:focus, a:focus, input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2);
    transition: box-shadow 0.2s;
}

/* Transições suaves para botões, cards e elementos interativos */
.btn, .stat-card, .chart-card, .filter-card, .summary-item, .filters-container, .results-container {
    transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
}

/* Utilitários de espaçamento (exemplo, pode expandir conforme necessidade) */
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.px-2 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
.px-3 { padding-left: 1rem !important; padding-right: 1rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-3 { padding-top: 1rem !important; padding-bottom: 1rem !important; }

/* Padronização de bordas e sombras */
.rounded-md { border-radius: 0.75rem !important; }
.shadow-light { box-shadow: 0 2px 10px rgba(0,0,0,0.08) !important; }
.shadow-medium { box-shadow: 0 4px 20px rgba(0,0,0,0.12) !important; }
.shadow-heavy { box-shadow: 0 8px 30px rgba(0,0,0,0.15) !important; }

/* Scrollbar refinado para todos navegadores modernos */
* {
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}
::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

/* Comentários para manutenção */
/*
    .btn, .stat-card, .chart-card, .filter-card, .summary-item, .filters-container, .results-container:
        - Transições suaves para hover/focus
    .rounded-md, .shadow-light, .shadow-medium, .shadow-heavy:
        - Utilitários para padronizar bordas e sombras
    .mb-2, .mb-3, .mt-2, .mt-3, .px-2, .px-3, .py-2, .py-3:
        - Utilitários de espaçamento
    Foco visível:
        - Melhora navegação por teclado e acessibilidade
    Scrollbar refinado:
        - Aparência consistente em todos navegadores
*/
/* Estilos globais do projeto (responsividade e controle do accordion) */

/* Garante que o conteúdo principal ocupe a tela, ajuste o valor conforme seu header/nav */
.full-height {
	min-height: calc(100vh - 120px);
}

/* Limita altura do corpo do accordion e permite rolagem interna para evitar empurrar o layout */
.accordion-body-scroll {
	max-height: 45vh;
	overflow: auto;
}

/* Ajustes responsivos: em telas menores o accordion pode ter limite menor */
@media (max-width: 767.98px) {
	.accordion-body-scroll {
		max-height: 60vh;
	}
	/* Garante que cards dentro de colunas ocupem 100% da largura em mobile */
	.card.w-100 { width: 100% !important; }
}

/* Pequenas melhorias visuais */
.card.mb-3 { margin-bottom: 1rem; }


html, body {
  height: 100%;
  margin: 0;
}

body {
    min-height: 100vh; /* garante ocupar a viewport inteira */
}

/* Header e footer mantêm altura natural */
header, footer {
  flex: 0 0 auto; /* não crescem nem encolhem */
}

/* Main (ou a sua div.container) ocupa todo o espaço restante */
main, .app-container { /* substitua .app-container pela sua div.container se preferir */
    min-height: 60vh; /* garante que o conteúdo principal apareça */
    overflow: auto; /* permite rolagem apenas na área principal */
}

/* App Container - responsivo e flexível */
.app-container {
  margin: 1rem auto;
  margin-bottom: 1rem auto;
  margin-top: 3px;
  width: 100%;
  max-width: 1140px; /* Bootstrap 5 XL breakpoint */
  padding: 0 0.75rem;
}

/* ===== ESTILOS DA PÁGINA MAIN ===== */

/* Main Wrapper - Design system responsivo */
main .main-wrapper,
.app-container .main-wrapper {
    background: white;
    max-width: 1140px;
    width: 100%;
    min-height: 100vh;
    border-radius: 0.75rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.125);
     overflow: visible;
     /* Garantir que o wrapper contenha elementos flutuantes e não colapse
         usando flow-root (substitui clearfix manual) */
     display: flow-root;
}

/* Responsive adjustments - Bootstrap 5 breakpoints */
@media (max-width: 767.98px) {
    main .main-wrapper,
    .app-container .main-wrapper {
        margin: 0.75rem auto;
        border-radius: 0.5rem;
        max-width: calc(100% - 1.5rem);
        min-height: auto;
    }
    
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

@media (max-width: 575.98px) {
    main .main-wrapper,
    .app-container .main-wrapper {
        margin: 0.5rem auto;
        border-radius: 0.375rem;
        max-width: calc(100% - 1rem);
    }
    
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        padding-top: 1.5rem;
        padding-bottom: 1.5rem;
    }
}

/* Modern UX/UI Improvements */

/* Root Variables */
:root {
    --primary-color: #0d6efd;
    --primary-rgb: 13, 110, 253;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --warning-gradient: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    --shadow-light: 0 2px 10px rgba(0,0,0,0.08);
    --shadow-medium: 0 4px 20px rgba(0,0,0,0.12);
    --shadow-heavy: 0 8px 30px rgba(0,0,0,0.15);
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Stats Cards */
.stat-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow-light);
    border: 1px solid rgba(0,0,0,0.05);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.stat-card-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    margin-bottom: 1.5rem;
    position: relative;
    z-index: 2;
}

.bg-gradient-primary { background: var(--primary-gradient); }
.bg-gradient-success { background: var(--success-gradient); }
.bg-gradient-warning { background: var(--warning-gradient); }

.stat-number {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    display: block;
}

.stat-label {
    color: #6c757d;
    font-weight: 500;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.stat-progress {
    height: 4px;
    background: #e9ecef;
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s ease;
}

/* Chart Card */
.chart-card {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-light);
    border: 1px solid rgba(0,0,0,0.05);
    overflow: hidden;
}

.chart-card-header {
    padding: 2rem 2rem 1rem;
    border-bottom: 1px solid #e9ecef;
}

.chart-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #2d3748;
}

.chart-subtitle {
    color: #6c757d;
    margin-bottom: 0;
    font-size: 0.9rem;
}

.chart-card-body {
    padding: 2rem;
}

.chart-wrapper {
    min-height: 350px;
}

.chart-legend-wrapper {
    padding-left: 1rem;
}

.legend-title {
    font-weight: 600;
    margin-bottom: 1rem;
    color: #495057;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chart-legend {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chart-legend li {
    display: flex;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.85rem;
    color: #495057;
}

/* Filters Container */
.filters-container {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-light);
    border: 1px solid rgba(0,0,0,0.05);
    overflow: hidden;
}

.filters-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 2rem;
    border-bottom: 1px solid #dee2e6;
}

.filters-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #2d3748;
}

.filters-subtitle {
    color: #6c757d;
    margin-bottom: 0;
    font-size: 0.9rem;
}

.filters-actions .btn {
    font-weight: 500;
    border-radius: 8px;
    padding: 0.5rem 1rem;
}

/* Filter Summary */
.filter-summary {
    padding: 2rem;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.summary-item {
    display: flex;
    align-items: center;
    background: white;
    padding: 1.5rem;
    border-radius: 10px;
    box-shadow: var(--shadow-light);
    transition: var(--transition);
}

.summary-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-medium);
}

.summary-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin-right: 1rem;
    font-size: 1.2rem;
}

.summary-content {
    display: flex;
    flex-direction: column;
}

.summary-number {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2d3748;
    line-height: 1;
    transition: all 0.3s ease;
}

/* Animação de destaque quando o número muda */
.summary-number.highlight-change {
    transform: scale(1.2);
    color: #0d6efd;
    text-shadow: 0 0 8px rgba(13, 110, 253, 0.3);
}

.summary-label {
    color: #6c757d;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Filter Cards */
.filters-body {
    padding: 2rem;
}

.filter-card {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: var(--border-radius);
    transition: var(--transition);
    height: 100%;
}

.filter-card:hover {
    border-color: #0d6efd;
    box-shadow: var(--shadow-light);
}

.filter-card-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid #f1f3f4;
}

/* Controles da Tabela CNAE */
.cnae-controls {
    background: #f8f9fa;
    border-radius: var(--border-radius-small);
    padding: 1rem;
    border: 1px solid #e9ecef;
}

.cnae-controls .form-floating > label {
    color: #6c757d;
    font-weight: 500;
    font-size: 0.9rem;
}

.filter-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #2d3748;
}

.filter-card-subtitle {
    color: #6c757d;
    font-size: 0.85rem;
    margin-bottom: 0;
}

.filter-card-body {
    padding: 1.5rem;
}

.filter-card-footer {
    padding: 1rem 1.5rem;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

/* Table Container */
.table-container {
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    width: 100% !important;
    box-sizing: border-box;
}

.custom-table {
    margin-bottom: 0;
    font-size: 0.9rem;
    width: 100% !important;
    table-layout: auto;
}

/* Garantir que a tabela de CNAE ocupe toda largura disponível */
#cnaeTable {
    width: 100% !important;
    min-width: 100%;
}

/* Forçar larguras das colunas da tabela CNAE */
#cnaeTable th:nth-child(1) {
    width: 50px !important;
    min-width: 50px;
    max-width: 50px;
}

#cnaeTable th:nth-child(2) {
    width: 120px !important;
    min-width: 120px;
    max-width: 120px;
}

#cnaeTable th:nth-child(3) {
    width: auto !important;
    min-width: 200px;
}

.custom-table thead th {
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    color: #495057;
    position: sticky;
    top: 0;
    z-index: 10;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.cnae-row:hover {
    background-color: #f8f9fa;
}

.cnae-description {
    color: #495057;
    line-height: 1.4;
}

/* States Grid - Duas colunas fixas */
.location-section .states-container .states-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important; /* Duas colunas iguais - forçado */
    grid-auto-flow: row !important;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
}

/* Garantir que cada item do estado ocupe apenas uma célula */
.states-grid .state-item {
    display: block !important;
    width: 100% !important;
}

.state-item .btn {
    width: 100%;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.5rem 0.25rem;
    border-radius: 6px;
    transition: var(--transition);
}

.state-item .btn-check:checked + .btn {
    background: #0d6efd;
    border-color: #0d6efd;
    color: white;
    transform: scale(1.05);
}

/* Botões de localização menores */
.state-item .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 45px;
    text-align: center;
}

/* Section Titles */
.section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

/* Location Section */
.location-section {
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 1rem;
}

/* Results Container */
.results-container {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-light);
    border: 1px solid rgba(0,0,0,0.05);
    overflow: hidden;
}

.results-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 2rem;
    border-bottom: 1px solid #dee2e6;
}

.results-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #2d3748;
}

.results-subtitle {
    color: #6c757d;
    margin-bottom: 0;
    font-size: 0.9rem;
}

.results-body {
    background: white;
}

/* Results Table */
.results-table {
    margin-bottom: 0;
}

.results-table thead th {
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    color: #495057;
    font-size: 0.9rem;
    padding: 1rem 0.75rem;
}

.results-table tbody tr:hover {
    background-color: #f8f9fa;
}

.results-table tbody td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid #e9ecef;
}

/* Loading State */
.loading-state {
    padding: 4rem 2rem;
    text-align: center;
    background: white;
}

.loading-content {
    max-width: 300px;
    margin: 0 auto;
}

.loading-title {
    color: #495057;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.loading-subtitle {
    color: #6c757d;
    font-size: 0.9rem;
}

/* Empty State */
.empty-state-content {
    padding: 2rem;
}

.empty-state-content i {
    opacity: 0.3;
}

/* Pagination */
.pagination-container {
    padding: 1.5rem 2rem;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

.pagination-info {
    font-size: 0.9rem;
}

/* Form Improvements */
.form-floating > label {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
}

.form-control:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.form-select:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

/* CEP Result */
.cep-result {
    font-size: 0.8rem;
    color: #6c757d;
    padding: 0.5rem 0.75rem;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

/* Responsive Improvements - Bootstrap 5 breakpoints */
@media (max-width: 767.98px) {
    .filters-header, .results-header {
        padding: 1rem;
    }

    .filters-body {
        padding: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .chart-card-body {
        padding: 1rem;
    }

    .states-container .states-grid {
        grid-template-columns: 1fr 1fr !important; /* Mantém duas colunas em mobile - forçado */
    }

    .results-table {
        font-size: 0.8rem;
    }

    .results-table th,
    .results-table td {
        padding: 0.75rem 0.5rem;
    }
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Custom Scrollbars */
.table-container::-webkit-scrollbar,
.states-grid::-webkit-scrollbar {
    width: 6px;
}

.table-container::-webkit-scrollbar-track,
.states-grid::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.table-container::-webkit-scrollbar-thumb,
.states-grid::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.table-container::-webkit-scrollbar-thumb:hover,
.states-grid::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ========================================
   LOADING OVERLAY - GLOBAL SCREEN LOADER
======================================== */
.global-loading-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(8px) !important;
    z-index: 999999 !important; /* Z-index máximo */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
    pointer-events: none; /* Inicialmente não bloqueia */
}

.global-loading-overlay.show {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important; /* Bloqueia cliques quando ativo */
}

.loading-content-overlay {
    text-align: center;
    padding: 2rem;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    max-width: 320px;
    width: 90%;
    animation: loadingPulse 2s ease-in-out infinite;
    position: relative;
    z-index: 1000000; /* Z-index ainda maior para o conteúdo */
}

.loading-gif {
    width: 80px;
    height: 80px;
    margin-bottom: 1rem;
    border-radius: 50%;
}

.loading-title-overlay {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.loading-subtitle-overlay {
    color: #6c757d;
    font-size: 0.95rem;
    margin-bottom: 0;
}

@keyframes loadingPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Loading spinner para quando não houver GIF */
.loading-spinner-overlay {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(var(--primary-rgb), 0.2);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== THEME GLOBAL - BUSCA AVANCADA / DETALHES ===== */
:root {
    --bg-primary: #F4F6F9;
    --bg-secondary: #FFFFFF;
    --bg-card: #FFFFFF;
    --text-primary: #1A2A3A;
    --text-secondary: #5A6E7A;
    --border-color: #E2E8F0;
    --accent-primary: #2C6E9E;
    --accent-hover: #1E5A8A;
    --success: #2E7D64;
    --danger: #C23B22;
    --warning: #E6A017;

    --app-bg: var(--bg-primary);
    --app-text: var(--text-primary);
    --app-primary: var(--accent-primary);
    --app-border: var(--border-color);
    --app-surface: var(--bg-card);
    --app-surface-alt: var(--bg-secondary);
    --app-text-muted: var(--text-secondary);
    --app-success: var(--success);
    --app-danger: var(--danger);
    --app-warning: var(--warning);
    --app-hover: var(--accent-hover);
    --app-shadow: 0 10px 30px rgba(44, 110, 158, 0.10);
    --app-ease: 0.2s ease;
}

html[data-theme='dark'],
body.dark-mode,
.dark-mode {
    --bg-primary: #121212;
    --bg-secondary: #1E1E1E;
    --bg-card: #2D2D2D;
    --text-primary: #E0E0E0;
    --text-secondary: #A0A0A0;
    --border-color: #404040;
    --accent-primary: #4A90E2;
    --accent-hover: #5A9EF2;
    --success: #27AE60;
    --danger: #C23B22;
    --warning: #E6A017;

    --app-bg: var(--bg-primary);
    --app-text: var(--text-primary);
    --app-primary: var(--accent-primary);
    --app-border: var(--border-color);
    --app-surface: var(--bg-card);
    --app-surface-alt: var(--bg-secondary);
    --app-text-muted: var(--text-secondary);
    --app-success: var(--success);
    --app-danger: var(--danger);
    --app-warning: var(--warning);
    --app-hover: var(--accent-hover);
    --app-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

body {
    color: var(--app-text);
    background-color: var(--app-bg);
    background: radial-gradient(circle at top right, rgba(44, 110, 158, 0.15), transparent 35%), var(--app-bg);
    font-family: 'Roboto', sans-serif;
}

.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1050;
    border-bottom: 1px solid var(--app-border);
    background: color-mix(in srgb, var(--app-surface) 92%, transparent);
    backdrop-filter: blur(8px);
}

.app-topbar__inner {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 20px;
}

.app-topbar__brand-wrap,
.app-topbar__actions,
.app-topbar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-topbar__brand {
    color: var(--app-text);
    text-decoration: none;
    font-size: 24px;
    line-height: 1.1;
}

.app-topbar__brand:visited,
.app-topbar__brand:hover {
    color: var(--app-text);
    text-decoration: none;
}

.app-topbar__logo {
    width: 92px;
    height: 46px;
    object-fit: contain;
}

.app-topbar__menu {
    border: 1px solid var(--app-border);
    background: var(--app-surface);
    color: var(--app-text);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.65rem 1rem;
    text-decoration: none;
    border-radius: 8px;
    transition: transform var(--app-ease), background-color var(--app-ease), color var(--app-ease), border-color var(--app-ease), box-shadow var(--app-ease);
    font-size: 14px;
    font-weight: 500;
}

.app-btn:hover { transform: scale(1.02); }
.app-btn:active { transform: scale(0.98); }
.app-btn:visited { text-decoration: none; }

.app-btn--ghost {
    border: 1px solid var(--app-border);
    color: var(--app-text);
    background: var(--app-surface);
}

.app-btn--ghost:visited,
.app-btn--ghost:hover {
    color: var(--app-text);
    text-decoration: none;
}

.app-btn--primary {
    border: 1px solid var(--app-primary);
    color: #fff;
    background: var(--app-primary);
}

.app-btn--primary:hover {
    background: var(--app-hover);
    border-color: var(--app-hover);
}

.app-btn--primary:visited,
.app-btn--primary:hover {
    color: #fff;
    text-decoration: none;
}

.app-footer {
    border-top: 1px solid var(--app-border);
    background: var(--app-surface-alt);
}

.app-footer__inner {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    font-size: 14px;
}

.app-footer__copy {
    margin: 0;
    color: #000;
}

html[data-theme='dark'] .app-footer__copy,
body.dark-mode .app-footer__copy,
.dark-mode .app-footer__copy {
    color: #fff;
}

.app-footer__links {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    gap: 14px;
}

.app-footer__links a,
.app-footer__links a:visited,
.app-footer__links a:hover,
.detail-recent-link,
.detail-recent-link:visited {
    color: var(--app-text);
    text-decoration: none;
}

.main-content-wrapper {
    padding-top: 72px;
}

.detail-page,
.detail-page.container {
    width: 90%;
    max-width: 1400px;
    margin: 0 auto;
}

.detail-shell {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto 2rem;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 12px;
    box-shadow: var(--app-shadow);
    padding: 1.5rem 2rem;
}

.detail-title-chip {
    background: var(--app-primary);
    color: #fff;
    border-radius: 10px;
    padding: 12px 14px;
}

.detail-card {
    border: 1px solid var(--app-border);
    border-radius: 12px;
    box-shadow: var(--app-shadow);
    background: var(--app-surface);
    color: var(--app-text);
}

.detail-table thead th {
    background: var(--accent-primary);
    color: #fff;
    font-weight: 600;
    padding: 12px;
    text-align: left;
}

.detail-table {
    color: var(--app-text);
    --bs-table-color: var(--app-text);
    --bs-table-bg: var(--app-surface);
    --bs-table-striped-color: var(--app-text);
    --bs-table-striped-bg: color-mix(in srgb, var(--app-surface) 92%, var(--app-bg));
    --bs-table-border-color: var(--app-border);
}

.detail-table tbody td {
    background: var(--app-surface);
    color: var(--app-text);
    border-color: var(--app-border);
}

.table-empresas-vinculadas {
    background: var(--app-surface-alt);
}

.table-empresas-vinculadas tbody td {
    background: var(--app-surface-alt);
    color: var(--app-text);
}

.table-empresas-vinculadas tbody tr:hover td {
    background: color-mix(in srgb, var(--app-surface-alt) 85%, var(--app-primary));
}

.btn-acessar-empresa {
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.2;
    transition: background-color var(--app-ease), transform var(--app-ease);
}

.btn-acessar-empresa:hover {
    background: var(--accent-hover);
    color: #fff;
    transform: translateY(-1px);
}

.action-cell {
    white-space: nowrap;
}

.detail-layout {
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.detail-sidebar {
    position: sticky;
    top: 92px;
    background: var(--app-surface-alt);
    border: 1px solid var(--app-border);
    border-radius: 14px;
    box-shadow: var(--app-shadow);
    overflow: hidden;
}

.detail-sidebar__head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--app-border);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--app-text-muted);
    font-weight: 700;
}

.detail-recent-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: calc(100vh - 180px);
    overflow: auto;
}

.detail-recent-item + .detail-recent-item {
    border-top: 1px solid var(--app-border);
}

.detail-recent-link {
    display: block;
    padding: 12px 16px;
}

.detail-recent-link:hover {
    background: color-mix(in srgb, var(--app-primary) 10%, transparent);
    text-decoration: none;
}

.detail-recent-title {
    display: block;
    font-weight: 700;
    margin-bottom: 4px;
}

.detail-recent-meta {
    font-size: 13px;
    color: var(--app-text-muted);
}

.detail-main {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.detail-hero {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: start;
}

.detail-hero__copy {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.detail-status-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.detail-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.detail-status-badge--success { background: color-mix(in srgb, var(--app-success) 20%, transparent); color: var(--app-success); }
.detail-status-badge--danger { background: color-mix(in srgb, var(--app-danger) 18%, transparent); color: var(--app-danger); }
.detail-status-badge--muted { background: color-mix(in srgb, var(--app-text-muted) 20%, transparent); color: var(--app-text-muted); }

.detail-period {
    font-size: 14px;
    color: var(--app-text-muted);
}

.detail-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.detail-card__title {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--app-text-muted);
    font-weight: 700;
    margin-bottom: 12px;
}

.detail-list {
    display: grid;
    gap: 10px;
}

.detail-list__row {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 12px;
}

.detail-list__label {
    font-weight: 700;
}

.detail-meta-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
    color: var(--app-text-muted);
    font-size: 14px;
}

.detail-section-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.detail-section-title {
    margin: 0;
    font-size: 22px;
}

.detail-table-wrap {
    position: relative;
    min-height: 160px;
}

.detail-table-loading {
    position: absolute;
    inset: 0;
    display: none;
    padding: 12px;
    background: color-mix(in srgb, var(--app-surface-alt) 92%, transparent);
    border-radius: 12px;
    z-index: 2;
}

.detail-table-loading.is-visible {
    display: block;
}

.detail-skeleton-line {
    height: 42px;
    border-radius: 8px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--app-border) 80%, transparent) 25%, color-mix(in srgb, var(--app-border) 45%, transparent) 37%, color-mix(in srgb, var(--app-border) 80%, transparent) 63%);
    background-size: 400% 100%;
    animation: skeleton 1.5s infinite linear;
}

.detail-skeleton-line + .detail-skeleton-line {
    margin-top: 10px;
}

.detail-scroll {
    max-height: 420px;
    overflow: auto;
}

.detail-watermark {
    color: var(--app-text-muted);
    font-size: 13px;
    text-align: right;
}

html[data-theme='dark'] .card-dados-socio,
body.dark-mode .card-dados-socio,
.dark-mode .card-dados-socio {
    background-color: #2D2D2D;
    color: #FFFFFF;
    border-color: #404040;
}

html[data-theme='dark'] .card-dados-socio p,
html[data-theme='dark'] .card-dados-socio span,
html[data-theme='dark'] .card-dados-socio label,
body.dark-mode .card-dados-socio p,
body.dark-mode .card-dados-socio span,
body.dark-mode .card-dados-socio label,
.dark-mode .card-dados-socio p,
.dark-mode .card-dados-socio span,
.dark-mode .card-dados-socio label {
    color: #FFFFFF !important;
}

html[data-theme='dark'] .card-dados-socio strong,
body.dark-mode .card-dados-socio strong,
.dark-mode .card-dados-socio strong {
    color: #E0E0E0;
}

html[data-theme='dark'] .table-empresas-vinculadas,
body.dark-mode .table-empresas-vinculadas,
.dark-mode .table-empresas-vinculadas {
    background-color: #1E1E1E;
}

html[data-theme='dark'] .table-empresas-vinculadas th,
body.dark-mode .table-empresas-vinculadas th,
.dark-mode .table-empresas-vinculadas th {
    background-color: #2C6E9E;
    color: #FFFFFF;
}

html[data-theme='dark'] .table-empresas-vinculadas td,
body.dark-mode .table-empresas-vinculadas td,
.dark-mode .table-empresas-vinculadas td {
    background-color: #1E1E1E;
    color: #FFFFFF;
}

html[data-theme='dark'] .table-empresas-vinculadas tr:hover td,
body.dark-mode .table-empresas-vinculadas tr:hover td,
.dark-mode .table-empresas-vinculadas tr:hover td {
    background-color: #2D2D2D;
}

html[data-theme='dark'] .btn-acessar-empresa,
body.dark-mode .btn-acessar-empresa,
.dark-mode .btn-acessar-empresa {
    background-color: #4A90E2;
    color: #FFFFFF;
    border: none;
}

html[data-theme='dark'] .btn-acessar-empresa:hover,
body.dark-mode .btn-acessar-empresa:hover,
.dark-mode .btn-acessar-empresa:hover {
    background-color: #5A9EF2;
    color: #FFFFFF;
}

.socio-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--app-ease);
}

.socio-link:hover,
.socio-link:visited:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.socio-link:visited {
    color: var(--accent-primary);
}

@media (max-width: 991.98px) {
    .detail-page,
    .detail-page.container {
        width: 95%;
    }

    .detail-layout {
        grid-template-columns: 1fr;
    }

    .detail-sidebar {
        position: static;
    }
}

@media (max-width: 767.98px) {
    .detail-page,
    .detail-page.container {
        width: 100%;
        max-width: 100%;
    }

    .detail-shell {
        max-width: 100%;
        padding: 1rem;
        margin-bottom: 1.5rem;
    }

    .detail-hero,
    .detail-actions,
    .detail-section-header,
    .detail-meta-row,
    .app-footer__inner {
        flex-direction: column;
        align-items: stretch;
    }

    .detail-list__row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .app-topbar__brand {
        font-size: 18px;
    }

    .app-topbar__actions .app-btn span {
        display: none;
    }
}

/* ===== DESIGN SYSTEM RESPONSIVO ===== */



/* ===== OVERLAY DE LOADING OTIMIZADO PARA PERFORMANCE ===== */
.main-loading-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: linear-gradient(135deg, rgba(248, 249, 250, 0.97), rgba(255, 255, 255, 0.95)) !important;
    backdrop-filter: blur(8px) !important;
    z-index: 99999 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 1 !important;
    visibility: visible !important;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1) !important;
    pointer-events: all !important;
    will-change: opacity, visibility !important;
}

.main-loading-overlay.hidden {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.main-loading-content {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
    max-width: 380px;
    width: 90%;
    border: 1px solid rgba(0, 123, 255, 0.2);
    backdrop-filter: blur(10px);
    transform: scale(1);
    transition: transform 0.3s ease;
}

.main-loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e8f4ff;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: mainLoadingSpin 0.8s linear infinite;
    margin: 0 auto 1.2rem auto;
    box-shadow: 0 2px 10px rgba(0, 123, 255, 0.2);
}

@keyframes mainLoadingSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.main-loading-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: #007bff;
    margin-bottom: 0.75rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.main-loading-subtitle {
    color: #6c757d;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.main-loading-progress {
    width: 100%;
    height: 6px;
    background: #f1f3f4;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.main-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #28a745, #007bff);
    background-size: 200% 100%;
    border-radius: 8px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    animation: progressShimmer 2s infinite;
}

@keyframes progressShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.main-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: progressShine 2s infinite;
}

@keyframes progressShine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.main-loading-step {
    color: #495057;
    font-size: 0.85rem;
    font-style: italic;
    display: block;
}
