/**
 * Estilos CSS Consolidados para la pestaña de Accesos del sistema IRS Basquet
 * Incluye fixes de layout, scroll y visualización
 */

/* ===== FIXES DE LAYOUT Y SCROLL (ALTA PRIORIDAD) ===== */

/* Scroll general de la página */
body, html {
    overflow-y: auto !important;
    height: auto !important;
    max-height: none !important;
}

#irs-admin-container {
    overflow-y: auto !important;
    max-height: 100vh !important;
    height: 100vh !important;
}

.tab-content {
    overflow-y: auto !important;
    max-height: calc(100vh - 120px) !important;
    min-height: calc(100vh - 100px) !important;
    padding-bottom: 20px !important;
}

/* Asegurar que todas las pestañas tengan contenido suficiente */
#tab-usuarios, #tab-salas, #tab-chats, #tab-accesos {
    min-height: 120vh !important;
    overflow-y: auto !important;
}

/* Estilo personalizado para scrollbar */
#irs-admin-container::-webkit-scrollbar,
.tab-content::-webkit-scrollbar {
    width: 12px;
}

#irs-admin-container::-webkit-scrollbar-track,
.tab-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: var(--radius-md);
}

#irs-admin-container::-webkit-scrollbar-thumb,
.tab-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: var(--radius-md);
    border: 2px solid #f1f1f1;
}

#irs-admin-container::-webkit-scrollbar-thumb:hover,
.tab-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ===== CONTENEDOR PRINCIPAL DE LA PESTAÑA DE ACCESOS ===== */
#tab-accesos {
    background: var(--bg-secondary) !important;
    padding: 20px;
    min-height: 120vh !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* ===== TABLA DE ACCESOS - FORZAR VISIBILIDAD ===== */

/* Contenedor de la tabla - FORZAR VISIBILIDAD */
#tab-accesos .table-container {
    background: white !important;
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Wrapper con scroll - FORZAR VISIBILIDAD */
#tab-accesos .table-wrapper {
    max-height: 500px;
    overflow: auto;
    border: 1px solid var(--border-light);
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Tabla principal - FORZAR VISIBILIDAD */
#accesos-table {
    width: 100% !important;
    min-width: 1000px;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    background: white !important;
    display: table !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Encabezados - FORZAR VISIBILIDAD */
#accesos-table thead {
    position: sticky;
    top: 0;
    background: var(--secondary-color) !important;
    z-index: 10;
    display: table-header-group !important;
    visibility: visible !important;
}

#accesos-table th {
    background: var(--secondary-color) !important;
    color: white !important;
    display: table-cell !important;
    visibility: visible !important;
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    border-right: 1px solid var(--secondary-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Cuerpo de la tabla - FORZAR VISIBILIDAD */
#accesos-table tbody {
    background: white !important;
    display: table-row-group !important;
    visibility: visible !important;
}

#accesos-table td {
    padding: 8px 6px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: table-cell !important;
    visibility: visible !important;
    background: white;
    color: var(--text-secondary);
}

/* Filas - FORZAR VISIBILIDAD */
#accesos-table tr {
    display: table-row !important;
    visibility: visible !important;
}

#accesos-table tr:nth-child(even) {
    background: #f9fafb;
}

#accesos-table tr:nth-child(even) td {
    background: #f9fafb;
}

#accesos-table tr:hover {
    background: #f3f4f6;
}

#accesos-table tr:hover td {
    background: #f3f4f6;
}

/* Anchos específicos de columnas */
#accesos-table th.col-usuario,
#accesos-table td.col-usuario { width: 100px; }

#accesos-table th.col-ip,
#accesos-table td.col-ip { width: 120px; }

#accesos-table th.col-dispositivo,
#accesos-table td.col-dispositivo { width: 90px; }

#accesos-table th.col-navegador,
#accesos-table td.col-navegador { width: 110px; }

#accesos-table th.col-os,
#accesos-table td.col-os { width: 90px; }

#accesos-table th.col-ubicacion,
#accesos-table td.col-ubicacion { width: 150px; }

#accesos-table th.col-fecha,
#accesos-table td.col-fecha { width: 140px; }

#accesos-table th.col-duracion,
#accesos-table td.col-duracion { width: 80px; }

#accesos-table th.col-proveedor,
#accesos-table td.col-proveedor { width: 120px; }

/* Estilos específicos para el contenido de la columna proveedor */
#accesos-table td.col-proveedor .proveedor,
#accesos-table td.col-proveedor .provider-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

/* Scrollbar personalizada para la tabla */
#tab-accesos .table-wrapper::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

#tab-accesos .table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: var(--radius-md);
}

#tab-accesos .table-wrapper::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: var(--radius-md);
}

#tab-accesos .table-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-dark);
}

/* ===== COMPONENTES DE INTERFAZ ===== */

/* ===== FILTROS DE BÚSQUEDA MEJORADOS ===== */
.filters-section {
    background: #f8f9fc;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
}

.filters-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 20px;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-input {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    background: white;
    transition: var(--transition-colors);
}

.filter-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.filter-input::placeholder {
    color: #9ca3af;
}

.filter-actions {
    display: flex;
    gap: 10px;
}

.filter-actions .btn {
    padding: 10px 16px;
    font-size: 14px;
    white-space: nowrap;
}

/* Responsive para filtros */
@media (max-width: 768px) {
    .filters-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .filter-actions {
        flex-direction: column;
    }
}

/* Filtros de búsqueda (estilo alternativo) */
.search-filters-container {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    overflow: hidden;
}

.search-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-input, .form-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
    align-items: end;
}

.filter-actions .btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Tabla de accesos */
.table-container {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-bottom: 2rem;
}

.table-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.table-info {
    font-size: 0.875rem;
    opacity: 0.9;
}

/* Estilos de table-wrapper están definidos arriba con forzado de visibilidad */

/* Estilos específicos para la tabla están definidos arriba con forzado de visibilidad */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 1rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.data-table th.sortable:hover {
    background: var(--border-light);
}

.data-table th i {
    margin-right: 0.5rem;
    opacity: 0.7;
}

.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background: #f9fafb;
}

/* Estilos específicos para columnas */
.data-table .ip-cell {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: #6b7280;
}

.data-table .location-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.country-flag {
    width: 20px;
    height: 15px;
    border-radius: 2px;
    background: var(--border-light);
    display: inline-block;
}

.device-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.device-badge.desktop {
    background: #dbeafe;
    color: #1d4ed8;
}

.device-badge.mobile {
    background: #d1fae5;
    color: #065f46;
}

.device-badge.tablet {
    background: #fef3c7;
    color: #92400e;
}

.browser-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.browser-icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.duration-badge {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-xl);
    font-size: 0.75rem;
    font-weight: 500;
    background: #f3f4f6;
    color: var(--text-secondary);
}

.details-btn {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: white;
    color: #6b7280;
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition-base);
}

.details-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
    background: #f8faff;
}

/* Paginación */
.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-light);
}

.pagination-info {
    color: #6b7280;
    font-size: 0.875rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-numbers {
    display: flex;
    gap: 0.25rem;
}

.page-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition-base);
}

.page-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

.page-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Gráficos y estadísticas */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.chart-card {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
}

.chart-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem;
}

.chart-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.chart-body {
    padding: 1.5rem;
}

.chart-body canvas {
    max-width: 100%;
    height: auto;
}

/* Listas de países y usuarios */
.countries-list, .users-list {
    max-height: 200px;
    overflow-y: auto;
}

.country-item, .user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.country-item:last-child, .user-item:last-child {
    border-bottom: none;
}

.country-name, .user-name {
    font-weight: 500;
    color: var(--text-secondary);
}

.country-count, .user-count {
    background: #f3f4f6;
    color: #6b7280;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-xl);
    font-size: 0.75rem;
    font-weight: 500;
}

/* Modal de detalles */
#acceso-details-modal .modal-content {
    max-width: 800px;
    width: 90vw;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.detail-group {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--radius-lg);
}

.detail-group h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    font-size: 0.875rem;
}

.detail-label {
    color: #6b7280;
    font-weight: 500;
}

.detail-value {
    color: var(--text-secondary);
    font-weight: 400;
    text-align: right;
    word-break: break-word;
}

/* Estados de carga */
.loading-row td {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.loading-spinner i {
    animation: spin 1s linear infinite;
}

/* Responsive design */
@media (max-width: 768px) {
    .search-filters {
        grid-template-columns: 1fr;
    }
    
    .filter-actions {
        grid-column: 1 / -1;
        justify-content: stretch;
    }
    
    .filter-actions .btn {
        flex: 1;
    }
    
    .table-pagination {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .pagination-controls {
        justify-content: center;
    }
    
    .charts-container {
        grid-template-columns: 1fr;
    }
    
    .data-table {
        font-size: 0.75rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.5rem 0.25rem;
    }
}

/* Animaciones */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

/* Estados vacíos */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-secondary);
}

.empty-state p {
    margin: 0;
    font-size: 0.875rem;
}

/* Badges de estado */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge.online {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.offline {
    background: #fee2e2;
    color: #991b1b;
}

.status-badge.unknown {
    background: #f3f4f6;
    color: #6b7280;
}

/* Tooltips */
.tooltip {
    position: relative;
    cursor: help;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-secondary);
    color: white;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}

.tooltip:hover::after {
    opacity: 1;
}
