/* =================================================================
   LAYOUT SIDEBAR CONTENT - Sistema integrado profesional
   Paxapos - CakePHP 2 + Bootstrap 3
   CSS optimizado y moderno sin duplicaciones
   ================================================================= */

:root {
    --header-height: 60px;
    --sidebar-width: 280px;
    --content-padding: 20px;
    --transition-speed: 0.3s;
}




/* =================================================================
   SIDEBAR BASE - Estilos fundamentales
   ================================================================= */

.sidebar-global {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--color-white);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1025; /* Entre header (1030) y overlay (1020) */
    display: block !important; /* Forzar visibilidad */
    visibility: visible;
    opacity: 1;
    transform: translateX(0);
    transition: transform var(--transition-speed) ease;
}

.sidebar-overlay {
    display: none; /* Oculto por defecto */
}

/* Contenedor principal */
.sidebar-container {
    position: relative;
    width: 100%;
}

.main-content {
    width: 100%;
}

/* =================================================================
   SIDEBAR CONTROLS
   ================================================================= */

.sidebar-toggle {
    background: transparent;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.sidebar-toggle:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.sidebar-close {
    padding: 4px 8px;
    font-size: 12px;
    background: transparent;
    border: 1px solid var(--color-grey-3);
}

/* =================================================================
   RESPONSIVE LAYOUT
   ================================================================= */

/* DESKTOP */
@media (min-width: 769px) {
    #content.container-fluid {
        padding: 0;
        margin: 0;
        max-width: none;
    }
    
    .sidebar-container {
        display: flex;
        min-height: calc(100vh - var(--header-height));
        position: relative;
    }
    
    .sidebar-container .sidebar-global {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: var(--sidebar-width);
        height: calc(100vh - var(--header-height));
        z-index: 1025;
        overflow-y: auto;
        display: block !important;
        transform: translateX(0) !important;
    }
    
    .sidebar-container .main-content {
        flex: 1;
        margin-left: var(--sidebar-width); /* Espacio para el sidebar fijo */
        padding: var(--content-padding);
        min-height: calc(100vh - var(--header-height));
        width: calc(100% - var(--sidebar-width));
    }
    
    .sidebar-overlay {
        display: none;
    }
    
    #globalSidebarToggle {
        display: none;
    }
}

/* MÓVIL - TABLET (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .sidebar-container .sidebar-global {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: var(--sidebar-width);
        height: calc(100vh - var(--header-height));
        z-index: 1025; /* Arriba del overlay */
        transform: translateX(-100%); /* Oculto por defecto */
        transition: transform var(--transition-speed) ease;
        overflow-y: auto;
    }
    
    .sidebar-overlay {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100%;
        height: calc(100vh - var(--header-height));
        background: rgba(0, 0, 0, 0.5);
        z-index: 1020; /* Debajo del sidebar */
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition-speed) ease;
        display: block; /* Mostrar overlay en tablet */
    }
    
    /* Estados del sidebar abierto en tablet */
    .sidebar-open .sidebar-container .sidebar-global,
    body.sidebar-open .sidebar-global { 
        transform: translateX(0); /* Mostrar sidebar */
    }
    
    .sidebar-open .sidebar-overlay,
    body.sidebar-open .sidebar-overlay { 
        opacity: 1; 
        visibility: visible; 
    }
    
    /* Prevenir scroll del body cuando sidebar está abierto */
    body.sidebar-open {
        overflow: hidden;
    }
    
    .main-content {
        padding: var(--content-padding);
        min-height: calc(100vh - var(--header-height));
        width: 100%;
    }
    
    #globalSidebarToggle { 
        display: inline-block; 
        padding: 5px 10px;
        border-radius: 3px;
        font-size: 12px;
    }
}

/* MÓVIL - CELULAR (≤480px) */
@media (max-width: 480px) {
    .sidebar-container .sidebar-global {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100%; /* 100% del ancho en celular */
        height: calc(100vh - var(--header-height));
        z-index: 1025;
        transform: translateX(-100%); /* Oculto por defecto */
        transition: transform var(--transition-speed) ease;
        overflow-y: auto;
    }
    
    .sidebar-overlay {
        display: none !important; /* Sin overlay en celular */
    }
    
    /* Estados del sidebar abierto en celular */
    .sidebar-open .sidebar-container .sidebar-global,
    body.sidebar-open .sidebar-global { 
        transform: translateX(0); /* Mostrar sidebar a pantalla completa */
    }
    
    /* Prevenir scroll del body cuando sidebar está abierto */
    body.sidebar-open {
        overflow: hidden;
    }
    
    .main-content {
        padding: var(--content-padding);
        min-height: calc(100vh - var(--header-height));
        width: 100%;
    }
    
    #globalSidebarToggle { 
        display: inline-block; 
        padding: 5px 10px;
        border-radius: 3px;
        font-size: 12px;
    }
}

/* Bootstrap compatibility */
.main-content .row {
    margin-left: -15px;
    margin-right: -15px;
}

.main-content .row > [class*="col-"] {
    padding-left: 15px;
    padding-right: 15px;
}

/* =================================================================
   SECCIONES DEL SIDEBAR - Separación visual entre apps y admin
   ================================================================= */

.sidebar-section-header {
    padding: 10px 15px 5px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 5px;
}

.sidebar-section-header.admin-mode {
    background: #e3f2fd;
    border-bottom: 1px solid #90caf9;
}

.sidebar-section-header.admin-mode small {
    color: #1976d2;
    font-weight: 600;
}

.sidebar-section-header small {
    font-weight: 500;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10px;
}

.sidebar-section-header i {
    margin-right: 5px;
}

.apps-separator {
    margin: 0;
    border-color: #dee2e6;
    border-width: 2px;
}
