/* --- 1. IMPORTACIÓN DE FUENTES --- */
@import url('https://fonts.googleapis.com/css2?family=Geist:wght@100..900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,100..900&display=swap');

/* --- 2. FUENTE GLOBAL --- */
body, table, input, button, select, textarea, .dataTables_wrapper {
    font-family: 'Geist', 'Inter', sans-serif !important;
}

/* --- 3. VARIABLES GLOBALES --- */
:root {
    --sidebar-bg: #09090b;
    --emerald-primary: #10b981;
    --emerald-dark: #059669;
    --rose-accent: #f43f5e;
    --slate-text: #64748b;
    --slate-dark: #1e293b;
    --slate-light: #f8fafc;
    --bg-main: #f8fafc;
    --border-light: #e2e8f0;
}

/* --- 4. ESTILOS BASE --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    color: var(--slate-dark);
    margin: 0;
    overflow-x: hidden;
}

/* Scrollbar Estilo macOS / Moderno */
::-webkit-scrollbar { 
    width: 6px; 
    height: 6px; 
}

::-webkit-scrollbar-track { 
    background: transparent; 
}

::-webkit-scrollbar-thumb { 
    background: #cbd5e1; 
    border-radius: 10px; 
}

::-webkit-scrollbar-thumb:hover { 
    background: #94a3b8; 
}

/* --- 5. QUITAR BORDES DEL CONTENEDOR PRINCIPAL --- */
#main-wrapper-card, .main-content-wrapper { 
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

/* --- 6. ESTILO SAAS PARA LA TABLA (CONTENEDOR) --- */
.dataTables_wrapper {
    background-color: #ffffff;
    border: 1px solid var(--border-light);
    border-radius: 0.75rem;
    overflow: hidden;
}

/* --- 7. DATATABLES ESTILOS INTERNOS --- */
table.dataTable {
    border: none !important;
    width: 100% !important;
    margin: 0 !important;
    border-collapse: collapse !important;
}

table.dataTable thead th {
    background-color: #ffffff !important;
    color: #94a3b8 !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    padding: 16px 20px !important;
    border-bottom: 1px solid var(--border-light) !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

table.dataTable tbody td {
    padding: 14px 20px !important;
    border-bottom: 1px solid var(--slate-light) !important;
    font-size: 11px !important;
    vertical-align: middle;
    color: #475569;
}

/* Limpiar doble borde inferior nativo de DataTables */
table.dataTable.no-footer {
    border-bottom: 1px solid var(--slate-light) !important;
}

/* Paginación y Textos Inferiores */
.dataTables_info, .dataTables_paginate {
    font-size: 11px !important;
    color: var(--slate-text) !important;
    padding: 1rem !important;
}

.paginate_button {
    border-radius: 8px !important;
    border: 1px solid var(--border-light) !important;
    margin: 0 2px !important;
    padding: 5px 10px !important;
    background: white !important;
    font-weight: 600 !important;
    cursor: pointer;
    transition: all 0.2s;
}

.paginate_button.current {
    background: var(--emerald-primary) !important;
    color: white !important;
    border-color: var(--emerald-primary) !important;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
}

.paginate_button:hover:not(.current) {
    background: var(--slate-light) !important;
    border-color: #cbd5e1 !important;
}

/* --- 8. DATATABLES RESPONSIVE (FLECHA DESPLEGABLE) --- */
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control {
    position: relative;
    padding-left: 30px !important;
    cursor: pointer;
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
    content: '►' !important; 
    top: 50%;
    left: 10px;
    height: 1em;
    width: 1em;
    margin-top: -9px;
    display: block;
    position: absolute;
    color: #94a3b8 !important;
    border: none !important;
    box-shadow: none !important;
    background-color: transparent !important;
    font-size: 14px;
    transition: transform 0.2s ease;
}

table.dataTable.dtr-inline.collapsed > tbody > tr.parent > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr.parent > th.dtr-control:before {
    content: '▼' !important;
    color: var(--emerald-primary) !important;
}

/* --- 9. ESTILOS DE MODALES Y FORMULARIOS --- */

/* Modal con estilo más moderno */
#modal-box {
    border-radius: 1rem !important;
    overflow: hidden;
}

/* Inputs limpios estilo SaaS */
.input-saas {
    width: 100%;
    border: 1px solid var(--border-light);
    border-radius: 0.5rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    color: #334155;
    outline: none;
    transition: all 0.2s;
    background-color: #fdfdfd;
}

.input-saas:focus {
    border-color: var(--emerald-primary);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.1);
    background-color: #ffffff;
}

.label-saas {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Selectores con flecha SVG personalizada */
select.input-saas {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
    cursor: pointer;
}

select.input-saas:invalid {
    color: #94a3b8;
}

select.input-saas option {
    color: #1e293b;
    padding: 8px;
}

/* Scrollbar interno para historial en modales */
.custom-scrollbar::-webkit-scrollbar { 
    width: 4px; 
}
.custom-scrollbar::-webkit-scrollbar-thumb { 
    background: var(--border-light); 
    border-radius: 4px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--emerald-primary);
}

/* --- 10. UTILIDADES GLOBALES --- */
.fade-in {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-slow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-pulse-slow {
    animation: pulse-slow 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--emerald-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge-rubro {
    padding: 2px 8px;
    background: #f1f5f9;
    color: #64748b;
    border-radius: 4px;
    font-weight: 700;
    font-size: 9px;
    border: 1px solid var(--border-light);
}

/* Badges modernos */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.025em;
}

.badge-success {
    background-color: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

.badge-warning {
    background-color: #fffbeb;
    color: #d97706;
    border: 1px solid #fde68a;
}

.badge-danger {
    background-color: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.badge-info {
    background-color: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
}

/* --- 11. SIDEBAR COLAPSABLE --- */
#sidebar {
    transition: all 0.3s ease-in-out;
}

#sidebar.collapsed {
    width: 5rem !important;
}

#sidebar.collapsed .sidebar-text {
    display: none !important;
}

#sidebar.collapsed .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

#sidebar.collapsed .profile-container {
    justify-content: center;
}

#sidebar.collapsed .header-container {
    justify-content: center;
}

/* --- 12. NAVEGACIÓN --- */
.nav-link {
    transition: all 0.2s ease;
    cursor: pointer;
}

.nav-link.active {
    background-color: #18181b;
    color: var(--emerald-primary);
}

.nav-link.active i {
    color: var(--emerald-primary);
}

.nav-link i {
    transition: all 0.2s;
}

.nav-link:hover i {
    transform: translateX(2px);
}

/* --- 13. MODIFICADORES PARA MÓVIL --- */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease-in-out;
    }
    
    #sidebar.mobile-open {
        left: 0;
    }
    
    /* Overlay para móvil */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    /* Ajustes de tablas en móvil */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: center;
        margin-bottom: 1rem;
    }
    
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: center;
        margin-top: 1rem;
    }
    
    table.dataTable thead th {
        padding: 12px 12px !important;
        font-size: 10px !important;
    }
    
    table.dataTable tbody td {
        padding: 10px 12px !important;
        font-size: 10px !important;
    }
}

/* --- 14. TABLA DESACOPLADA (Estilo ePost) --- */
/* 1. Hacemos el wrapper transparente y sin bordes */
.dataTables_wrapper {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* 2. Aplicamos el fondo blanco y borde curvo SOLO a la tabla */
table.dataTable {
    background-color: #ffffff;
    border: 1px solid var(--border-light) !important;
    border-radius: 1rem !important;
    overflow: hidden;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

/* 3. Ajustamos thead para que combine con el borde redondeado */
table.dataTable thead th:first-child { 
    border-top-left-radius: 1rem; 
}
table.dataTable thead th:last-child { 
    border-top-right-radius: 1rem; 
}

/* 4. Estilos de Paginación Desacoplada (Abajo de la tabla) */
.dataTables_info {
    color: var(--slate-text) !important;
    padding-top: 1.5rem !important;
}
.dataTables_paginate {
    padding-top: 1.5rem !important;
}
.paginate_button {
    border-radius: 0.5rem !important;
    border: 1px solid var(--border-light) !important;
    margin: 0 2px !important;
    padding: 6px 12px !important;
    background: white !important;
    font-weight: 500 !important;
    color: #475569 !important;
}
.paginate_button.current {
    background: var(--emerald-primary) !important;
    color: white !important;
    border-color: var(--emerald-primary) !important;
}
.paginate_button:hover:not(.current) {
    background: var(--slate-light) !important;
}

/* --- 15. CARD HOVER EFFECTS --- */
.card-hover {
    transition: all 0.3s ease;
}

.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.02);
}

/* --- 16. TOOLTIPS PERSONALIZADOS --- */
[data-tooltip] {
    position: relative;
    cursor: pointer;
}

[data-tooltip]:before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #1e293b;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
}

[data-tooltip]:hover:before {
    opacity: 1;
}

/* --- 17. ESTILOS PARA EL DASHBOARD --- */
.kpi-card {
    transition: all 0.3s ease;
    border: 1px solid var(--border-light);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* --- 18. ESTILOS PARA FILTROS Y BÚSQUEDA --- */
.filter-container {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.filter-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-light);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    outline: none;
    transition: all 0.2s;
}

.filter-input:focus {
    border-color: var(--emerald-primary);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.1);
}

/* --- 19. ESTILOS PARA MENSAJES Y ALERTAS --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-success {
    background-color: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background-color: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.alert-info {
    background-color: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
}

/* --- 20. ESTILOS PARA BOTONES --- */
.btn-primary {
    background-color: var(--emerald-primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: var(--emerald-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: white;
    color: #475569;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s;
    border: 1px solid var(--border-light);
    cursor: pointer;
}

.btn-secondary:hover {
    background-color: var(--slate-light);
    border-color: #cbd5e1;
}