/* ========================================
   CORREÇÕES DE RESPONSIVIDADE PARA TABELAS
   Versão: 1.0
   Objetivo: Garantir que tabelas respeitem os limites da tela
======================================== */

/* Container da tabela com scroll horizontal */
.table-container {
    overflow-x: auto !important; /* Scroll horizontal quando necessário */
    overflow-y: auto !important; /* Scroll vertical mantido */
    max-height: 420px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    width: 100% !important; /* Garante que ocupe toda a largura disponível */
    -webkit-overflow-scrolling: touch; /* Melhor experiência no iOS */
}

/* Tabela responsiva com largura mínima */
.results-table {
    margin-bottom: 0;
    min-width: 800px; /* Largura mínima para manter layout adequado */
    width: 100%;
}

/* Wrapper responsivo adicional usando Bootstrap */
.table-responsive-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* ========================================
   BREAKPOINTS MOBILE
======================================== */

/* Para telas pequenas (576px e menos) */
@media (max-width: 575.98px) {
    .table-container {
        max-height: 350px; /* Reduz altura em mobile */
        font-size: 0.75rem; /* Fonte menor */
    }
    
    .results-table {
        min-width: 600px; /* Reduz largura mínima */
    }
    
    .results-table th,
    .results-table td {
        padding: 0.5rem 0.25rem; /* Padding menor */
        white-space: nowrap; /* Evita quebra de linha */
    }
    
    /* Oculta colunas menos importantes em mobile */
    .results-table .d-md-table-cell {
        display: none !important;
    }
    
    /* Headers ficam menores */
    .results-header {
        padding: 1rem;
    }
    
    .results-title {
        font-size: 1.25rem;
    }
}

/* Para tablets em modo retrato (768px e menos) */
@media (max-width: 767.98px) {
    .table-container {
        max-height: 380px;
    }
    
    .results-table {
        min-width: 700px;
        font-size: 0.85rem;
    }
    
    .results-table th,
    .results-table td {
        padding: 0.75rem 0.5rem;
    }
}

/* ========================================
   MELHORIAS NA EXPERIÊNCIA MOBILE
======================================== */

/* Scroll indicators visuais */
.table-container::before {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to left, rgba(255,255,255,0.8), transparent);
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.table-container.has-scroll::before {
    opacity: 1;
}

/* Estilização dos scrollbars para mobile */
.table-container::-webkit-scrollbar {
    height: 8px; /* Scrollbar horizontal */
    width: 6px;  /* Scrollbar vertical */
}

.table-container::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #6c757d;
    border-radius: 4px;
    opacity: 0.7;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #495057;
    opacity: 1;
}

/* Para dispositivos touch */
@media (hover: none) and (pointer: coarse) {
    .table-container::-webkit-scrollbar {
        height: 12px; /* Scrollbar maior em touch */
        width: 8px;
    }
    
    .table-container::-webkit-scrollbar-thumb {
        background: #0d6efd;
        opacity: 0.8;
    }
}

/* ========================================
   SOLUÇÕES ALTERNATIVAS PARA MOBILE
======================================== */

/* Cards para mobile como alternativa à tabela */
.mobile-card-view {
    display: none;
}

@media (max-width: 575.98px) {
    .table-view {
        display: none;
    }
    
    .mobile-card-view {
        display: block;
    }
    
    .empresa-card {
        border: 1px solid #dee2e6;
        border-radius: 8px;
        margin-bottom: 1rem;
        padding: 1rem;
        background: white;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .empresa-card .card-header {
        font-weight: 600;
        color: #0d6efd;
        margin-bottom: 0.5rem;
        font-size: 0.9rem;
    }
    
    .empresa-card .card-body {
        font-size: 0.8rem;
        color: #6c757d;
    }
    
    .empresa-card .card-footer {
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid #e9ecef;
        font-size: 0.75rem;
        color: #6c757d;
    }
}

/* ========================================
   INDICADORES DE RESPONSIVIDADE
======================================== */

/* Badge indicando que a tabela é rolável */
.scroll-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(13, 110, 253, 0.1);
    color: #0d6efd;
    padding: 0.25rem 0.5rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 500;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.table-container.has-scroll .scroll-indicator {
    opacity: 1;
}

@media (max-width: 767.98px) {
    .scroll-indicator {
        display: block;
    }
}

/* ========================================
   CORREÇÕES ESPECÍFICAS DO DATATABLES
======================================== */

/* Se usando DataTables */
.dataTables_wrapper .table-responsive {
    overflow-x: auto !important;
}

.dataTables_wrapper .dataTables_scroll {
    overflow-x: auto !important;
}

.dataTables_wrapper .dataTables_scrollBody {
    overflow-x: auto !important;
}

/* Paginação responsiva do DataTables */
@media (max-width: 767.98px) {
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: center !important;
        margin-top: 1rem;
    }
    
    .dataTables_wrapper .dataTables_info {
        float: none !important;
        text-align: center !important;
        margin-bottom: 1rem;
    }
    
    .dataTables_wrapper .dataTables_length {
        float: none !important;
        text-align: center !important;
        margin-bottom: 1rem;
    }
    
    .dataTables_wrapper .dataTables_filter {
        float: none !important;
        text-align: center !important;
        margin-bottom: 1rem;
    }
}

/* ========================================
   PERFORMANCE E ACESSIBILIDADE
======================================== */

/* Smooth scrolling */
.table-container {
    scroll-behavior: smooth;
}

/* Focus indicators */
.table-container:focus-within {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .table-container {
        scroll-behavior: auto;
    }
    
    .table-container::before {
        transition: none;
    }
    
    .scroll-indicator {
        transition: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .table-container {
        border: 2px solid #000;
    }
    
    .results-table th {
        background: #000;
        color: #fff;
    }
    
    .results-table td {
        border-bottom: 1px solid #000;
    }
}

/* ========================================
   CORREÇÕES ESPECÍFICAS PARA PAGINAÇÃO
======================================== */

/* Garantir que a paginação respeite os limites do container */
.results-body {
    width: 100%;
    overflow: hidden; /* Previne overflow horizontal */
}

.pagination-container {
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    box-sizing: border-box;
    padding: 15px;
    margin: 0;
}

.pagination-container .d-flex {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Forçar quebra de linha em mobile para paginação */
@media (max-width: 767.98px) {
    .pagination-container .d-flex {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center;
    }
    
    .pagination-info {
        width: 100%;
        margin-bottom: 15px;
        text-align: center !important;
    }
    
    .pagination {
        width: 100%;
        justify-content: center !important;
        flex-wrap: wrap !important;
    }
    
    /* Ocultar alguns números de página em telas muito pequenas */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child):not(.disabled) {
        display: none;
    }
    
    /* Mostrar apenas primeira, última e ativa */
    .pagination .page-item:first-child,
    .pagination .page-item:last-child,
    .pagination .page-item.active,
    .pagination .page-item.disabled {
        display: flex !important;
    }
}

/* Print styles */
@media print {
    .table-container {
        overflow: visible !important;
        max-height: none !important;
        border: none;
    }
    
    .results-table {
        min-width: auto !important;
    }
    
    .scroll-indicator,
    .table-container::before,
    .pagination-container {
        display: none !important;
    }
}