﻿/* ========================================================================
   SIDEBAR COLAPSABLE - NavegaciÃ³n lateral con transparencia
   ======================================================================== */

/* ----------------------------------------------------------------
   SIDEBAR PRINCIPAL
   ---------------------------------------------------------------- */
.app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 60px; /* Ancho colapsado - solo iconos */
    background: rgba(25, 25, 35, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.app-sidebar:hover,
.app-sidebar.expanded {
    width: 240px; /* Ancho expandido */
}

/* ----------------------------------------------------------------
   LOGO / BRAND
   ---------------------------------------------------------------- */
.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 12px;
    height: 56px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.sidebar-logo:hover {
    transform: scale(1.05);
}

.sidebar-title {
    margin-left: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease 0.1s;
}

.app-sidebar:hover .sidebar-title,
.app-sidebar.expanded .sidebar-title {
    opacity: 1;
}

/* ----------------------------------------------------------------
   MENÃš DE NAVEGACIÃ“N
   ---------------------------------------------------------------- */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* Items de menÃº */
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    margin: 2px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    position: relative;
}

.sidebar-item i {
    width: 24px;
    font-size: 1.1rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-item-text {
    margin-left: 12px;
    font-size: 0.875rem;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease 0.1s;
}

.app-sidebar:hover .sidebar-item-text,
.app-sidebar.expanded .sidebar-item-text {
    opacity: 1;
}

.sidebar-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.sidebar-item.active {
    background: rgba(102, 126, 234, 0.25);
    color: #a5b4fc;
}

.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: #a5b4fc;
    border-radius: 0 3px 3px 0;
}

.sidebar-item.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* ----------------------------------------------------------------
   SUBMENÃšS
   ---------------------------------------------------------------- */
.sidebar-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(0, 0, 0, 0.15);
    margin: 0 8px;
    border-radius: 0 0 8px 8px;
}

.sidebar-item.has-submenu.open + .sidebar-submenu {
    max-height: 200px;
}

.sidebar-submenu .sidebar-item {
    padding: 8px 16px 8px 48px;
    margin: 0;
    border-radius: 0;
    font-size: 0.82rem;
}

.sidebar-submenu .sidebar-item:first-child {
    margin-top: 4px;
}

.sidebar-submenu .sidebar-item:last-child {
    margin-bottom: 4px;
    border-radius: 0 0 8px 8px;
}

/* Flecha de submenÃº */
.sidebar-item.has-submenu::after {
    content: '\f054'; /* fa-chevron-right */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 0.65rem;
    position: absolute;
    right: 12px;
    opacity: 0;
    transition: all 0.2s ease;
}

.app-sidebar:hover .sidebar-item.has-submenu::after,
.app-sidebar.expanded .sidebar-item.has-submenu::after {
    opacity: 0.5;
}

.sidebar-item.has-submenu.open::after {
    transform: rotate(90deg);
    opacity: 0.8;
}

/* ----------------------------------------------------------------
   SEPARADORES
   ---------------------------------------------------------------- */
.sidebar-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 8px 16px;
}

.sidebar-section-title {
    padding: 12px 16px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.35);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease 0.1s;
}

.app-sidebar:hover .sidebar-section-title,
.app-sidebar.expanded .sidebar-section-title {
    opacity: 1;
}

/* ----------------------------------------------------------------
   USUARIO Y LOGOUT (FOOTER)
   ---------------------------------------------------------------- */
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px;
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user-info {
    margin-left: 10px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.2s ease 0.1s;
}

.app-sidebar:hover .sidebar-user-info,
.app-sidebar.expanded .sidebar-user-info {
    opacity: 1;
}

.sidebar-user-name {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
}

.sidebar-logout {
    margin-left: auto;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
}

.app-sidebar:hover .sidebar-logout,
.app-sidebar.expanded .sidebar-logout {
    opacity: 1;
}

.sidebar-logout:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

/* ----------------------------------------------------------------
   AJUSTE DEL CONTENIDO PRINCIPAL
   ---------------------------------------------------------------- */
.main-panel.with-sidebar {
    margin-left: 60px;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 100vh;
}

/* Cuando la sidebar estÃ¡ hover, NO mover el contenido (overlay) */
/* El contenido se queda en su lugar */

/* Overlay y botÃ³n mÃ³vil - ocultos por defecto en desktop */
.sidebar-overlay {
    display: none;
}

.mobile-menu-toggle {
    display: none;
}

/* ----------------------------------------------------------------
   RESPONSIVE - MÃ“VIL
   ---------------------------------------------------------------- */
@media (max-width: 768px) {
    .app-sidebar {
        width: 0;
        transform: translateX(-100%);
    }
    
    .app-sidebar.mobile-open {
        width: 240px;
        transform: translateX(0);
    }
    
    .main-panel.with-sidebar {
        margin-left: 0;
    }
    
    /* BotÃ³n hamburguesa para mÃ³vil */
    .mobile-menu-toggle {
        display: flex;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 1001;
        background: rgba(25, 25, 35, 0.9);
        border: none;
        color: white;
        padding: 10px;
        border-radius: 8px;
        cursor: pointer;
    }
    
    /* Overlay para cerrar en mÃ³vil */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

@media (min-width: 769px) {
    .mobile-menu-toggle {
        display: none;
    }
}

/* ----------------------------------------------------------------
   OCULTAR NAVBAR ORIGINAL CUANDO HAY SIDEBAR
   ---------------------------------------------------------------- */
.main-panel.with-sidebar .main-navbar {
    display: none;
}

/* ----------------------------------------------------------------
   AJUSTES ADICIONALES PARA CONTENIDO
   ---------------------------------------------------------------- */

/* Asegurar que el contenido principal no se superponga con el sidebar */
.main-panel.with-sidebar .module-content,
.main-panel.with-sidebar .main-content {
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Module header ajustado */
.main-panel.with-sidebar .module-header {
    margin-top: 0;
    padding-top: 20px;
}

/* Ajuste para el contenido del mÃ³dulo exterior */
.main-panel.with-sidebar > .module-content {
    margin-left: 60px;
    transition: margin-left 0.3s ease;
}

/* Ajuste para main-content */
.main-panel.with-sidebar .main-content {
    margin-left: 60px;
    transition: margin-left 0.3s ease;
    padding-left: 20px;
    padding-right: 20px;
}

/* Ajustar scroll en el Ã¡rea de contenido */
.main-panel.with-sidebar {
    overflow-x: hidden;
}

/* Ajustar altura de mÃ³dulos con sidebar (ya no hay navbar de 48px) */
.main-panel.with-sidebar #planningStatus.module-content.active {
    height: 100vh !important;
}

.main-panel.with-sidebar #ejecucionObra.module-content.active {
    height: 100vh !important;
}

/* Z-index correcto para que el selector de proyectos funcione */
.main-panel.with-sidebar .proyecto-selector {
    position: relative;
    z-index: 10;
}

.main-panel.with-sidebar .proyecto-select {
    position: relative;
    z-index: 11;
}

/* ----------------------------------------------------------------
   SELECTOR GLOBAL DE PROYECTO EN SIDEBAR
   ---------------------------------------------------------------- */
.sidebar-project-selector {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
}

.project-selector-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    opacity: 0;
    transition: opacity 0.2s ease 0.1s;
}

.app-sidebar:hover .project-selector-header,
.app-sidebar.expanded .project-selector-header {
    opacity: 1;
}

.project-selector-current {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 36px;
}

.project-selector-current:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(139, 92, 246, 0.4);
}

.project-selector-current .project-name {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.project-selector-current .project-arrow {
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    opacity: 0;
}

.app-sidebar:hover .project-arrow,
.app-sidebar.expanded .project-arrow {
    opacity: 1;
}

.sidebar-project-selector.open .project-arrow {
    transform: rotate(180deg);
}

/* Dropdown de proyectos */
.project-selector-dropdown {
    position: absolute;
    top: 100%;
    left: 8px;
    right: 8px;
    background: rgba(30, 30, 45, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 1100;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.2s ease;
}

.sidebar-project-selector.open .project-selector-dropdown {
    max-height: 300px;
    opacity: 1;
    overflow-y: auto;
}

.project-search {
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.project-search input {
    width: 100%;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #fff;
    font-size: 0.85rem;
}

.project-search input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.project-search input:focus {
    outline: none;
    border-color: rgba(139, 92, 246, 0.5);
}

.project-list {
    padding: 4px;
    max-height: 220px;
    overflow-y: auto;
}

.project-list-item {
    padding: 10px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
}

.project-list-item:hover {
    background: rgba(139, 92, 246, 0.2);
    color: #fff;
}

.project-list-item.active {
    background: rgba(139, 92, 246, 0.3);
    color: #fff;
}

/* BotÃ³n de bloqueo */
.project-lock-btn {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    background: rgba(139, 92, 246, 0.3);
    border: none;
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.8);
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
}

.app-sidebar:hover .project-lock-btn,
.app-sidebar.expanded .project-lock-btn {
    opacity: 1;
}

.project-lock-btn:hover {
    background: rgba(139, 92, 246, 0.5);
}

.project-lock-btn.unlocked i::before {
    content: "\f09c"; /* fa-unlock */
}

/* Estado congelado */
.sidebar-project-selector.locked .project-selector-current {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.3);
    cursor: default;
}

.sidebar-project-selector.locked .project-name {
    color: #a78bfa;
}

/* ----------------------------------------------------------------
   PANTALLA INICIAL (SIN PROYECTO)
   ---------------------------------------------------------------- */
.initial-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 40px);
    margin-left: 60px;
    background: linear-gradient(135deg, 
        rgba(30, 27, 75, 0.5) 0%, 
        rgba(59, 35, 94, 0.5) 50%,
        rgba(30, 27, 75, 0.5) 100%);
    position: relative;
    overflow: hidden;
}

/* Fondo animado similar al login */
.initial-screen::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(79, 70, 229, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(147, 51, 234, 0.1) 0%, transparent 40%);
    animation: floatBg 20s ease-in-out infinite;
}

@keyframes floatBg {
    0%, 100% { transform: translate(-10%, -10%) rotate(0deg); }
    33% { transform: translate(0%, -5%) rotate(5deg); }
    66% { transform: translate(-5%, 0%) rotate(-5deg); }
}

.initial-screen-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px;
}

.initial-logo {
    margin-bottom: 24px;
}

.initial-logo img {
    width: 80px;
    height: 80px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(139, 92, 246, 0.3);
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.initial-title {
    font-size: 2rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.95);
    margin: 0 0 8px 0;
    text-shadow: 0 2px 10px rgba(139, 92, 246, 0.3);
}

.initial-subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.5);
    margin: 0 0 32px 0;
}

.initial-instruction {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    animation: fadeInUp 0.5s ease 0.3s both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.initial-instruction i {
    color: rgba(139, 92, 246, 0.8);
    font-size: 1.2rem;
}

.initial-instruction span {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95rem;
}

/* Ocultar pantalla inicial cuando hay proyecto O cuando se navega a un mÃ³dulo */
.main-panel.project-selected .initial-screen,
.main-panel.module-active .initial-screen {
    display: none;
}

/* Ocultar mÃ³dulos cuando no hay proyecto (excepto Dashboard y Upload) */
.main-panel:not(.project-selected) #planningStatus,
.main-panel:not(.project-selected) #ejecucionObra,
.main-panel:not(.project-selected) #analisisProgramacion {
    display: none !important;
}

/* Dashboard y Upload siempre visibles (no requieren proyecto) */
.main-panel #controlProyectos,
.main-panel #uploadObra {
    /* Estos mÃ³dulos funcionan independientemente del proyecto global */
    position: relative;
}

/* ----------------------------------------------------------------
   OCULTAR SELECTORES INDIVIDUALES DE PROYECTO EN MÃ“DULOS
   El selector global del sidebar es el Ãºnico punto de selecciÃ³n
   ---------------------------------------------------------------- */
/* SIEMPRE ocultar el selector antiguo del Dashboard */
#proyectoSelector {
    display: none !important;
}

/* SIEMPRE ocultar el selector de proyecto en Upload */
#uploadProyectoSelector {
    display: none !important;
}

/* Ocultar otros selectores cuando hay proyecto global */
.main-panel.project-selected #planningProyectoSelector,
.main-panel.project-selected #analisisProyectoSelector,
.main-panel.project-selected #ejecucionProyectoSelector,
.main-panel.project-selected .ejecucion-proyecto-select {
    display: none !important;
}

/* Mostrar directamente las vistas cuando hay proyecto global */
/* NOTA: Solo aplicar display:block si el mÃ³dulo padre tambiÃ©n estÃ¡ activo */
.main-panel.project-selected #planningStatus.active #planningStatusView {
    display: block !important;
}

/* Mostrar vista de partidas en Dashboard cuando hay proyecto */
.main-panel.project-selected #controlProyectos.active #partidasView {
    display: block !important;
}

/* Mensaje "Sin Proyecto" en Dashboard */
.dashboard-no-project {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #6b7280;
    padding: 40px;
    padding-left: 80px; /* Compensar el sidebar */
    overflow: hidden;
    z-index: 5; /* Debajo del sidebar */
    /* Fondo similar al login */
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f0f0f 100%);
}

/* Canvas de fondo para grafos animados */
.main-graph-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* Contenido sobre el canvas */
.no-project-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.dashboard-no-project .no-project-content i,
.dashboard-no-project > i {
    font-size: 4rem;
    color: #1a1a2e;
    margin-bottom: 20px;
    opacity: 0.8;
}

.dashboard-no-project .no-project-content h3,
.dashboard-no-project > h3 {
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 10px;
}

.dashboard-no-project .no-project-content p,
.dashboard-no-project > p {
    font-size: 1rem;
    max-width: 400px;
    color: rgba(255, 255, 255, 0.6);
}

/* Ocultar mensaje cuando hay proyecto */
.main-panel.project-selected .dashboard-no-project {
    display: none !important;
}

/* Ocultar partidas cuando NO hay proyecto */
.main-panel:not(.project-selected) #partidasView {
    display: none !important;
}

/* Asegurar que el contenedor del Dashboard ocupe todo el espacio */
#controlProyectos.module-content {
    position: relative;
    min-height: calc(100vh - 60px);
    height: 100%;
}

/* Main content debe ocupar todo el espacio disponible */
.main-content {
    flex: 1;
    min-height: calc(100vh - 60px);
}

/* Cuando se muestra el fondo de "sin proyecto", quitar padding del main-content */
.main-panel:not(.project-selected) .main-content {
    padding: 0 !important;
    margin: 0 !important;
}

.main-panel:not(.project-selected) #controlProyectos {
    padding: 0 !important;
    margin: 0 !important;
}

/* AnimaciÃ³n para notificaciÃ³n */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}
