/* ============================================================================
   DATATABLES CUSTOM STYLES - Estilos personalizados para DataTables
   ============================================================================ */

/* Contenedor de botones de DataTables */
.dt-buttons {
    margin-bottom: 1rem;
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    clear: both;  /* Evitar superposición */
}

/* Botones de exportación */
.dt-button {
    background-color: var(--primary-orange) !important;
    color: white !important;
    border: none !important;
    padding: 0.5rem 1rem !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    font-size: 0.875rem !important;
    transition: all 0.3s ease !important;
}

.dt-button:hover {
    opacity: 0.9 !important;
    transform: translateY(-1px);
}

/* Input de búsqueda de DataTables */
.dataTables_filter input {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.875rem;
    width: 300px;
    margin-left: 0.5rem;
}

.dataTables_filter input:focus {
    outline: none;
    border-color: var(--primary-orange);
    box-shadow: 0 0 0 2px rgba(251, 135, 7, 0.1);
}

/* Label de búsqueda */
.dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #666;
}

/* Headers de tabla con DataTables */
.dataTable thead th {
    background-color: #f8f9fa;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 1rem;
    cursor: pointer;
    user-select: none;
}

.dataTable thead th:hover {
    background-color: #e9ecef;
}

/* Iconos de ordenamiento */
.dataTable thead .sorting:before,
.dataTable thead .sorting_asc:before,
.dataTable thead .sorting_desc:before {
    content: ' ';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 0.5rem;
}

.dataTable thead .sorting:after {
    content: '⇅';
    opacity: 0.3;
    margin-left: 0.5rem;
}

.dataTable thead .sorting_asc:after {
    content: '↑';
    color: var(--primary-orange);
    margin-left: 0.5rem;
}

.dataTable thead .sorting_desc:after {
    content: '↓';
    color: var(--primary-orange);
    margin-left: 0.5rem;
}

/* Filas de tabla */
.dataTable tbody tr {
    transition: background-color 0.2s ease;
}

.dataTable tbody tr:hover {
    background-color: #f8f9fa;
}

/* Responsive - ocultar columnas en móvil */
@media (max-width: 768px) {
    .dataTable thead th:nth-child(n+5),
    .dataTable tbody td:nth-child(n+5) {
        display: none;
    }
    
    .dataTables_filter input {
        width: 200px;
    }
}

/* Ajuste de espaciado */
.dataTables_wrapper {
    padding: 0;
}

.dataTables_wrapper .dataTables_filter {
    text-align: right;
    margin-bottom: 1rem;
}

/* Contenedor principal */
.dataTables_wrapper .dt-buttons {
    float: left;
}

.dataTables_wrapper .dataTables_filter {
    float: right;
}

/* Limpiar floats */
.dataTables_wrapper::after {
    content: "";
    display: table;
    clear: both;
}

/* Ajustar tabla */
.dataTable {
    width: 100% !important;
    margin-top: 1rem !important;
}

/* Sin resultados */
.dataTables_empty {
    padding: 2rem !important;
    text-align: center !important;
    color: #999 !important;
}

/* Procesando */
.dataTables_processing {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 1rem 2rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Ajustes para columna de dirección larga */
.dataTable td {
    max-width: 300px;
    white-space: normal !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Columna de propiedad/dirección específicamente */
.dataTable td:nth-child(2) {
    min-width: 200px;
    max-width: 400px;
}

/* ID más compacto */
.dataTable td:first-child {
    white-space: nowrap;
    width: 80px;
}

/* Estado más compacto */
.dataTable td:nth-child(3) {
    white-space: nowrap;
    width: 120px;
}

/* Fechas y renta más compactas */
.dataTable td:nth-child(4),
.dataTable td:nth-child(5),
.dataTable td:nth-child(6) {
    white-space: nowrap;
    width: 110px;
}

/* Botones de acción */
.dataTable td:nth-child(7),
.dataTable td:nth-child(8) {
    white-space: nowrap;
    width: 100px;
}

/* ============================================================================
   TABLA DE CONTRATOS - Configuración específica
   ============================================================================ */

/* Forzar layout fijo para controlar anchos */
#contratosTable {
    table-layout: fixed !important;
    width: 100% !important;
}

/* Headers con anchos específicos */
#contratosTable thead th:nth-child(1) { width: 70px !important; }    /* ID */
#contratosTable thead th:nth-child(2) { width: 25% !important; }      /* PROPIEDAD */
#contratosTable thead th:nth-child(3) { width: 18% !important; }      /* ESTADO */
#contratosTable thead th:nth-child(4) { width: 10% !important; }      /* FECHA INICIO */
#contratosTable thead th:nth-child(5) { width: 10% !important; }      /* FECHA FIN */
#contratosTable thead th:nth-child(6) { width: 10% !important; }      /* RENTA */
#contratosTable thead th:nth-child(7) { width: 100px !important; }    /* CREAR CENSO */
#contratosTable thead th:nth-child(8) { width: 120px !important; }    /* ACCIONES */

/* Celdas con mismo ancho que headers */
#contratosTable tbody td:nth-child(1) { 
    width: 70px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#contratosTable tbody td:nth-child(2) { 
    width: 25% !important;
    white-space: normal !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 0; /* Truco para que funcione text-overflow con table-layout fixed */
}

#contratosTable tbody td:nth-child(3) { 
    width: 18% !important;
    white-space: normal !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.85rem;
    line-height: 1.3;
}

#contratosTable tbody td:nth-child(4),
#contratosTable tbody td:nth-child(5),
#contratosTable tbody td:nth-child(6) { 
    white-space: nowrap;
    text-align: center;
}

#contratosTable tbody td:nth-child(7),
#contratosTable tbody td:nth-child(8) { 
    white-space: nowrap;
    text-align: center;
}

/* Ajustar padding para celdas más compactas */
#contratosTable tbody td {
    padding: 0.75rem 0.5rem !important;
    vertical-align: middle;
}

/* Badges de estado más compactos */
#contratosTable .badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.2;
    white-space: normal;
    word-wrap: break-word;
    max-width: 100%;
}

#contratosTable_wrapper .dt-buttons {
    margin-top: 1rem;
}

/* Ocultar barra de búsqueda de DataTables cuando se usa búsqueda manual por tokens */
.no-internal-search .dataTables_filter {
    display: none !important;
}

/* Ocultar información de paginación cuando se usa paginación manual */
.no-internal-paging .dataTables_info,
.no-internal-paging .dataTables_paginate {
    display: none !important;
}

/* Separación adecuada entre búsqueda manual y botones de exportación */
.search-section + .data-table .dt-buttons {
    margin-top: 1.5rem;
}

/* Ajustes para evitar que los botones se superpongan con la tabla */
.dataTables_wrapper .dt-buttons {
    float: none;
    margin-bottom: 1rem;
}

.dataTables_wrapper .dataTables_filter {
    float: none;
    text-align: left;
    margin-bottom: 1rem;
}

/* Limpiar floats para evitar superposición */
.dataTables_wrapper > div:first-child {
    display: block;
    clear: both;
}