/* ================================================================= */
/* ==== ARCHIVO DEFINITIVO Y CORREGIDO: CSS/layout.css ==== */
/* ================================================================= */

:root {
    --sidebar-width-expanded: 250px; /* Ancho del menú expandido */
    --sidebar-width-collapsed: 80px;  /* Ancho del menú colapsado en escritorio */
    --header-height: 70px;            /* Altura del header superior */
    --sidebar-transition-speed: 0.3s;
}

/* --- El Sidebar (menú lateral) --- */
/* --- El Sidebar (menú lateral) --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width-expanded);
    height: 100vh;
    background-color: var(--card-bg);
    border-right: none; 
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.03); 
    z-index: 2000;
    display: flex;
    flex-direction: column;
    /* REEMPLAZAR AQUÍ */
    transition: width var(--sidebar-transition-speed) ease, transform var(--sidebar-transition-speed) ease !important;
}

/* --- Contenido Principal de la Página --- */
.page-content {
    margin-left: var(--sidebar-width-expanded);
    min-height: 100vh;
    padding-top: var(--header-height);
    box-sizing: border-box;
    /* REEMPLAZAR AQUÍ */
    transition: margin-left var(--sidebar-transition-speed) ease !important;
}

/* --- LÓGICA DE VISIBILIDAD DE LOGOS --- */
.header .nav-left .logo { display: none; }
body.sidebar-collapsed .header .nav-left .logo { display: flex; }

/* --- Estilos internos del Sidebar (Header y Navegación) --- */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: flex-start; 
    padding: 0 18px; /* ¡AQUÍ ESTÁ LA MAGIA! (antes era 16px) */
    height: var(--header-height);
    flex-shrink: 0;
    border-bottom: none !important; 
}

.sidebar .logo {
    order: 2; 
    display: flex;
    align-items: center;
    gap: 15px;
    text-decoration: none;
    overflow: hidden;
    opacity: 1;
}

.sidebar .logo img { height: 30px; width: auto; flex-shrink: 0; }

.sidebar .logo-text {
    font-size: 1.3rem; 
    font-weight: 700;
    background: var(--logo-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    white-space: nowrap;
    padding: 0;
}

.hamburger-menu {
    order: 1; 
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 44px; 
    height: 44px;
    cursor: pointer;
    background: transparent !important; 
    border: none !important; 
    border-radius: 50% !important; 
    padding: 0;
    flex-shrink: 0;
    transition: background 0.2s ease !important;
    transform: none !important;
}

.hamburger-menu:hover { background: rgba(0, 0, 0, 0.05) !important; }
body.dark-mode .hamburger-menu:hover { background: rgba(255, 255, 255, 0.1) !important; }

.hamburger-menu span {
    display: block;
    width: 18px;
    height: 2px;
    background-color: var(--text-primary);
    border-radius: 2px;
    transition: none !important;
}

body.sidebar-collapsed .hamburger-menu span { background-color: var(--primary-color); }
.mobile-hamburger { display: none; }

.sidebar-content {
    display: flex;
    flex-direction: column;
    height: calc(100% - var(--header-height));
    overflow: hidden;
}

.sidebar-nav {
    list-style: none;
    padding: 20px 0;
    margin: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex-grow: 1;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    padding: 12px 18px; /* Cambiado a 18px para que quede estático (antes era 16px) */
    margin: 4px 12px; 
    border-radius: 24px; 
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    border: none !important;
}

.sidebar-nav li a.active {
    color: var(--primary-color);
    font-weight: 600;
    background-color: rgba(13, 110, 253, 0.1); 
}

.sidebar-nav li a:hover {
    background-color: rgba(0, 0, 0, 0.03); 
    color: var(--text-primary);
    transform: none !important;
}

body.dark-mode .sidebar-nav li a:hover { background-color: rgba(255, 255, 255, 0.05); }

.sidebar-nav .link-text { margin-left: 15px; }

.sidebar-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-top: 1px solid var(--header-border);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
    overflow: hidden;
}

.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-info {
    flex-grow: 1;
    margin-left: 12px;
    overflow: hidden;
    transition: none !important; 
}

.user-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 5px;
    margin-left: 5px;
    border-radius: 6px;
}

.logout-btn:hover { color: var(--danger-color); background-color: var(--input-bg); }

@media (min-width: 769px) {
    /* 1. REDUCCIÓN REAL DEL ANCHO AL COLAPSAR */
    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-width-collapsed) !important;
    }
    body.sidebar-collapsed .page-content {
        margin-left: var(--sidebar-width-collapsed) !important;
    }

    /* 2. COMPORTAMIENTO DEL HEADER COLAPSADO */
    body.sidebar-collapsed .sidebar-header {
        padding: 0 !important;
        justify-content: center !important;
        pointer-events: auto !important; /* Habilita los clics de nuevo */
    }

    /* Ocultamos el logo y la palabra FELIX */
    body.sidebar-collapsed .sidebar .logo {
        display: none !important;
    }

    /* Centramos el botón y lo hacemos girar 180 grados */
    body.sidebar-collapsed .gemini-toggle {
        display: flex !important;
        margin: 0 auto !important;
    }

    body.sidebar-collapsed .gemini-toggle .toggle-icon {
        transform: rotate(180deg);
        color: var(--primary-color) !important;
    }

    /* 3. ESTILOS Y ANIMACIONES DEL BOTÓN (HOVER) */
    .gemini-toggle:hover {
        background-color: var(--input-bg) !important;
        color: var(--primary-color) !important;
    }

    .gemini-toggle .toggle-icon {
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

}


/* ================================================================= */
/* ==== RESPONSIVIDAD PARA MÓVILES (SIDEBAR OVERLAY) ==== */
/* ================================================================= */
@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-width-expanded);
        transform: translateX(-100%);
        z-index: 4000;
        box-shadow: 0 5px 25px rgba(0,0,0,0.3);
    }

    body:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
    }
    
    .page-content {
        margin-left: 0 !important;
        transition: none;
    }

    /* Ocultamos el logo del header superior y mostramos el del sidebar siempre */
    .header .nav-left .logo { display: none !important; }
    .sidebar .logo { opacity: 1 !important; display: flex !important; }
    
    .mobile-hamburger {
        display: flex; 
        margin-right: 15px; 
    }
    .desktop-hamburger { display: none; }
    
    body.sidebar-collapsed .header .nav-left .logo { display: none; }

    .sidebar-nav .link-text, .user-info, .logout-btn {
        opacity: 1 !important;
        width: auto !important;
        pointer-events: all !important;
        transition: none !important; 
    }

    body:not(.sidebar-collapsed)::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 3999;
        cursor: pointer;
    }

    /* Comportamiento del header en Celulares (Móvil) */
    .header {
        left: 0 !important;
        width: 100% !important; 
        background: var(--card-bg) !important; 
        border-bottom: 1px solid var(--card-border) !important;
        backdrop-filter: none !important;
        box-shadow: none !important;
    }

    .nav {
        justify-content: space-between !important; 
        padding: 0 1rem !important;
    }

    .header .nav-left {
        display: flex !important;
        align-items: center;
        gap: 10px;
    }
}

/* ======================================================== */
/* === CORRECCIÓN DEFINITIVA: ANCLAJE IZQUIERDO ESTÁTICO === */
/* ======================================================== */

/* 1. Anclar el Header y el botón de Hamburguesa */
.sidebar-header {
    padding: 0 !important;
    justify-content: flex-start !important; 
}

.sidebar-header .hamburger-menu {
    margin-left: 18px !important; /* Centro matemático exacto de 80px */
}

.sidebar-header .logo {
    margin-left: 12px !important; /* Espacio visual entre el botón y tu logo */
}

/* 2. Anclar los enlaces de navegación (Iconos) */
.sidebar-nav li a {
    justify-content: flex-start !important;
    padding: 12px 18px !important; /* Anclado a los mismos 18px */
}

/* 3. Evitar que el modo colapsado en PC recalcule posiciones */
@media (min-width: 769px) {
    body.sidebar-collapsed .sidebar-header,
    body.sidebar-collapsed .sidebar-nav li a,
    body.sidebar-collapsed .sidebar-footer {
        justify-content: flex-start !important; /* Prohibido usar center */
    }
    
    body.sidebar-collapsed .sidebar-nav li a {
        padding: 12px 18px !important; 
    }
    
    body.sidebar-collapsed .sidebar-nav .lucide {
        margin-right: 0 !important; /* Evita que el margen invisible empuje el icono */
    }
    
    body.sidebar-collapsed .sidebar-footer {
        padding: 15px 21px !important; /* Centro matemático exacto del avatar */
    }
}

/* ======================================================== */
/* === BOTÓN FLOTANTE PARA COLAPSAR (ESTILO GEMINI) === */
/* ======================================================== */

/* 1. Restauramos las rayitas para el celular */
.hamburger-menu span {
    display: block !important;
}

/* 2. El botón flotante en el borde derecho del panel */
.sidebar-collapse-float {
    position: absolute;
    bottom: 80px; /* Se ubica justo arriba de la sección de tu perfil */
    right: -14px; /* Sobresale por la mitad fuera del panel */
    width: 28px;
    height: 28px;
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    z-index: 2010;
    color: var(--text-secondary);
    padding: 0;
    transition: all 0.3s ease;
}

.sidebar-collapse-float:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(1.15); /* Efecto de resalte al pasar el mouse */
}

.sidebar-collapse-float .lucide {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

/* Magia: La flecha gira hacia la derecha cuando el menú está colapsado */
body.sidebar-collapsed .sidebar-collapse-float .lucide {
    transform: rotate(180deg); 
}

/* Ocultar este botón flotante en móviles (porque ahí usas la hamburguesa) */
@media (max-width: 768px) {
    .sidebar-collapse-float { display: none !important; }
}

/* Asegurar que el texto Felix se oculte limpiamente al colapsar */
body.sidebar-collapsed .sidebar-header .logo-text-prospera {
    opacity: 0;
    pointer-events: none;
    display: none;
}

/* ======================================================== */
/* === FORZAR VISIBILIDAD DEL LOGO EN EL SIDEBAR MÓVIL  === */
/* ======================================================== */
@media (max-width: 768px) {
    .sidebar-header .desktop-hamburger {
        display: flex !important; /* Fuerza a que el logo aparezca en celular */
    }
}

/* ======================================================== */
/* === ÁREA CLICABLE EXPANDIDA PARA EL LOGO Y EL TEXTO === */
/* ======================================================== */

/* El logo rebota cuando pasas el mouse por CUALQUIER parte del header */
.hamburger-toggle:hover .hamburger-menu img {
    transform: scale(1.1);
}

/* Sutil sombreado de fondo para indicar que toda el área es clicable */
.hamburger-toggle {
    transition: background-color 0.2s ease;
}

.hamburger-toggle:hover {
    background-color: rgba(0, 0, 0, 0.03); 
}

body.dark-mode .hamburger-toggle:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Efecto para que el usuario sepa que el fondo del panel es clicable en PC */
@media (min-width: 769px) {
    .sidebar { cursor: pointer; }
    .sidebar-content, .sidebar-header { cursor: default; }
}

/* ======================================================== */
/* === CORRECCIÓN DEFINITIVA SIDEBAR (PEGAR AL FINAL) === */
/* ======================================================== */

/* 1. Quitar el orden forzado que ponía el botón a la izquierda */
.sidebar .logo { order: unset !important; }
.hamburger-menu { order: unset !important; }

/* 2. Asegurar que el header distribuya los elementos (Logo a la izq, Botón a la der) */
.sidebar-header {
    justify-content: space-between !important;
    padding: 0 18px !important;
}

@media (min-width: 769px) {
    /* 3. Ocultar COMPLETAMENTE el logo y texto al colapsar */
    body.sidebar-collapsed .sidebar .logo {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    /* 4. Centrar el botón y rotarlo al colapsar */
    body.sidebar-collapsed .sidebar-header {
        justify-content: center !important;
        padding: 0 !important;
    }

    body.sidebar-collapsed .gemini-toggle {
        margin: 0 auto !important;
    }

    body.sidebar-collapsed .gemini-toggle .toggle-icon {
        transform: rotate(180deg);
        color: var(--primary-color) !important;
    }
    
    /* 5. Asegurar que el botón cambie de color al pasar el mouse */
    .gemini-toggle:hover {
        background-color: var(--input-bg) !important;
        color: var(--primary-color) !important;
    }
    
    /* Animación fluida del icono */
    .gemini-toggle .toggle-icon {
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* ======================================================== */
/* === OCULTAR TEXTOS AL COLAPSAR EL SIDEBAR EN PC ======== */
/* ======================================================== */
@media (min-width: 769px) {
    /* Ocultar las letras de los enlaces de navegación */
    body.sidebar-collapsed .sidebar-nav .link-text {
        display: none !important;
    }

    /* Ocultar el nombre/correo del usuario y el botón de apagar */
    body.sidebar-collapsed .user-info,
    body.sidebar-collapsed .logout-btn {
        display: none !important;
    }
}

