/* =========================================
   1. VARIABLES GLOBALES Y BASE
   ========================================= */
:root { 
    --bb-blue: #001A4D; 
    --bb-yellow: #FFCC00; 
    --light-bg: #f4f4f9; 
    --bb-red: #D32F2F; 
    --bb-green: #388E3C; 
}

body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(--light-bg); color: #333; margin: 0; }

/* Animación de carga inicial de la pantalla entera */
body.panel-body { padding: 30px; animation: pageFadeIn 0.8s ease-in-out forwards !important; }
@keyframes pageFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =========================================
   2. LOGIN Y RECUPERAR CONTRASEÑA
   ========================================= */
/* El body ahora entra de forma clásica y suave */
.login-body { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    height: 100vh; 
    background-color: var(--light-bg); 
    animation: pageFadeIn 1s ease-out forwards; 
}
@keyframes pageFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Caja Homologada: Medidas idénticas para evitar saltos */
.login-box { 
    background: white; 
    padding: 40px; 
    border-radius: 8px; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.1); 
    width: 100%; 
    max-width: 420px; 
    min-height: 480px; 
    text-align: center; 
    border-top: 5px solid var(--bb-yellow); 
    display: flex; 
    flex-direction: column;
    box-sizing: border-box;
    /* ESTA ES LA LÍNEA NUEVA */
    animation: entrarDesdeAbajo 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.login-box a { 
    color: #555;                /* El mismo color gris que tus labels */
    text-decoration: none; 
    font-size: 14px;            /* Subimos de 13px a 14px para homologar */
    font-weight: bold;          /* Misma intensidad que el label */
    display: inline-block; 
    margin-top: 20px; 
    transition: all 0.3s ease; 
    cursor: pointer;
}

.login-box a:hover { 
    color: var(--bb-blue);      /* Al pasar el mouse vuelve a tu azul profesional */
    text-decoration: underline; 
}

.login-box p.text-muted { 
    color: #555;            /* El mismo gris oscuro de tus labels */
    font-size: 14px;        /* Homologado al tamaño de los labels */
    font-weight: bold;      /* Le damos el mismo peso visual */
    margin-bottom: 25px;    /* Un poco más de aire para que respire el diseño */
    line-height: 1.5;       /* Mejora la lectura si el texto ocupa dos líneas */
}

/* El movimiento sutil de abajo hacia arriba para la caja */
@keyframes entrarDesdeAbajo { 
    from { 
        opacity: 0; 
        transform: translateY(30px); /* Empieza 30 pixeles más abajo */
    } 
    to { 
        opacity: 1; 
        transform: translateY(0);    /* Sube a su posición original */
    } 
}

.login-box h2 { color: var(--bb-blue); margin-bottom: 25px; font-size: 24px; margin-top: 0; }
.login-box .input-group { margin-bottom: 15px; text-align: left; }
.login-box .input-group label { display: block; margin-bottom: 5px; font-weight: bold; color: #555; font-size: 14px; }
.login-box .input-group input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; font-size: 14px; }

/* Botones Homologados al estilo del Panel */
.login-box .btn-login, .login-box button[type="submit"] { 
    width: 100%; 
    background-color: var(--bb-blue); 
    color: white; 
    font-family: inherit; 
    font-size: 16px; 
    font-weight: bold; 
    padding: 12px; 
    border: none; 
    border-bottom: 3px solid var(--bb-yellow); 
    border-radius: 4px; 
    cursor: pointer; 
    transition: all 0.3s ease; 
    margin-top: 10px; 
}

/* Efecto al pasar el mouse (Se agranda sutilmente un 2%) */
.login-box .btn-login:hover, .login-box button[type="submit"]:hover { 
    filter: brightness(1.15); 
    transform: scale(1.02); 
}

/* Efecto en el instante de hacer clic (Se achica sutilmente simulando presión) */
.login-box .btn-login:active, .login-box button[type="submit"]:active { 
    transform: scale(0.96); 
    filter: brightness(0.9);
}

/* --- MENSAJES DE ALERTA Y ÉXITO --- */
.msg-box { padding: 12px; border-radius: 4px; margin-bottom: 20px; text-align: center; font-size: 14px; line-height: 1.5; font-weight: bold; }
.msg-error { color: #D8000C; background-color: #FFBABA; border: 1px solid #D8000C; }
.msg-success { color: #4F8A10; background-color: #DFF2BF; border: 1px solid #4F8A10; }

/* --- ANIMACIÓN DE CARGA (BOTÓN LOGIN) --- */
.bars-loader { display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 18px; }
.bars-loader span { width: 3px; height: 100%; background-color: #fff; border-radius: 2px; animation: bars-bounce 1s infinite ease-in-out; }
.bars-loader span:nth-child(1) { animation-delay: -0.3s; }
.bars-loader span:nth-child(2) { animation-delay: -0.15s; }
.bars-loader span:nth-child(3) { animation-delay: 0s; }
@keyframes bars-bounce { 0%, 80%, 100% { transform: scaleY(0.4); opacity: 0.6; } 40% { transform: scaleY(1); opacity: 1; } }

/* --- ANIMACIONES UNIFICADAS (SPA) --- */
/* Clases para las vistas internas intercambiables */
.vista-auth {
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
    transform: translateY(0);
}

.vista-oculta {
    display: none !important;
    opacity: 0;
    transform: translateY(10px);
}

/* =========================================
   3. HEADER Y BOTONES SUPERIORES (PANEL)
   ========================================= */
.header { background-color: var(--bb-blue); color: var(--bb-yellow); padding: 15px 30px; border-radius: 8px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 4px 6px rgba(0,0,0,0.1); flex-wrap: wrap; gap: 15px; }
.logo-container { display: flex; align-items: center; gap: 15px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.user-badge { background-color: rgba(255,255,255,0.1); padding: 0 12px; height: 36px; display: inline-flex; align-items: center; border-radius: 4px; font-size: 14px; cursor: pointer; transition: 0.2s; font-weight: bold; border: 1px solid rgba(255,255,255,0.2); box-sizing: border-box; }
.user-badge:hover { background-color: rgba(255,255,255,0.2); }
.bulk-bar { background-color: white; padding: 10px 20px; border-radius: 8px; margin-bottom: 20px; display: flex; gap: 10px; align-items: center; box-shadow: 0 2px 4px rgba(0,0,0,0.05); flex-wrap: wrap; }
.btn-top { font-family: inherit !important; font-size: 14px !important; font-weight: bold !important; padding: 0 16px !important; border-radius: 4px !important; text-decoration: none !important; border: none !important; cursor: pointer !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; height: 36px !important; box-sizing: border-box !important; transition: filter 0.2s, transform 0.2s; }
.btn-top:hover { filter: brightness(0.9); transform: scale(1.02); }
.btn-top:active { transform: scale(0.95); }
.btn-top.volver { background-color: var(--bb-yellow); color: var(--bb-blue); }
.btn-top.logout { background-color: var(--bb-red); color: white; }
.btn-top.edit-btn { background-color: #1976D2; color: white; }
.btn-top.del-btn { background-color: var(--bb-red); color: white; }
.group-dropdown-container { height: 36px !important; max-height: 36px !important; }
.group-dropdown-container .btn-top { height: 100% !important; }

/* =========================================
   4. PESTAÑAS Y FILTROS (TABS)
   ========================================= */
.tabs-container { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; border-bottom: 2px solid #ccc; padding-bottom: 12px; }
.tab-btn { background: #e0e0e0; border: none; padding: 8px 18px; border-radius: 5px; cursor: pointer; font-family: inherit !important; font-size: 13px !important; font-weight: bold !important; letter-spacing: 0.3px; color: #555; transition: 0.2s ease-in-out !important; }
.tab-btn:hover { background: #d0d0d0; }
.tab-btn.active { background: var(--bb-blue); color: var(--bb-yellow); box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 220px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 100; border-radius: 4px; overflow: hidden; top: 100%; left: 0; margin-top: 5px; }
.dropdown-content button { color: #333; padding: 12px 16px; text-decoration: none; display: block; width: 100%; border: none; background: none; text-align: left; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: bold; }
.dropdown-content button:hover { background-color: #e6e6e6; }
.show-dropdown { display: block; }

/* =========================================
   5. ESTRUCTURA Y ANIMACIÓN DE TABLAS
   ========================================= */
.table-container { background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); width: 100%; box-sizing: border-box; }

/* FIX FOUC: Oculto de raíz para que jamás aparezca de golpe */
#vista-individual .table-container, #vista-colecciones .table-container { 
    opacity: 0; 
    transition: opacity 0.6s ease-in-out !important; /* El fade inicial (0.6s) */
}
#vista-individual.ready-view .table-container, #vista-colecciones.ready-view .table-container { 
    opacity: 1 !important; 
}
#vista-individual.fast-transition .table-container, #vista-colecciones.fast-transition .table-container { 
    transition: opacity 0.125s ease-in-out !important; /* Pasa a rápido (0.125s) para los tabs */
}

/* FIX ANCHO COLUMNAS (Mantiene estricto el ancho en PC aunque no haya datos) */
@media (min-width: 1025px) {
    table.dataTable { 
        table-layout: fixed !important; 
        width: 100% !important; 
    }
}

table.dataTable { border-collapse: collapse; border-bottom: none !important; }
table.dataTable thead th { font-family: inherit !important; font-size: 13px !important; letter-spacing: 0.2px; font-weight: bold !important; text-transform: uppercase; color: white !important; background-color: var(--bb-blue) !important; padding: 10px !important; border-bottom: none !important; position: sticky !important; top: 0 !important; z-index: 10 !important; box-shadow: 0 2px 2px rgba(0,0,0,0.1); }
table.dataTable tbody td { font-family: inherit !important; font-size: 13px !important; letter-spacing: 0.2px; vertical-align: middle !important; padding: 8px 10px !important; word-wrap: break-word; }
table.dataTable tbody tr { transition: background-color 0.2s ease; }
table.dataTable tbody tr:hover { background-color: rgba(0, 51, 160, 0.04) !important; }
table.dataTable th.centrar-dt, table.dataTable td.centrar-dt { text-align: center !important; vertical-align: middle !important; }
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { font-family: inherit !important; font-size: 13px !important; color: #555 !important; margin-bottom: 20px; }
.dataTables_wrapper .dataTables_filter input, .dataTables_wrapper .dataTables_length select { font-family: inherit !important; font-size: 13px !important; padding: 4px 8px; border-radius: 4px; border: 1px solid #ccc; }
table.dataTable tbody td.dataTables_empty { height: 32px !important; vertical-align: middle !important; text-align: center !important; font-size: 15px !important; color: #666 !important; background-color: #f9f9f9 !important; font-style: italic; border-bottom: 1px solid #eee !important; }
.codificado-link { cursor: pointer; color: var(--bb-blue); text-decoration: underline; font-weight: bold; }
.codificado-link:hover { color: #003399; }
.password-box { background-color: #f1f3f5; border: 1px solid #ced4da; padding: 6px 10px; border-radius: 5px; font-family: monospace; font-size: 14px; font-weight: bold; color: #d63384; display: inline-block; min-width: 180px; max-width: 250px; text-align: center; letter-spacing: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; box-sizing: border-box; }
.activo-cell { font-size: 18px; user-select: none; display: inline-block; }
.activo-cell.admin { cursor: pointer; }
.activo-cell.admin:hover { transform: scale(1.1); }

/* =========================================
   6. BOTONES DE ACCIÓN EN TABLAS
   ========================================= */
.action-btns { display: flex !important; gap: 3px !important; justify-content: center !important; align-items: center !important; flex-wrap: nowrap !important; }
.action-btn { appearance: none !important; width: 32px !important; height: 32px !important; min-width: 32px !important; min-height: 32px !important; padding: 0 !important; margin: 0 !important; border: none !important; border-radius: 4px !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; font-size: 16px !important; box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important; cursor: pointer !important; transition: transform 0.1s, filter 0.2s !important; }important; margin: 0 2px !important; border: none !important; border-radius: 4px !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; font-size: 16px !important; box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important; cursor: pointer !important; transition: transform 0.1s, filter 0.2s !important; }
.action-btn:hover { transform: scale(1.08) !important; filter: brightness(0.9) !important; }
.nzb-btn { background-color: #4CAF50 !important; }      
.nzb-rev-btn { background-color: #009688 !important; }  
.copy-btn { background-color: #FFC107 !important; }     
.edit-btn { background-color: #1976D2 !important; }     
.log-btn { background-color: #9C27B0 !important; }      
.del-btn { background-color: #E53935 !important; }      
.nzb-btn.uploadable, .nzb-rev-btn.uploadable { background-color: #ccc !important; filter: grayscale(100%) !important; color: white !important; }
.nzb-btn.uploadable:hover { filter: grayscale(0%) !important; background-color: #4CAF50 !important; }
.nzb-rev-btn.uploadable:hover { filter: grayscale(0%) !important; background-color: #008CBA !important; }
#logTableDT th:last-child, #logTableDT td:last-child, #globalLogTableDT th:last-child, #globalLogTableDT td:last-child { width: 60px !important; min-width: 60px !important; max-width: 60px !important; text-align: center !important; }

/* =========================================
   7. VENTANAS MODALES
   ========================================= */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); backdrop-filter: blur(2px); overflow-y: auto; animation: fadeIn 0.2s ease-out; }
.modal-content { background-color: white; margin: 5vh auto; padding: 30px; border-radius: 8px; width: 100%; max-width: 400px; box-sizing: border-box; box-shadow: 0 4px 20px rgba(0,0,0,0.2); animation: slideDown 0.3s ease-out; }
.modal-content.large { max-width: 900px; }
.modal-content.extra-large { max-width: 1260px; }
.modal-content > div[style*="margin-bottom: 15px"] { max-height: 55vh !important; overflow-y: auto !important; overflow-x: hidden !important; }
#adminUsersModal .modal-content, #logModal .modal-content, #globalLogModal .modal-content { padding-bottom: 30px !important; min-height: auto !important; }
#adminUsersModal .dataTables_wrapper, #logModal .dataTables_wrapper, #globalLogModal .dataTables_wrapper { margin-bottom: 0 !important; padding-bottom: 0 !important; }
#adminUsersModal .modal-footer, #logModal .modal-footer, #globalLogModal .modal-footer { margin-top: 15px !important; margin-bottom: 0 !important; padding-bottom: 0 !important; }
.modal h2, .modal h3, .modal-content h2, .modal-content h3 { word-wrap: break-word !important; word-break: break-all !important; white-space: normal !important; padding-right: 10px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-weight: bold; margin-bottom: 5px; color: #555; font-size: 14px; }
.form-group input, .form-group select { width: 100%; padding: 8px; border-radius: 4px; border: 1px solid #ccc; font-size: 14px; box-sizing: border-box; }
.form-group input[type="checkbox"] { width: 16px !important; height: 16px !important; margin: 0 8px 0 0 !important; cursor: pointer; }
.form-group div[style*="flex-direction: column"] label { display: flex !important; align-items: center !important; justify-content: flex-start !important; font-weight: normal !important; margin-bottom: 0 !important; cursor: pointer; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.btn-save { background-color: var(--bb-green); color: white; border: none; padding: 8px 15px; border-radius: 4px; cursor: pointer; font-weight: bold; transition: filter 0.2s; }
.btn-cancel { background-color: #ccc; color: #333; border: none; padding: 8px 15px; border-radius: 4px; cursor: pointer; font-weight: bold; transition: background 0.2s; }
.btn-save:hover { filter: brightness(0.9); }
.btn-cancel:hover { background-color: #bbb; }
.fade-in-datos { animation: modalFadeIn 0.5s ease forwards; }
@keyframes modalFadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.modal.fade-out { animation: fadeOutModal 0.5s ease forwards !important; }
@keyframes fadeOutModal { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =========================================
   8. FIX RESPONSIVO (MÓVILES)
   ========================================= */
@media (max-width: 1024px) {
    table.dataTable { table-layout: auto !important; width: 100% !important; } 
    
    /* ALINEAR ENCABEZADOS A LA IZQUIERDA EN MÓVILES */
    table.dataTable thead th { text-align: left !important; }
    
    .bulk-bar { justify-content: center !important; text-align: center !important; }
    .tabs-container { justify-content: center !important; text-align: center !important; }
    
    /* Mantenemos la casilla de selección (checkbox) en su centro */
    th.col-check, td.col-check { padding-left: 2px !important; padding-right: 2px !important; width: 20px !important; max-width: 20px !important; text-align: center !important; }
    
    th.col-nombre, td.col-nombre { 
        padding-left: 5px !important; 
        width: auto !important; 
        min-width: 0 !important; 
        max-width: 100% !important;
    }
    
    td.col-nombre div { 
        white-space: normal !important; 
        word-break: break-all !important; 
        overflow-wrap: break-word !important; 
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* Diseño Tarjeta (1 Columna) */
table.dataTable > tbody > tr.child ul.dtr-details {
    display: block !important; width: 100% !important; padding: 15px !important; margin: 0 !important;
    list-style-type: none !important; background-color: #f8f9fa !important; border-radius: 6px !important;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05) !important; box-sizing: border-box !important;
}

table.dataTable > tbody > tr.child ul.dtr-details > li {
    display: flex !important; flex-direction: row !important; justify-content: space-between !important;
    align-items: center !important; padding: 12px 0 !important; border-bottom: 1px solid #ddd !important; gap: 15px !important;
}

table.dataTable > tbody > tr.child ul.dtr-details > li:last-child { border-bottom: none !important; }

table.dataTable > tbody > tr.child span.dtr-title {
    font-weight: bold !important; color: var(--bb-blue) !important; margin-bottom: 0 !important;
    font-size: 13px !important; text-transform: uppercase !important; flex-shrink: 0 !important;
}

table.dataTable > tbody > tr.child span.dtr-data {
    white-space: normal !important; word-break: break-word !important; font-size: 14px !important;
    color: #333 !important; text-align: right !important; flex-grow: 1 !important;
}

table.dataTable > tbody > tr.child .password-box {
    max-width: 100% !important; white-space: normal !important; word-break: break-all !important; text-align: center !important;
}

/* 2. Botones de acción alineados a la derecha en la vista móvil de 1 columna */
table.dataTable > tbody > tr.child .action-btns {
    justify-content: flex-end !important; /* <-- ALINEADOS A LA DERECHA */
    flex-wrap: wrap !important;
    gap: 3px !important; 
    margin-top: 10px !important;
    width: 100% !important;
}

/* Matamos el margen heredado para que queden bien compactos */
table.dataTable > tbody > tr.child .action-btn {
    margin: 0 !important; 
}

/* Excepción: Si la fila solo contiene los botones, alineamos el contenedor a la derecha */
table.dataTable > tbody > tr.child ul.dtr-details > li:has(.action-btns) {
    justify-content: flex-end !important; /* <-- ALINEADOS A LA DERECHA */
}

/* =========================================
   9. ALINEACIÓN INTELIGENTE DE ENCABEZADOS
   ========================================= */

/* Solo para PC: Centramos obligatoriamente las columnas "ID", "Acción", etc. */
@media (min-width: 1025px) {
    th.centrar-pc { 
        text-align: center !important; 
    }
}

/* Solo para MÓVIL: Todos los encabezados se recargan a la izquierda sin excepción */
@media (max-width: 1024px) {
    table.dataTable thead th { 
        text-align: left !important; 
    }
    /* Mantenemos el checkbox siempre en medio para que no se desalinee */
    th.col-check, td.col-check { 
        text-align: center !important; 
    }
    
    /* Pequeño ajuste visual para que "NOMBRE ORIGINAL" quede perfectamente alineado con el texto de abajo (por el ícono [+] ) */
    th.col-nombre {
        padding-left: 30px !important;
    }
}

/* =========================================
   10. AJUSTES FINALES: MODALES Y CENTRADO
   ========================================= */

/* 1. Recuperamos el centrado de la columna Antigüedad y Activo */
.text-center { 
    text-align: center !important; 
}

/* 2. Fijamos la columna "Usuario" en los Logs a un ancho estricto */
#logTableDT th:first-child, #logTableDT td:first-child, 
#globalLogTableDT th:first-child, #globalLogTableDT td:first-child { 
    width: 120px !important; 
    min-width: 120px !important; 
    max-width: 120px !important; 
    overflow: hidden !important; 
    text-overflow: ellipsis !important; 
}

/* 3. Fijamos la columna "ID" en Gestión de Usuarios a un ancho estricto */
#adminUsersTable th:first-child, #adminUsersTable td:first-child { 
    width: 45px !important; 
    min-width: 45px !important; 
    max-width: 45px !important; 
    text-align: center !important; 
}